Bug 1101670 - UITour: ability to set a search term and show the search popup. r=dolske

This commit is contained in:
Felipe Gomes 2014-11-21 19:19:31 -02:00
parent 798f4334cb
commit a5ca978c20
4 changed files with 89 additions and 2 deletions

View File

@ -629,6 +629,12 @@
]]></body>
</method>
<method name="inputChanged">
<body><![CDATA[
this.updateGoButtonVisibility();
]]></body>
</method>
<method name="updateGoButtonVisibility">
<body><![CDATA[
document.getAnonymousElementByAttribute(this, "anonid",
@ -657,8 +663,8 @@
</method>
</implementation>
<handlers>
<handler event="input" action="this.updateGoButtonVisibility();"/>
<handler event="drop" action="this.updateGoButtonVisibility();"/>
<handler event="input" action="this.inputChanged();"/>
<handler event="drop" action="this.inputChanged();"/>
<handler event="focus">
<![CDATA[
if (this._textbox.value)

View File

@ -527,6 +527,36 @@ this.UITour = {
enginePromise.catch(Cu.reportError);
break;
}
case "setSearchTerm": {
let targetPromise = this.getTarget(window, "search");
targetPromise.then(target => {
let searchbar = target.node;
searchbar.value = data.term;
searchbar.inputChanged();
}).then(null, Cu.reportError);
break;
}
case "openSearchPanel": {
let targetPromise = this.getTarget(window, "search");
targetPromise.then(target => {
let searchbar = target.node;
if (searchbar.textbox.open) {
this.sendPageCallback(messageManager, data.callbackID);
} else {
let onPopupShown = () => {
searchbar.textbox.popup.removeEventListener("popupshown", onPopupShown);
this.sendPageCallback(messageManager, data.callbackID);
};
searchbar.textbox.popup.addEventListener("popupshown", onPopupShown);
searchbar.openSuggestionsPanel();
}
}).then(null, Cu.reportError);
break;
}
}
if (!window.gMultiProcessBrowser) { // Non-e10s. See bug 1089000.

View File

@ -157,4 +157,43 @@ let tests = [
});
});
},
function test_setSearchTerm(done) {
const TERM = "UITour Search Term";
gContentAPI.setSearchTerm(TERM);
let searchbar = document.getElementById("searchbar");
// The UITour gets to the searchbar element through a promise, so the value setting
// only happens after a tick.
waitForCondition(() => searchbar.value == TERM, done, "Correct term set");
},
function test_clearSearchTerm(done) {
gContentAPI.setSearchTerm("");
let searchbar = document.getElementById("searchbar");
// The UITour gets to the searchbar element through a promise, so the value setting
// only happens after a tick.
waitForCondition(() => searchbar.value == "", done, "Search term cleared");
},
function test_openSearchPanel(done) {
let searchbar = document.getElementById("searchbar");
// If suggestions are enabled, the panel will attempt to use the network to connect
// to the suggestions provider, causing the test suite to fail.
Services.prefs.setBoolPref("browser.search.suggest.enabled", false);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.search.suggest.enabled");
});
ok(!searchbar.textbox.open, "Popup starts as closed");
gContentAPI.openSearchPanel(() => {
ok(searchbar.textbox.open, "Popup was opened");
searchbar.textbox.closePopup();
ok(!searchbar.textbox.open, "Popup was closed");
done();
});
},
];

View File

@ -213,4 +213,16 @@ if (typeof Mozilla == 'undefined') {
});
};
Mozilla.UITour.setSearchTerm = function(term) {
_sendEvent('setSearchTerm', {
term: term
});
};
Mozilla.UITour.openSearchPanel = function(callback) {
_sendEvent('openSearchPanel', {
callbackID: _waitForCallback(callback)
});
};
})();