Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 "use strict";
8 function clearFormHistory() {
9 FormHistory.update({ op : "remove" });
10 }
12 function test() {
13 runTests();
14 clearFormHistory();
15 }
17 function setUp() {
18 clearFormHistory();
19 PanelUI.hide();
20 yield hideContextUI();
21 }
23 function tearDown() {
24 PanelUI.hide();
25 }
27 function checkAutofillMenuItemContents(aItemList)
28 {
29 let errors = 0;
30 let found = 0;
31 for (let idx = 0; idx < AutofillMenuUI.commands.childNodes.length; idx++) {
32 let item = AutofillMenuUI.commands.childNodes[idx];
33 let label = item.firstChild.getAttribute("value");
34 let value = item.getAttribute("data");
35 if (aItemList.indexOf(value) == -1) {
36 errors++;
37 info("unexpected entry:" + value);
38 } else {
39 found++;
40 }
41 }
42 is(errors, 0, "autofill menu item list error check");
43 is(found, aItemList.length, "autofill item list length mismatch, some items were not found.");
44 }
46 gTests.push({
47 desc: "simple auto complete test to insure auto complete code doesn't break.",
48 setUp: setUp,
49 tearDown: tearDown,
50 run: function () {
51 let loadedPromise, shownPromise;
53 yield addTab(chromeRoot + "browser_form_auto_complete.html");
54 yield waitForCondition(function () {
55 return !Browser.selectedTab.isLoading();
56 });
58 let tabDocument = Browser.selectedTab.browser.contentWindow.document;
59 let form = tabDocument.getElementById("form1");
60 let input = tabDocument.getElementById("textedit1");
62 input.value = "hellothere";
64 loadedPromise = waitForObserver("satchel-storage-changed", null, "formhistory-add");
65 form.submit();
66 yield loadedPromise;
68 // XXX Solves a problem with events not getting delivered to Content.js
69 // immediately after submitting the form.
70 yield waitForMs(500);
72 tabDocument = Browser.selectedTab.browser.contentWindow.document;
73 input = tabDocument.getElementById("textedit1");
74 ok(input, "input isn't null");
75 input.focus();
77 // Desktop and metrofx display auto-completes in response to double mouse clicks. The
78 // first click is ignored.
79 shownPromise = waitForEvent(document, "popupshown");
80 EventUtils.synthesizeMouseAtCenter(input, {}, Browser.selectedTab.browser.contentWindow);
81 EventUtils.synthesizeMouseAtCenter(input, {}, Browser.selectedTab.browser.contentWindow);
82 yield shownPromise;
84 checkAutofillMenuItemContents(["hellothere", "one", "two", "three", "four", "five"]);
85 }
86 });
88 gTests.push({
89 desc: "Test autocomplete selection with arrow key.",
90 setUp: setUp,
91 tearDown: tearDown,
92 run: function () {
94 let newTab = yield addTab(chromeRoot + "browser_form_auto_complete.html");
95 yield waitForCondition(function () {
96 return !Browser.selectedTab.isLoading();
97 });
99 let tabDocument = newTab.browser.contentWindow.document;
100 let input = tabDocument.getElementById("textedit1");
101 input.focus();
103 let shownPromise = waitForEvent(document, "popupshown");
104 EventUtils.synthesizeKey("o", {}, window);
105 yield shownPromise;
107 EventUtils.synthesizeKey("VK_DOWN", {}, window);
109 yield waitForCondition(() => input.value == "one");
111 is(input.value, "one", "Input updated correctly");
113 EventUtils.synthesizeKey("VK_DOWN", {}, window);
115 yield waitForCondition(() => input.value == "two");
117 is(input.value, "two", "Input updated correctly");
119 Browser.closeTab(newTab, { forceClose: true });
120 }
121 });