зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1606392, pass along and update the match case, diacriticals and whole word state to the child for each find attempt, r=mikedeboer
Differential Revision: https://phabricator.services.mozilla.com/D60010 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
d22fe9878a
Коммит
e1685e02b7
|
@ -349,6 +349,103 @@ add_task(async function test_hotkey_insubframe() {
|
|||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* Reloading a page should use the same match case / whole word
|
||||
* state for the search.
|
||||
*/
|
||||
add_task(async function test_preservestate_on_reload() {
|
||||
for (let stateChange of ["case-sensitive", "entire-word"]) {
|
||||
let tab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
"data:text/html,<p>There is a cat named Theo in the kitchen with another cat named Catherine. The two of them are thirsty."
|
||||
);
|
||||
|
||||
// Start a find and wait for the findbar to open.
|
||||
let findBarOpenPromise = BrowserTestUtils.waitForEvent(
|
||||
gBrowser,
|
||||
"findbaropen"
|
||||
);
|
||||
EventUtils.synthesizeKey("f", { accelKey: true });
|
||||
await findBarOpenPromise;
|
||||
|
||||
let isEntireWord = stateChange == "entire-word";
|
||||
|
||||
let findbar = await gBrowser.getFindBar();
|
||||
|
||||
// Find some text.
|
||||
let promiseMatches = promiseGetMatchCount(findbar);
|
||||
await promiseFindFinished("The", true);
|
||||
|
||||
let matches = await promiseMatches;
|
||||
is(matches.current, 1, "Correct match position " + stateChange);
|
||||
is(matches.total, 7, "Correct number of matches " + stateChange);
|
||||
|
||||
// Turn on the case sensitive or entire word option.
|
||||
findbar.getElement("find-" + stateChange).click();
|
||||
|
||||
promiseMatches = promiseGetMatchCount(findbar);
|
||||
gFindBar.onFindAgainCommand();
|
||||
matches = await promiseMatches;
|
||||
is(
|
||||
matches.current,
|
||||
2,
|
||||
"Correct match position after state change matches " + stateChange
|
||||
);
|
||||
is(
|
||||
matches.total,
|
||||
isEntireWord ? 2 : 3,
|
||||
"Correct number after state change matches " + stateChange
|
||||
);
|
||||
|
||||
// Reload the page.
|
||||
let loadedPromise = BrowserTestUtils.browserLoaded(
|
||||
gBrowser.selectedBrowser,
|
||||
true
|
||||
);
|
||||
gBrowser.reload();
|
||||
await loadedPromise;
|
||||
|
||||
// Perform a find again. The state should be preserved.
|
||||
promiseMatches = promiseGetMatchCount(findbar);
|
||||
gFindBar.onFindAgainCommand();
|
||||
matches = await promiseMatches;
|
||||
is(
|
||||
matches.current,
|
||||
1,
|
||||
"Correct match position after reload and find again " + stateChange
|
||||
);
|
||||
is(
|
||||
matches.total,
|
||||
isEntireWord ? 2 : 3,
|
||||
"Correct number of matches after reload and find again " + stateChange
|
||||
);
|
||||
|
||||
// Turn off the case sensitive or entire word option and find again.
|
||||
findbar.getElement("find-" + stateChange).click();
|
||||
|
||||
promiseMatches = promiseGetMatchCount(findbar);
|
||||
gFindBar.onFindAgainCommand();
|
||||
matches = await promiseMatches;
|
||||
|
||||
is(
|
||||
matches.current,
|
||||
isEntireWord ? 4 : 2,
|
||||
"Correct match position after reload and find again reset " + stateChange
|
||||
);
|
||||
is(
|
||||
matches.total,
|
||||
7,
|
||||
"Correct number of matches after reload and find again reset " +
|
||||
stateChange
|
||||
);
|
||||
|
||||
findbar.clear();
|
||||
await closeFindbarAndWait(findbar);
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
}
|
||||
});
|
||||
|
||||
async function promiseFindFinished(searchText, highlightOn) {
|
||||
let findbar = await gBrowser.getFindBar();
|
||||
findbar.startFind(findbar.FIND_NORMAL);
|
||||
|
@ -392,6 +489,23 @@ async function promiseFindFinished(searchText, highlightOn) {
|
|||
});
|
||||
}
|
||||
|
||||
function promiseGetMatchCount(findbar) {
|
||||
return new Promise(resolve => {
|
||||
let resultListener = {
|
||||
onFindResult() {},
|
||||
onCurrentSelection() {},
|
||||
onHighlightFinished() {},
|
||||
onMatchesCountResult(response) {
|
||||
if (response.total > 0) {
|
||||
findbar.browser.finder.removeResultListener(resultListener);
|
||||
resolve(response);
|
||||
}
|
||||
},
|
||||
};
|
||||
findbar.browser.finder.addResultListener(resultListener);
|
||||
});
|
||||
}
|
||||
|
||||
function promiseRemotenessChange(tab, shouldBeRemote) {
|
||||
return new Promise(resolve => {
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
|
|
|
@ -291,8 +291,15 @@ Finder.prototype = {
|
|||
* linksOnly Only consider nodes that are links for the search.
|
||||
* drawOutline Puts an outline around matched links.
|
||||
* useSubFrames True to iterate over subframes.
|
||||
* caseSensitive True for case sensitive searching.
|
||||
* entireWord True to match entire words.
|
||||
* matchDiacritics True to match diacritics.
|
||||
*/
|
||||
find(options) {
|
||||
this.caseSensitive = options.caseSensitive;
|
||||
this.entireWord = options.entireWord;
|
||||
this.matchDiacritics = options.matchDiacritics;
|
||||
|
||||
this._lastFindResult = this._fastFind.find(
|
||||
options.searchString,
|
||||
options.linksOnly,
|
||||
|
|
|
@ -57,6 +57,11 @@ function FinderParent(browser) {
|
|||
this._foundSearchString = null;
|
||||
this._lastFoundBrowsingContext = null;
|
||||
|
||||
// The correct states of these will be updated when the findbar is opened.
|
||||
this._caseSensitive = false;
|
||||
this._entireWord = false;
|
||||
this._matchDiacritics = false;
|
||||
|
||||
this.swapBrowser(browser);
|
||||
}
|
||||
|
||||
|
@ -224,18 +229,21 @@ FinderParent.prototype = {
|
|||
},
|
||||
|
||||
set caseSensitive(aSensitive) {
|
||||
this._caseSensitive = aSensitive;
|
||||
this.sendMessageToAllContexts("Finder:CaseSensitive", {
|
||||
caseSensitive: aSensitive,
|
||||
});
|
||||
},
|
||||
|
||||
set entireWord(aEntireWord) {
|
||||
this._entireWord = aEntireWord;
|
||||
this.sendMessageToAllContexts("Finder:EntireWord", {
|
||||
entireWord: aEntireWord,
|
||||
});
|
||||
},
|
||||
|
||||
set matchDiacritics(aMatchDiacritics) {
|
||||
this._matchDiacritics = aMatchDiacritics;
|
||||
this.sendMessageToAllContexts("Finder:MatchDiacritics", {
|
||||
matchDiacritics: aMatchDiacritics,
|
||||
});
|
||||
|
@ -309,6 +317,10 @@ FinderParent.prototype = {
|
|||
}
|
||||
aArgs.findAgain = aFindNext;
|
||||
|
||||
aArgs.caseSensitive = this._caseSensitive;
|
||||
aArgs.matchDiacritics = this._matchDiacritics;
|
||||
aArgs.entireWord = this._entireWord;
|
||||
|
||||
aArgs.useSubFrames = this.needSubFrameSearch(searchList);
|
||||
if (aArgs.useSubFrames) {
|
||||
// Use the single frame for the highlight list as well.
|
||||
|
|
Загрузка…
Ссылка в новой задаче