michael@0: // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: function clearFormHistory() { michael@0: FormHistory.update({ op : "remove" }); michael@0: } michael@0: michael@0: function test() { michael@0: runTests(); michael@0: clearFormHistory(); michael@0: } michael@0: michael@0: function setUp() { michael@0: clearFormHistory(); michael@0: PanelUI.hide(); michael@0: yield hideContextUI(); michael@0: } michael@0: michael@0: function tearDown() { michael@0: PanelUI.hide(); michael@0: } michael@0: michael@0: function checkAutofillMenuItemContents(aItemList) michael@0: { michael@0: let errors = 0; michael@0: let found = 0; michael@0: for (let idx = 0; idx < AutofillMenuUI.commands.childNodes.length; idx++) { michael@0: let item = AutofillMenuUI.commands.childNodes[idx]; michael@0: let label = item.firstChild.getAttribute("value"); michael@0: let value = item.getAttribute("data"); michael@0: if (aItemList.indexOf(value) == -1) { michael@0: errors++; michael@0: info("unexpected entry:" + value); michael@0: } else { michael@0: found++; michael@0: } michael@0: } michael@0: is(errors, 0, "autofill menu item list error check"); michael@0: is(found, aItemList.length, "autofill item list length mismatch, some items were not found."); michael@0: } michael@0: michael@0: gTests.push({ michael@0: desc: "simple auto complete test to insure auto complete code doesn't break.", michael@0: setUp: setUp, michael@0: tearDown: tearDown, michael@0: run: function () { michael@0: let loadedPromise, shownPromise; michael@0: michael@0: yield addTab(chromeRoot + "browser_form_auto_complete.html"); michael@0: yield waitForCondition(function () { michael@0: return !Browser.selectedTab.isLoading(); michael@0: }); michael@0: michael@0: let tabDocument = Browser.selectedTab.browser.contentWindow.document; michael@0: let form = tabDocument.getElementById("form1"); michael@0: let input = tabDocument.getElementById("textedit1"); michael@0: michael@0: input.value = "hellothere"; michael@0: michael@0: loadedPromise = waitForObserver("satchel-storage-changed", null, "formhistory-add"); michael@0: form.submit(); michael@0: yield loadedPromise; michael@0: michael@0: // XXX Solves a problem with events not getting delivered to Content.js michael@0: // immediately after submitting the form. michael@0: yield waitForMs(500); michael@0: michael@0: tabDocument = Browser.selectedTab.browser.contentWindow.document; michael@0: input = tabDocument.getElementById("textedit1"); michael@0: ok(input, "input isn't null"); michael@0: input.focus(); michael@0: michael@0: // Desktop and metrofx display auto-completes in response to double mouse clicks. The michael@0: // first click is ignored. michael@0: shownPromise = waitForEvent(document, "popupshown"); michael@0: EventUtils.synthesizeMouseAtCenter(input, {}, Browser.selectedTab.browser.contentWindow); michael@0: EventUtils.synthesizeMouseAtCenter(input, {}, Browser.selectedTab.browser.contentWindow); michael@0: yield shownPromise; michael@0: michael@0: checkAutofillMenuItemContents(["hellothere", "one", "two", "three", "four", "five"]); michael@0: } michael@0: }); michael@0: michael@0: gTests.push({ michael@0: desc: "Test autocomplete selection with arrow key.", michael@0: setUp: setUp, michael@0: tearDown: tearDown, michael@0: run: function () { michael@0: michael@0: let newTab = yield addTab(chromeRoot + "browser_form_auto_complete.html"); michael@0: yield waitForCondition(function () { michael@0: return !Browser.selectedTab.isLoading(); michael@0: }); michael@0: michael@0: let tabDocument = newTab.browser.contentWindow.document; michael@0: let input = tabDocument.getElementById("textedit1"); michael@0: input.focus(); michael@0: michael@0: let shownPromise = waitForEvent(document, "popupshown"); michael@0: EventUtils.synthesizeKey("o", {}, window); michael@0: yield shownPromise; michael@0: michael@0: EventUtils.synthesizeKey("VK_DOWN", {}, window); michael@0: michael@0: yield waitForCondition(() => input.value == "one"); michael@0: michael@0: is(input.value, "one", "Input updated correctly"); michael@0: michael@0: EventUtils.synthesizeKey("VK_DOWN", {}, window); michael@0: michael@0: yield waitForCondition(() => input.value == "two"); michael@0: michael@0: is(input.value, "two", "Input updated correctly"); michael@0: michael@0: Browser.closeTab(newTab, { forceClose: true }); michael@0: } michael@0: });