mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Further tests for bug 451286, and tidy up the relevant file somewhat. r=mano
This commit is contained in:
parent
f89f2766b4
commit
3c701be2a5
@ -50,6 +50,8 @@
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cr = Components.results;
|
||||
const SEARCH_TEXT = "text";
|
||||
const DATAURI = "data:text/html," + SEARCH_TEXT;
|
||||
|
||||
var gFindBar = null;
|
||||
var gBrowser;
|
||||
@ -69,7 +71,17 @@
|
||||
gFindBar = document.getElementById("FindToolbar");
|
||||
gBrowser = document.getElementById("content");
|
||||
gBrowser.addEventListener("pageshow", onPageShow, false);
|
||||
gBrowser.loadURI("data:text/html,text<iframe style='display: none;' src='data:text/html,text'></iframe>text<iframe id='if' src='data:text/html,text'></iframe>text");
|
||||
|
||||
// Bug 451286. An iframe that should be highlighted
|
||||
var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>";
|
||||
|
||||
// Bug 493658. An invisible iframe that shouldn't interfere with
|
||||
// highlighting matches lying after it in the document
|
||||
var invisible = "<iframe id='invisible' style='display: none;' " +
|
||||
"src='" + DATAURI + "'></iframe>";
|
||||
|
||||
var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT;
|
||||
gBrowser.loadURI(uri);
|
||||
}
|
||||
let tm = Cc["@mozilla.org/thread-manager;1"].
|
||||
getService(Ci.nsIThreadManager);
|
||||
@ -80,9 +92,14 @@
|
||||
|
||||
function onPageShow() {
|
||||
gBrowser.removeEventListener("pageshow", onPageShow, false);
|
||||
|
||||
// First, take a snapshot of the window without highlighting
|
||||
// to be used later to test the unhighlighting case
|
||||
var gWin = gBrowser.contentWindow;
|
||||
var noHighlightSnapshot = snapshotWindow(gWin);
|
||||
|
||||
gFindBar.open();
|
||||
var search = "text";
|
||||
gFindBar._findField.value = search;
|
||||
gFindBar._findField.value = SEARCH_TEXT;
|
||||
var matchCase = gFindBar.getElement("find-case-sensitive");
|
||||
if (matchCase.checked)
|
||||
matchCase.doCommand();
|
||||
@ -91,21 +108,25 @@
|
||||
gFindBar.toggleHighlight(true);
|
||||
gFindBar.close();
|
||||
|
||||
// Take snapshot
|
||||
var gWin = gBrowser.contentWindow;
|
||||
// Take snapshot of highlighing
|
||||
var findSnapshot = snapshotWindow(gWin);
|
||||
|
||||
// Now, perform the same selections manually
|
||||
// Now, remove the highlighting, and take a snapshot to compare
|
||||
// to our original state
|
||||
gFindBar.open();
|
||||
gFindBar.toggleHighlight(false);
|
||||
gFindBar.close();
|
||||
var unhighlightSnapshot = snapshotWindow(gWin);
|
||||
|
||||
// Select the matches that should have been highlighted manually
|
||||
var doc = gBrowser.contentDocument;
|
||||
var iframe = doc.getElementById("if");
|
||||
|
||||
// Create a manual highlight in the visible iframe to test bug 451286
|
||||
var iframe = doc.getElementById("visible");
|
||||
var ifBody = iframe.contentDocument.body;
|
||||
var range = iframe.contentDocument.createRange();
|
||||
range.selectNodeContents(ifBody.childNodes[0]);
|
||||
var ifWindow = doc.getElementById("if").contentWindow;
|
||||
var ifWindow = iframe.contentWindow;
|
||||
var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell);
|
||||
@ -114,10 +135,12 @@
|
||||
.getInterface(Ci.nsISelectionDisplay)
|
||||
.QueryInterface(Ci.nsISelectionController);
|
||||
|
||||
var findSelection = ifController.getSelection(ifController.SELECTION_FIND);
|
||||
findSelection.addRange(range);
|
||||
|
||||
var frameFindSelection =
|
||||
ifController.getSelection(ifController.SELECTION_FIND);
|
||||
frameFindSelection.addRange(range);
|
||||
|
||||
// Create manual highlights in the main document (the matches that lie
|
||||
// before/after the iframes
|
||||
var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||
.getInterface(Ci.nsIWebNavigation)
|
||||
.QueryInterface(Ci.nsIDocShell);
|
||||
@ -126,21 +149,30 @@
|
||||
.getInterface(Ci.nsISelectionDisplay)
|
||||
.QueryInterface(Ci.nsISelectionController);
|
||||
|
||||
var findSelection2 = controller.getSelection(ifController.SELECTION_FIND);
|
||||
var docFindSelection =
|
||||
controller.getSelection(ifController.SELECTION_FIND);
|
||||
|
||||
range = doc.createRange();
|
||||
range.selectNodeContents(doc.body.childNodes[0]);
|
||||
findSelection2.addRange(range);
|
||||
docFindSelection.addRange(range);
|
||||
range = doc.createRange();
|
||||
range.selectNodeContents(doc.body.childNodes[2]);
|
||||
findSelection2.addRange(range);
|
||||
docFindSelection.addRange(range);
|
||||
range = doc.createRange();
|
||||
range.selectNodeContents(doc.body.childNodes[4]);
|
||||
findSelection2.addRange(range);
|
||||
docFindSelection.addRange(range);
|
||||
|
||||
//Take snapshots
|
||||
// Take snapshot of manual highlighting
|
||||
var manualSnapshot = snapshotWindow(gBrowser.contentWindow);
|
||||
|
||||
// Test 1: Were the matches in iframe correctly highlighted?
|
||||
var res = compareSnapshots(findSnapshot, manualSnapshot, true);
|
||||
ok(res[0], "Matches found in iframe correctly highlighted");
|
||||
|
||||
// Test 2: Were the matches in iframe correctly unhighlighted?
|
||||
res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true);
|
||||
ok(res[0], "Highlighting in iframe correctly removed");
|
||||
|
||||
finish();
|
||||
}
|
||||
]]></script>
|
||||
|
Loading…
Reference in New Issue
Block a user