Bug 1293197 - make sure that toggling Entire Words mode also retriggers the active search. Also fixes a JS error that crept in recently. r?jaws
MozReview-Commit-ID: DcXhhRxk3Mw
--- a/toolkit/content/tests/chrome/findbar_window.xul
+++ b/toolkit/content/tests/chrome/findbar_window.xul
@@ -147,16 +147,17 @@
yield openFindbar();
yield testFailedStringReset();
gFindBar.close();
yield testQuickFindClose();
// TODO: This doesn't seem to work when the findbar is connected to a
// remote browser element.
if (!gBrowser.hasAttribute("remote"))
yield testFindAgainNotFound();
+ yield testToggleEntireWord();
}
function* testFindbarSelection() {
function checkFindbarState(aTestName, aExpSelection) {
ok(!gFindBar.hidden, "testFindbarSelection: failed to open findbar: " + aTestName);
ok(document.commandDispatcher.focusedElement == gFindBar._findField.inputField,
"testFindbarSelection: find field is not focused: " + aTestName);
if (!gHasFindClipboard) {
@@ -230,19 +231,19 @@
};
setTimeout(_delayedCheckStatusText, 100);
});
}
function promiseFindResult() {
return new Promise(resolve => {
let listener = {
- onFindResult: function() {
+ onFindResult: function(result) {
gFindBar.browser.finder.removeResultListener(listener);
- resolve();
+ resolve(result);
}
};
gFindBar.browser.finder.addResultListener(listener);
});
}
function promiseMatchesCountResult() {
return new Promise(resolve => {
@@ -645,16 +646,34 @@
yield enterStringIntoFindField(SEARCH_TEXT);
gFindBar.close();
ok(gFindBar.hidden, "The findbar is closed.");
promise = promiseFindResult();
gFindBar.onFindAgainCommand();
yield promise;
ok(gFindBar.hidden, "Successful Find Again leaves the find bar closed.");
}
+
+ function* testToggleEntireWord() {
+ yield openFindbar();
+ let promise = promiseFindResult();
+ yield enterStringIntoFindField("Tex", false);
+ let result = yield promise;
+ is(result.result, Ci.nsITypeAheadFind.FIND_FOUND, "Text should be found");
+
+ yield new Promise(resolve => setTimeout(resolve, ITERATOR_TIMEOUT));
+ promise = promiseFindResult();
+ let check = gFindBar.getElement("find-entire-word");
+ check.click();
+ result = yield promise;
+ is(result.result, Ci.nsITypeAheadFind.FIND_NOTFOUND, "Text should NOT be found");
+
+ check.click();
+ gFindBar.close(true);
+ }
]]></script>
<commandset>
<command id="cmd_find" oncommand="document.getElementById('FindToolbar').onFindCommand();"/>
</commandset>
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
<browser type="content-primary" flex="1" id="content-remote" remote="true" src="about:blank"/>
<findbar id="FindToolbar" browserid="content"/>
--- a/toolkit/content/widgets/findbar.xml
+++ b/toolkit/content/widgets/findbar.xml
@@ -194,17 +194,17 @@
oncommand="_setCaseSensitivity(this.checked ? 1 : 0);"
type="checkbox"
xbl:inherits="accesskey=matchcaseaccesskey"/>
<xul:toolbarbutton anonid="find-entire-word"
class="findbar-entire-word findbar-button tabbable"
label="&entireWord.label;"
accesskey="&entireWord.accesskey;"
tooltiptext="&entireWord.tooltiptext;"
- oncommand="_setEntireWord(this.checked);"
+ oncommand="toggleEntireWord(this.checked);"
type="checkbox"
xbl:inherits="accesskey=entirewordaccesskey"/>
<xul:label anonid="match-case-status" class="findbar-find-fast"/>
<xul:label anonid="entire-word-status" class="findbar-find-fast"/>
<xul:label anonid="found-matches" class="findbar-find-fast found-matches" hidden="true"/>
<xul:image anonid="find-status-icon" class="findbar-find-fast find-status-icon"/>
<xul:description anonid="find-status"
control="findbar-textbox"
@@ -338,19 +338,17 @@
case "accessibility.typeaheadfind.linksonly":
this._self._typeAheadLinksOnly = prefsvc.getBoolPref(aPrefName);
break;
case "accessibility.typeaheadfind.casesensitive":
this._self._setCaseSensitivity(prefsvc.getIntPref(aPrefName));
break;
case "findbar.entireword":
this._self._entireWord = prefsvc.getBoolPref(aPrefName);
- this._self._updateEntireWord();
- // Update the matches count.
- this._updateMatchesCount(this.nsITypeAheadFind.FIND_FOUND);
+ this._self.toggleEntireWord(this._self._entireWord, true);
break;
case "findbar.highlightAll":
this._self.toggleHighlight(prefsvc.getBoolPref(aPrefName), true);
break;
case "findbar.modalHighlight":
this._self._useModalHighlight = prefsvc.getBoolPref(aPrefName);
if (this._self.browser.finder)
this._self.browser.finder.onModalHighlightChange(this._self._useModalHighlight);
@@ -633,17 +631,17 @@
this._dispatchFindEvent("casesensitivitychange");
]]></body>
</method>
<!--
- Updates the entire-word mode of the findbar and its UI.
-->
- <method name="_updateEntireWord">
+ <method name="_setEntireWord">
<body><![CDATA[
let entireWord = this._entireWord;
let checkbox = this.getElement("find-entire-word");
let statusLabel = this.getElement("entire-word-status");
checkbox.checked = entireWord;
statusLabel.value = entireWord ? this._entireWordStr : "";
@@ -657,27 +655,28 @@
]]></body>
</method>
<!--
- Sets the findbar entire-word mode
- @param aEntireWord (boolean)
- Whether or not entire-word mode should be turned on.
-->
- <method name="_setEntireWord">
+ <method name="toggleEntireWord">
<parameter name="aEntireWord"/>
+ <parameter name="aFromPrefObserver"/>
<body><![CDATA[
- let prefsvc =
- Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
+ if (!aFromPrefObserver) {
+ // Just set the pref; our observer will change the find bar behavior.
+ this._prefsvc.setBoolPref("findbar.entireword", aEntireWord);
+ return;
+ }
- // Just set the pref; our observer will change the find bar behavior.
- prefsvc.setBoolPref("findbar.entireword", aEntireWord);
-
- this._maybeHighlightAll();
+ this._findFailedString = null;
+ this._find();
]]></body>
</method>
<field name="_strBundle">null</field>
<property name="strBundle">
<getter><![CDATA[
if (!this._strBundle) {
this._strBundle =
@@ -966,17 +965,17 @@
if (node == wrapper || node == foundMatches)
continue;
node.hidden = showMinimalUI;
}
this.getElement("find-next").hidden =
this.getElement("find-previous").hidden = showMinimalUI;
foundMatches.hidden = showMinimalUI || !foundMatches.value;
this._updateCaseSensitivity();
- this._updateEntireWord();
+ this._setEntireWord();
this._setHighlightAll();
if (showMinimalUI)
this._findField.classList.add("minimal");
else
this._findField.classList.remove("minimal");
if (this._findMode == this.FIND_TYPEAHEAD)
@@ -1014,17 +1013,17 @@
// initial prefilling is ignored if it hasn't happened yet.
if (this._startFindDeferred) {
this._startFindDeferred.resolve();
this._startFindDeferred = null;
}
this._enableFindButtons(val);
this._updateCaseSensitivity(val);
- this._updateEntireWord();
+ this._setEntireWord();
this.browser.finder.fastFind(val, this._findMode == this.FIND_LINKS,
this._findMode != this.FIND_NORMAL);
}
if (this._findMode != this.FIND_NORMAL)
this._setFindCloseTimeout();