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