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 | |
michael@0 | 2 | let Cu = Components.utils; |
michael@0 | 3 | let Cc = Components.classes; |
michael@0 | 4 | let Ci = Components.interfaces; |
michael@0 | 5 | |
michael@0 | 6 | const URL1 = MAIN_DOMAIN + "navigate-first.html"; |
michael@0 | 7 | const URL2 = MAIN_DOMAIN + "navigate-second.html"; |
michael@0 | 8 | |
michael@0 | 9 | let { DebuggerClient } = Cu.import("resource://gre/modules/devtools/dbg-client.jsm", {}); |
michael@0 | 10 | let { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {}); |
michael@0 | 11 | |
michael@0 | 12 | let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools; |
michael@0 | 13 | let events = devtools.require("sdk/event/core"); |
michael@0 | 14 | |
michael@0 | 15 | let client; |
michael@0 | 16 | |
michael@0 | 17 | // State machine to check events order |
michael@0 | 18 | let i = 0; |
michael@0 | 19 | function assertEvent(event, data) { |
michael@0 | 20 | let x = 0; |
michael@0 | 21 | switch(i++) { |
michael@0 | 22 | case x++: |
michael@0 | 23 | is(event, "request", "Get first page load"); |
michael@0 | 24 | is(data, URL1); |
michael@0 | 25 | break; |
michael@0 | 26 | case x++: |
michael@0 | 27 | is(event, "load-new-document", "Ask to load the second page"); |
michael@0 | 28 | break; |
michael@0 | 29 | case x++: |
michael@0 | 30 | is(event, "unload-dialog", "We get the dialog on first page unload"); |
michael@0 | 31 | break; |
michael@0 | 32 | case x++: |
michael@0 | 33 | is(event, "will-navigate", "The very first event is will-navigate on server side"); |
michael@0 | 34 | is(data.newURI, URL2, "newURI property is correct"); |
michael@0 | 35 | break; |
michael@0 | 36 | case x++: |
michael@0 | 37 | is(event, "tabNavigated", "Right after will-navigate, the client receive tabNavigated"); |
michael@0 | 38 | is(data.state, "start", "state is start"); |
michael@0 | 39 | is(data.url, URL2, "url property is correct"); |
michael@0 | 40 | break; |
michael@0 | 41 | case x++: |
michael@0 | 42 | is(event, "request", "Given that locally, the Debugger protocol is sync, the request happens after tabNavigated"); |
michael@0 | 43 | is(data, URL2); |
michael@0 | 44 | break; |
michael@0 | 45 | case x++: |
michael@0 | 46 | is(event, "DOMContentLoaded"); |
michael@0 | 47 | is(content.document.readyState, "interactive"); |
michael@0 | 48 | break; |
michael@0 | 49 | case x++: |
michael@0 | 50 | is(event, "load"); |
michael@0 | 51 | is(content.document.readyState, "complete"); |
michael@0 | 52 | break; |
michael@0 | 53 | case x++: |
michael@0 | 54 | is(event, "navigate", "Then once the second doc is loaded, we get the navigate event"); |
michael@0 | 55 | is(content.document.readyState, "complete", "navigate is emitted only once the document is fully loaded"); |
michael@0 | 56 | break; |
michael@0 | 57 | case x++: |
michael@0 | 58 | is(event, "tabNavigated", "Finally, the receive the client event"); |
michael@0 | 59 | is(data.state, "stop", "state is stop"); |
michael@0 | 60 | is(data.url, URL2, "url property is correct"); |
michael@0 | 61 | |
michael@0 | 62 | // End of test! |
michael@0 | 63 | cleanup(); |
michael@0 | 64 | break; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function waitForOnBeforeUnloadDialog(browser, callback) { |
michael@0 | 69 | browser.addEventListener("DOMWillOpenModalDialog", function onModalDialog() { |
michael@0 | 70 | browser.removeEventListener("DOMWillOpenModalDialog", onModalDialog, true); |
michael@0 | 71 | |
michael@0 | 72 | executeSoon(() => { |
michael@0 | 73 | let stack = browser.parentNode; |
michael@0 | 74 | let dialogs = stack.getElementsByTagName("tabmodalprompt"); |
michael@0 | 75 | let {button0, button1} = dialogs[0].ui; |
michael@0 | 76 | callback(button0, button1); |
michael@0 | 77 | }); |
michael@0 | 78 | }, true); |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | let httpObserver = function (subject, topic, state) { |
michael@0 | 82 | let channel = subject.QueryInterface(Ci.nsIHttpChannel); |
michael@0 | 83 | let url = channel.URI.spec; |
michael@0 | 84 | // Only listen for our document request, as many other requests can happen |
michael@0 | 85 | if (url == URL1 || url == URL2) { |
michael@0 | 86 | assertEvent("request", url); |
michael@0 | 87 | } |
michael@0 | 88 | }; |
michael@0 | 89 | Services.obs.addObserver(httpObserver, "http-on-modify-request", false); |
michael@0 | 90 | |
michael@0 | 91 | function onDOMContentLoaded() { |
michael@0 | 92 | assertEvent("DOMContentLoaded"); |
michael@0 | 93 | } |
michael@0 | 94 | function onLoad() { |
michael@0 | 95 | assertEvent("load"); |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | function getServerTabActor(callback) { |
michael@0 | 99 | // Ensure having a minimal server |
michael@0 | 100 | if (!DebuggerServer.initialized) { |
michael@0 | 101 | DebuggerServer.init(function () { return true; }); |
michael@0 | 102 | DebuggerServer.addBrowserActors(); |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | // Connect to this tab |
michael@0 | 106 | let transport = DebuggerServer.connectPipe(); |
michael@0 | 107 | client = new DebuggerClient(transport); |
michael@0 | 108 | client.connect(function onConnect() { |
michael@0 | 109 | client.listTabs(function onListTabs(aResponse) { |
michael@0 | 110 | // Fetch the BrowserTabActor for this tab |
michael@0 | 111 | let actorID = aResponse.tabs[aResponse.selected].actor; |
michael@0 | 112 | client.attachTab(actorID, function(aResponse, aTabClient) { |
michael@0 | 113 | // !Hack! Retrieve a server side object, the BrowserTabActor instance |
michael@0 | 114 | let conn = transport._serverConnection; |
michael@0 | 115 | let tabActor = conn.getActor(actorID); |
michael@0 | 116 | callback(tabActor); |
michael@0 | 117 | }); |
michael@0 | 118 | }); |
michael@0 | 119 | }); |
michael@0 | 120 | |
michael@0 | 121 | client.addListener("tabNavigated", function (aEvent, aPacket) { |
michael@0 | 122 | assertEvent("tabNavigated", aPacket); |
michael@0 | 123 | }); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | function test() { |
michael@0 | 127 | waitForExplicitFinish(); |
michael@0 | 128 | |
michael@0 | 129 | // Open a test tab |
michael@0 | 130 | addTab(URL1, function(doc) { |
michael@0 | 131 | getServerTabActor(function (tabActor) { |
michael@0 | 132 | // In order to listen to internal will-navigate/navigate events |
michael@0 | 133 | events.on(tabActor, "will-navigate", function (data) { |
michael@0 | 134 | assertEvent("will-navigate", data); |
michael@0 | 135 | }); |
michael@0 | 136 | events.on(tabActor, "navigate", function (data) { |
michael@0 | 137 | assertEvent("navigate", data); |
michael@0 | 138 | }); |
michael@0 | 139 | |
michael@0 | 140 | // Start listening for page load events |
michael@0 | 141 | let browser = gBrowser.selectedTab.linkedBrowser; |
michael@0 | 142 | browser.addEventListener("DOMContentLoaded", onDOMContentLoaded, true); |
michael@0 | 143 | browser.addEventListener("load", onLoad, true); |
michael@0 | 144 | |
michael@0 | 145 | // Listen for alert() call being made in navigate-first during unload |
michael@0 | 146 | waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { |
michael@0 | 147 | assertEvent("unload-dialog"); |
michael@0 | 148 | // accept to quit this page to another |
michael@0 | 149 | btnLeave.click(); |
michael@0 | 150 | }); |
michael@0 | 151 | |
michael@0 | 152 | // Load another document in this doc to dispatch these events |
michael@0 | 153 | assertEvent("load-new-document"); |
michael@0 | 154 | content.location = URL2; |
michael@0 | 155 | }); |
michael@0 | 156 | |
michael@0 | 157 | }); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | function cleanup() { |
michael@0 | 161 | let browser = gBrowser.selectedTab.linkedBrowser; |
michael@0 | 162 | browser.removeEventListener("DOMContentLoaded", onDOMContentLoaded); |
michael@0 | 163 | browser.removeEventListener("load", onLoad); |
michael@0 | 164 | client.close(function () { |
michael@0 | 165 | Services.obs.addObserver(httpObserver, "http-on-modify-request", false); |
michael@0 | 166 | DebuggerServer.destroy(); |
michael@0 | 167 | finish(); |
michael@0 | 168 | }); |
michael@0 | 169 | } |