browser/metro/base/tests/mochitest/browser_form_auto_complete.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/metro/base/tests/mochitest/browser_form_auto_complete.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,121 @@
     1.4 +// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +"use strict";
    1.10 +
    1.11 +function clearFormHistory() {
    1.12 +  FormHistory.update({ op : "remove" });
    1.13 +}
    1.14 +
    1.15 +function test() {
    1.16 +  runTests();
    1.17 +  clearFormHistory();
    1.18 +}
    1.19 +
    1.20 +function setUp() {
    1.21 +  clearFormHistory();
    1.22 +  PanelUI.hide();
    1.23 +  yield hideContextUI();
    1.24 +}
    1.25 +
    1.26 +function tearDown() {
    1.27 +  PanelUI.hide();
    1.28 +}
    1.29 +
    1.30 +function checkAutofillMenuItemContents(aItemList)
    1.31 +{
    1.32 +  let errors = 0;
    1.33 +  let found = 0;
    1.34 +  for (let idx = 0; idx < AutofillMenuUI.commands.childNodes.length; idx++) {
    1.35 +    let item = AutofillMenuUI.commands.childNodes[idx];
    1.36 +    let label = item.firstChild.getAttribute("value");
    1.37 +    let value = item.getAttribute("data");
    1.38 +    if (aItemList.indexOf(value) == -1) {
    1.39 +      errors++;
    1.40 +      info("unexpected entry:" + value);
    1.41 +    } else {
    1.42 +      found++;
    1.43 +    }
    1.44 +  }
    1.45 +  is(errors, 0, "autofill menu item list error check");
    1.46 +  is(found, aItemList.length, "autofill item list length mismatch, some items were not found.");
    1.47 +}
    1.48 +
    1.49 +gTests.push({
    1.50 +  desc: "simple auto complete test to insure auto complete code doesn't break.",
    1.51 +  setUp: setUp,
    1.52 +  tearDown: tearDown,
    1.53 +  run: function () {
    1.54 +    let loadedPromise, shownPromise;
    1.55 +
    1.56 +    yield addTab(chromeRoot + "browser_form_auto_complete.html");
    1.57 +    yield waitForCondition(function () {
    1.58 +      return !Browser.selectedTab.isLoading();
    1.59 +    });
    1.60 +
    1.61 +    let tabDocument = Browser.selectedTab.browser.contentWindow.document;
    1.62 +    let form = tabDocument.getElementById("form1");
    1.63 +    let input = tabDocument.getElementById("textedit1");
    1.64 +
    1.65 +    input.value = "hellothere";
    1.66 +
    1.67 +    loadedPromise = waitForObserver("satchel-storage-changed", null, "formhistory-add");
    1.68 +    form.submit();
    1.69 +    yield loadedPromise;
    1.70 +
    1.71 +    // XXX Solves a problem with events not getting delivered to Content.js
    1.72 +    // immediately after submitting the form.
    1.73 +    yield waitForMs(500);
    1.74 +
    1.75 +    tabDocument = Browser.selectedTab.browser.contentWindow.document;
    1.76 +    input = tabDocument.getElementById("textedit1");
    1.77 +    ok(input, "input isn't null");
    1.78 +    input.focus();
    1.79 +
    1.80 +    // Desktop and metrofx display auto-completes in response to double mouse clicks. The
    1.81 +    // first click is ignored.
    1.82 +    shownPromise = waitForEvent(document, "popupshown");
    1.83 +    EventUtils.synthesizeMouseAtCenter(input, {}, Browser.selectedTab.browser.contentWindow);
    1.84 +    EventUtils.synthesizeMouseAtCenter(input, {}, Browser.selectedTab.browser.contentWindow);
    1.85 +    yield shownPromise;
    1.86 +
    1.87 +    checkAutofillMenuItemContents(["hellothere", "one", "two", "three", "four", "five"]);
    1.88 +  }
    1.89 +});
    1.90 +
    1.91 +gTests.push({
    1.92 +  desc: "Test autocomplete selection with arrow key.",
    1.93 +  setUp: setUp,
    1.94 +  tearDown: tearDown,
    1.95 +  run: function () {
    1.96 +
    1.97 +    let newTab = yield addTab(chromeRoot + "browser_form_auto_complete.html");
    1.98 +    yield waitForCondition(function () {
    1.99 +      return !Browser.selectedTab.isLoading();
   1.100 +    });
   1.101 +
   1.102 +    let tabDocument = newTab.browser.contentWindow.document;
   1.103 +    let input = tabDocument.getElementById("textedit1");
   1.104 +    input.focus();
   1.105 +
   1.106 +    let shownPromise = waitForEvent(document, "popupshown");
   1.107 +    EventUtils.synthesizeKey("o", {}, window);
   1.108 +    yield shownPromise;
   1.109 +
   1.110 +    EventUtils.synthesizeKey("VK_DOWN", {}, window);
   1.111 +
   1.112 +    yield waitForCondition(() => input.value == "one");
   1.113 +
   1.114 +    is(input.value, "one", "Input updated correctly");
   1.115 +
   1.116 +    EventUtils.synthesizeKey("VK_DOWN", {}, window);
   1.117 +
   1.118 +    yield waitForCondition(() => input.value == "two");
   1.119 +
   1.120 +    is(input.value, "two", "Input updated correctly");
   1.121 +
   1.122 +    Browser.closeTab(newTab, { forceClose: true });
   1.123 +  }
   1.124 +});

mercurial