зеркало из https://github.com/mozilla/gecko-dev.git
Bug 409624 - Sanitizer should clear findBar data. r=adw
This commit is contained in:
Родитель
d00fa73602
Коммит
051422810f
|
@ -220,12 +220,16 @@ Sanitizer.prototype = {
|
|||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var windows = windowManager.getEnumerator("navigator:browser");
|
||||
while (windows.hasMoreElements()) {
|
||||
var searchBar = windows.getNext().document.getElementById("searchbar");
|
||||
let currentDocument = windows.getNext().document;
|
||||
let searchBar = currentDocument.getElementById("searchbar");
|
||||
if (searchBar)
|
||||
searchBar.textbox.reset();
|
||||
let findBar = currentDocument.getElementById("FindToolbar");
|
||||
if (findBar)
|
||||
findBar.clear();
|
||||
}
|
||||
|
||||
var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
|
||||
let formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
|
||||
.getService(Components.interfaces.nsIFormHistory2);
|
||||
if (this.range)
|
||||
formHistory.removeEntriesByTimeframe(this.range[0], this.range[1]);
|
||||
|
@ -239,17 +243,21 @@ Sanitizer.prototype = {
|
|||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
var windows = windowManager.getEnumerator("navigator:browser");
|
||||
while (windows.hasMoreElements()) {
|
||||
var searchBar = windows.getNext().document.getElementById("searchbar");
|
||||
let currentDocument = windows.getNext().document;
|
||||
let searchBar = currentDocument.getElementById("searchbar");
|
||||
if (searchBar) {
|
||||
var transactionMgr = searchBar.textbox.editor.transactionManager;
|
||||
let transactionMgr = searchBar.textbox.editor.transactionManager;
|
||||
if (searchBar.value ||
|
||||
transactionMgr.numberOfUndoItems ||
|
||||
transactionMgr.numberOfRedoItems)
|
||||
return true;
|
||||
}
|
||||
let findBar = currentDocument.getElementById("FindToolbar");
|
||||
if (findBar && findBar.canClear)
|
||||
return true;
|
||||
}
|
||||
|
||||
var formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
|
||||
let formHistory = Components.classes["@mozilla.org/satchel/form-history;1"]
|
||||
.getService(Components.interfaces.nsIFormHistory2);
|
||||
return formHistory.hasEntries;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ _BROWSER_FILES = \
|
|||
browser_bug405137.js \
|
||||
browser_bug406216.js \
|
||||
browser_bug409481.js \
|
||||
browser_bug409624.js \
|
||||
browser_bug413915.js \
|
||||
browser_bug416661.js \
|
||||
browser_bug417483.js \
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let prefService = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch2);
|
||||
|
||||
let findBar = gFindBar;
|
||||
let textbox = gFindBar.getElement("findbar-textbox");
|
||||
|
||||
let tempScope = {};
|
||||
Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader)
|
||||
.loadSubScript("chrome://browser/content/sanitize.js", tempScope);
|
||||
let Sanitizer = tempScope.Sanitizer;
|
||||
let s = new Sanitizer();
|
||||
s.prefDomain = "privacy.cpd.";
|
||||
let prefBranch = prefService.getBranch(s.prefDomain);
|
||||
|
||||
prefBranch.setBoolPref("cache", false);
|
||||
prefBranch.setBoolPref("cookies", false);
|
||||
prefBranch.setBoolPref("downloads", false);
|
||||
prefBranch.setBoolPref("formdata", true);
|
||||
prefBranch.setBoolPref("history", false);
|
||||
prefBranch.setBoolPref("offlineApps", false);
|
||||
prefBranch.setBoolPref("passwords", false);
|
||||
prefBranch.setBoolPref("sessions", false);
|
||||
prefBranch.setBoolPref("siteSettings", false);
|
||||
|
||||
// Sanitize now so we can test that canClear is correct
|
||||
s.sanitize();
|
||||
ok(!s.canClearItem("formdata"), "pre-test baseline for sanitizer");
|
||||
textbox.value = "m";
|
||||
ok(s.canClearItem("formdata"), "formdata can be cleared after input");
|
||||
s.sanitize();
|
||||
is(textbox.value, "", "findBar textbox should be empty after sanitize");
|
||||
ok(!s.canClearItem("formdata"), "canClear now false after sanitize");
|
||||
finish();
|
||||
}
|
|
@ -3,38 +3,45 @@
|
|||
*/
|
||||
|
||||
let Ci = Components.interfaces;
|
||||
let testWindow = null;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
let tab = gBrowser.addTab();
|
||||
gBrowser.selectedTab = tab;
|
||||
tab.linkedBrowser.addEventListener("load", function(aEvent) {
|
||||
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
|
||||
|
||||
testWindow = OpenBrowserWindow();
|
||||
testWindow.addEventListener("load", function(aEvent) {
|
||||
testWindow.removeEventListener("load", arguments.callee, false);
|
||||
ok(true, "Load listener called");
|
||||
waitForFocus(onFocus, content);
|
||||
}, true);
|
||||
|
||||
content.location = "data:text/html,<h1 id='h1'>Select Me</h1>";
|
||||
executeSoon(function() {
|
||||
let selectedBrowser = testWindow.gBrowser.selectedBrowser;
|
||||
selectedBrowser.addEventListener("pageshow", function() {
|
||||
selectedBrowser.removeEventListener("pageshow", arguments.callee, true);
|
||||
ok(true, "pageshow listener called");
|
||||
waitForFocus(onFocus, testWindow.contentWindow);
|
||||
}, true);
|
||||
testWindow.content.location = "data:text/html,<h1 id='h1'>Select Me</h1>";
|
||||
});
|
||||
}, false);
|
||||
}
|
||||
|
||||
function selectText() {
|
||||
let elt = content.document.getElementById("h1");
|
||||
let selection = content.getSelection();
|
||||
let range = content.document.createRange();
|
||||
let elt = testWindow.content.document.getElementById("h1");
|
||||
let selection = testWindow.content.getSelection();
|
||||
let range = testWindow.content.document.createRange();
|
||||
range.setStart(elt, 0);
|
||||
range.setEnd(elt, 1);
|
||||
selection.removeAllRanges();
|
||||
selection.addRange(range);
|
||||
}
|
||||
|
||||
|
||||
function onFocus() {
|
||||
ok(!gFindBarInitialized, "find bar is not yet initialized");
|
||||
ok(!testWindow.gFindBarInitialized, "find bar is not yet initialized");
|
||||
let findBar = testWindow.gFindBar;
|
||||
selectText();
|
||||
gFindBar.onFindCommand();
|
||||
ok(gFindBar._findField.value == "Select Me", "Findbar is initialized with selection");
|
||||
gFindBar.close();
|
||||
gBrowser.removeCurrentTab();
|
||||
findBar.onFindCommand();
|
||||
is(findBar._findField.value, "Select Me", "Findbar is initialized with selection");
|
||||
findBar.close();
|
||||
testWindow.close();
|
||||
finish();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ MOCHITEST_CHROME_FILES = findbar_window.xul \
|
|||
test_bug360437.xul \
|
||||
bug366992_window.xul \
|
||||
test_bug366992.xul \
|
||||
test_bug409624.xul \
|
||||
bug409624_window.xul \
|
||||
test_bug418874.xul \
|
||||
bug429723_window.xul \
|
||||
test_bug429723.xul \
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
<?xml version="1.0"?>
|
||||
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
|
||||
<window id="409624test"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
width="600"
|
||||
height="600"
|
||||
title="409624 test">
|
||||
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
var gFindBar = null;
|
||||
var gBrowser;
|
||||
|
||||
var imports = ["SimpleTest", "ok", "is"];
|
||||
for each (var name in imports) {
|
||||
window[name] = window.opener.wrappedJSObject[name];
|
||||
}
|
||||
|
||||
function finish() {
|
||||
window.close();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function startTest() {
|
||||
gFindBar = document.getElementById("FindToolbar");
|
||||
gBrowser = document.getElementById("content");
|
||||
gBrowser.addEventListener("pageshow", onPageShow, false);
|
||||
gBrowser.loadURI('data:text/html,<h2>Text mozilla</h2><input id="inp" type="text" />');
|
||||
}
|
||||
|
||||
function onPageShow() {
|
||||
gBrowser.removeEventListener("pageshow", onPageShow, false);
|
||||
gFindBar.clear();
|
||||
let textbox = gFindBar.getElement("findbar-textbox");
|
||||
|
||||
// canClear / clear should work regardless of whether or not editor has
|
||||
// been lazily initialised yet
|
||||
ok(!gFindBar.canClear, "canClear property false when findbar empty");
|
||||
textbox.value = "mozilla";
|
||||
ok(gFindBar.canClear, "canClear property true when findbar value set without editor init");
|
||||
gFindBar.clear();
|
||||
is(textbox.value, '', "findbar input value cleared after clear() call without editor init");
|
||||
ok(!gFindBar.canClear, "canClear property false after clear() call");
|
||||
|
||||
gFindBar.open();
|
||||
let matchCaseCheckbox = gFindBar.getElement("find-case-sensitive");
|
||||
if (!matchCaseCheckbox.hidden && matchCaseCheckbox.checked)
|
||||
matchCaseCheckbox.click();
|
||||
ok(!matchCaseCheckbox.checked, "case-insensitivity correctly set");
|
||||
|
||||
// Simulate typical input
|
||||
textbox.focus();
|
||||
sendChar("m");
|
||||
ok(gFindBar.canClear, "canClear property true after input");
|
||||
let preSelection = gBrowser.contentWindow.getSelection();
|
||||
ok(!preSelection.isCollapsed, "Found item and selected range");
|
||||
gFindBar.clear();
|
||||
is(textbox.value, '', "findbar input value cleared after clear() call");
|
||||
let postSelection = gBrowser.contentWindow.getSelection();
|
||||
ok(postSelection.isCollapsed, "item found deselected after clear() call");
|
||||
let fp = gFindBar.getElement("find-previous");
|
||||
ok(fp.disabled, "find-previous button disabled after clear() call");
|
||||
let fn = gFindBar.getElement("find-next");
|
||||
ok(fn.disabled, "find-next button disabled after clear() call");
|
||||
|
||||
// Test status updated after a search for text not in page
|
||||
textbox.focus();
|
||||
sendChar("x");
|
||||
gFindBar.clear();
|
||||
let ftext = gFindBar.getElement("find-status");
|
||||
is(ftext.textContent, "", "status text disabled after clear() call");
|
||||
|
||||
// Test input empty with undo stack non-empty
|
||||
textbox.focus();
|
||||
sendChar("m");
|
||||
sendKey("BACK_SPACE");
|
||||
ok(gFindBar.canClear, "canClear property true when undo available");
|
||||
gFindBar.clear();
|
||||
gFindBar.close();
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForFocus(startTest, window);
|
||||
]]></script>
|
||||
|
||||
<browser type="content-primary" flex="1" id="content" src="about:blank"/>
|
||||
<findbar id="FindToolbar" browserid="content"/>
|
||||
</window>
|
|
@ -0,0 +1,41 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet
|
||||
href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=409624
|
||||
-->
|
||||
<window title="Mozilla Bug 409624"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<title>Test for Bug 409624</title>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a target="_blank"
|
||||
href="https://bugzilla.mozilla.org/show_bug.cgi?id=409624">
|
||||
Mozilla Bug 409624
|
||||
</a>
|
||||
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
/** Test for Bug 409624 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
window.open("bug409624_window.xul", "409624test",
|
||||
"chrome,width=600,height=600");
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
|
@ -279,6 +279,20 @@
|
|||
readonly="true"
|
||||
onget="return this._findMode;"/>
|
||||
|
||||
<property name="canClear" readonly="true">
|
||||
<getter><![CDATA[
|
||||
if (this._findField.value)
|
||||
return true;
|
||||
|
||||
// Watch out for lazy editor init
|
||||
if (this._findField.editor) {
|
||||
let tm = this._findField.editor.transactionManager;
|
||||
return !!(tm.numberOfUndoItems || tm.numberOfRedoItems);
|
||||
}
|
||||
return false;
|
||||
]]></getter>
|
||||
</property>
|
||||
|
||||
<field name="_browser">null</field>
|
||||
<property name="browser">
|
||||
<getter><![CDATA[
|
||||
|
@ -1186,6 +1200,19 @@
|
|||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="clear">
|
||||
<body><![CDATA[
|
||||
this.browser.fastFind.collapseSelection();
|
||||
this._findField.reset();
|
||||
this.toggleHighlight(false);
|
||||
this._updateStatusUI();
|
||||
this._enableFindButtons(false);
|
||||
this._setFoundLink(null);
|
||||
this._foundEditable = null;
|
||||
this._currentWindow = null;
|
||||
]]></body>
|
||||
</method>
|
||||
|
||||
<method name="_dispatchKeypressEvent">
|
||||
<parameter name="aTarget"/>
|
||||
<parameter name="aEvent"/>
|
||||
|
|
Загрузка…
Ссылка в новой задаче