Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | |
michael@0 | 3 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 6 | |
michael@0 | 7 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 8 | |
michael@0 | 9 | <window id="451286test" |
michael@0 | 10 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 11 | width="600" |
michael@0 | 12 | height="600" |
michael@0 | 13 | onload="SimpleTest.executeSoon(startTest);" |
michael@0 | 14 | title="451286 test (also tests bug 493658)"> |
michael@0 | 15 | |
michael@0 | 16 | <script type="application/javascript"><![CDATA[ |
michael@0 | 17 | const Ci = Components.interfaces; |
michael@0 | 18 | const Cc = Components.classes; |
michael@0 | 19 | const Cr = Components.results; |
michael@0 | 20 | const SEARCH_TEXT = "text"; |
michael@0 | 21 | const DATAURI = "data:text/html," + SEARCH_TEXT; |
michael@0 | 22 | |
michael@0 | 23 | var gFindBar = null; |
michael@0 | 24 | var gBrowser; |
michael@0 | 25 | var gWin; |
michael@0 | 26 | |
michael@0 | 27 | var noHighlightSnapshot; |
michael@0 | 28 | var findSnapshot; |
michael@0 | 29 | |
michael@0 | 30 | var imports = ["SimpleTest", "ok", "snapshotWindow", "compareSnapshots", |
michael@0 | 31 | "parentFinish"]; |
michael@0 | 32 | for each (var name in imports) { |
michael@0 | 33 | window[name] = window.opener.wrappedJSObject[name]; |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function finish() { |
michael@0 | 37 | window.close(); |
michael@0 | 38 | parentFinish(); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function startTest() { |
michael@0 | 42 | gFindBar = document.getElementById("FindToolbar"); |
michael@0 | 43 | gBrowser = document.getElementById("content"); |
michael@0 | 44 | gBrowser.addEventListener("pageshow", onPageShow, false); |
michael@0 | 45 | |
michael@0 | 46 | // Bug 451286. An iframe that should be highlighted |
michael@0 | 47 | var visible = "<iframe id='visible' src='" + DATAURI + "'></iframe>"; |
michael@0 | 48 | |
michael@0 | 49 | // Bug 493658. An invisible iframe that shouldn't interfere with |
michael@0 | 50 | // highlighting matches lying after it in the document |
michael@0 | 51 | var invisible = "<iframe id='invisible' style='display: none;' " + |
michael@0 | 52 | "src='" + DATAURI + "'></iframe>"; |
michael@0 | 53 | |
michael@0 | 54 | var uri = DATAURI + invisible + SEARCH_TEXT + visible + SEARCH_TEXT; |
michael@0 | 55 | gBrowser.loadURI(uri); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function onPageShow(aEvent) { |
michael@0 | 59 | // Don't respond to pageshow events coming from the <iframes> |
michael@0 | 60 | if (aEvent.target != gBrowser.contentDocument) |
michael@0 | 61 | return; |
michael@0 | 62 | |
michael@0 | 63 | gBrowser.removeEventListener("pageshow", onPageShow, false); |
michael@0 | 64 | |
michael@0 | 65 | // First, take a snapshot of the window without highlighting |
michael@0 | 66 | // to be used later to test the unhighlighting case |
michael@0 | 67 | gWin = gBrowser.contentWindow; |
michael@0 | 68 | noHighlightSnapshot = snapshotWindow(gWin); |
michael@0 | 69 | |
michael@0 | 70 | gFindBar.open(); |
michael@0 | 71 | gFindBar._findField.value = SEARCH_TEXT; |
michael@0 | 72 | var matchCase = gFindBar.getElement("find-case-sensitive"); |
michael@0 | 73 | if (matchCase.checked) |
michael@0 | 74 | matchCase.doCommand(); |
michael@0 | 75 | |
michael@0 | 76 | // Turn on highlighting |
michael@0 | 77 | gFindBar.toggleHighlight(true); |
michael@0 | 78 | gFindBar.close(); |
michael@0 | 79 | gFindBar.addEventListener('transitionend', part2); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function part2(aEvent) { |
michael@0 | 83 | if (aEvent.propertyName != 'visibility') { |
michael@0 | 84 | return; |
michael@0 | 85 | } |
michael@0 | 86 | gFindBar.removeEventListener('transitionend', part2); |
michael@0 | 87 | // Take snapshot of highlighing |
michael@0 | 88 | findSnapshot = snapshotWindow(gWin); |
michael@0 | 89 | |
michael@0 | 90 | // Now, remove the highlighting, and take a snapshot to compare |
michael@0 | 91 | // to our original state |
michael@0 | 92 | gFindBar.open(); |
michael@0 | 93 | gFindBar.toggleHighlight(false); |
michael@0 | 94 | gFindBar.close(); |
michael@0 | 95 | gFindBar.addEventListener('transitionend', part3); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function part3(aEvent) { |
michael@0 | 99 | if (aEvent.propertyName != 'visibility') { |
michael@0 | 100 | return; |
michael@0 | 101 | } |
michael@0 | 102 | gFindBar.removeEventListener('transitionend', part3); |
michael@0 | 103 | var unhighlightSnapshot = snapshotWindow(gWin); |
michael@0 | 104 | |
michael@0 | 105 | // Select the matches that should have been highlighted manually |
michael@0 | 106 | var doc = gBrowser.contentDocument; |
michael@0 | 107 | |
michael@0 | 108 | // Create a manual highlight in the visible iframe to test bug 451286 |
michael@0 | 109 | var iframe = doc.getElementById("visible"); |
michael@0 | 110 | var ifBody = iframe.contentDocument.body; |
michael@0 | 111 | var range = iframe.contentDocument.createRange(); |
michael@0 | 112 | range.selectNodeContents(ifBody.childNodes[0]); |
michael@0 | 113 | var ifWindow = iframe.contentWindow; |
michael@0 | 114 | var ifDocShell = ifWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 115 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 116 | .QueryInterface(Ci.nsIDocShell); |
michael@0 | 117 | |
michael@0 | 118 | var ifController = ifDocShell.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 119 | .getInterface(Ci.nsISelectionDisplay) |
michael@0 | 120 | .QueryInterface(Ci.nsISelectionController); |
michael@0 | 121 | |
michael@0 | 122 | var frameFindSelection = |
michael@0 | 123 | ifController.getSelection(ifController.SELECTION_FIND); |
michael@0 | 124 | frameFindSelection.addRange(range); |
michael@0 | 125 | |
michael@0 | 126 | // Create manual highlights in the main document (the matches that lie |
michael@0 | 127 | // before/after the iframes |
michael@0 | 128 | var docShell = gWin.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 129 | .getInterface(Ci.nsIWebNavigation) |
michael@0 | 130 | .QueryInterface(Ci.nsIDocShell); |
michael@0 | 131 | |
michael@0 | 132 | var controller = docShell.QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 133 | .getInterface(Ci.nsISelectionDisplay) |
michael@0 | 134 | .QueryInterface(Ci.nsISelectionController); |
michael@0 | 135 | |
michael@0 | 136 | var docFindSelection = |
michael@0 | 137 | controller.getSelection(ifController.SELECTION_FIND); |
michael@0 | 138 | |
michael@0 | 139 | range = doc.createRange(); |
michael@0 | 140 | range.selectNodeContents(doc.body.childNodes[0]); |
michael@0 | 141 | docFindSelection.addRange(range); |
michael@0 | 142 | range = doc.createRange(); |
michael@0 | 143 | range.selectNodeContents(doc.body.childNodes[2]); |
michael@0 | 144 | docFindSelection.addRange(range); |
michael@0 | 145 | range = doc.createRange(); |
michael@0 | 146 | range.selectNodeContents(doc.body.childNodes[4]); |
michael@0 | 147 | docFindSelection.addRange(range); |
michael@0 | 148 | |
michael@0 | 149 | // Take snapshot of manual highlighting |
michael@0 | 150 | var manualSnapshot = snapshotWindow(gBrowser.contentWindow); |
michael@0 | 151 | |
michael@0 | 152 | // Test 1: Were the matches in iframe correctly highlighted? |
michael@0 | 153 | var res = compareSnapshots(findSnapshot, manualSnapshot, true); |
michael@0 | 154 | ok(res[0], "Matches found in iframe correctly highlighted"); |
michael@0 | 155 | |
michael@0 | 156 | // Test 2: Were the matches in iframe correctly unhighlighted? |
michael@0 | 157 | res = compareSnapshots(noHighlightSnapshot, unhighlightSnapshot, true); |
michael@0 | 158 | ok(res[0], "Highlighting in iframe correctly removed"); |
michael@0 | 159 | |
michael@0 | 160 | finish(); |
michael@0 | 161 | } |
michael@0 | 162 | ]]></script> |
michael@0 | 163 | |
michael@0 | 164 | <browser type="content-primary" flex="1" id="content" src="about:blank"/> |
michael@0 | 165 | <findbar id="FindToolbar" browserid="content"/> |
michael@0 | 166 | </window> |