From 6a763081019832143c0000ffabbc9f62d177443c Mon Sep 17 00:00:00 2001 From: Blair McBride Date: Mon, 24 Nov 2014 12:19:44 +1300 Subject: [PATCH] Bug 1067903 - Part 3: Update tests to deal with autoselect and textValue. r=mak --HG-- extra : transplant_source : %27%23%DC/%3E%866%CB%AC%FD%87%8C%16hP%28%B8%04%F4O --- browser/base/content/test/general/browser.ini | 4 +- .../test/general/browser_URLBarSetURI.js | 8 +- .../general/browser_action_searchengine.js | 5 +- .../browser_autocomplete_autoselect.js | 59 ++++++++++++++ .../browser_bug1003461-switchtab-override.js | 4 +- ...er_bug1024133-switchtab-override-keynav.js | 15 +--- .../test/general/browser_bug1070778.js | 8 +- .../content/test/general/browser_bug304198.js | 19 +++-- .../content/test/general/browser_bug556061.js | 12 +-- .../test/general/browser_canonizeURL.js | 4 +- .../general/browser_locationBarCommand.js | 10 +-- ...er_removeUnsafeProtocolsFromURLBarPaste.js | 2 +- .../general/browser_urlbarAutoFillTrimURLs.js | 9 ++- .../test/general/browser_urlbarCopying.js | 4 +- .../test/general/browser_urlbarEnter.js | 4 +- .../test/general/browser_urlbarStop.js | 12 +-- .../test/general/browser_urlbarTrimURLs.js | 4 +- browser/base/content/test/general/head.js | 2 + .../sessionstore/test/browser_522545.js | 14 ++-- .../places/tests/PlacesTestUtils.jsm | 76 +++++++++++++++++++ toolkit/components/places/tests/moz.build | 4 + toolkit/content/widgets/autocomplete.xml | 12 ++- 22 files changed, 214 insertions(+), 77 deletions(-) create mode 100644 browser/base/content/test/general/browser_autocomplete_autoselect.js create mode 100644 toolkit/components/places/tests/PlacesTestUtils.jsm diff --git a/browser/base/content/test/general/browser.ini b/browser/base/content/test/general/browser.ini index 613461122694..35237b072789 100644 --- a/browser/base/content/test/general/browser.ini +++ b/browser/base/content/test/general/browser.ini @@ -122,6 +122,8 @@ skip-if = os == "linux" || e10s # Bug 1073339 - Investigate autocomplete test un [browser_alltabslistener.js] [browser_autocomplete_a11y_label.js] skip-if = e10s # Bug 1101993 - times out for unknown reasons when run in the dir (works on its own) +[browser_autocomplete_autoselect.js] +skip-if = os == "linux" || e10s # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s [browser_backButtonFitts.js] skip-if = os != "win" || e10s # The Fitts Law back button is only supported on Windows (bug 571454) / e10s - Bug 1099154: test touches content (attempts to add an event listener directly to the contentWindow) [browser_blob-channelname.js] @@ -289,7 +291,7 @@ skip-if = e10s # Bug 1093155 - tries to use context menu from browser-chrome and skip-if = os == 'win' || e10s # Bug 1056146 - zoom tests use FullZoomHelper and break in e10s [browser_bug1064280_changeUrlInPinnedTab.js] [browser_bug1070778.js] -skip-if = os == "linux" # Bug 1073339 - Investigate autocomplete test unreliability on Linux +skip-if = os == "linux" || e10s # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s [browser_canonizeURL.js] skip-if = e10s # Bug 1094510 - test hits the network in e10s mode only [browser_contentAreaClick.js] diff --git a/browser/base/content/test/general/browser_URLBarSetURI.js b/browser/base/content/test/general/browser_URLBarSetURI.js index f98dbc5f0ac7..e67a6e1fc60b 100644 --- a/browser/base/content/test/general/browser_URLBarSetURI.js +++ b/browser/base/content/test/general/browser_URLBarSetURI.js @@ -31,7 +31,7 @@ let tests = [ function revert(next) { loadTabInWindow(window, function (tab) { gURLBar.handleRevert(); - is(gURLBar.value, "example.com", "URL bar had user/pass stripped after reverting"); + is(gURLBar.textValue, "example.com", "URL bar had user/pass stripped after reverting"); gBrowser.removeTab(tab); next(); }); @@ -44,7 +44,7 @@ let tests = [ loadTabInWindow(win, function () { openToolbarCustomizationUI(function () { closeToolbarCustomizationUI(function () { - is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped after customize"); + is(win.gURLBar.textValue, "example.com", "URL bar had user/pass stripped after customize"); win.close(); next(); }, win); @@ -59,7 +59,7 @@ let tests = [ // error. tab.linkedBrowser.loadURI("http://test1.example.com"); tab.linkedBrowser.stop(); - is(gURLBar.value, "example.com", "URL bar had user/pass stripped after load error"); + is(gURLBar.textValue, "example.com", "URL bar had user/pass stripped after load error"); gBrowser.removeTab(tab); next(); }); @@ -76,7 +76,7 @@ function loadTabInWindow(win, callback) { return; tab.linkedBrowser.removeEventListener("load", listener, true); - is(win.gURLBar.value, "example.com", "URL bar had user/pass stripped initially"); + is(win.gURLBar.textValue, "example.com", "URL bar had user/pass stripped initially"); callback(tab); }, true); } diff --git a/browser/base/content/test/general/browser_action_searchengine.js b/browser/base/content/test/general/browser_action_searchengine.js index 054190805be8..eece0c60a57e 100644 --- a/browser/base/content/test/general/browser_action_searchengine.js +++ b/browser/base/content/test/general/browser_action_searchengine.js @@ -43,11 +43,14 @@ add_task(function* () { let result = yield promise_first_result("open a search"); isnot(result, null, "Should have a result"); + is(result.getAttribute("url"), + `moz-action:searchengine,{"engineName":"MozSearch","input":"open a search","searchQuery":"open a search"}`, + "Result should be a moz-action: for the correct search engine"); is(result.hasAttribute("image"), false, "Result shouldn't have an image attribute"); let tabPromise = promiseTabLoaded(gBrowser.selectedTab); EventUtils.synthesizeMouseAtCenter(result, {}); yield tabPromise; - is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search"); + is(gBrowser.selectedBrowser.currentURI.spec, "http://example.com/?q=open+a+search", "Correct URL should be loaded"); }); diff --git a/browser/base/content/test/general/browser_autocomplete_autoselect.js b/browser/base/content/test/general/browser_autocomplete_autoselect.js new file mode 100644 index 000000000000..ea7289576f58 --- /dev/null +++ b/browser/base/content/test/general/browser_autocomplete_autoselect.js @@ -0,0 +1,59 @@ +function repeat(limit, func) { + for (let i = 0; i < limit; i++) { + func(i); + } +} + +function* promiseAutoComplete(inputText) { + gURLBar.focus(); + gURLBar.value = inputText.slice(0, -1); + EventUtils.synthesizeKey(inputText.slice(-1), {}); + yield promiseSearchComplete(); +} + +function is_selected(index) { + is(gURLBar.popup.richlistbox.selectedIndex, index, `Item ${index + 1} should be selected`); +} + +add_task(function*() { + registerCleanupFunction(promiseClearHistory); + + let visits = []; + repeat(10, i => { + visits.push({ + uri: makeURI("http://example.com/autocomplete/?" + i), + }); + }); + yield PlacesTestUtils.addVisits(visits); + + yield promiseAutoComplete("example.com/autocomplete"); + + let popup = gURLBar.popup; + let results = popup.richlistbox.children; + // 1 extra for the current search engine match + is(results.length, 11, "Should get 11 results"); + is_selected(0); + + info("Key Down to select the next item"); + EventUtils.synthesizeKey("VK_DOWN", {}); + is_selected(1); + + info("Key Down 11 times should wrap around all the way around"); + repeat(11, () => EventUtils.synthesizeKey("VK_DOWN", {})); + is_selected(1); + + info("Key Up 11 times should wrap around the other way"); + repeat(11, () => EventUtils.synthesizeKey("VK_UP", {})); + is_selected(1); + + info("Page Up will go up the list, but not wrap"); + EventUtils.synthesizeKey("VK_PAGE_UP", {}) + is_selected(0); + + info("Page Up again will wrap around to the end of the list"); + EventUtils.synthesizeKey("VK_PAGE_UP", {}) + is_selected(10); + + EventUtils.synthesizeKey("VK_ESCAPE", {}); + yield promisePopupHidden(gURLBar.popup); +}); diff --git a/browser/base/content/test/general/browser_bug1003461-switchtab-override.js b/browser/base/content/test/general/browser_bug1003461-switchtab-override.js index 1d4ee0c0f390..1a71a028d5e8 100644 --- a/browser/base/content/test/general/browser_bug1003461-switchtab-override.js +++ b/browser/base/content/test/general/browser_bug1003461-switchtab-override.js @@ -35,7 +35,7 @@ add_task(function* test_switchtab_override() { onSearchComplete.apply(gURLBar); deferred.resolve(); } - + gURLBar.focus(); gURLBar.value = "dummy_pag"; EventUtils.synthesizeKey("e" , {}); @@ -43,7 +43,6 @@ add_task(function* test_switchtab_override() { info("Select second autocomplete popup entry"); EventUtils.synthesizeKey("VK_DOWN" , {}); - EventUtils.synthesizeKey("VK_DOWN" , {}); ok(/moz-action:switchtab/.test(gURLBar.value), "switch to tab entry found"); info("Override switch-to-tab"); @@ -61,6 +60,7 @@ add_task(function* test_switchtab_override() { EventUtils.synthesizeKey("VK_SHIFT" , { type: "keydown" }); EventUtils.synthesizeKey("VK_RETURN" , { }); + info(`gURLBar.value = ${gURLBar.value}`); EventUtils.synthesizeKey("VK_SHIFT" , { type: "keyup" }); yield deferred.promise; diff --git a/browser/base/content/test/general/browser_bug1024133-switchtab-override-keynav.js b/browser/base/content/test/general/browser_bug1024133-switchtab-override-keynav.js index 02082f1eb939..2a5fb0b72657 100644 --- a/browser/base/content/test/general/browser_bug1024133-switchtab-override-keynav.js +++ b/browser/base/content/test/general/browser_bug1024133-switchtab-override-keynav.js @@ -21,26 +21,13 @@ add_task(function* test_switchtab_override_keynav() { return promiseClearHistory(); }); - info("Wait for autocomplete") - let searchDeferred = Promise.defer(); - let onSearchComplete = gURLBar.onSearchComplete; - registerCleanupFunction(() => { - gURLBar.onSearchComplete = onSearchComplete; - }); - gURLBar.onSearchComplete = function () { - ok(gURLBar.popupOpen, "The autocomplete popup is correctly open"); - onSearchComplete.apply(gURLBar); - searchDeferred.resolve(); - } - gURLBar.focus(); gURLBar.value = "dummy_pag"; EventUtils.synthesizeKey("e" , {}); - yield searchDeferred.promise; + yield promiseSearchComplete(); info("Select second autocomplete popup entry"); EventUtils.synthesizeKey("VK_DOWN" , {}); - EventUtils.synthesizeKey("VK_DOWN" , {}); ok(/moz-action:switchtab/.test(gURLBar.value), "switch to tab entry found"); info("Shift+left on switch-to-tab entry"); diff --git a/browser/base/content/test/general/browser_bug1070778.js b/browser/base/content/test/general/browser_bug1070778.js index 31ee7b19551a..81b6d2c0b056 100644 --- a/browser/base/content/test/general/browser_bug1070778.js +++ b/browser/base/content/test/general/browser_bug1070778.js @@ -17,9 +17,8 @@ add_task(function*() { if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) return; - let itemIds = []; registerCleanupFunction(() => { - itemIds.forEach(PlacesUtils.bookmarks.removeItem); + PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId); }); let itemId = @@ -28,7 +27,6 @@ add_task(function*() { PlacesUtils.bookmarks.DEFAULT_INDEX, "test"); PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword"); - itemIds.push(itemId); // This item only needed so we can select the keyword item, select something // else, then select the keyword item again. @@ -37,12 +35,10 @@ add_task(function*() { NetUtil.newURI("http://example.com/keyword"), PlacesUtils.bookmarks.DEFAULT_INDEX, "keyword abc"); - itemIds.push(itemId); yield promiseAutoComplete("keyword a"); - // Select keyword item - EventUtils.synthesizeKey("VK_DOWN", {}); + // First item should already be selected is_selected(0); // Select next one (important!) EventUtils.synthesizeKey("VK_DOWN", {}); diff --git a/browser/base/content/test/general/browser_bug304198.js b/browser/base/content/test/general/browser_bug304198.js index 044c2f9f5973..bd8c104e043c 100644 --- a/browser/base/content/test/general/browser_bug304198.js +++ b/browser/base/content/test/general/browser_bug304198.js @@ -21,16 +21,15 @@ function test() { function cycleTabs() { gBrowser.selectedTab = fullURLTab; - is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); + is(gURLBar.textValue, testURL, 'gURLBar.textValue should be testURL after switching back to fullURLTab'); gBrowser.selectedTab = partialURLTab; - is(gURLBar.value, testPartialURL, 'gURLBar.value should be testPartialURL after switching back to partialURLTab'); - + is(gURLBar.textValue, testPartialURL, 'gURLBar.textValue should be testPartialURL after switching back to partialURLTab'); gBrowser.selectedTab = deletedURLTab; - is(gURLBar.value, '', 'gURLBar.value should be "" after switching back to deletedURLTab'); + is(gURLBar.textValue, '', 'gURLBar.textValue should be "" after switching back to deletedURLTab'); gBrowser.selectedTab = fullURLTab; - is(gURLBar.value, testURL, 'gURLBar.value should be testURL after switching back to fullURLTab'); + is(gURLBar.textValue, testURL, 'gURLBar.textValue should be testURL after switching back to fullURLTab'); } // function borrowed from browser_bug386835.js @@ -59,13 +58,13 @@ function test() { function prepareDeletedURLTab(cb) { gBrowser.selectedTab = deletedURLTab; - is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to deletedURLTab'); + is(gURLBar.textValue, testURL, 'gURLBar.textValue should be testURL after initial switch to deletedURLTab'); // simulate the user removing the whole url from the location bar gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", true); urlbarBackspace(function () { - is(gURLBar.value, "", 'gURLBar.value should be "" (just set)'); + is(gURLBar.textValue, "", 'gURLBar.textValue should be "" (just set)'); if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); cb(); @@ -74,13 +73,13 @@ function test() { function prepareFullURLTab(cb) { gBrowser.selectedTab = fullURLTab; - is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to fullURLTab'); + is(gURLBar.textValue, testURL, 'gURLBar.textValue should be testURL after initial switch to fullURLTab'); cb(); } function preparePartialURLTab(cb) { gBrowser.selectedTab = partialURLTab; - is(gURLBar.value, testURL, 'gURLBar.value should be testURL after initial switch to partialURLTab'); + is(gURLBar.textValue, testURL, 'gURLBar.textValue should be testURL after initial switch to partialURLTab'); // simulate the user removing part of the url from the location bar gPrefService.setBoolPref("browser.urlbar.clickSelectsAll", false); @@ -91,7 +90,7 @@ function test() { if (deleted < charsToDelete) { urlbarBackspace(arguments.callee); } else { - is(gURLBar.value, testPartialURL, "gURLBar.value should be testPartialURL (just set)"); + is(gURLBar.textValue, testPartialURL, "gURLBar.textValue should be testPartialURL (just set)"); if (gPrefService.prefHasUserValue("browser.urlbar.clickSelectsAll")) gPrefService.clearUserPref("browser.urlbar.clickSelectsAll"); cb(); diff --git a/browser/base/content/test/general/browser_bug556061.js b/browser/base/content/test/general/browser_bug556061.js index 1a0563d5a312..61260d122bde 100644 --- a/browser/base/content/test/general/browser_bug556061.js +++ b/browser/base/content/test/general/browser_bug556061.js @@ -31,8 +31,8 @@ let tests = [ setup: function() { gURLBar.value = testActionURL; gURLBar.valueIsTyped = true; - is(gURLBar._value, testActionURL, "gURLBar starts with the correct real value"); - is(gURLBar.value, testURL, "gURLBar starts with the correct display value"); + is(gURLBar.value, testActionURL, "gURLBar starts with the correct real value"); + is(gURLBar.textValue, testURL, "gURLBar starts with the correct display value"); // Focus the urlbar so we can select it all & copy gURLBar.focus(); @@ -40,7 +40,7 @@ let tests = [ goDoCommand("cmd_copy"); }, success: function() { - is(gURLBar._value, testActionURL, "gURLBar.value didn't change when copying"); + is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); } }, { @@ -52,7 +52,7 @@ let tests = [ goDoCommand("cmd_copy"); }, success: function() { - is(gURLBar._value, testActionURL, "gURLBar.value didn't change when copying"); + is(gURLBar.value, testActionURL, "gURLBar.value didn't change when copying"); } }, { @@ -74,8 +74,8 @@ let tests = [ gURLBar.value = testActionURL; gURLBar.valueIsTyped = true; // Sanity check that we have the right value - is(gURLBar._value, testActionURL, "gURLBar starts with the correct real value"); - is(gURLBar.value, testURL, "gURLBar starts with the correct display value"); + is(gURLBar.value, testActionURL, "gURLBar starts with the correct real value"); + is(gURLBar.textValue, testURL, "gURLBar starts with the correct display value"); // Now just select part of the value & cut that. gURLBar.selectionStart = testURL.length - 10; diff --git a/browser/base/content/test/general/browser_canonizeURL.js b/browser/base/content/test/general/browser_canonizeURL.js index 983d0941ce1b..48fd814440fe 100644 --- a/browser/base/content/test/general/browser_canonizeURL.js +++ b/browser/base/content/test/general/browser_canonizeURL.js @@ -45,10 +45,12 @@ function testNext() { gURLBar.addEventListener("focus", function onFocus() { gURLBar.removeEventListener("focus", onFocus); + gURLBar.inputField.value = inputValue.slice(0, -1); + EventUtils.synthesizeKey(inputValue.slice(-1) , {}); EventUtils.synthesizeKey("VK_RETURN", { shiftKey: true }); }); gBrowser.selectedBrowser.focus(); - gURLBar.inputField.value = inputValue; gURLBar.focus(); + } diff --git a/browser/base/content/test/general/browser_locationBarCommand.js b/browser/base/content/test/general/browser_locationBarCommand.js index fe70300f9e80..876eb12d2a48 100644 --- a/browser/base/content/test/general/browser_locationBarCommand.js +++ b/browser/base/content/test/general/browser_locationBarCommand.js @@ -37,10 +37,10 @@ function runShiftLeftClickTest() { addPageShowListener(aWindow.gBrowser.selectedBrowser, function() { executeSoon(function () { info("URL should be loaded in a new window"); - is(gURLBar.value, "", "Urlbar reverted to original value"); + is(gURLBar.value, "", "Urlbar reverted to original value"); is(gFocusManager.focusedElement, null, "There should be no focused element"); is(gFocusManager.focusedWindow, aWindow.gBrowser.contentWindow, "Content window should be focused"); - is(aWindow.gURLBar.value, TEST_VALUE, "New URL is loaded in new window"); + is(aWindow.gURLBar.textValue, TEST_VALUE, "New URL is loaded in new window"); aWindow.close(); @@ -61,7 +61,7 @@ function runNextTest() { finish(); return; } - + info("Running test: " + test.desc); // Tab will be blank if test.startValue is null let tab = gBrowser.selectedTab = gBrowser.addTab(test.startValue); @@ -106,7 +106,7 @@ let gTests = [ is(gURLBar.value, "", "Urlbar reverted to original value"); ok(!gURLBar.focused, "Urlbar is no longer focused after urlbar command"); is(gBrowser.selectedTab, aTab, "Focus did not change to the new tab"); - + // Select the new background tab gBrowser.selectedTab = gBrowser.selectedTab.nextSibling; is(gURLBar.value, TEST_VALUE, "New URL is loaded in new tab"); @@ -143,7 +143,7 @@ function triggerCommand(aClick, aEvent) { if (aClick) { is(gURLBar.getAttribute("pageproxystate"), "invalid", "page proxy state must be invalid for go button to be visible"); - EventUtils.synthesizeMouseAtCenter(gGoButton, aEvent); + EventUtils.synthesizeMouseAtCenter(gGoButton, aEvent); } else EventUtils.synthesizeKey("VK_RETURN", aEvent); diff --git a/browser/base/content/test/general/browser_removeUnsafeProtocolsFromURLBarPaste.js b/browser/base/content/test/general/browser_removeUnsafeProtocolsFromURLBarPaste.js index f66686974416..d0cff4fe755a 100644 --- a/browser/base/content/test/general/browser_removeUnsafeProtocolsFromURLBarPaste.js +++ b/browser/base/content/test/general/browser_removeUnsafeProtocolsFromURLBarPaste.js @@ -41,7 +41,7 @@ function testNext() { gURLBar.focus(); paste(inputValue, function() { - is(gURLBar.value, expectedURL, "entering '" + inputValue + "' strips relevant bits."); + is(gURLBar.textValue, expectedURL, "entering '" + inputValue + "' strips relevant bits."); setTimeout(testNext, 0); }); diff --git a/browser/base/content/test/general/browser_urlbarAutoFillTrimURLs.js b/browser/base/content/test/general/browser_urlbarAutoFillTrimURLs.js index e9d6bbe39e82..0d6208de3e03 100644 --- a/browser/base/content/test/general/browser_urlbarAutoFillTrimURLs.js +++ b/browser/base/content/test/general/browser_urlbarAutoFillTrimURLs.js @@ -27,7 +27,7 @@ function test() { }; let history = Cc["@mozilla.org/browser/history;1"] .getService(Ci.mozIAsyncHistory); - history.updatePlaces({ uri: NetUtil.newURI("http://www.autofilltrimurl.com/") + history.updatePlaces({ uri: NetUtil.newURI("http://www.autofilltrimurl.com/whatever") , visits: [ { transitionType: Ci.nsINavHistoryService.TRANSITION_TYPED , visitDate: Date.now() * 1000 } ] @@ -44,7 +44,8 @@ function continue_test() { EventUtils.synthesizeKey(aTyped.substr(-1), {}); waitForSearchComplete(function () { - is(gURLBar.value, aExpected, "trim was applied correctly"); + info(`Got value: ${gURLBar.value}`); + is(gURLBar.value, aExpected, "Autofilled value is as expected"); aCallback(); }); } @@ -53,9 +54,9 @@ function continue_test() { test_autoFill("http://au", "http://autofilltrimurl.com/", function () { test_autoFill("http://www.autofilltrimurl.com", "http://www.autofilltrimurl.com/", function () { // Now ensure selecting from the popup correctly trims. - is(gURLBar.controller.matchCount, 1, "Found the expected number of matches"); + is(gURLBar.controller.matchCount, 2, "Found the expected number of matches"); EventUtils.synthesizeKey("VK_DOWN", {}); - is(gURLBar.value, "www.autofilltrimurl.com", "trim was applied correctly"); + is(gURLBar.textValue, "www.autofilltrimurl.com/whatever", "trim was applied correctly"); gURLBar.closePopup(); waitForClearHistory(finish); }); diff --git a/browser/base/content/test/general/browser_urlbarCopying.js b/browser/base/content/test/general/browser_urlbarCopying.js index 1d72288d0b34..afb76dd45753 100644 --- a/browser/base/content/test/general/browser_urlbarCopying.js +++ b/browser/base/content/test/general/browser_urlbarCopying.js @@ -156,7 +156,7 @@ function runTest(test, cb) { function doCheck() { if (test.setURL || test.loadURL) { gURLBar.valueIsTyped = !!test.setURL; - is(gURLBar.value, test.expectedURL, "url bar value set"); + is(gURLBar.textValue, test.expectedURL, "url bar value set"); } testCopy(test.copyVal, test.copyExpected, cb); @@ -180,7 +180,7 @@ function testCopy(copyVal, targetValue, cb) { let endBracket = copyVal.indexOf(">"); if (startBracket == -1 || endBracket == -1 || startBracket > endBracket || - copyVal.replace("<", "").replace(">", "") != gURLBar.value) { + copyVal.replace("<", "").replace(">", "") != gURLBar.textValue) { ok(false, "invalid copyVal: " + copyVal); } gURLBar.selectionStart = startBracket; diff --git a/browser/base/content/test/general/browser_urlbarEnter.js b/browser/base/content/test/general/browser_urlbarEnter.js index defea1396a2a..951c182c7692 100644 --- a/browser/base/content/test/general/browser_urlbarEnter.js +++ b/browser/base/content/test/general/browser_urlbarEnter.js @@ -51,12 +51,12 @@ let gTests = [ ] function checkCurrent(aTab) { - is(gURLBar.value, TEST_VALUE, "Urlbar should preserve the value on return keypress"); + is(gURLBar.textValue, TEST_VALUE, "Urlbar should preserve the value on return keypress"); is(gBrowser.selectedTab, aTab, "New URL was loaded in the current tab"); } function checkNewTab(aTab) { - is(gURLBar.value, TEST_VALUE, "Urlbar should preserve the value on return keypress"); + is(gURLBar.textValue, TEST_VALUE, "Urlbar should preserve the value on return keypress"); isnot(gBrowser.selectedTab, aTab, "New URL was loaded in a new tab"); } diff --git a/browser/base/content/test/general/browser_urlbarStop.js b/browser/base/content/test/general/browser_urlbarStop.js index 2d9a87a71f73..5cb7fc3f3f56 100644 --- a/browser/base/content/test/general/browser_urlbarStop.js +++ b/browser/base/content/test/general/browser_urlbarStop.js @@ -11,23 +11,23 @@ function test() { function onload() { gBrowser.selectedBrowser.removeEventListener("load", onload, true); - is(gURLBar.value, gURLBar.trimValue(goodURL), "location bar reflects loaded page"); + is(gURLBar.textValue, gURLBar.trimValue(goodURL), "location bar reflects loaded page"); typeAndSubmit(badURL); - is(gURLBar.value, gURLBar.trimValue(badURL), "location bar reflects loading page"); + is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects loading page"); gBrowser.contentWindow.stop(); - is(gURLBar.value, gURLBar.trimValue(goodURL), "location bar reflects loaded page after stop()"); + is(gURLBar.textValue, gURLBar.trimValue(goodURL), "location bar reflects loaded page after stop()"); gBrowser.removeCurrentTab(); gBrowser.selectedTab = gBrowser.addTab("about:blank"); - is(gURLBar.value, "", "location bar is empty"); + is(gURLBar.textValue, "", "location bar is empty"); typeAndSubmit(badURL); - is(gURLBar.value, gURLBar.trimValue(badURL), "location bar reflects loading page"); + is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects loading page"); gBrowser.contentWindow.stop(); - is(gURLBar.value, gURLBar.trimValue(badURL), "location bar reflects stopped page in an empty tab"); + is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects stopped page in an empty tab"); gBrowser.removeCurrentTab(); finish(); diff --git a/browser/base/content/test/general/browser_urlbarTrimURLs.js b/browser/base/content/test/general/browser_urlbarTrimURLs.js index c68f595bef18..f3276022d24f 100644 --- a/browser/base/content/test/general/browser_urlbarTrimURLs.js +++ b/browser/base/content/test/general/browser_urlbarTrimURLs.js @@ -5,7 +5,7 @@ function testVal(originalValue, targetValue) { gURLBar.value = originalValue; gURLBar.valueIsTyped = false; - is(gURLBar.value, targetValue || originalValue, "url bar value set"); + is(gURLBar.textValue, targetValue || originalValue, "url bar value set"); } function test() { @@ -96,7 +96,7 @@ function test() { function testCopy(originalValue, targetValue, cb) { waitForClipboard(targetValue, function () { - is(gURLBar.value, originalValue, "url bar copy value set"); + is(gURLBar.textValue, originalValue, "url bar copy value set"); gURLBar.focus(); gURLBar.select(); diff --git a/browser/base/content/test/general/head.js b/browser/base/content/test/general/head.js index 559b2cd8b47d..bce905e48d97 100644 --- a/browser/base/content/test/general/head.js +++ b/browser/base/content/test/general/head.js @@ -6,6 +6,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", "resource://gre/modules/PlacesUtils.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "PlacesTestUtils", + "resource://testing-common/PlacesTestUtils.jsm"); function closeAllNotifications () { let notificationBox = document.getElementById("global-notificationbox"); diff --git a/browser/components/sessionstore/test/browser_522545.js b/browser/components/sessionstore/test/browser_522545.js index ddabd976f969..a002b2b921db 100644 --- a/browser/components/sessionstore/test/browser_522545.js +++ b/browser/components/sessionstore/test/browser_522545.js @@ -193,16 +193,16 @@ function test() { is(browser.userTypedValue, null, "userTypedValue is empty to start"); is(browser.userTypedClear, 0, "userTypedClear is 0 to start"); - gURLBar.value = "example.org"; - let event = document.createEvent("Events"); - event.initEvent("input", true, false); - gURLBar.dispatchEvent(event); + let inputText = "example.org"; + gURLBar.focus(); + gURLBar.value = inputText.slice(0, -1); + EventUtils.synthesizeKey(inputText.slice(-1) , {}); executeSoon(function () { is(browser.userTypedValue, "example.org", - "userTypedValue was set when changing gURLBar.value"); + "userTypedValue was set when changing URLBar value"); is(browser.userTypedClear, 0, - "userTypedClear was not changed when changing gURLBar.value"); + "userTypedClear was not changed when changing URLBar value"); // Now make sure ss gets these values too let newState = JSON.parse(ss.getBrowserState()); @@ -235,7 +235,7 @@ function test() { "userTypedValue was null after loading a URI"); is(browser.userTypedClear, 0, "userTypeClear reset to 0"); - is(gURLBar.value, gURLBar.trimValue("http://example.com/"), + is(gURLBar.textValue, gURLBar.trimValue("http://example.com/"), "Address bar's value set after loading URI"); runNextTest(); }); diff --git a/toolkit/components/places/tests/PlacesTestUtils.jsm b/toolkit/components/places/tests/PlacesTestUtils.jsm new file mode 100644 index 000000000000..3ee74896168f --- /dev/null +++ b/toolkit/components/places/tests/PlacesTestUtils.jsm @@ -0,0 +1,76 @@ +"use strict"; + +this.EXPORTED_SYMBOLS = [ + "PlacesTestUtils", +]; + +const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; + +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", + "resource://gre/modules/PlacesUtils.jsm"); + + +this.PlacesTestUtils = Object.freeze({ + /** + * Asynchronously adds visits to a page. + * + * @param aPlaceInfo + * Can be an nsIURI, in such a case a single LINK visit will be added. + * Otherwise can be an object describing the visit to add, or an array + * of these objects: + * { uri: nsIURI of the page, + * [optional] transition: one of the TRANSITION_* from nsINavHistoryService, + * [optional] title: title of the page, + * [optional] visitDate: visit date in microseconds from the epoch + * [optional] referrer: nsIURI of the referrer for this visit + * } + * + * @return {Promise} + * @resolves When all visits have been added successfully. + * @rejects JavaScript exception. + */ + addVisits(placeInfo) { + return new Promise((resolve, reject) => { + let places = []; + if (placeInfo instanceof Ci.nsIURI) { + places.push({ uri: placeInfo }); + } + else if (Array.isArray(placeInfo)) { + places = places.concat(placeInfo); + } else { + places.push(placeInfo) + } + + // Create mozIVisitInfo for each entry. + let now = Date.now(); + for (let place of places) { + if (typeof place.title != "string") { + place.title = "test visit for " + place.uri.spec; + } + place.visits = [{ + transitionType: place.transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK + : place.transition, + visitDate: place.visitDate || (now++) * 1000, + referrerURI: place.referrer + }]; + } + + PlacesUtils.asyncHistory.updatePlaces( + places, + { + handleError: function AAV_handleError(resultCode, placeInfo) { + let ex = new Components.Exception("Unexpected error in adding visits.", + resultCode); + reject(ex); + }, + handleResult: function () {}, + handleCompletion: function UP_handleCompletion() { + resolve(); + } + } + ); + }); + }, +}); diff --git a/toolkit/components/places/tests/moz.build b/toolkit/components/places/tests/moz.build index 1cd63261dbc3..d4781e4d3c80 100644 --- a/toolkit/components/places/tests/moz.build +++ b/toolkit/components/places/tests/moz.build @@ -6,6 +6,10 @@ TEST_DIRS += ['cpp'] +TESTING_JS_MODULES += [ + 'PlacesTestUtils.jsm', +] + XPCSHELL_TESTS_MANIFESTS += [ 'autocomplete/xpcshell.ini', 'bookmarks/xpcshell.ini', diff --git a/toolkit/content/widgets/autocomplete.xml b/toolkit/content/widgets/autocomplete.xml index aa1730d9f229..487a4e9bec6f 100644 --- a/toolkit/content/widgets/autocomplete.xml +++ b/toolkit/content/widgets/autocomplete.xml @@ -1129,7 +1129,7 @@ extends="chrome://global/content/bindings/popup.xml#popup"> // Process maxRows per chunk to improve performance and user experience for (let i = 0; i < this.maxRows; i++) { if (this._currentIndex >= matchCount) - return; + break; var item; @@ -1185,8 +1185,14 @@ extends="chrome://global/content/bindings/popup.xml#popup"> this._currentIndex++; } - // yield after each batch of items so that typing the url bar is responsive - setTimeout(function (self) { self._appendCurrentResult(); }, 0, this); + if (typeof this.onResultsAdded == "function") + this.onResultsAdded(); + + if (this._currentIndex < matchCount) { + // yield after each batch of items so that typing the url bar is + // responsive + setTimeout(function (self) { self._appendCurrentResult(); }, 0, this); + } ]]>