From 3c701be2a56fcfab92a25b4443adf0c040bf9b0a Mon Sep 17 00:00:00 2001 From: Graeme McCutcheon Date: Sat, 1 Aug 2009 17:16:03 +0100 Subject: [PATCH] Further tests for bug 451286, and tidy up the relevant file somewhat. r=mano --- .../content/tests/chrome/bug451286_window.xul | 64 ++++++++++++++----- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/toolkit/content/tests/chrome/bug451286_window.xul b/toolkit/content/tests/chrome/bug451286_window.xul index 390cf2b06e82..b05c3cdca16c 100644 --- a/toolkit/content/tests/chrome/bug451286_window.xul +++ b/toolkit/content/tests/chrome/bug451286_window.xul @@ -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,texttexttext"); + + // Bug 451286. An iframe that should be highlighted + var visible = ""; + + // Bug 493658. An invisible iframe that shouldn't interfere with + // highlighting matches lying after it in the document + var invisible = ""; + + 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(); } ]]>