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 | <!DOCTYPE HTML> |
michael@0 | 2 | <html lang="en"> |
michael@0 | 3 | <head> |
michael@0 | 4 | <meta charset="utf8"> |
michael@0 | 5 | <title>Test that the network actor uses the LongStringActor</title> |
michael@0 | 6 | <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 7 | <script type="text/javascript;version=1.8" src="common.js"></script> |
michael@0 | 8 | <!-- Any copyright is dedicated to the Public Domain. |
michael@0 | 9 | - http://creativecommons.org/publicdomain/zero/1.0/ --> |
michael@0 | 10 | </head> |
michael@0 | 11 | <body> |
michael@0 | 12 | <p>Test that the network actor uses the LongStringActor</p> |
michael@0 | 13 | |
michael@0 | 14 | <iframe src="http://example.com/chrome/toolkit/devtools/webconsole/test/network_requests_iframe.html"></iframe> |
michael@0 | 15 | |
michael@0 | 16 | <script class="testbody" type="text/javascript;version=1.8"> |
michael@0 | 17 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 18 | |
michael@0 | 19 | function startTest() |
michael@0 | 20 | { |
michael@0 | 21 | removeEventListener("load", startTest); |
michael@0 | 22 | |
michael@0 | 23 | attachConsole(["NetworkActivity"], onAttach, true); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function onAttach(aState, aResponse) |
michael@0 | 27 | { |
michael@0 | 28 | info("enable network request and response body logging"); |
michael@0 | 29 | |
michael@0 | 30 | window.ORIGINAL_LONG_STRING_LENGTH = DebuggerServer.LONG_STRING_LENGTH; |
michael@0 | 31 | window.ORIGINAL_LONG_STRING_INITIAL_LENGTH = |
michael@0 | 32 | DebuggerServer.LONG_STRING_INITIAL_LENGTH; |
michael@0 | 33 | |
michael@0 | 34 | DebuggerServer.LONG_STRING_LENGTH = 400; |
michael@0 | 35 | DebuggerServer.LONG_STRING_INITIAL_LENGTH = 400; |
michael@0 | 36 | |
michael@0 | 37 | onSetPreferences = onSetPreferences.bind(null, aState); |
michael@0 | 38 | aState.client.setPreferences({ |
michael@0 | 39 | "NetworkMonitor.saveRequestAndResponseBodies": true, |
michael@0 | 40 | }, onSetPreferences); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function onSetPreferences(aState, aResponse) |
michael@0 | 44 | { |
michael@0 | 45 | is(aResponse.updated.length, 1, "updated prefs length"); |
michael@0 | 46 | is(aResponse.updated[0], "NetworkMonitor.saveRequestAndResponseBodies", |
michael@0 | 47 | "updated prefs length"); |
michael@0 | 48 | |
michael@0 | 49 | info("test network POST request"); |
michael@0 | 50 | |
michael@0 | 51 | onNetworkEvent = onNetworkEvent.bind(null, aState); |
michael@0 | 52 | aState.dbgClient.addListener("networkEvent", onNetworkEvent); |
michael@0 | 53 | onNetworkEventUpdate = onNetworkEventUpdate.bind(null, aState); |
michael@0 | 54 | aState.dbgClient.addListener("networkEventUpdate", onNetworkEventUpdate); |
michael@0 | 55 | |
michael@0 | 56 | let iframe = document.querySelector("iframe").contentWindow; |
michael@0 | 57 | iframe.wrappedJSObject.testXhrPost(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function onNetworkEvent(aState, aType, aPacket) |
michael@0 | 61 | { |
michael@0 | 62 | is(aPacket.from, aState.actor, "network event actor"); |
michael@0 | 63 | |
michael@0 | 64 | info("checking the network event packet"); |
michael@0 | 65 | |
michael@0 | 66 | let netActor = aPacket.eventActor; |
michael@0 | 67 | |
michael@0 | 68 | checkObject(netActor, { |
michael@0 | 69 | actor: /[a-z]/, |
michael@0 | 70 | startedDateTime: /^\d+\-\d+\-\d+T.+$/, |
michael@0 | 71 | url: /data\.json/, |
michael@0 | 72 | method: "POST", |
michael@0 | 73 | }); |
michael@0 | 74 | |
michael@0 | 75 | aState.netActor = netActor.actor; |
michael@0 | 76 | |
michael@0 | 77 | aState.dbgClient.removeListener("networkEvent", onNetworkEvent); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | let updates = []; |
michael@0 | 81 | |
michael@0 | 82 | function onNetworkEventUpdate(aState, aType, aPacket) |
michael@0 | 83 | { |
michael@0 | 84 | info("received networkEventUpdate " + aPacket.updateType); |
michael@0 | 85 | is(aPacket.from, aState.netActor, "networkEventUpdate actor"); |
michael@0 | 86 | |
michael@0 | 87 | updates.push(aPacket.updateType); |
michael@0 | 88 | |
michael@0 | 89 | let expectedPacket = null; |
michael@0 | 90 | |
michael@0 | 91 | switch (aPacket.updateType) { |
michael@0 | 92 | case "requestHeaders": |
michael@0 | 93 | case "responseHeaders": |
michael@0 | 94 | ok(aPacket.headers > 0, "headers > 0"); |
michael@0 | 95 | ok(aPacket.headersSize > 0, "headersSize > 0"); |
michael@0 | 96 | break; |
michael@0 | 97 | case "requestCookies": |
michael@0 | 98 | expectedPacket = { |
michael@0 | 99 | cookies: 3, |
michael@0 | 100 | }; |
michael@0 | 101 | break; |
michael@0 | 102 | case "requestPostData": |
michael@0 | 103 | ok(aPacket.dataSize > 0, "dataSize > 0"); |
michael@0 | 104 | ok(!aPacket.discardRequestBody, "discardRequestBody"); |
michael@0 | 105 | break; |
michael@0 | 106 | case "responseStart": |
michael@0 | 107 | expectedPacket = { |
michael@0 | 108 | response: { |
michael@0 | 109 | httpVersion: /^HTTP\/\d\.\d$/, |
michael@0 | 110 | status: 200, |
michael@0 | 111 | statusText: "OK", |
michael@0 | 112 | headersSize: /^\d+$/, |
michael@0 | 113 | discardResponseBody: false, |
michael@0 | 114 | }, |
michael@0 | 115 | }; |
michael@0 | 116 | break; |
michael@0 | 117 | case "responseCookies": |
michael@0 | 118 | expectedPacket = { |
michael@0 | 119 | cookies: 0, |
michael@0 | 120 | }; |
michael@0 | 121 | break; |
michael@0 | 122 | case "responseContent": |
michael@0 | 123 | expectedPacket = { |
michael@0 | 124 | mimeType: "application/json", |
michael@0 | 125 | contentSize: /^\d+$/, |
michael@0 | 126 | discardResponseBody: false, |
michael@0 | 127 | }; |
michael@0 | 128 | break; |
michael@0 | 129 | case "eventTimings": |
michael@0 | 130 | expectedPacket = { |
michael@0 | 131 | totalTime: /^\d+$/, |
michael@0 | 132 | }; |
michael@0 | 133 | break; |
michael@0 | 134 | default: |
michael@0 | 135 | ok(false, "unknown network event update type: " + |
michael@0 | 136 | aPacket.updateType); |
michael@0 | 137 | return; |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | if (expectedPacket) { |
michael@0 | 141 | info("checking the packet content"); |
michael@0 | 142 | checkObject(aPacket, expectedPacket); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | if (updates.indexOf("responseContent") > -1 && |
michael@0 | 146 | updates.indexOf("eventTimings") > -1) { |
michael@0 | 147 | aState.dbgClient.removeListener("networkEventUpdate", |
michael@0 | 148 | onNetworkEvent); |
michael@0 | 149 | |
michael@0 | 150 | onRequestHeaders = onRequestHeaders.bind(null, aState); |
michael@0 | 151 | aState.client.getRequestHeaders(aState.netActor, |
michael@0 | 152 | onRequestHeaders); |
michael@0 | 153 | } |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | function onRequestHeaders(aState, aResponse) |
michael@0 | 157 | { |
michael@0 | 158 | info("checking request headers"); |
michael@0 | 159 | |
michael@0 | 160 | ok(aResponse.headers.length > 0, "request headers > 0"); |
michael@0 | 161 | ok(aResponse.headersSize > 0, "request headersSize > 0"); |
michael@0 | 162 | |
michael@0 | 163 | checkHeadersOrCookies(aResponse.headers, { |
michael@0 | 164 | Referer: /network_requests_iframe\.html/, |
michael@0 | 165 | Cookie: /bug768096/, |
michael@0 | 166 | }); |
michael@0 | 167 | |
michael@0 | 168 | onRequestCookies = onRequestCookies.bind(null, aState); |
michael@0 | 169 | aState.client.getRequestCookies(aState.netActor, |
michael@0 | 170 | onRequestCookies); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | function onRequestCookies(aState, aResponse) |
michael@0 | 174 | { |
michael@0 | 175 | info("checking request cookies"); |
michael@0 | 176 | |
michael@0 | 177 | is(aResponse.cookies.length, 3, "request cookies length"); |
michael@0 | 178 | |
michael@0 | 179 | checkHeadersOrCookies(aResponse.cookies, { |
michael@0 | 180 | foobar: "fooval", |
michael@0 | 181 | omgfoo: "bug768096", |
michael@0 | 182 | badcookie: "bug826798=st3fan", |
michael@0 | 183 | }); |
michael@0 | 184 | |
michael@0 | 185 | onRequestPostData = onRequestPostData.bind(null, aState); |
michael@0 | 186 | aState.client.getRequestPostData(aState.netActor, |
michael@0 | 187 | onRequestPostData); |
michael@0 | 188 | } |
michael@0 | 189 | |
michael@0 | 190 | function onRequestPostData(aState, aResponse) |
michael@0 | 191 | { |
michael@0 | 192 | info("checking request POST data"); |
michael@0 | 193 | |
michael@0 | 194 | checkObject(aResponse, { |
michael@0 | 195 | postData: { |
michael@0 | 196 | text: { |
michael@0 | 197 | type: "longString", |
michael@0 | 198 | initial: /^Hello world! foobaz barr.+foobaz barrfo$/, |
michael@0 | 199 | length: 552, |
michael@0 | 200 | actor: /[a-z]/, |
michael@0 | 201 | }, |
michael@0 | 202 | }, |
michael@0 | 203 | postDataDiscarded: false, |
michael@0 | 204 | }); |
michael@0 | 205 | |
michael@0 | 206 | is(aResponse.postData.text.initial.length, |
michael@0 | 207 | DebuggerServer.LONG_STRING_INITIAL_LENGTH, "postData text initial length"); |
michael@0 | 208 | |
michael@0 | 209 | onResponseHeaders = onResponseHeaders.bind(null, aState); |
michael@0 | 210 | aState.client.getResponseHeaders(aState.netActor, |
michael@0 | 211 | onResponseHeaders); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | function onResponseHeaders(aState, aResponse) |
michael@0 | 215 | { |
michael@0 | 216 | info("checking response headers"); |
michael@0 | 217 | |
michael@0 | 218 | ok(aResponse.headers.length > 0, "response headers > 0"); |
michael@0 | 219 | ok(aResponse.headersSize > 0, "response headersSize > 0"); |
michael@0 | 220 | |
michael@0 | 221 | checkHeadersOrCookies(aResponse.headers, { |
michael@0 | 222 | "Content-Type": /^application\/(json|octet-stream)$/, |
michael@0 | 223 | "Content-Length": /^\d+$/, |
michael@0 | 224 | "x-very-short": "hello world", |
michael@0 | 225 | "x-very-long": { |
michael@0 | 226 | "type": "longString", |
michael@0 | 227 | "length": 521, |
michael@0 | 228 | "initial": /^Lorem ipsum.+\. Donec vitae d$/, |
michael@0 | 229 | "actor": /[a-z]/, |
michael@0 | 230 | }, |
michael@0 | 231 | }); |
michael@0 | 232 | |
michael@0 | 233 | onResponseCookies = onResponseCookies.bind(null, aState); |
michael@0 | 234 | aState.client.getResponseCookies(aState.netActor, |
michael@0 | 235 | onResponseCookies); |
michael@0 | 236 | } |
michael@0 | 237 | |
michael@0 | 238 | function onResponseCookies(aState, aResponse) |
michael@0 | 239 | { |
michael@0 | 240 | info("checking response cookies"); |
michael@0 | 241 | |
michael@0 | 242 | is(aResponse.cookies.length, 0, "response cookies length"); |
michael@0 | 243 | |
michael@0 | 244 | onResponseContent = onResponseContent.bind(null, aState); |
michael@0 | 245 | aState.client.getResponseContent(aState.netActor, |
michael@0 | 246 | onResponseContent); |
michael@0 | 247 | } |
michael@0 | 248 | |
michael@0 | 249 | function onResponseContent(aState, aResponse) |
michael@0 | 250 | { |
michael@0 | 251 | info("checking response content"); |
michael@0 | 252 | |
michael@0 | 253 | checkObject(aResponse, { |
michael@0 | 254 | content: { |
michael@0 | 255 | text: { |
michael@0 | 256 | type: "longString", |
michael@0 | 257 | initial: /^\{ id: "test JSON data"(.|\r|\n)+ barfoo ba$/g, |
michael@0 | 258 | length: 1070, |
michael@0 | 259 | actor: /[a-z]/, |
michael@0 | 260 | }, |
michael@0 | 261 | }, |
michael@0 | 262 | contentDiscarded: false, |
michael@0 | 263 | }); |
michael@0 | 264 | |
michael@0 | 265 | is(aResponse.content.text.initial.length, |
michael@0 | 266 | DebuggerServer.LONG_STRING_INITIAL_LENGTH, "content initial length"); |
michael@0 | 267 | |
michael@0 | 268 | onEventTimings = onEventTimings.bind(null, aState); |
michael@0 | 269 | aState.client.getEventTimings(aState.netActor, |
michael@0 | 270 | onEventTimings); |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | function onEventTimings(aState, aResponse) |
michael@0 | 274 | { |
michael@0 | 275 | info("checking event timings"); |
michael@0 | 276 | |
michael@0 | 277 | checkObject(aResponse, { |
michael@0 | 278 | timings: { |
michael@0 | 279 | blocked: /^-1|\d+$/, |
michael@0 | 280 | dns: /^-1|\d+$/, |
michael@0 | 281 | connect: /^-1|\d+$/, |
michael@0 | 282 | send: /^-1|\d+$/, |
michael@0 | 283 | wait: /^-1|\d+$/, |
michael@0 | 284 | receive: /^-1|\d+$/, |
michael@0 | 285 | }, |
michael@0 | 286 | totalTime: /^\d+$/, |
michael@0 | 287 | }); |
michael@0 | 288 | |
michael@0 | 289 | closeDebugger(aState, function() { |
michael@0 | 290 | DebuggerServer.LONG_STRING_LENGTH = ORIGINAL_LONG_STRING_LENGTH; |
michael@0 | 291 | DebuggerServer.LONG_STRING_INITIAL_LENGTH = ORIGINAL_LONG_STRING_INITIAL_LENGTH; |
michael@0 | 292 | |
michael@0 | 293 | SimpleTest.finish(); |
michael@0 | 294 | }); |
michael@0 | 295 | } |
michael@0 | 296 | |
michael@0 | 297 | addEventListener("load", startTest); |
michael@0 | 298 | </script> |
michael@0 | 299 | </body> |
michael@0 | 300 | </html> |