Skip to content

Commit

Permalink
Bug 1125117 - Use the new keywords API in autocomplete. r=ttaubert
Browse files Browse the repository at this point in the history
  • Loading branch information
mak77 committed Mar 26, 2015
1 parent 7e6dfb4 commit 80a46b8
Show file tree
Hide file tree
Showing 27 changed files with 488 additions and 515 deletions.
30 changes: 15 additions & 15 deletions browser/base/content/test/general/browser_action_keyword.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ function* promise_first_result(inputText) {

add_task(function*() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla");
let tabs = [tab];
registerCleanupFunction(() => {
registerCleanupFunction(function* () {
for (let tab of tabs)
gBrowser.removeTab(tab);
PlacesUtils.bookmarks.removeItem(itemId);
yield PlacesUtils.bookmarks.remove(bm);
});

yield promiseTabLoadEvent(tab);

let itemId =
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://example.com/?q=%s"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"test");
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword");
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/?q=%s",
title: "test" });
yield PlacesUtils.keywords.insert({ keyword: "keyword",
url: "http://example.com/?q=%s" });

let result = yield promise_first_result("keyword something");
isnot(result, null, "Expect a keyword result");

is(result.getAttribute("type"), "action keyword", "Expect correct `type` attribute");
is(result.getAttribute("actiontype"), "keyword", "Expect correct `actiontype` attribute");
is(result.getAttribute("title"), "test", "Expect correct title");
is(result.getAttribute("title"), "example.com", "Expect correct title");

// We need to make a real URI out of this to ensure it's normalised for
// comparison.
Expand All @@ -50,9 +50,9 @@ add_task(function*() {
is_element_visible(result._title, "Title element should be visible");
is(result._title.childNodes.length, 1, "Title element should have 1 child");
is(result._title.childNodes[0].nodeName, "#text", "That child should be a text node");
is(result._title.childNodes[0].data, "test", "Node should contain the name of the bookmark");
is(result._title.childNodes[0].data, "example.com", "Node should contain the name of the bookmark");

is_element_visible(result._extra, "Extra element should be visible");
is_element_visible(result._extraBox, "Extra element should be visible");
is(result._extra.childNodes.length, 1, "Title element should have 1 child");
is(result._extra.childNodes[0].nodeName, "span", "That child should be a span node");
let span = result._extra.childNodes[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
add_task(function*() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let itemId =
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://example.com/?q=%s"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"test");
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword");
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/?q=%s",
title: "test" });
yield PlacesUtils.keywords.insert({ keyword: "keyword",
url: "http://example.com/?q=%s" })

registerCleanupFunction(() => {
PlacesUtils.bookmarks.removeItem(itemId);
registerCleanupFunction(function* () {
yield PlacesUtils.bookmarks.remove(bm);
});

yield promiseAutocompleteResultPopup("keyword search");
let result = gURLBar.popup.richlistbox.children[0];

info("Before override");
is_element_hidden(result._url, "URL element should be hidden");
is_element_visible(result._extra, "Extra element should be visible");
is_element_visible(result._extraBox, "Extra element should be visible");

info("During override");
EventUtils.synthesizeKey("VK_SHIFT" , { type: "keydown" });
is_element_hidden(result._url, "URL element should be hidden");
is_element_visible(result._extra, "Extra element should be visible");
is_element_visible(result._extraBox, "Extra element should be visible");

EventUtils.synthesizeKey("VK_SHIFT" , { type: "keyup" });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

add_task(function* () {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

Services.search.addEngineWithDetails("MozSearch", "", "", "", "GET",
"http://example.com/?q={searchTerms}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
**/

add_task(function* () {
// This test is only relevant if UnifiedComplete is enabled.
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let iconURI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABGklEQVQoz2NgGB6AnZ1dUlJSXl4eSDIyMhLW4Ovr%2B%2Fr168uXL69Zs4YoG%2BLi4i5dusTExMTGxsbNzd3f37937976%2BnpmZmagbHR09J49e5YvX66kpATVEBYW9ubNm2nTphkbG7e2tp44cQLIuHfvXm5urpaWFlDKysqqu7v73LlzECMYIiIiHj58mJCQoKKicvXq1bS0NKBgW1vbjh074uPjgeqAXE1NzSdPnvDz84M0AEUvXLgAsW379u1z5swBen3jxo2zZ892cHB4%2BvQp0KlAfwI1cHJyghQFBwfv2rULokFXV%2FfixYu7d%2B8GGqGgoMDKyrpu3br9%2B%2FcDuXl5eVA%2FAEWBfoWHAdAYoNuAYQ0XAeoUERFhGDYAAPoUaT2dfWJuAAAAAElFTkSuQmCC";
Services.search.addEngineWithDetails("MozSearch", iconURI, "moz", "", "GET",
Expand All @@ -20,7 +25,6 @@ add_task(function* () {
Services.search.currentEngine = originalEngine;
let engine = Services.search.getEngineByName("MozSearch");
Services.search.removeEngine(engine);
Services.prefs.clearUserPref("browser.urlbar.unifiedcomplete");

try {
gBrowser.removeTab(tab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

add_task(function*() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let tab = gBrowser.addTab("about:about");
yield promiseTabLoaded(tab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ function is_selected(index) {

add_task(function*() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

registerCleanupFunction(() => PlacesTestUtils.clearHistory());
registerCleanupFunction(function* () {
yield PlacesTestUtils.clearHistory();
});

let visits = [];
repeat(10, i => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ add_task(function*() {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);

registerCleanupFunction(() => {
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
Services.prefs.clearUserPref("browser.urlbar.unifiedcomplete");
yield PlacesUtils.bookmarks.remove(bm);
});

let itemId =
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://example.com/?q=%s"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"test");
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword");
let bm = yield PlacesUtils.bookmarks.insert({ parentGuid: PlacesUtils.unfiledGuid,
url: "http://example.com/?q=%s",
title: "test" });
yield PlacesUtils.keywords.insert({ keyword: "keyword",
url: "http://example.com/?q=%s" });

yield new Promise(resolve => waitForFocus(resolve, window));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

add_task(function*() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
yield promiseTabLoaded(tab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ add_task(function*() {
return;
}

registerCleanupFunction(() => PlacesTestUtils.clearHistory());

yield PlacesTestUtils.clearHistory();
let visits = [];
repeat(10, i => {
visits.push({
Expand All @@ -25,13 +24,18 @@ add_task(function*() {
});
yield PlacesTestUtils.addVisits(visits);

registerCleanupFunction(function* () {
yield PlacesTestUtils.clearHistory();
});

let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
yield promiseTabLoaded(tab);
yield promiseAutocompleteResultPopup("example.com/autocomplete");

let popup = gURLBar.popup;
let results = popup.richlistbox.children;
is(results.length, 10, "Should get 11 results");
let results = popup.richlistbox.children.filter(is_visible);

is(results.length, 10, "Should get 10 results");
is_selected(-1);

info("Key Down to select the next item");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

add_task(function* test_switchtab_override() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}
let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let testURL = "http://example.org/browser/browser/base/content/test/general/dummy_page.html";

Expand Down
37 changes: 20 additions & 17 deletions browser/base/content/test/general/browser_bug1070778.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@ function is_selected(index) {

add_task(function*() {
// This test is only relevant if UnifiedComplete is enabled.
if (!Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete")) {
todo(false, "Stop supporting old autocomplete components.");
return;
}

let ucpref = Services.prefs.getBoolPref("browser.urlbar.unifiedcomplete");
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", true);
registerCleanupFunction(() => {
PlacesUtils.bookmarks.removeFolderChildren(PlacesUtils.unfiledBookmarksFolderId);
Services.prefs.setBoolPref("browser.urlbar.unifiedcomplete", ucpref);
});

let itemId =
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://example.com/?q=%s"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"test");
PlacesUtils.bookmarks.setKeywordForBookmark(itemId, "keyword");
let bookmarks = [];
bookmarks.push((yield PlacesUtils.bookmarks
.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/?q=%s",
title: "test" })));
yield PlacesUtils.keywords.insert({ keyword: "keyword",
url: "http://example.com/?q=%s" });

// This item only needed so we can select the keyword item, select something
// else, then select the keyword item again.
itemId =
PlacesUtils.bookmarks.insertBookmark(PlacesUtils.unfiledBookmarksFolderId,
NetUtil.newURI("http://example.com/keyword"),
PlacesUtils.bookmarks.DEFAULT_INDEX,
"keyword abc");
bookmarks.push((yield PlacesUtils.bookmarks
.insert({ parentGuid: PlacesUtils.bookmarks.unfiledGuid,
url: "http://example.com/keyword",
title: "keyword abc" })));

registerCleanupFunction(function* () {
for (let bm of bookmarks) {
yield PlacesUtils.bookmarks.remove(bm);
}
});

let tab = gBrowser.selectedTab = gBrowser.addTab("about:mozilla", {animate: false});
yield promiseTabLoaded(tab);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ function is_selected(index) {
}

add_task(function*() {
registerCleanupFunction(() => PlacesTestUtils.clearHistory());
registerCleanupFunction(function* () {
yield PlacesTestUtils.clearHistory();
});

yield PlacesTestUtils.clearHistory();
let tabCount = gBrowser.tabs.length;
Expand Down
Loading

0 comments on commit 80a46b8

Please sign in to comment.