widget/tests/test_imestate.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/tests/test_imestate.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1506 @@
     1.4 +<html style="ime-mode: disabled;">
     1.5 +<head>
     1.6 +  <title>Test for IME state controling</title>
     1.7 +  <script type="text/javascript"
     1.8 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript"
    1.10 +          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    1.11 +  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css"
    1.13 +          href="chrome://mochikit/content/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body onload="setTimeout(runTests, 0);" style="ime-mode: disabled;">
    1.16 +<div id="display" style="ime-mode: disabled;">
    1.17 +  <!-- input elements -->
    1.18 +  <input type="text"     id="text"/><br/>
    1.19 +  <input type="text"     id="text_readonly" readonly="readonly"/><br/>
    1.20 +  <input type="password" id="password"/><br/>
    1.21 +  <input type="password" id="password_readonly" readonly="readonly"/><br/>
    1.22 +  <input type="checkbox" id="checkbox"/><br/>
    1.23 +  <input type="radio"    id="radio"/><br/>
    1.24 +  <input type="submit"   id="submit"/><br/>
    1.25 +  <input type="reset"    id="reset"/><br/>
    1.26 +  <input type="file"     id="file"/><br/>
    1.27 +  <input type="button"   id="ibutton"/><br/>
    1.28 +  <input type="image"    id="image" alt="image"/><br/>
    1.29 +
    1.30 +  <!-- html5 input elements -->
    1.31 +  <input type="url"      id="url"/><br/>
    1.32 +  <input type="email"    id="email"/><br/>
    1.33 +  <input type="search"   id="search"/><br/>
    1.34 +  <input type="tel"      id="tel"/><br/>
    1.35 +  <input type="number"   id="number"/><br/>
    1.36 +
    1.37 +  <!-- form controls -->
    1.38 +  <button id="button">button</button><br/>
    1.39 +  <textarea id="textarea">textarea</textarea><br/>
    1.40 +  <textarea id="textarea_readonly" readonly="readonly">textarea[readonly]</textarea><br/>
    1.41 +  <select id="select">
    1.42 +    <option value="option" selected="selected"/>
    1.43 +  </select><br/>
    1.44 +  <select id="select_multiple" multiple="multiple">
    1.45 +    <option value="option" selected="selected"/>
    1.46 +  </select><br/>
    1.47 +  <isindex id="isindex" prompt="isindex"/><br/>
    1.48 +
    1.49 +  <!-- a element -->
    1.50 +  <a id="a_href" href="about:blank">a[href]</a><br/>
    1.51 +
    1.52 +  <!-- ime-mode test -->
    1.53 +  <input type="text" id="ime_mode_auto"     style="ime-mode: auto;"/><br/>
    1.54 +  <input type="text" id="ime_mode_normal"   style="ime-mode: normal;"/><br/>
    1.55 +  <input type="text" id="ime_mode_active"   style="ime-mode: active;"/><br/>
    1.56 +  <input type="text" id="ime_mode_inactive" style="ime-mode: inactive;"/><br/>
    1.57 +  <input type="text" id="ime_mode_disabled" style="ime-mode: disabled;"/><br/>
    1.58 +
    1.59 +  <input type="text" id="ime_mode_auto_url"     style="ime-mode: auto;"/><br/>
    1.60 +  <input type="text" id="ime_mode_normal_url"   style="ime-mode: normal;"/><br/>
    1.61 +  <input type="text" id="ime_mode_active_url"   style="ime-mode: active;"/><br/>
    1.62 +  <input type="text" id="ime_mode_inactive_url" style="ime-mode: inactive;"/><br/>
    1.63 +  <input type="text" id="ime_mode_disabled_url" style="ime-mode: disabled;"/><br/>
    1.64 +
    1.65 +  <input type="text" id="ime_mode_auto_email"     style="ime-mode: auto;"/><br/>
    1.66 +  <input type="text" id="ime_mode_normal_email"   style="ime-mode: normal;"/><br/>
    1.67 +  <input type="text" id="ime_mode_active_email"   style="ime-mode: active;"/><br/>
    1.68 +  <input type="text" id="ime_mode_inactive_email" style="ime-mode: inactive;"/><br/>
    1.69 +  <input type="text" id="ime_mode_disabled_email" style="ime-mode: disabled;"/><br/>
    1.70 +
    1.71 +  <input type="text" id="ime_mode_auto_search"     style="ime-mode: auto;"/><br/>
    1.72 +  <input type="text" id="ime_mode_normal_search"   style="ime-mode: normal;"/><br/>
    1.73 +  <input type="text" id="ime_mode_active_search"   style="ime-mode: active;"/><br/>
    1.74 +  <input type="text" id="ime_mode_inactive_search" style="ime-mode: inactive;"/><br/>
    1.75 +  <input type="text" id="ime_mode_disabled_search" style="ime-mode: disabled;"/><br/>
    1.76 +
    1.77 +  <input type="text" id="ime_mode_auto_tel"     style="ime-mode: auto;"/><br/>
    1.78 +  <input type="text" id="ime_mode_normal_tel"   style="ime-mode: normal;"/><br/>
    1.79 +  <input type="text" id="ime_mode_active_tel"   style="ime-mode: active;"/><br/>
    1.80 +  <input type="text" id="ime_mode_inactive_tel" style="ime-mode: inactive;"/><br/>
    1.81 +  <input type="text" id="ime_mode_disabled_tel" style="ime-mode: disabled;"/><br/>
    1.82 +
    1.83 +  <input type="text" id="ime_mode_auto_number"     style="ime-mode: auto;"/><br/>
    1.84 +  <input type="text" id="ime_mode_normal_number"   style="ime-mode: normal;"/><br/>
    1.85 +  <input type="text" id="ime_mode_active_number"   style="ime-mode: active;"/><br/>
    1.86 +  <input type="text" id="ime_mode_inactive_number" style="ime-mode: inactive;"/><br/>
    1.87 +  <input type="text" id="ime_mode_disabled_number" style="ime-mode: disabled;"/><br/>
    1.88 +
    1.89 +  <input type="password" id="ime_mode_auto_p"     style="ime-mode: auto;"/><br/>
    1.90 +  <input type="password" id="ime_mode_normal_p"   style="ime-mode: normal;"/><br/>
    1.91 +  <input type="password" id="ime_mode_active_p"   style="ime-mode: active;"/><br/>
    1.92 +  <input type="password" id="ime_mode_inactive_p" style="ime-mode: inactive;"/><br/>
    1.93 +  <input type="password" id="ime_mode_disabled_p" style="ime-mode: disabled;"/><br/>
    1.94 +  <textarea id="ime_mode_auto_t"     style="ime-mode: auto;">textarea</textarea><br/>
    1.95 +  <textarea id="ime_mode_normal_t"   style="ime-mode: normal;">textarea</textarea><br/>
    1.96 +  <textarea id="ime_mode_active_t"   style="ime-mode: active;">textarea</textarea><br/>
    1.97 +  <textarea id="ime_mode_inactive_t" style="ime-mode: inactive;">textarea</textarea><br/>
    1.98 +  <textarea id="ime_mode_disabled_t" style="ime-mode: disabled;">textarea</textarea><br/>
    1.99 +
   1.100 +  <!-- plugin -->
   1.101 +  <object type="application/x-test" id="plugin"></object><br/>
   1.102 +
   1.103 +  <!-- contenteditable editor -->
   1.104 +  <div id="contenteditableEditor" contenteditable="true"></div>
   1.105 +
   1.106 +  <!-- designMode editor -->
   1.107 +  <iframe id="designModeEditor"
   1.108 +   onload="document.getElementById('designModeEditor').contentDocument.designMode = 'on';"
   1.109 +   src="data:text/html,<html><body></body></html>"></iframe><br/>
   1.110 +</div>
   1.111 +<div id="content" style="display: none">
   1.112 +  
   1.113 +</div>
   1.114 +<pre id="test">
   1.115 +</pre>
   1.116 +
   1.117 +<script class="testbody" type="application/javascript">
   1.118 +
   1.119 +SimpleTest.waitForExplicitFinish();
   1.120 +
   1.121 +function hitEventLoop(aFunc, aTimes)
   1.122 +{
   1.123 +  if (--aTimes) {
   1.124 +    setTimeout(hitEventLoop, 0, aFunc, aTimes);
   1.125 +  } else {
   1.126 +    setTimeout(aFunc, 20);
   1.127 +  }
   1.128 +}
   1.129 +
   1.130 +var gUtils = window.
   1.131 +      QueryInterface(Components.interfaces.nsIInterfaceRequestor).
   1.132 +      getInterface(Components.interfaces.nsIDOMWindowUtils);
   1.133 +var gFM = Components.classes["@mozilla.org/focus-manager;1"].
   1.134 +      getService(Components.interfaces.nsIFocusManager);
   1.135 +const kIMEEnabledSupported = navigator.platform.indexOf("Mac") == 0 ||
   1.136 +                             navigator.platform.indexOf("Win") == 0 ||
   1.137 +                             navigator.platform.indexOf("Linux") == 0;
   1.138 +
   1.139 +// We support to control IME open state on Windows and Mac actually.  However,
   1.140 +// we cannot test it on Mac if the current keyboard layout is not CJK. And also
   1.141 +// we cannot test it on Win32 if the system didn't be installed IME. So,
   1.142 +// currently we should not run the open state testing.
   1.143 +const kIMEOpenSupported = false;
   1.144 +
   1.145 +function runBasicTest(aIsEditable, aInDesignMode, aDescription)
   1.146 +{
   1.147 +  function test(aTest)
   1.148 +  {
   1.149 +    function moveFocus(aTest, aFocusEventHandler)
   1.150 +    {
   1.151 +      if (aInDesignMode) {
   1.152 +        if (document.activeElement) {
   1.153 +          document.activeElement.blur();
   1.154 +        }
   1.155 +      } else if (aIsEditable) {
   1.156 +        document.getElementById("display").focus();
   1.157 +      } else if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED) {
   1.158 +        document.getElementById("password").focus();
   1.159 +      } else {
   1.160 +        document.getElementById("text").focus();
   1.161 +      }
   1.162 +      var previousFocusedElement = gFM.focusedElement;
   1.163 +      var element = document.getElementById(aTest.id);
   1.164 +      var focusEventTarget = element;
   1.165 +      var subDocument = null;
   1.166 +      if (element.contentDocument) {
   1.167 +        focusEventTarget = element.contentDocument;
   1.168 +        subDocument = element.contentDocument;
   1.169 +        element = element.contentDocument.documentElement;
   1.170 +      }
   1.171 +
   1.172 +      focusEventTarget.addEventListener("focus", aFocusEventHandler, true);
   1.173 +      document.addEventListener("MozIMEFocusIn", aFocusEventHandler, true);
   1.174 +      document.addEventListener("MozIMEFocusOut", aFocusEventHandler, true);
   1.175 +      if (subDocument) {
   1.176 +        subDocument.addEventListener("MozIMEFocusIn", aFocusEventHandler, true);
   1.177 +        subDocument.addEventListener("MozIMEFocusOut", aFocusEventHandler, true);
   1.178 +      }
   1.179 +
   1.180 +      element.focus();
   1.181 +
   1.182 +      focusEventTarget.removeEventListener("focus", aFocusEventHandler, true);
   1.183 +      document.removeEventListener("MozIMEFocusIn", aFocusEventHandler, true);
   1.184 +      document.removeEventListener("MozIMEFocusOut", aFocusEventHandler, true);
   1.185 +      if (element.contentDocument) {
   1.186 +        subDocument.removeEventListener("MozIMEFocusIn", aFocusEventHandler, true);
   1.187 +        subDocument.removeEventListener("MozIMEFocusOut", aFocusEventHandler, true);
   1.188 +      }
   1.189 +
   1.190 +      var focusedElement = gFM.focusedElement;
   1.191 +      if (focusedElement) {
   1.192 +        var bindingParent = document.getBindingParent(focusedElement);
   1.193 +        if (bindingParent) {
   1.194 +          focusedElement = bindingParent;
   1.195 +        }
   1.196 +      }
   1.197 +      if (aTest.focusable) {
   1.198 +        is(focusedElement, element,
   1.199 +           aDescription + ": " + aTest.description + ", focus didn't move");
   1.200 +        return (element == focusedElement);
   1.201 +      }
   1.202 +      is(focusedElement, previousFocusedElement,
   1.203 +         aDescription + ": " + aTest.description + ", focus moved as unexpected");
   1.204 +      return (previousFocusedElement == focusedElement);
   1.205 +    }
   1.206 +
   1.207 +    function testOpened(aTest, aOpened)
   1.208 +    {
   1.209 +      document.getElementById("text").focus();
   1.210 +      gUtils.IMEIsOpen = aOpened;
   1.211 +      if (!moveFocus(aTest)) {
   1.212 +        return;
   1.213 +      }
   1.214 +      var message = aDescription + ": " + aTest.description +
   1.215 +                                            ", wrong opened state";
   1.216 +      is(gUtils.IMEIsOpen,
   1.217 +         aTest.changeOpened ? aTest.expectedOpened : aOpened, message);
   1.218 +    }
   1.219 +
   1.220 +    // IME Enabled state testing
   1.221 +    var enabled = gUtils.IME_STATUS_ENABLED;
   1.222 +    if (kIMEEnabledSupported) {
   1.223 +      var focusEventCount = 0;
   1.224 +      var mozIMEFocusInCount = 0;
   1.225 +      var mozIMEFocusOutCount = 0;
   1.226 +      var IMEHasFocus = false;
   1.227 +
   1.228 +      function onFocus(aEvent)
   1.229 +      {
   1.230 +        switch (aEvent.type) {
   1.231 +          case "focus":
   1.232 +            focusEventCount++;
   1.233 +            is(gUtils.IMEStatus, aTest.expectedEnabled,
   1.234 +               aDescription + ": " + aTest.description + ", wrong enabled state at focus event");
   1.235 +            break;
   1.236 +          case "MozIMEFocusIn":
   1.237 +            mozIMEFocusInCount++;
   1.238 +            IMEHasFocus = true;
   1.239 +            is(gUtils.IMEStatus, aTest.expectedEnabled,
   1.240 +               aDescription + ": " + aTest.description +
   1.241 +                 ", MozIMEFocusIn event must be fired after IME state is updated");
   1.242 +            break;
   1.243 +          case "MozIMEFocusOut":
   1.244 +            mozIMEFocusOutCount++;
   1.245 +            IMEHasFocus = false;
   1.246 +            var changingStatus = !(aIsEditable && aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED);
   1.247 +            if (aTest.toDesignModeEditor) {
   1.248 +              is(gUtils.IME_STATUS_ENABLED, aTest.expectedEnabled,
   1.249 +                 aDescription + ": " + aTest.description +
   1.250 +                   ", MozIMEFocusOut event must be fired after IME state is updated");
   1.251 +            } else if (changingStatus) {
   1.252 +              isnot(gUtils.IMEStatus, aTest.expectedEnabled,
   1.253 +                    aDescription + ": " + aTest.description +
   1.254 +                      ", MozIMEFocusOut event must be fired before IME state is updated");
   1.255 +            } else {
   1.256 +              is(gUtils.IMEStatus, aTest.expectedEnabled,
   1.257 +                 aDescription + ": " + aTest.description +
   1.258 +                   ", MozIMEFocusOut event must be fired with expected IME state if the state isn't being changed");
   1.259 +            }
   1.260 +            break;
   1.261 +        }
   1.262 +      }
   1.263 +
   1.264 +      if (!moveFocus(aTest, onFocus)) {
   1.265 +        return;
   1.266 +      }
   1.267 +
   1.268 +      if (aTest.focusable) {
   1.269 +        if (!aTest.focusEventNotFired) {
   1.270 +          ok(focusEventCount > 0,
   1.271 +             aDescription + ": " + aTest.description + ", focus event is never fired");
   1.272 +          if (aTest.expectedEnabled == gUtils.IME_STATUS_ENABLED || aTest.expectedEnabled == gUtils.IME_STATUS_PASSWORD) {
   1.273 +            ok(mozIMEFocusInCount > 0,
   1.274 +               aDescription + ": " + aTest.description + ", MozIMEFocusIn event should be fired");
   1.275 +            if (aInDesignMode && !aTest.toDesignModeEditor) {
   1.276 +              is(mozIMEFocusOutCount, 0,
   1.277 +                 aDescription + ": " + aTest.description +
   1.278 +                   ", MozIMEFocusOut event shouldn't be fired in designMode since focus isn't moved from another editor");
   1.279 +            } else {
   1.280 +              ok(mozIMEFocusOutCount > 0,
   1.281 +                 aDescription + ": " + aTest.description +
   1.282 +                   ", MozIMEFocusOut event should be fired for the previous focused editor");
   1.283 +            }
   1.284 +            ok(IMEHasFocus,
   1.285 +               aDescription + ": " + aTest.description +
   1.286 +                 ", The latest MozIMEFocus* event must be MozIMEFocusIn");
   1.287 +          } else {
   1.288 +            is(mozIMEFocusInCount, 0,
   1.289 +               aDescription + ": " + aTest.description +
   1.290 +                 ", MozIMEFocusIn event shouldn't be fired");
   1.291 +            ok(mozIMEFocusOutCount > 0,
   1.292 +               aDescription + ": " + aTest.description +
   1.293 +                 ", MozIMEFocusOut event should be fired");
   1.294 +            ok(!IMEHasFocus,
   1.295 +               aDescription + ": " + aTest.description +
   1.296 +                 ", The latest MozIMEFocus* event must be MozIMEFocusOut");
   1.297 +          }
   1.298 +        } else {
   1.299 +          todo(focusEventCount > 0,
   1.300 +               aDescription + ": " + aTest.description + ", focus event should be fired");
   1.301 +        }
   1.302 +      } else {
   1.303 +        is(mozIMEFocusInCount, 0,
   1.304 +           aDescription + ": " + aTest.description +
   1.305 +             ", MozIMEFocusIn event shouldn't be fired at testing non-focusable element");
   1.306 +        is(mozIMEFocusOutCount, 0,
   1.307 +           aDescription + ": " + aTest.description +
   1.308 +             ", MozIMEFocusOut event shouldn't be fired at testing non-focusable element");
   1.309 +      }
   1.310 +
   1.311 +      enabled = gUtils.IMEStatus;
   1.312 +      inputtype = gUtils.focusedInputType;
   1.313 +      is(enabled, aTest.expectedEnabled,
   1.314 +         aDescription + ": " + aTest.description + ", wrong enabled state");
   1.315 +      if (aTest.expectedType && !aInDesignMode) {
   1.316 +        is(inputtype, aTest.expectedType,
   1.317 +           aDescription + ": " + aTest.description + ", wrong input type");
   1.318 +      } else if (aInDesignMode) {
   1.319 +        is(inputtype, "",
   1.320 +           aDescription + ": " + aTest.description + ", wrong input type")
   1.321 +      }
   1.322 +    }
   1.323 +
   1.324 +    if (!kIMEOpenSupported || enabled != gUtils.IME_STATUS_ENABLED ||
   1.325 +        aTest.expectedEnabled != gUtils.IME_STATUS_ENABLED) {
   1.326 +      return;
   1.327 +    }
   1.328 +
   1.329 +    // IME Open state testing
   1.330 +    testOpened(aTest, false);
   1.331 +    testOpened(aTest, true);
   1.332 +  }
   1.333 +
   1.334 +  if (kIMEEnabledSupported) {
   1.335 +    // make sure there is an active element
   1.336 +    document.getElementById("text").focus();
   1.337 +    document.activeElement.blur();
   1.338 +    is(gUtils.IMEStatus,
   1.339 +       aInDesignMode ? gUtils.IME_STATUS_ENABLED : gUtils.IME_STATUS_DISABLED,
   1.340 +       aDescription + ": unexpected enabled state when no element has focus");
   1.341 +  }
   1.342 +
   1.343 +  // Form controls except text editable elements are "disable" in normal
   1.344 +  // condition, however, if they are editable, they are "enabled".
   1.345 +  // XXX Probably there are some bugs: If the form controls editable, they
   1.346 +  //     shouldn't be focusable.
   1.347 +  const kEnabledStateOnNonEditableElement =
   1.348 +    (aInDesignMode || aIsEditable) ? gUtils.IME_STATUS_ENABLED :
   1.349 +                                     gUtils.IME_STATUS_DISABLED;
   1.350 +  const kEnabledStateOnPasswordField =
   1.351 +    aInDesignMode ? gUtils.IME_STATUS_ENABLED : gUtils.IME_STATUS_PASSWORD;
   1.352 +  const kEnabledStateOnReadonlyField =
   1.353 +    aInDesignMode ? gUtils.IME_STATUS_ENABLED : gUtils.IME_STATUS_DISABLED;
   1.354 +  const kTests = [
   1.355 +    { id: "text",
   1.356 +      description: "input[type=text]",
   1.357 +      focusable: !aInDesignMode,
   1.358 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.359 +      expectedType: "text" },
   1.360 +    { id: "text_readonly",
   1.361 +      description: "input[type=text][readonly]",
   1.362 +      focusable: !aInDesignMode,
   1.363 +      expectedEnabled: kEnabledStateOnReadonlyField },
   1.364 +    { id: "password",
   1.365 +      description: "input[type=password]",
   1.366 +      focusable: !aInDesignMode,
   1.367 +      expectedEnabled: kEnabledStateOnPasswordField,
   1.368 +      expectedType: "password" },
   1.369 +    { id: "password_readonly",
   1.370 +      description: "input[type=password][readonly]",
   1.371 +      focusable: !aInDesignMode,
   1.372 +      expectedEnabled: kEnabledStateOnReadonlyField },
   1.373 +    { id: "checkbox",
   1.374 +      description: "input[type=checkbox]",
   1.375 +      focusable: !aInDesignMode,
   1.376 +      focusEventNotFired: aIsEditable && !aInDesignMode,
   1.377 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.378 +    { id: "radio",
   1.379 +      description: "input[type=radio]",
   1.380 +      focusable: !aInDesignMode,
   1.381 +      focusEventNotFired: aIsEditable && !aInDesignMode,
   1.382 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.383 +    { id: "submit",
   1.384 +      description: "input[type=submit]",
   1.385 +      focusable: !aInDesignMode,
   1.386 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.387 +    { id: "reset",
   1.388 +      description: "input[type=reset]",
   1.389 +      focusable: !aInDesignMode,
   1.390 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.391 +    { id: "file",
   1.392 +      description: "input[type=file]",
   1.393 +      focusable: !aInDesignMode,
   1.394 +      focusEventNotFired: aIsEditable && !aInDesignMode,
   1.395 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.396 +    { id: "button",
   1.397 +      description: "input[type=button]",
   1.398 +      focusable: !aInDesignMode,
   1.399 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.400 +    { id: "image",
   1.401 +      description: "input[type=image]",
   1.402 +      focusable: !aInDesignMode,
   1.403 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.404 +    { id: "url",
   1.405 +      description: "input[type=url]",
   1.406 +      focusable: !aInDesignMode,
   1.407 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.408 +      expectedType: "url" },
   1.409 +    { id: "email",
   1.410 +      description: "input[type=email]",
   1.411 +      focusable: !aInDesignMode,
   1.412 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.413 +      expectedType: "email" },
   1.414 +    { id: "search",
   1.415 +      description: "input[type=search]",
   1.416 +      focusable: !aInDesignMode,
   1.417 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.418 +      expectedType: "search" },
   1.419 +    { id: "tel",
   1.420 +      description: "input[type=tel]",
   1.421 +      focusable: !aInDesignMode,
   1.422 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.423 +      expectedType: "tel" },
   1.424 +    { id: "number",
   1.425 +      description: "input[type=number]",
   1.426 +      focusable: !aInDesignMode,
   1.427 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.428 +      expectedType: "number" },
   1.429 +
   1.430 +    // form controls
   1.431 +    { id: "button",
   1.432 +      description: "button",
   1.433 +      focusable: !aInDesignMode,
   1.434 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.435 +    { id: "textarea",
   1.436 +      description: "textarea",
   1.437 +      focusable: !aInDesignMode,
   1.438 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.439 +    { id: "textarea_readonly",
   1.440 +      description: "textarea[readonly]",
   1.441 +      focusable: !aInDesignMode,
   1.442 +      expectedEnabled: kEnabledStateOnReadonlyField },
   1.443 +    { id: "select",
   1.444 +      description: "select (dropdown list)",
   1.445 +      focusable: !aInDesignMode,
   1.446 +      focusEventNotFired: aIsEditable && !aInDesignMode,
   1.447 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.448 +    { id: "select_multiple",
   1.449 +      description: "select (list box)",
   1.450 +      focusable: !aInDesignMode,
   1.451 +      focusEventNotFired: aIsEditable && !aInDesignMode,
   1.452 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.453 +
   1.454 +    // a element
   1.455 +    { id: "a_href",
   1.456 +      description: "a[href]",
   1.457 +      focusable: !aIsEditable && !aInDesignMode,
   1.458 +      expectedEnabled: kEnabledStateOnNonEditableElement },
   1.459 +
   1.460 +    // ime-mode
   1.461 +    { id: "ime_mode_auto",
   1.462 +      description: "input[type=text][style=\"ime-mode: auto;\"]",
   1.463 +      focusable: !aInDesignMode,
   1.464 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.465 +    { id: "ime_mode_normal",
   1.466 +      description: "input[type=text][style=\"ime-mode: normal;\"]",
   1.467 +      focusable: !aInDesignMode,
   1.468 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.469 +    { id: "ime_mode_active",
   1.470 +      description: "input[type=text][style=\"ime-mode: active;\"]",
   1.471 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.472 +      focusable: !aInDesignMode,
   1.473 +      changeOpened: true, expectedOpened: true },
   1.474 +    { id: "ime_mode_inactive",
   1.475 +      description: "input[type=text][style=\"ime-mode: inactive;\"]",
   1.476 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.477 +      focusable: !aInDesignMode,
   1.478 +      changeOpened: true, expectedOpened: false },
   1.479 +    { id: "ime_mode_disabled",
   1.480 +      description: "input[type=text][style=\"ime-mode: disabled;\"]",
   1.481 +      focusable: !aInDesignMode,
   1.482 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.483 +
   1.484 +    { id: "ime_mode_auto_url",
   1.485 +      description: "input[type=url][style=\"ime-mode: auto;\"]",
   1.486 +      focusable: !aInDesignMode,
   1.487 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.488 +    { id: "ime_mode_normal_url",
   1.489 +      description: "input[type=url][style=\"ime-mode: normal;\"]",
   1.490 +      focusable: !aInDesignMode,
   1.491 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.492 +    { id: "ime_mode_active_url",
   1.493 +      description: "input[type=url][style=\"ime-mode: active;\"]",
   1.494 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.495 +      focusable: !aInDesignMode,
   1.496 +      changeOpened: true, expectedOpened: true },
   1.497 +    { id: "ime_mode_inactive_url",
   1.498 +      description: "input[type=url][style=\"ime-mode: inactive;\"]",
   1.499 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.500 +      focusable: !aInDesignMode,
   1.501 +      changeOpened: true, expectedOpened: false },
   1.502 +    { id: "ime_mode_disabled_url",
   1.503 +      description: "input[type=url][style=\"ime-mode: disabled;\"]",
   1.504 +      focusable: !aInDesignMode,
   1.505 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.506 +
   1.507 +    { id: "ime_mode_auto_email",
   1.508 +      description: "input[type=email][style=\"ime-mode: auto;\"]",
   1.509 +      focusable: !aInDesignMode,
   1.510 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.511 +    { id: "ime_mode_normal_email",
   1.512 +      description: "input[type=email][style=\"ime-mode: normal;\"]",
   1.513 +      focusable: !aInDesignMode,
   1.514 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.515 +    { id: "ime_mode_active_email",
   1.516 +      description: "input[type=email][style=\"ime-mode: active;\"]",
   1.517 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.518 +      focusable: !aInDesignMode,
   1.519 +      changeOpened: true, expectedOpened: true },
   1.520 +    { id: "ime_mode_inactive_email",
   1.521 +      description: "input[type=email][style=\"ime-mode: inactive;\"]",
   1.522 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.523 +      focusable: !aInDesignMode,
   1.524 +      changeOpened: true, expectedOpened: false },
   1.525 +    { id: "ime_mode_disabled_email",
   1.526 +      description: "input[type=email][style=\"ime-mode: disabled;\"]",
   1.527 +      focusable: !aInDesignMode,
   1.528 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.529 +
   1.530 +    { id: "ime_mode_auto_search",
   1.531 +      description: "input[type=search][style=\"ime-mode: auto;\"]",
   1.532 +      focusable: !aInDesignMode,
   1.533 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.534 +    { id: "ime_mode_normal_search",
   1.535 +      description: "input[type=search][style=\"ime-mode: normal;\"]",
   1.536 +      focusable: !aInDesignMode,
   1.537 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.538 +    { id: "ime_mode_active_search",
   1.539 +      description: "input[type=search][style=\"ime-mode: active;\"]",
   1.540 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.541 +      focusable: !aInDesignMode,
   1.542 +      changeOpened: true, expectedOpened: true },
   1.543 +    { id: "ime_mode_inactive_search",
   1.544 +      description: "input[type=search][style=\"ime-mode: inactive;\"]",
   1.545 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.546 +      focusable: !aInDesignMode,
   1.547 +      changeOpened: true, expectedOpened: false },
   1.548 +    { id: "ime_mode_disabled_search",
   1.549 +      description: "input[type=search][style=\"ime-mode: disabled;\"]",
   1.550 +      focusable: !aInDesignMode,
   1.551 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.552 +
   1.553 +    { id: "ime_mode_auto_tel",
   1.554 +      description: "input[type=tel][style=\"ime-mode: auto;\"]",
   1.555 +      focusable: !aInDesignMode,
   1.556 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.557 +    { id: "ime_mode_normal_tel",
   1.558 +      description: "input[type=tel][style=\"ime-mode: normal;\"]",
   1.559 +      focusable: !aInDesignMode,
   1.560 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.561 +    { id: "ime_mode_active_tel",
   1.562 +      description: "input[type=tel][style=\"ime-mode: active;\"]",
   1.563 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.564 +      focusable: !aInDesignMode,
   1.565 +      changeOpened: true, expectedOpened: true },
   1.566 +    { id: "ime_mode_inactive_tel",
   1.567 +      description: "input[type=tel][style=\"ime-mode: inactive;\"]",
   1.568 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.569 +      focusable: !aInDesignMode,
   1.570 +      changeOpened: true, expectedOpened: false },
   1.571 +    { id: "ime_mode_disabled_tel",
   1.572 +      description: "input[type=tel][style=\"ime-mode: disabled;\"]",
   1.573 +      focusable: !aInDesignMode,
   1.574 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.575 +
   1.576 +    { id: "ime_mode_auto_number",
   1.577 +      description: "input[type=number][style=\"ime-mode: auto;\"]",
   1.578 +      focusable: !aInDesignMode,
   1.579 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.580 +    { id: "ime_mode_normal_number",
   1.581 +      description: "input[type=number][style=\"ime-mode: normal;\"]",
   1.582 +      focusable: !aInDesignMode,
   1.583 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.584 +    { id: "ime_mode_active_number",
   1.585 +      description: "input[type=number][style=\"ime-mode: active;\"]",
   1.586 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.587 +      focusable: !aInDesignMode,
   1.588 +      changeOpened: true, expectedOpened: true },
   1.589 +    { id: "ime_mode_inactive_number",
   1.590 +      description: "input[type=number][style=\"ime-mode: inactive;\"]",
   1.591 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.592 +      focusable: !aInDesignMode,
   1.593 +      changeOpened: true, expectedOpened: false },
   1.594 +    { id: "ime_mode_disabled_number",
   1.595 +      description: "input[type=number][style=\"ime-mode: disabled;\"]",
   1.596 +      focusable: !aInDesignMode,
   1.597 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.598 +
   1.599 +    { id: "ime_mode_auto_p",
   1.600 +      description: "input[type=password][style=\"ime-mode: auto;\"]",
   1.601 +      focusable: !aInDesignMode,
   1.602 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.603 +    { id: "ime_mode_normal_p",
   1.604 +      description: "input[type=password][style=\"ime-mode: normal;\"]",
   1.605 +      focusable: !aInDesignMode,
   1.606 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.607 +    { id: "ime_mode_active_p",
   1.608 +      description: "input[type=password][style=\"ime-mode: active;\"]",
   1.609 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.610 +      focusable: !aInDesignMode,
   1.611 +      changeOpened: true, expectedOpened: true },
   1.612 +    { id: "ime_mode_inactive_p",
   1.613 +      description: "input[type=password][style=\"ime-mode: inactive;\"]",
   1.614 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.615 +      focusable: !aInDesignMode,
   1.616 +      changeOpened: true, expectedOpened: false },
   1.617 +    { id: "ime_mode_disabled_p",
   1.618 +      description: "input[type=password][style=\"ime-mode: disabled;\"]",
   1.619 +      focusable: !aInDesignMode,
   1.620 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.621 +    { id: "ime_mode_auto",
   1.622 +      description: "textarea[style=\"ime-mode: auto;\"]",
   1.623 +      focusable: !aInDesignMode,
   1.624 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.625 +    { id: "ime_mode_normal",
   1.626 +      description: "textarea[style=\"ime-mode: normal;\"]",
   1.627 +      focusable: !aInDesignMode,
   1.628 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.629 +    { id: "ime_mode_active",
   1.630 +      description: "textarea[style=\"ime-mode: active;\"]",
   1.631 +      focusable: !aInDesignMode,
   1.632 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.633 +      changeOpened: true, expectedOpened: true },
   1.634 +    { id: "ime_mode_inactive",
   1.635 +      description: "textarea[style=\"ime-mode: inactive;\"]",
   1.636 +      focusable: !aInDesignMode,
   1.637 +      expectedEnabled: gUtils.IME_STATUS_ENABLED,
   1.638 +      changeOpened: true, expectedOpened: false },
   1.639 +    { id: "ime_mode_disabled",
   1.640 +      description: "textarea[style=\"ime-mode: disabled;\"]",
   1.641 +      focusable: !aInDesignMode,
   1.642 +      expectedEnabled: kEnabledStateOnPasswordField },
   1.643 +
   1.644 +    // HTML editors
   1.645 +    { id: "contenteditableEditor",
   1.646 +      description: "div[contenteditable=\"true\"]",
   1.647 +      focusable: !aIsEditable && !aInDesignMode,
   1.648 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.649 +    { id: "designModeEditor",
   1.650 +      description: "designMode editor",
   1.651 +      focusable: true,
   1.652 +      toDesignModeEditor: true,
   1.653 +      expectedEnabled: gUtils.IME_STATUS_ENABLED },
   1.654 +  ];
   1.655 +
   1.656 +  for (var i = 0; i < kTests.length; i++) {
   1.657 +    test(kTests[i]);
   1.658 +  }
   1.659 +}
   1.660 +
   1.661 +function runPluginTest()
   1.662 +{
   1.663 +  if (!kIMEEnabledSupported) {
   1.664 +    return;
   1.665 +  }
   1.666 +
   1.667 +  if (navigator.platform.indexOf("Mac") == 0) {
   1.668 +    // XXX on mac, currently, this test isn't passed because it doesn't return
   1.669 +    // IME_STATUS_PLUGIN by its bug.
   1.670 +    return;
   1.671 +  }
   1.672 +
   1.673 +  var plugin = document.getElementById("plugin");
   1.674 +
   1.675 +  document.activeElement.blur();
   1.676 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
   1.677 +     "runPluginTest: unexpected enabled state when no element has focus");
   1.678 +
   1.679 +  plugin.focus();
   1.680 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_PLUGIN,
   1.681 +     "runPluginTest: unexpected enabled state when plugin has focus");
   1.682 +
   1.683 +  plugin.blur();
   1.684 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
   1.685 +     "runPluginTest: unexpected enabled state when plugin has focus");
   1.686 +
   1.687 +  plugin.focus();
   1.688 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_PLUGIN,
   1.689 +     "runPluginTest: unexpected enabled state when plugin has focus #2");
   1.690 +
   1.691 +  var parent = plugin.parentNode;
   1.692 +  parent.removeChild(plugin);
   1.693 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
   1.694 +     "runPluginTest: unexpected enabled state when plugin is removed from tree");
   1.695 +
   1.696 +  document.getElementById("text").focus();
   1.697 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
   1.698 +     "runPluginTest: unexpected enabled state when input[type=text] has focus");
   1.699 +}
   1.700 +
   1.701 +function runTypeChangingTest()
   1.702 +{
   1.703 +  if (!kIMEEnabledSupported)
   1.704 +    return;
   1.705 +
   1.706 +  const kInputControls = [
   1.707 +    { id: "text",
   1.708 +      type: "text",     expected: gUtils.IME_STATUS_ENABLED,
   1.709 +      description: "[type=\"text\"]" },
   1.710 +    { id: "text_readonly",
   1.711 +      type: "text",     expected: gUtils.IME_STATUS_DISABLED, isReadonly: true,
   1.712 +      description: "[type=\"text\"][readonly]" },
   1.713 +    { id: "password",
   1.714 +      type: "password", expected: gUtils.IME_STATUS_PASSWORD,
   1.715 +      description: "[type=\"password\"]" },
   1.716 +    { id: "password_readonly",
   1.717 +      type: "password", expected: gUtils.IME_STATUS_DISABLED, isReadonly: true,
   1.718 +      description: "[type=\"password\"][readonly]" },
   1.719 +    { id: "checkbox",
   1.720 +      type: "checkbox", expected: gUtils.IME_STATUS_DISABLED,
   1.721 +      description: "[type=\"checkbox\"]" },
   1.722 +    { id: "radio",
   1.723 +      type: "radio",    expected: gUtils.IME_STATUS_DISABLED,
   1.724 +      description: "[type=\"radio\"]" },
   1.725 +    { id: "submit",
   1.726 +      type: "submit",   expected: gUtils.IME_STATUS_DISABLED,
   1.727 +      description: "[type=\"submit\"]" },
   1.728 +    { id: "reset",
   1.729 +      type: "reset",    expected: gUtils.IME_STATUS_DISABLED,
   1.730 +      description: "[type=\"reset\"]" },
   1.731 +    { id: "file",
   1.732 +      type: "file",     expected: gUtils.IME_STATUS_DISABLED,
   1.733 +      description: "[type=\"file\"]" },
   1.734 +    { id: "ibutton",
   1.735 +      type: "button",   expected: gUtils.IME_STATUS_DISABLED,
   1.736 +      description: "[type=\"button\"]" },
   1.737 +    { id: "image",
   1.738 +      type: "image",    expected: gUtils.IME_STATUS_DISABLED,
   1.739 +      description: "[type=\"image\"]" },
   1.740 +    { id: "url",
   1.741 +      type: "url",     expected: gUtils.IME_STATUS_ENABLED,
   1.742 +      description: "[type=\"url\"]" },
   1.743 +    { id: "email",
   1.744 +      type: "email",     expected: gUtils.IME_STATUS_ENABLED,
   1.745 +      description: "[type=\"email\"]" },
   1.746 +    { id: "search",
   1.747 +      type: "search",     expected: gUtils.IME_STATUS_ENABLED,
   1.748 +      description: "[type=\"search\"]" },
   1.749 +    { id: "tel",
   1.750 +      type: "tel",     expected: gUtils.IME_STATUS_ENABLED,
   1.751 +      description: "[type=\"tel\"]" },
   1.752 +    { id: "number",
   1.753 +      type: "number",     expected: gUtils.IME_STATUS_ENABLED,
   1.754 +      description: "[type=\"number\"]" },
   1.755 +    { id: "ime_mode_auto",
   1.756 +      type: "text",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.757 +      description: "[type=\"text\"][ime-mode: auto;]" },
   1.758 +    { id: "ime_mode_normal",
   1.759 +      type: "text",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.760 +      description: "[type=\"text\"][ime-mode: normal;]" },
   1.761 +    { id: "ime_mode_active",
   1.762 +      type: "text",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.763 +      description: "[type=\"text\"][ime-mode: active;]" },
   1.764 +    { id: "ime_mode_inactive",
   1.765 +      type: "text",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.766 +      description: "[type=\"text\"][ime-mode: inactive;]" },
   1.767 +    { id: "ime_mode_disabled",
   1.768 +      type: "text",     expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.769 +      description: "[type=\"text\"][ime-mode: disabled;]" },
   1.770 +
   1.771 +    { id: "ime_mode_auto_url",
   1.772 +      type: "url",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.773 +      description: "[type=\"url\"][ime-mode: auto;]" },
   1.774 +    { id: "ime_mode_normal_url",
   1.775 +      type: "url",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.776 +      description: "[type=\"url\"][ime-mode: normal;]" },
   1.777 +    { id: "ime_mode_active_url",
   1.778 +      type: "url",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.779 +      description: "[type=\"url\"][ime-mode: active;]" },
   1.780 +    { id: "ime_mode_inactive_url",
   1.781 +      type: "url",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.782 +      description: "[type=\"url\"][ime-mode: inactive;]" },
   1.783 +    { id: "ime_mode_disabled_url",
   1.784 +      type: "url",     expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.785 +      description: "[type=\"url\"][ime-mode: disabled;]" },
   1.786 +
   1.787 +    { id: "ime_mode_auto_email",
   1.788 +      type: "email",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.789 +      description: "[type=\"email\"][ime-mode: auto;]" },
   1.790 +    { id: "ime_mode_normal_email",
   1.791 +      type: "email",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.792 +      description: "[type=\"email\"][ime-mode: normal;]" },
   1.793 +    { id: "ime_mode_active_email",
   1.794 +      type: "email",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.795 +      description: "[type=\"email\"][ime-mode: active;]" },
   1.796 +    { id: "ime_mode_inactive_email",
   1.797 +      type: "email",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.798 +      description: "[type=\"email\"][ime-mode: inactive;]" },
   1.799 +    { id: "ime_mode_disabled_email",
   1.800 +      type: "email",     expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.801 +      description: "[type=\"email\"][ime-mode: disabled;]" },
   1.802 +
   1.803 +    { id: "ime_mode_auto_search",
   1.804 +      type: "search",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.805 +      description: "[type=\"search\"][ime-mode: auto;]" },
   1.806 +    { id: "ime_mode_normal_search",
   1.807 +      type: "search",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.808 +      description: "[type=\"search\"][ime-mode: normal;]" },
   1.809 +    { id: "ime_mode_active_search",
   1.810 +      type: "search",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.811 +      description: "[type=\"search\"][ime-mode: active;]" },
   1.812 +    { id: "ime_mode_inactive_search",
   1.813 +      type: "search",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.814 +      description: "[type=\"search\"][ime-mode: inactive;]" },
   1.815 +    { id: "ime_mode_disabled_search",
   1.816 +      type: "search",     expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.817 +      description: "[type=\"search\"][ime-mode: disabled;]" },
   1.818 +
   1.819 +    { id: "ime_mode_auto_tel",
   1.820 +      type: "tel",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.821 +      description: "[type=\"tel\"][ime-mode: auto;]" },
   1.822 +    { id: "ime_mode_normal_tel",
   1.823 +      type: "tel",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.824 +      description: "[type=\"tel\"][ime-mode: normal;]" },
   1.825 +    { id: "ime_mode_active_tel",
   1.826 +      type: "tel",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.827 +      description: "[type=\"tel\"][ime-mode: active;]" },
   1.828 +    { id: "ime_mode_inactive_tel",
   1.829 +      type: "tel",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.830 +      description: "[type=\"tel\"][ime-mode: inactive;]" },
   1.831 +    { id: "ime_mode_disabled_tel",
   1.832 +      type: "tel",     expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.833 +      description: "[type=\"tel\"][ime-mode: disabled;]" },
   1.834 +
   1.835 +    { id: "ime_mode_auto_number",
   1.836 +      type: "number",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.837 +      description: "[type=\"number\"][ime-mode: auto;]" },
   1.838 +    { id: "ime_mode_normal_number",
   1.839 +      type: "number",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.840 +      description: "[type=\"number\"][ime-mode: normal;]" },
   1.841 +    { id: "ime_mode_active_number",
   1.842 +      type: "number",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.843 +      description: "[type=\"number\"][ime-mode: active;]" },
   1.844 +    { id: "ime_mode_inactive_number",
   1.845 +      type: "number",     expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.846 +      description: "[type=\"number\"][ime-mode: inactive;]" },
   1.847 +    { id: "ime_mode_disabled_number",
   1.848 +      type: "number",     expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.849 +      description: "[type=\"number\"][ime-mode: disabled;]" },
   1.850 +
   1.851 +    { id: "ime_mode_auto_p",
   1.852 +      type: "password", expected: gUtils.IME_STATUS_PASSWORD,  imeMode:  true,
   1.853 +      description: "[type=\"password\"][ime-mode: auto;]" },
   1.854 +    { id: "ime_mode_normal_p",
   1.855 +      type: "password", expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.856 +      description: "[type=\"password\"][ime-mode: normal;]" },
   1.857 +    { id: "ime_mode_active_p",
   1.858 +      type: "password", expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.859 +      description: "[type=\"password\"][ime-mode: active;]" },
   1.860 +    { id: "ime_mode_inactive_p",
   1.861 +      type: "password", expected: gUtils.IME_STATUS_ENABLED,  imeMode:  true,
   1.862 +      description: "[type=\"password\"][ime-mode: inactive;]" },
   1.863 +    { id: "ime_mode_disabled_p",
   1.864 +      type: "password", expected: gUtils.IME_STATUS_PASSWORD, imeMode:  true,
   1.865 +      description: "[type=\"password\"][ime-mode: disabled;]" }
   1.866 +  ];
   1.867 +
   1.868 +  const kInputTypes = [
   1.869 +    { type: "",         expected: gUtils.IME_STATUS_ENABLED  },
   1.870 +    { type: "text",     expected: gUtils.IME_STATUS_ENABLED  },
   1.871 +    { type: "password", expected: gUtils.IME_STATUS_PASSWORD },
   1.872 +    { type: "checkbox", expected: gUtils.IME_STATUS_DISABLED },
   1.873 +    { type: "radio",    expected: gUtils.IME_STATUS_DISABLED },
   1.874 +    { type: "submit",   expected: gUtils.IME_STATUS_DISABLED },
   1.875 +    { type: "reset",    expected: gUtils.IME_STATUS_DISABLED },
   1.876 +    { type: "file",     expected: gUtils.IME_STATUS_DISABLED },
   1.877 +    { type: "button",   expected: gUtils.IME_STATUS_DISABLED },
   1.878 +    { type: "image",    expected: gUtils.IME_STATUS_DISABLED },
   1.879 +    { type: "url",      expected: gUtils.IME_STATUS_ENABLED  },
   1.880 +    { type: "email",    expected: gUtils.IME_STATUS_ENABLED  },
   1.881 +    { type: "search",   expected: gUtils.IME_STATUS_ENABLED  },
   1.882 +    { type: "tel",      expected: gUtils.IME_STATUS_ENABLED  },
   1.883 +    { type: "number",   expected: gUtils.IME_STATUS_ENABLED  }
   1.884 +  ];
   1.885 +
   1.886 +  function getExpectedIMEEnabled(aNewType, aInputControl)
   1.887 +  {
   1.888 +    if (aNewType.expected == gUtils.IME_STATUS_DISABLED ||
   1.889 +        aInputControl.isReadonly)
   1.890 +      return gUtils.IME_STATUS_DISABLED;
   1.891 +    return aInputControl.imeMode ? aInputControl.expected : aNewType.expected;
   1.892 +  }
   1.893 +
   1.894 +  const kOpenedState = [ true, false ];
   1.895 +
   1.896 +  for (var i = 0; i < kOpenedState.length; i++) {
   1.897 +    const kOpened = kOpenedState[i];
   1.898 +    for (var j = 0; j < kInputControls.length; j++) {
   1.899 +      const kInput = kInputControls[j];
   1.900 +      var e = document.getElementById(kInput.id);
   1.901 +      e.focus();
   1.902 +      for (var k = 0; k < kInputTypes.length; k++) {
   1.903 +        const kType = kInputTypes[k];
   1.904 +        var typeChangingDescription =
   1.905 +          "\"" + e.getAttribute("type") + "\" to \"" + kInput.type + "\"";
   1.906 +        e.setAttribute("type", kInput.type);
   1.907 +        is(gUtils.IMEStatus, kInput.expected,
   1.908 +           "type attr changing test (IMEStatus): " + typeChangingDescription +
   1.909 +             " (" +  kInput.description + ")");
   1.910 +        is(gUtils.focusedInputType, kInput.type,
   1.911 +           "type attr changing test (type): " + typeChangingDescription +
   1.912 +             " (" +  kInput.description + ")");
   1.913 +
   1.914 +        const kTestOpenState = kIMEOpenSupported &&
   1.915 +                gUtils.IMEStatus == gUtils.IME_STATUS_ENABLED &&
   1.916 +                getExpectedIMEEnabled(kType, kInput) == gUtils.IME_STATUS_ENABLED;
   1.917 +        if (kTestOpenState) {
   1.918 +          gUtils.IMEIsOpen = kOpened;
   1.919 +        }
   1.920 +
   1.921 +        typeChangingDescription =
   1.922 +          "\"" + e.getAttribute("type") + "\" to \"" + kType.type + "\"";
   1.923 +        if (kType.type != "")
   1.924 +          e.setAttribute("type", kType.type);
   1.925 +        else
   1.926 +          e.removeAttribute("type");
   1.927 +
   1.928 +        is(gUtils.IMEStatus, getExpectedIMEEnabled(kType, kInput),
   1.929 +           "type attr changing test (IMEStatus): " + typeChangingDescription +
   1.930 +             " (" +  kInput.description + ")");
   1.931 +        is(gUtils.focusedInputType, kType.type,
   1.932 +           "type attr changing test (type): " + typeChangingDescription +
   1.933 +             " (" +  kInput.description + ")");
   1.934 +        if (kTestOpenState && gUtils.IMEStatus == gUtils.IME_STATUS_ENABLED) {
   1.935 +          is(gUtils.IMEIsOpen, kOpened,
   1.936 +             "type attr changing test (open state is changed): " +
   1.937 +               typeChangingDescription + " (" +  kInput.description + ")");
   1.938 +        }
   1.939 +      }
   1.940 +      // reset the type to default
   1.941 +      e.setAttribute("type", kInput.type);
   1.942 +    }
   1.943 +    if (!kIMEOpenSupported)
   1.944 +      break;
   1.945 +  }
   1.946 +}
   1.947 +
   1.948 +function runReadonlyChangingTest()
   1.949 +{
   1.950 +  if (!kIMEEnabledSupported)
   1.951 +    return;
   1.952 +
   1.953 +  const kInputControls = [
   1.954 +    { id: "text",
   1.955 +      type: "text",     expected: gUtils.IME_STATUS_ENABLED  },
   1.956 +    { id: "password",
   1.957 +      type: "password", expected: gUtils.IME_STATUS_PASSWORD },
   1.958 +    { id: "url",
   1.959 +      type: "url",      expected: gUtils.IME_STATUS_ENABLED  },
   1.960 +    { id: "email",
   1.961 +      type: "email",    expected: gUtils.IME_STATUS_ENABLED  },
   1.962 +    { id: "search",
   1.963 +      type: "search",   expected: gUtils.IME_STATUS_ENABLED  },
   1.964 +    { id: "tel",
   1.965 +      type: "tel",      expected: gUtils.IME_STATUS_ENABLED  },
   1.966 +    { id: "number",
   1.967 +      type: "number",   expected: gUtils.IME_STATUS_ENABLED  },
   1.968 +    { id: "textarea",
   1.969 +      type: "textarea", expected: gUtils.IME_STATUS_ENABLED  }
   1.970 +  ];
   1.971 +  const kOpenedState = [ true, false ];
   1.972 +
   1.973 +  for (var i = 0; i < kOpenedState.length; i++) {
   1.974 +    const kOpened = kOpenedState[i];
   1.975 +    for (var j = 0; j < kInputControls.length; j++) {
   1.976 +      const kInput = kInputControls[j];
   1.977 +      var e = document.getElementById(kInput.id);
   1.978 +      e.focus();
   1.979 +      if (kIMEOpenSupported && gUtils.IMEStatus == gUtils.IME_STATUS_ENABLED) {
   1.980 +        gUtils.IMEIsOpen = kOpened;
   1.981 +      }
   1.982 +      e.setAttribute("readonly", "readonly");
   1.983 +      is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
   1.984 +         "readonly attr setting test: type=" + kInput.type);
   1.985 +      e.removeAttribute("readonly");
   1.986 +      is(gUtils.IMEStatus, kInput.expected,
   1.987 +         "readonly attr removing test: type=" + kInput.type);
   1.988 +      if (kIMEOpenSupported && gUtils.IMEStatus == gUtils.IME_STATUS_ENABLED) {
   1.989 +        is(gUtils.IMEIsOpen, kOpened,
   1.990 +           "readonly attr removing test (open state is changed): type=" +
   1.991 +           kInput.type);
   1.992 +      }
   1.993 +    }
   1.994 +    if (!kIMEOpenSupported)
   1.995 +      break;
   1.996 +  }
   1.997 +}
   1.998 +
   1.999 +function runComplexContenteditableTests()
  1.1000 +{
  1.1001 +  if (!kIMEEnabledSupported) {
  1.1002 +    return;
  1.1003 +  }
  1.1004 +
  1.1005 +  var description = "runReadonlyChangingOnContenteditable: ";
  1.1006 +
  1.1007 +  var container = document.getElementById("display");
  1.1008 +  var button = document.getElementById("button");
  1.1009 +
  1.1010 +  // the editor has focus directly.
  1.1011 +  container.setAttribute("contenteditable", "true");
  1.1012 +  container.focus();
  1.1013 +
  1.1014 +  is(gFM.focusedElement, container,
  1.1015 +     description + "The editor doesn't get focus");
  1.1016 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1017 +     description + "IME isn't enabled on HTML editor");
  1.1018 +  const kReadonly =
  1.1019 +    Components.interfaces.nsIPlaintextEditor.eEditorReadonlyMask;
  1.1020 +  var editor =
  1.1021 +    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  1.1022 +      getInterface(Components.interfaces.nsIWebNavigation).
  1.1023 +      QueryInterface(Components.interfaces.nsIDocShell).editor;
  1.1024 +  var flags = editor.flags;
  1.1025 +  editor.flags = flags | kReadonly;
  1.1026 +  is(gFM.focusedElement, container,
  1.1027 +     description + "The editor loses focus by flag change");
  1.1028 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
  1.1029 +     description + "IME is still enabled on readonly HTML editor");
  1.1030 +  editor.flags = flags;
  1.1031 +  is(gFM.focusedElement, container,
  1.1032 +     description + "The editor loses focus by flag change #2");
  1.1033 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1034 +     description + "IME is still disabled, the editor isn't readonly now");
  1.1035 +  container.removeAttribute("contenteditable");
  1.1036 +  todo_is(gFM.focusedElement, null,
  1.1037 +          description + "The container still has focus, the editor has been no editable");
  1.1038 +  todo_is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
  1.1039 +          description + "IME is still enabled on the editor, the editor has been no editable");
  1.1040 +
  1.1041 +  // a button which is in the editor has focus
  1.1042 +  button.focus();
  1.1043 +  is(gFM.focusedElement, button,
  1.1044 +     description + "The button doesn't get focus");
  1.1045 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
  1.1046 +     description + "IME is enabled on the button");
  1.1047 +  container.setAttribute("contenteditable", "true");
  1.1048 +  is(gFM.focusedElement, button,
  1.1049 +     description + "The button loses focus, the container is editable now");
  1.1050 +  todo_is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1051 +          description + "IME is still disabled on the button, the container is editable now");
  1.1052 +  editor =
  1.1053 +    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  1.1054 +      getInterface(Components.interfaces.nsIWebNavigation).
  1.1055 +      QueryInterface(Components.interfaces.nsIDocShell).editor;
  1.1056 +  flags = editor.flags;
  1.1057 +  editor.flags = flags | kReadonly;
  1.1058 +  is(gFM.focusedElement, button,
  1.1059 +     description + "The button loses focus by changing editor flags");
  1.1060 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
  1.1061 +     description + "IME is still enabled on the button, the container is readonly now");
  1.1062 +  editor.flags = flags;
  1.1063 +  is(gFM.focusedElement, button,
  1.1064 +     description + "The button loses focus by changing editor flags #2");
  1.1065 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1066 +     description + "IME is still disabled on the button, the container isn't readonly now");
  1.1067 +  container.removeAttribute("contenteditable");
  1.1068 +  is(gFM.focusedElement, button,
  1.1069 +     description + "The button loses focus, the container has been no editable");
  1.1070 +  todo_is(gUtils.IMEStatus, gUtils.IME_STATUS_DISABLED,
  1.1071 +          description + "IME is still enabled on the button, the container has been no editable");
  1.1072 +
  1.1073 +  description = "testOnIndependentEditor: ";
  1.1074 +  function testOnIndependentEditor(aEditor, aEditorDescription)
  1.1075 +  {
  1.1076 +    var isReadonly = aEditor.readOnly;
  1.1077 +    var expectedState =
  1.1078 +      aEditor.readOnly ? gUtils.IME_STATUS_DISABLED : gUtils.IME_STATUS_ENABLED;
  1.1079 +    var unexpectedStateDescription =
  1.1080 +      expectedState != gUtils.IME_STATUS_ENABLED ? "enabled" : "disabled";
  1.1081 +    aEditor.focus();
  1.1082 +    is(gFM.focusedElement, aEditor,
  1.1083 +       description + "The " + aEditorDescription + " doesn't get focus");
  1.1084 +    is(gUtils.IMEStatus, expectedState,
  1.1085 +       description + "IME is " + unexpectedStateDescription +
  1.1086 +         " on the " + aEditorDescription);
  1.1087 +    container.setAttribute("contenteditable", "true");
  1.1088 +    is(gFM.focusedElement, aEditor,
  1.1089 +       description + "The " + aEditorDescription +
  1.1090 +         " loses focus, the container is editable now");
  1.1091 +    is(gUtils.IMEStatus, expectedState,
  1.1092 +       description + "IME becomes " + unexpectedStateDescription +
  1.1093 +         " on the " + aEditorDescription + ", the container is editable now");
  1.1094 +    editor =
  1.1095 +      window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  1.1096 +        getInterface(Components.interfaces.nsIWebNavigation).
  1.1097 +        QueryInterface(Components.interfaces.nsIDocShell).editor;
  1.1098 +    flags = editor.flags;
  1.1099 +    editor.flags = flags | kReadonly;
  1.1100 +    is(gFM.focusedElement, aEditor,
  1.1101 +       description + "The " + aEditorDescription +
  1.1102 +         " loses focus by changing editor flags");
  1.1103 +    is(gUtils.IMEStatus, expectedState,
  1.1104 +       description + "IME becomes " + unexpectedStateDescription + " on the " +
  1.1105 +         aEditorDescription + ", the container is readonly now");
  1.1106 +    editor.flags = flags;
  1.1107 +    is(gFM.focusedElement, aEditor,
  1.1108 +       description + "The " + aEditorDescription +
  1.1109 +         " loses focus by changing editor flags #2");
  1.1110 +    is(gUtils.IMEStatus, expectedState,
  1.1111 +       description + "IME becomes " + unexpectedStateDescription + " on the " +
  1.1112 +         aEditorDescription + ", the container isn't readonly now");
  1.1113 +    container.removeAttribute("contenteditable");
  1.1114 +    is(gFM.focusedElement, aEditor,
  1.1115 +       description + "The " + aEditorDescription +
  1.1116 +         " loses focus, the container has been no editable");
  1.1117 +    is(gUtils.IMEStatus, expectedState,
  1.1118 +       description + "IME becomes " + unexpectedStateDescription + " on the " +
  1.1119 +         aEditorDescription + ", the container has been no editable");
  1.1120 +  }
  1.1121 +
  1.1122 +  // a textarea which is in the editor has focus
  1.1123 +  testOnIndependentEditor(document.getElementById("textarea"),
  1.1124 +                          "textarea");
  1.1125 +  // a readonly textarea which is in the editor has focus
  1.1126 +  testOnIndependentEditor(document.getElementById("textarea_readonly"),
  1.1127 +                          "textarea[readonly]");
  1.1128 +  // an input field which is in the editor has focus
  1.1129 +  testOnIndependentEditor(document.getElementById("text"),
  1.1130 +                          "input[type=\"text\"]");
  1.1131 +  // a readonly input field which is in the editor has focus
  1.1132 +  testOnIndependentEditor(document.getElementById("text_readonly"),
  1.1133 +                          "input[type=\"text\"][readonly]");
  1.1134 +
  1.1135 +  description = "testOnOutsideOfEditor: ";
  1.1136 +  function testOnOutsideOfEditor(aFocusNode, aFocusNodeDescription, aEditor)
  1.1137 +  {
  1.1138 +    if (aFocusNode) {
  1.1139 +      aFocusNode.focus();
  1.1140 +      is(gFM.focusedElement, aFocusNode,
  1.1141 +         description + "The " + aFocusNodeDescription + " doesn't get focus");
  1.1142 +    } else {
  1.1143 +      if (document.activeElement) {
  1.1144 +        document.activeElement.blur();
  1.1145 +      }
  1.1146 +      is(gFM.focusedElement, null,
  1.1147 +         description + "Unexpected element has focus");
  1.1148 +    }
  1.1149 +    var expectedState =
  1.1150 +      aFocusNode ? gUtils.IMEStatus : gUtils.IME_STATUS_DISABLED;
  1.1151 +    var unexpectedStateDescription =
  1.1152 +      expectedState != gUtils.IME_STATUS_ENABLED ? "enabled" : "disabled";
  1.1153 +
  1.1154 +    aEditor.setAttribute("contenteditable", "true");
  1.1155 +    is(gFM.focusedElement, aFocusNode,
  1.1156 +       description + "The " + aFocusNodeDescription +
  1.1157 +         " loses focus, a HTML editor is editable now");
  1.1158 +    is(gUtils.IMEStatus, expectedState,
  1.1159 +       description + "IME becomes " + unexpectedStateDescription +
  1.1160 +         " on the " + aFocusNodeDescription +
  1.1161 +         ", the HTML editor is editable now");
  1.1162 +    editor =
  1.1163 +      window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  1.1164 +        getInterface(Components.interfaces.nsIWebNavigation).
  1.1165 +        QueryInterface(Components.interfaces.nsIDocShell).editor;
  1.1166 +    flags = editor.flags;
  1.1167 +    editor.flags = flags | kReadonly;
  1.1168 +    is(gFM.focusedElement, aFocusNode,
  1.1169 +       description + aFocusNodeDescription +
  1.1170 +         " loses focus by changing HTML editor flags");
  1.1171 +    is(gUtils.IMEStatus, expectedState,
  1.1172 +       description + "IME becomes " + unexpectedStateDescription + " on " +
  1.1173 +         aFocusNodeDescription + ", the HTML editor is readonly now");
  1.1174 +    editor.flags = flags;
  1.1175 +    is(gFM.focusedElement, aFocusNode,
  1.1176 +       description + aFocusNodeDescription +
  1.1177 +         " loses focus by changing HTML editor flags #2");
  1.1178 +    is(gUtils.IMEStatus, expectedState,
  1.1179 +       description + "IME becomes " + unexpectedStateDescription + " on " +
  1.1180 +         aFocusNodeDescription + ", the HTML editor isn't readonly now");
  1.1181 +    container.removeAttribute("contenteditable");
  1.1182 +    is(gFM.focusedElement, aFocusNode,
  1.1183 +       description + aFocusNodeDescription +
  1.1184 +         " loses focus, the HTML editor has been no editable");
  1.1185 +    is(gUtils.IMEStatus, expectedState,
  1.1186 +       description + "IME becomes " + unexpectedStateDescription + " on " +
  1.1187 +         aFocusNodeDescription + ", the HTML editor has been no editable");
  1.1188 +  }
  1.1189 +
  1.1190 +  var div = document.getElementById("contenteditableEditor");
  1.1191 +  // a textarea which is outside of the editor has focus
  1.1192 +  testOnOutsideOfEditor(document.getElementById("textarea"), "textarea", div);
  1.1193 +  // a readonly textarea which is outside of the editor has focus
  1.1194 +  testOnOutsideOfEditor(document.getElementById("textarea_readonly"),
  1.1195 +                        "textarea[readonly]", div);
  1.1196 +  // an input field which is outside of the editor has focus
  1.1197 +  testOnOutsideOfEditor(document.getElementById("text"),
  1.1198 +                        "input[type=\"text\"]", div);
  1.1199 +  // a readonly input field which outside of the editor has focus
  1.1200 +  testOnOutsideOfEditor(document.getElementById("text_readonly"),
  1.1201 +                        "input[type=\"text\"][readonly]", div);
  1.1202 +  // a readonly input field which outside of the editor has focus
  1.1203 +  testOnOutsideOfEditor(document.getElementById("button"), "button", div);
  1.1204 +  // nobody has focus.
  1.1205 +  testOnOutsideOfEditor(null, "nobody", div);
  1.1206 +}
  1.1207 +
  1.1208 +function runEditorFlagChangeTests()
  1.1209 +{
  1.1210 +  if (!kIMEEnabledSupported) {
  1.1211 +    return;
  1.1212 +  }
  1.1213 +
  1.1214 +  var description = "runEditorFlagChangeTests: ";
  1.1215 +
  1.1216 +  var container = document.getElementById("display");
  1.1217 +
  1.1218 +  // the editor has focus directly.
  1.1219 +  container.setAttribute("contenteditable", "true");
  1.1220 +  container.focus();
  1.1221 +
  1.1222 +  is(gFM.focusedElement, container,
  1.1223 +     description + "The editor doesn't get focus");
  1.1224 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1225 +     description + "IME isn't enabled on HTML editor");
  1.1226 +  const kIMEStateChangeFlags =
  1.1227 +    Components.interfaces.nsIPlaintextEditor.eEditorPasswordMask |
  1.1228 +    Components.interfaces.nsIPlaintextEditor.eEditorReadonlyMask |
  1.1229 +    Components.interfaces.nsIPlaintextEditor.eEditorDisabledMask;
  1.1230 +  var editor =
  1.1231 +    window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  1.1232 +      getInterface(Components.interfaces.nsIWebNavigation).
  1.1233 +      QueryInterface(Components.interfaces.nsIDocShell).editor;
  1.1234 +  var editorIMESupport =
  1.1235 +    editor.QueryInterface(Components.interfaces.nsIEditorIMESupport);
  1.1236 +  var flags = editor.flags;
  1.1237 +
  1.1238 +  // start composition
  1.1239 +  synthesizeComposition({ type: "compositionstart" });
  1.1240 +
  1.1241 +  // input characters
  1.1242 +  synthesizeComposition({ type: "compositionupdate",
  1.1243 +                          data: "\u3078\u3093\u3057\u3093" });
  1.1244 +  synthesizeText(
  1.1245 +    { "composition":
  1.1246 +      { "string": "\u3078\u3093\u3057\u3093",
  1.1247 +        "clauses":
  1.1248 +        [
  1.1249 +          { "length": 4, "attr": COMPOSITION_ATTR_RAWINPUT }
  1.1250 +        ]
  1.1251 +      },
  1.1252 +      "caret": { "start": 4, "length": 0 }
  1.1253 +    });
  1.1254 +
  1.1255 +  editor.flags &= ~kIMEStateChangeFlags;
  1.1256 +  ok(editorIMESupport.composing,
  1.1257 +     description + "#1 IME composition was committed unexpectedly");
  1.1258 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1259 +     description + "#1 IME isn't enabled on HTML editor");
  1.1260 +
  1.1261 +  editor.flags |= ~kIMEStateChangeFlags;
  1.1262 +  ok(editorIMESupport.composing,
  1.1263 +     description + "#2 IME composition was committed unexpectedly");
  1.1264 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1265 +     description + "#2 IME isn't enabled on HTML editor");
  1.1266 +
  1.1267 +  editor.flags = flags;
  1.1268 +  ok(editorIMESupport.composing,
  1.1269 +     description + "#3 IME composition was committed unexpectedly");
  1.1270 +  is(gUtils.IMEStatus, gUtils.IME_STATUS_ENABLED,
  1.1271 +     description + "#3 IME isn't enabled on HTML editor");
  1.1272 +
  1.1273 +  // cancel the composition
  1.1274 +  synthesizeComposition({ type: "compositionupdate", data: "" });
  1.1275 +  synthesizeText(
  1.1276 +    { "composition":
  1.1277 +      { "string": "",
  1.1278 +        "clauses":
  1.1279 +        [
  1.1280 +          { "length": 0, "attr": 0 }
  1.1281 +        ]
  1.1282 +      },
  1.1283 +      "caret": { "start": 0, "length": 0 }
  1.1284 +    });
  1.1285 +
  1.1286 +  synthesizeComposition({ type: "compositionend", data: "" });
  1.1287 +
  1.1288 +  container.removeAttribute("contenteditable");
  1.1289 +}
  1.1290 +
  1.1291 +function runEditableSubframeTests()
  1.1292 +{
  1.1293 +  window.open("window_imestate_iframes.html", "_blank",
  1.1294 +              "width=600,height=600");
  1.1295 +}
  1.1296 +
  1.1297 +function runTestPasswordFieldOnDialog()
  1.1298 +{
  1.1299 +  if (!kIMEEnabledSupported) {
  1.1300 +    return;
  1.1301 +  }
  1.1302 +
  1.1303 +  if (document.activeElement) {
  1.1304 +    document.activeElement.blur();
  1.1305 +  }
  1.1306 +
  1.1307 +  var dialog;
  1.1308 +
  1.1309 +  function WindowObserver()
  1.1310 +  {
  1.1311 +    Components.classes["@mozilla.org/observer-service;1"].
  1.1312 +               getService(Components.interfaces.nsIObserverService).
  1.1313 +               addObserver(this, "domwindowopened", false);
  1.1314 +  }
  1.1315 +
  1.1316 +  WindowObserver.prototype = {
  1.1317 +    QueryInterface: function (iid)
  1.1318 +    {
  1.1319 +      if (iid.equals(Components.interfaces.nsIObserver) ||
  1.1320 +          iid.equals(Components.interfaces.nsISupports)) {
  1.1321 +        return this;
  1.1322 +      }
  1.1323 +    },
  1.1324 +
  1.1325 +    observe: function (subject, topic, data)
  1.1326 +    {
  1.1327 +      if (topic === "domwindowopened") {
  1.1328 +        ok(true, "dialog window is created");
  1.1329 +        dialog = subject.QueryInterface(Components.interfaces.nsIDOMWindow);
  1.1330 +        dialog.addEventListener("load", onPasswordDialogLoad, false);
  1.1331 +      }
  1.1332 +    }
  1.1333 +  };
  1.1334 +
  1.1335 +  var observer = new WindowObserver();
  1.1336 +  var arg1 = new Object(), arg2 = new Object();
  1.1337 +  Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
  1.1338 +             getService(Components.interfaces.nsIPromptService).
  1.1339 +             promptPassword(window, "title", "text", arg1, "msg", arg2);
  1.1340 +
  1.1341 +  ok(true, "password dialog was closed");
  1.1342 +
  1.1343 +  Components.classes["@mozilla.org/observer-service;1"].
  1.1344 +             getService(Components.interfaces.nsIObserverService).
  1.1345 +             removeObserver(observer, "domwindowopened");
  1.1346 +
  1.1347 +  var passwordField;
  1.1348 +
  1.1349 +  function onPasswordDialogLoad()
  1.1350 +  {
  1.1351 +    ok(true, "onPasswordDialogLoad is called");
  1.1352 +    dialog.removeEventListener("load", onPasswordDialogLoad, false);
  1.1353 +    passwordField = dialog.document.getElementById("password1Textbox");
  1.1354 +    passwordField.addEventListener("focus", onPasswordFieldFocus, false);
  1.1355 +  }
  1.1356 +
  1.1357 +  function onPasswordFieldFocus()
  1.1358 +  {
  1.1359 +    ok(true, "onPasswordFieldFocus is called");
  1.1360 +    passwordField.removeEventListener("focus", onPasswordFieldFocus, false);
  1.1361 +    var utils = dialog.
  1.1362 +      QueryInterface(Components.interfaces.nsIInterfaceRequestor).
  1.1363 +      getInterface(Components.interfaces.nsIDOMWindowUtils);
  1.1364 +    is(utils.IMEStatus, utils.IME_STATUS_PASSWORD,
  1.1365 +       "IME isn't disabled on a password field of password dialog");
  1.1366 +    synthesizeKey("VK_ESCAPE", { }, dialog);
  1.1367 +  }
  1.1368 +}
  1.1369 +
  1.1370 +// Bug 580388 and bug 808287
  1.1371 +function runEditorReframeTests(aCallback)
  1.1372 +{
  1.1373 +  if (document.activeElement) {
  1.1374 +    document.activeElement.blur();
  1.1375 +  }
  1.1376 +
  1.1377 +  var input = document.getElementById("text");
  1.1378 +  input.focus();
  1.1379 +  input.style.overflow = "visible";
  1.1380 +
  1.1381 +  var mozIMEFocusIn = 0;
  1.1382 +  var mozIMEFocusOut = 0;
  1.1383 +  var IMEHasFocus = false;
  1.1384 +
  1.1385 +  var handler = function (aEvent) {
  1.1386 +    switch (aEvent.type) {
  1.1387 +      case "MozIMEFocusIn":
  1.1388 +        mozIMEFocusIn++;
  1.1389 +        IMEHasFocus = true;
  1.1390 +        break;
  1.1391 +      case "MozIMEFocusOut":
  1.1392 +        mozIMEFocusOut++;
  1.1393 +        IMEHasFocus = false;
  1.1394 +        break;
  1.1395 +    }
  1.1396 +  };
  1.1397 +
  1.1398 +  var onInput = function (aEvent) {
  1.1399 +    aEvent.target.style.overflow = "hidden";
  1.1400 +  }
  1.1401 +
  1.1402 +  document.addEventListener("MozIMEFocusIn", handler, true);
  1.1403 +  document.addEventListener("MozIMEFocusOut", handler, true);
  1.1404 +  input.addEventListener("input", onInput, true);
  1.1405 +
  1.1406 +  sendChar("a");
  1.1407 +
  1.1408 +  hitEventLoop(function () {
  1.1409 +    ok(mozIMEFocusOut > 0, "runEditorReframeTests(): IME focus must be lost at reframing");
  1.1410 +    ok(mozIMEFocusIn > 0, "runEditorReframeTests(): IME focus must be restored after reframing");
  1.1411 +    ok(IMEHasFocus, "runEditorReframeTests(): IME must have focus after reframing");
  1.1412 +
  1.1413 +    var focusQueryHandler = function(aEvent) {
  1.1414 +        // Perform a style change and query during focus to trigger reframing
  1.1415 +        input.style.overflow = "visible";
  1.1416 +        synthesizeQuerySelectedText();
  1.1417 +    }
  1.1418 +    document.addEventListener("MozIMEFocusIn", focusQueryHandler, true);
  1.1419 +    mozIMEFocusIn = mozIMEFocusOut = 0;
  1.1420 +
  1.1421 +    input.blur();
  1.1422 +    input.focus();
  1.1423 +    sendChar("a");
  1.1424 +
  1.1425 +    hitEventLoop(function() {
  1.1426 +        ok(IMEHasFocus, "runEditorReframeTests(): IME must have focus after reframing during focus");
  1.1427 +        ok(mozIMEFocusOut == mozIMEFocusIn, "runEditorReframeTests(): IME focus/blur (" + mozIMEFocusIn + "/" + mozIMEFocusOut + ") must match after reframing during focus");
  1.1428 +
  1.1429 +        document.removeEventListener("MozIMEFocusIn", focusQueryHandler, true);
  1.1430 +        document.removeEventListener("MozIMEFocusIn", handler, true);
  1.1431 +        document.removeEventListener("MozIMEFocusOut", handler, true);
  1.1432 +        input.removeEventListener("input", onInput, true);
  1.1433 +
  1.1434 +        input.style.overflow = "visible";
  1.1435 +        input.value = "";
  1.1436 +
  1.1437 +        hitEventLoop(aCallback, 20);
  1.1438 +    }, 20);
  1.1439 +  }, 20);
  1.1440 +}
  1.1441 +
  1.1442 +function runTests()
  1.1443 +{
  1.1444 +  if (!kIMEEnabledSupported && !kIMEOpenSupported)
  1.1445 +    return;
  1.1446 +
  1.1447 +  SpecialPowers.setBoolPref("test.IME", true);
  1.1448 +
  1.1449 +  // test for normal contents.
  1.1450 +  runBasicTest(false, false, "Testing of normal contents");
  1.1451 +
  1.1452 +  // test for plugin contents
  1.1453 +  runPluginTest();
  1.1454 +
  1.1455 +  var container = document.getElementById("display");
  1.1456 +  // test for contentEditable="true"
  1.1457 +  container.setAttribute("contenteditable", "true");
  1.1458 +  runBasicTest(true, false, "Testing [contentEditable=\"true\"]");
  1.1459 +
  1.1460 +  // test for contentEditable="false"
  1.1461 +  container.setAttribute("contenteditable", "false");
  1.1462 +  runBasicTest(false, false, "Testing [contentEditable=\"false\"]");
  1.1463 +
  1.1464 +  // test for removing contentEditable
  1.1465 +  container.setAttribute("contenteditable", "true");
  1.1466 +  container.removeAttribute("contenteditable");
  1.1467 +  runBasicTest(false, false, "Testing after contentEditable to be removed");
  1.1468 +
  1.1469 +  // test designMode
  1.1470 +  document.designMode = "on";
  1.1471 +  runBasicTest(true, true, "Testing designMode=\"on\"");
  1.1472 +  document.designMode = "off";
  1.1473 +  document.getElementById("text").focus();
  1.1474 +  runBasicTest(false, false, "Testing designMode=\"off\"");
  1.1475 +
  1.1476 +  // changing input[type] values
  1.1477 +  // XXX currently, type attribute changing doesn't work fine. bug 559728.
  1.1478 +  // runTypeChangingTest();
  1.1479 +
  1.1480 +  // changing readonly attribute
  1.1481 +  runReadonlyChangingTest();
  1.1482 +
  1.1483 +  // complex contenteditable editor's tests
  1.1484 +  runComplexContenteditableTests();
  1.1485 +
  1.1486 +  // test whether the IME state and composition are not changed unexpectedly
  1.1487 +  runEditorFlagChangeTests();
  1.1488 +
  1.1489 +  // test password field on dialog
  1.1490 +  // XXX temporary disable against failure
  1.1491 +  //runTestPasswordFieldOnDialog();
  1.1492 +
  1.1493 +  // Asynchronous tests
  1.1494 +  runEditorReframeTests(function () {
  1.1495 +    // This will call onFinish(), so, this test must be the last.
  1.1496 +    runEditableSubframeTests();
  1.1497 +  });
  1.1498 +}
  1.1499 +
  1.1500 +function onFinish()
  1.1501 +{
  1.1502 +  SpecialPowers.clearUserPref("test.IME");
  1.1503 +  SimpleTest.finish();
  1.1504 +}
  1.1505 +
  1.1506 +</script>
  1.1507 +</body>
  1.1508 +
  1.1509 +</html>

mercurial