Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function test(aTest) {
- function moveFocus(aTest, aFocusEventHandler) {
- if (aInDesignMode) {
- if (document.activeElement) {
- document.activeElement.blur();
- }
- } else if (aIsEditable) {
- document.getElementById("display").focus();
- } else if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED) {
- document.getElementById("password").focus();
- } else {
- document.getElementById("text").focus();
- }
- var previousFocusedElement = gFM.focusedElement;
- var element = document.getElementById(aTest.id);
- var focusEventTarget = element;
- if (element.contentDocument) {
- focusEventTarget = element.contentDocument;
- element = element.contentDocument.documentElement;
- }
- focusEventTarget.addEventListener("focus", aFocusEventHandler, true);
- onIMEFocusBlurHandler = aFocusEventHandler;
- element.focus();
- focusEventTarget.removeEventListener("focus", aFocusEventHandler, true);
- onIMEFocusBlurHandler = null;
- var focusedElement = gFM.focusedElement;
- if (focusedElement) {
- var bindingParent = document.getBindingParent(focusedElement);
- if (bindingParent) {
- focusedElement = bindingParent;
- }
- }
- if (aTest.focusable) {
- is(focusedElement, element,
- aDescription + ": " + aTest.description + ", focus didn't move");
- return (element == focusedElement);
- }
- is(focusedElement, previousFocusedElement,
- aDescription + ": " + aTest.description + ", focus moved as unexpected");
- return (previousFocusedElement == focusedElement);
- }
- function testOpened(aTest, aOpened) {
- document.getElementById("text").focus();
- gUtils.IMEIsOpen = aOpened;
- if (!moveFocus(aTest)) {
- return;
- }
- var message = aDescription + ": " + aTest.description +
- ", wrong opened state";
- is(gUtils.IMEIsOpen,
- aTest.changeOpened ? aTest.expectedOpened : aOpened, message);
- }
- // IME Enabled state testing
- var enabled = gUtils.IME_STATUS_ENABLED;
- if (kIMEEnabledSupported) {
- var focusEventCount = 0;
- var IMEReceivesFocus = 0;
- var IMEReceivesBlur = 0;
- var IMEHasFocus = false;
- function onFocus(aEvent) {
- switch (aEvent.type) {
- case "focus":
- focusEventCount++;
- is(gUtils.IMEStatus, aTest.expectedEnabled,
- aDescription + ": " + aTest.description + ", wrong enabled state at focus event");
- break;
- case "notify-focus":
- IMEReceivesFocus++;
- IMEHasFocus = true;
- is(gUtils.IMEStatus, aTest.expectedEnabled,
- aDescription + ": " + aTest.description +
- ", IME should receive a focus notification after IME state is updated");
- break;
- case "notify-blur":
- IMEReceivesBlur++;
- IMEHasFocus = false;
- var changingStatus = !(aIsEditable && aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED);
- if (aTest.toDesignModeEditor) {
- is(gUtils.IME_STATUS_ENABLED, aTest.expectedEnabled,
- aDescription + ": " + aTest.description +
- ", IME should receive a blur notification after IME state is updated");
- } else if (changingStatus) {
- isnot(gUtils.IMEStatus, aTest.expectedEnabled,
- aDescription + ": " + aTest.description +
- ", IME should receive a blur notification before IME state is updated");
- } else {
- is(gUtils.IMEStatus, aTest.expectedEnabled,
- aDescription + ": " + aTest.description +
- ", IME should receive a blur notification and its context has expected IME state if the state isn't being changed");
- }
- break;
- }
- }
- if (!moveFocus(aTest, onFocus)) {
- return;
- }
- if (aTest.focusable) {
- if (!aTest.focusEventNotFired) {
- ok(focusEventCount > 0,
- aDescription + ": " + aTest.description + ", focus event is never fired");
- if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED || aTest.expectedEnabled == gUtils.IME_STATUS_PASSWORD) {
- ok(IMEReceivesFocus > 0,
- aDescription + ": " + aTest.description + ", IME should receive a focus notification");
- if (aInDesignMode && !aTest.toDesignModeEditor) {
- is(IMEReceivesBlur, 0,
- aDescription + ": " + aTest.description +
- ", IME shouldn't receive a blur notification in designMode since focus isn't moved from another editor");
- } else {
- ok(IMEReceivesBlur > 0,
- aDescription + ": " + aTest.description +
- ", IME should receive a blur notification for the previous focused editor");
- }
- ok(IMEHasFocus,
- aDescription + ": " + aTest.description +
- ", IME should have focus right now");
- } else {
- is(IMEReceivesFocus, 0,
- aDescription + ": " + aTest.description +
- ", IME shouldn't receive a focus notification");
- ok(IMEReceivesBlur > 0,
- aDescription + ": " + aTest.description +
- ", IME should receive a blur notification");
- ok(!IMEHasFocus,
- aDescription + ": " + aTest.description +
- ", IME shouldn't have focus right now");
- }
- } else {
- todo(focusEventCount > 0,
- aDescription + ": " + aTest.description + ", focus event should be fired");
- }
- } else {
- is(IMEReceivesFocus, 0,
- aDescription + ": " + aTest.description +
- ", IME shouldn't receive a focus notification at testing non-focusable element");
- is(IMEReceivesBlur, 0,
- aDescription + ": " + aTest.description +
- ", IME shouldn't receive a blur notification at testing non-focusable element");
- }
- enabled = gUtils.IMEStatus;
- var inputtype = gUtils.focusedInputType;
- is(enabled, aTest.expectedEnabled,
- aDescription + ": " + aTest.description + ", wrong enabled state");
- if (aTest.expectedType && !aInDesignMode) {
- is(inputtype, aTest.expectedType,
- aDescription + ": " + aTest.description + ", wrong input type");
- } else if (aInDesignMode) {
- is(inputtype, "",
- aDescription + ": " + aTest.description + ", wrong input type");
- }
- }
- if (!kIMEOpenSupported || enabled != gUtils.IME_STATUS_ENABLED ||
- aTest.expectedEnabled != gUtils.IME_STATUS_ENABLED) {
- return;
- }
- // IME Open state testing
- testOpened(aTest, false);
- testOpened(aTest, true);
- }
Add Comment
Please, Sign In to add comment