|
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/. */ |
|
5 |
|
6 "use strict"; |
|
7 |
|
8 function clearFormHistory() { |
|
9 FormHistory.update({ op : "remove" }); |
|
10 } |
|
11 |
|
12 function test() { |
|
13 runTests(); |
|
14 clearFormHistory(); |
|
15 } |
|
16 |
|
17 function setUp() { |
|
18 clearFormHistory(); |
|
19 PanelUI.hide(); |
|
20 yield hideContextUI(); |
|
21 } |
|
22 |
|
23 function tearDown() { |
|
24 PanelUI.hide(); |
|
25 } |
|
26 |
|
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 } |
|
45 |
|
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; |
|
52 |
|
53 yield addTab(chromeRoot + "browser_form_auto_complete.html"); |
|
54 yield waitForCondition(function () { |
|
55 return !Browser.selectedTab.isLoading(); |
|
56 }); |
|
57 |
|
58 let tabDocument = Browser.selectedTab.browser.contentWindow.document; |
|
59 let form = tabDocument.getElementById("form1"); |
|
60 let input = tabDocument.getElementById("textedit1"); |
|
61 |
|
62 input.value = "hellothere"; |
|
63 |
|
64 loadedPromise = waitForObserver("satchel-storage-changed", null, "formhistory-add"); |
|
65 form.submit(); |
|
66 yield loadedPromise; |
|
67 |
|
68 // XXX Solves a problem with events not getting delivered to Content.js |
|
69 // immediately after submitting the form. |
|
70 yield waitForMs(500); |
|
71 |
|
72 tabDocument = Browser.selectedTab.browser.contentWindow.document; |
|
73 input = tabDocument.getElementById("textedit1"); |
|
74 ok(input, "input isn't null"); |
|
75 input.focus(); |
|
76 |
|
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; |
|
83 |
|
84 checkAutofillMenuItemContents(["hellothere", "one", "two", "three", "four", "five"]); |
|
85 } |
|
86 }); |
|
87 |
|
88 gTests.push({ |
|
89 desc: "Test autocomplete selection with arrow key.", |
|
90 setUp: setUp, |
|
91 tearDown: tearDown, |
|
92 run: function () { |
|
93 |
|
94 let newTab = yield addTab(chromeRoot + "browser_form_auto_complete.html"); |
|
95 yield waitForCondition(function () { |
|
96 return !Browser.selectedTab.isLoading(); |
|
97 }); |
|
98 |
|
99 let tabDocument = newTab.browser.contentWindow.document; |
|
100 let input = tabDocument.getElementById("textedit1"); |
|
101 input.focus(); |
|
102 |
|
103 let shownPromise = waitForEvent(document, "popupshown"); |
|
104 EventUtils.synthesizeKey("o", {}, window); |
|
105 yield shownPromise; |
|
106 |
|
107 EventUtils.synthesizeKey("VK_DOWN", {}, window); |
|
108 |
|
109 yield waitForCondition(() => input.value == "one"); |
|
110 |
|
111 is(input.value, "one", "Input updated correctly"); |
|
112 |
|
113 EventUtils.synthesizeKey("VK_DOWN", {}, window); |
|
114 |
|
115 yield waitForCondition(() => input.value == "two"); |
|
116 |
|
117 is(input.value, "two", "Input updated correctly"); |
|
118 |
|
119 Browser.closeTab(newTab, { forceClose: true }); |
|
120 } |
|
121 }); |