Guest User

Untitled

a guest
Jan 27th, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.93 KB | None | 0 0
  1. function test(aTest) {
  2. function moveFocus(aTest, aFocusEventHandler) {
  3. if (aInDesignMode) {
  4. if (document.activeElement) {
  5. document.activeElement.blur();
  6. }
  7. } else if (aIsEditable) {
  8. document.getElementById("display").focus();
  9. } else if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED) {
  10. document.getElementById("password").focus();
  11. } else {
  12. document.getElementById("text").focus();
  13. }
  14. var previousFocusedElement = gFM.focusedElement;
  15. var element = document.getElementById(aTest.id);
  16. var focusEventTarget = element;
  17. if (element.contentDocument) {
  18. focusEventTarget = element.contentDocument;
  19. element = element.contentDocument.documentElement;
  20. }
  21.  
  22. focusEventTarget.addEventListener("focus", aFocusEventHandler, true);
  23. onIMEFocusBlurHandler = aFocusEventHandler;
  24.  
  25. element.focus();
  26.  
  27. focusEventTarget.removeEventListener("focus", aFocusEventHandler, true);
  28. onIMEFocusBlurHandler = null;
  29.  
  30. var focusedElement = gFM.focusedElement;
  31. if (focusedElement) {
  32. var bindingParent = document.getBindingParent(focusedElement);
  33. if (bindingParent) {
  34. focusedElement = bindingParent;
  35. }
  36. }
  37. if (aTest.focusable) {
  38. is(focusedElement, element,
  39. aDescription + ": " + aTest.description + ", focus didn't move");
  40. return (element == focusedElement);
  41. }
  42. is(focusedElement, previousFocusedElement,
  43. aDescription + ": " + aTest.description + ", focus moved as unexpected");
  44. return (previousFocusedElement == focusedElement);
  45. }
  46.  
  47. function testOpened(aTest, aOpened) {
  48. document.getElementById("text").focus();
  49. gUtils.IMEIsOpen = aOpened;
  50. if (!moveFocus(aTest)) {
  51. return;
  52. }
  53. var message = aDescription + ": " + aTest.description +
  54. ", wrong opened state";
  55. is(gUtils.IMEIsOpen,
  56. aTest.changeOpened ? aTest.expectedOpened : aOpened, message);
  57. }
  58.  
  59. // IME Enabled state testing
  60. var enabled = gUtils.IME_STATUS_ENABLED;
  61. if (kIMEEnabledSupported) {
  62. var focusEventCount = 0;
  63. var IMEReceivesFocus = 0;
  64. var IMEReceivesBlur = 0;
  65. var IMEHasFocus = false;
  66.  
  67. function onFocus(aEvent) {
  68. switch (aEvent.type) {
  69. case "focus":
  70. focusEventCount++;
  71. is(gUtils.IMEStatus, aTest.expectedEnabled,
  72. aDescription + ": " + aTest.description + ", wrong enabled state at focus event");
  73. break;
  74. case "notify-focus":
  75. IMEReceivesFocus++;
  76. IMEHasFocus = true;
  77. is(gUtils.IMEStatus, aTest.expectedEnabled,
  78. aDescription + ": " + aTest.description +
  79. ", IME should receive a focus notification after IME state is updated");
  80. break;
  81. case "notify-blur":
  82. IMEReceivesBlur++;
  83. IMEHasFocus = false;
  84. var changingStatus = !(aIsEditable && aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED);
  85. if (aTest.toDesignModeEditor) {
  86. is(gUtils.IME_STATUS_ENABLED, aTest.expectedEnabled,
  87. aDescription + ": " + aTest.description +
  88. ", IME should receive a blur notification after IME state is updated");
  89. } else if (changingStatus) {
  90. isnot(gUtils.IMEStatus, aTest.expectedEnabled,
  91. aDescription + ": " + aTest.description +
  92. ", IME should receive a blur notification before IME state is updated");
  93. } else {
  94. is(gUtils.IMEStatus, aTest.expectedEnabled,
  95. aDescription + ": " + aTest.description +
  96. ", IME should receive a blur notification and its context has expected IME state if the state isn't being changed");
  97. }
  98. break;
  99. }
  100. }
  101.  
  102. if (!moveFocus(aTest, onFocus)) {
  103. return;
  104. }
  105.  
  106. if (aTest.focusable) {
  107. if (!aTest.focusEventNotFired) {
  108. ok(focusEventCount > 0,
  109. aDescription + ": " + aTest.description + ", focus event is never fired");
  110. if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED || aTest.expectedEnabled == gUtils.IME_STATUS_PASSWORD) {
  111. ok(IMEReceivesFocus > 0,
  112. aDescription + ": " + aTest.description + ", IME should receive a focus notification");
  113. if (aInDesignMode && !aTest.toDesignModeEditor) {
  114. is(IMEReceivesBlur, 0,
  115. aDescription + ": " + aTest.description +
  116. ", IME shouldn't receive a blur notification in designMode since focus isn't moved from another editor");
  117. } else {
  118. ok(IMEReceivesBlur > 0,
  119. aDescription + ": " + aTest.description +
  120. ", IME should receive a blur notification for the previous focused editor");
  121. }
  122. ok(IMEHasFocus,
  123. aDescription + ": " + aTest.description +
  124. ", IME should have focus right now");
  125. } else {
  126. is(IMEReceivesFocus, 0,
  127. aDescription + ": " + aTest.description +
  128. ", IME shouldn't receive a focus notification");
  129. ok(IMEReceivesBlur > 0,
  130. aDescription + ": " + aTest.description +
  131. ", IME should receive a blur notification");
  132. ok(!IMEHasFocus,
  133. aDescription + ": " + aTest.description +
  134. ", IME shouldn't have focus right now");
  135. }
  136. } else {
  137. todo(focusEventCount > 0,
  138. aDescription + ": " + aTest.description + ", focus event should be fired");
  139. }
  140. } else {
  141. is(IMEReceivesFocus, 0,
  142. aDescription + ": " + aTest.description +
  143. ", IME shouldn't receive a focus notification at testing non-focusable element");
  144. is(IMEReceivesBlur, 0,
  145. aDescription + ": " + aTest.description +
  146. ", IME shouldn't receive a blur notification at testing non-focusable element");
  147. }
  148.  
  149. enabled = gUtils.IMEStatus;
  150. var inputtype = gUtils.focusedInputType;
  151. is(enabled, aTest.expectedEnabled,
  152. aDescription + ": " + aTest.description + ", wrong enabled state");
  153. if (aTest.expectedType && !aInDesignMode) {
  154. is(inputtype, aTest.expectedType,
  155. aDescription + ": " + aTest.description + ", wrong input type");
  156. } else if (aInDesignMode) {
  157. is(inputtype, "",
  158. aDescription + ": " + aTest.description + ", wrong input type");
  159. }
  160. }
  161.  
  162. if (!kIMEOpenSupported || enabled != gUtils.IME_STATUS_ENABLED ||
  163. aTest.expectedEnabled != gUtils.IME_STATUS_ENABLED) {
  164. return;
  165. }
  166.  
  167. // IME Open state testing
  168. testOpened(aTest, false);
  169. testOpened(aTest, true);
  170. }
Add Comment
Please, Sign In to add comment