Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 for the network actor (GET request)</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 for the network actor (GET request)</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 | attachConsole(["NetworkActivity"], onAttach, true); |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function onAttach(aState, aResponse) |
michael@0 | 26 | { |
michael@0 | 27 | info("test network GET request"); |
michael@0 | 28 | |
michael@0 | 29 | onNetworkEvent = onNetworkEvent.bind(null, aState); |
michael@0 | 30 | aState.dbgClient.addListener("networkEvent", onNetworkEvent); |
michael@0 | 31 | onNetworkEventUpdate = onNetworkEventUpdate.bind(null, aState); |
michael@0 | 32 | aState.dbgClient.addListener("networkEventUpdate", onNetworkEventUpdate); |
michael@0 | 33 | |
michael@0 | 34 | let iframe = document.querySelector("iframe").contentWindow; |
michael@0 | 35 | iframe.wrappedJSObject.testXhrGet(); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function onNetworkEvent(aState, aType, aPacket) |
michael@0 | 39 | { |
michael@0 | 40 | is(aPacket.from, aState.actor, "network event actor"); |
michael@0 | 41 | |
michael@0 | 42 | info("checking the network event packet"); |
michael@0 | 43 | |
michael@0 | 44 | let netActor = aPacket.eventActor; |
michael@0 | 45 | |
michael@0 | 46 | checkObject(netActor, { |
michael@0 | 47 | actor: /[a-z]/, |
michael@0 | 48 | startedDateTime: /^\d+\-\d+\-\d+T.+$/, |
michael@0 | 49 | url: /data\.json/, |
michael@0 | 50 | method: "GET", |
michael@0 | 51 | }); |
michael@0 | 52 | |
michael@0 | 53 | aState.netActor = netActor.actor; |
michael@0 | 54 | |
michael@0 | 55 | aState.dbgClient.removeListener("networkEvent", onNetworkEvent); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | let updates = []; |
michael@0 | 59 | |
michael@0 | 60 | function onNetworkEventUpdate(aState, aType, aPacket) |
michael@0 | 61 | { |
michael@0 | 62 | info("received networkEventUpdate " + aPacket.updateType); |
michael@0 | 63 | is(aPacket.from, aState.netActor, "networkEventUpdate actor"); |
michael@0 | 64 | |
michael@0 | 65 | updates.push(aPacket.updateType); |
michael@0 | 66 | |
michael@0 | 67 | let expectedPacket = null; |
michael@0 | 68 | |
michael@0 | 69 | switch (aPacket.updateType) { |
michael@0 | 70 | case "requestHeaders": |
michael@0 | 71 | case "responseHeaders": |
michael@0 | 72 | ok(aPacket.headers > 0, "headers > 0"); |
michael@0 | 73 | ok(aPacket.headersSize > 0, "headersSize > 0"); |
michael@0 | 74 | break; |
michael@0 | 75 | case "requestCookies": |
michael@0 | 76 | expectedPacket = { |
michael@0 | 77 | cookies: 3, |
michael@0 | 78 | }; |
michael@0 | 79 | break; |
michael@0 | 80 | case "requestPostData": |
michael@0 | 81 | ok(false, "got unexpected requestPostData"); |
michael@0 | 82 | break; |
michael@0 | 83 | case "responseStart": |
michael@0 | 84 | expectedPacket = { |
michael@0 | 85 | response: { |
michael@0 | 86 | httpVersion: /^HTTP\/\d\.\d$/, |
michael@0 | 87 | status: 200, |
michael@0 | 88 | statusText: "OK", |
michael@0 | 89 | headersSize: /^\d+$/, |
michael@0 | 90 | discardResponseBody: true, |
michael@0 | 91 | }, |
michael@0 | 92 | }; |
michael@0 | 93 | break; |
michael@0 | 94 | case "responseCookies": |
michael@0 | 95 | expectedPacket = { |
michael@0 | 96 | cookies: 0, |
michael@0 | 97 | }; |
michael@0 | 98 | break; |
michael@0 | 99 | case "responseContent": |
michael@0 | 100 | expectedPacket = { |
michael@0 | 101 | mimeType: "application/json", |
michael@0 | 102 | contentSize: 0, |
michael@0 | 103 | discardResponseBody: true, |
michael@0 | 104 | }; |
michael@0 | 105 | break; |
michael@0 | 106 | case "eventTimings": |
michael@0 | 107 | expectedPacket = { |
michael@0 | 108 | totalTime: /^\d+$/, |
michael@0 | 109 | }; |
michael@0 | 110 | break; |
michael@0 | 111 | default: |
michael@0 | 112 | ok(false, "unknown network event update type: " + |
michael@0 | 113 | aPacket.updateType); |
michael@0 | 114 | return; |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | if (expectedPacket) { |
michael@0 | 118 | info("checking the packet content"); |
michael@0 | 119 | checkObject(aPacket, expectedPacket); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | if (updates.indexOf("responseContent") > -1 && |
michael@0 | 123 | updates.indexOf("eventTimings") > -1) { |
michael@0 | 124 | aState.dbgClient.removeListener("networkEventUpdate", |
michael@0 | 125 | onNetworkEvent); |
michael@0 | 126 | |
michael@0 | 127 | onRequestHeaders = onRequestHeaders.bind(null, aState); |
michael@0 | 128 | aState.client.getRequestHeaders(aState.netActor, |
michael@0 | 129 | onRequestHeaders); |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | function onRequestHeaders(aState, aResponse) |
michael@0 | 134 | { |
michael@0 | 135 | info("checking request headers"); |
michael@0 | 136 | |
michael@0 | 137 | ok(aResponse.headers.length > 0, "request headers > 0"); |
michael@0 | 138 | ok(aResponse.headersSize > 0, "request headersSize > 0"); |
michael@0 | 139 | |
michael@0 | 140 | checkHeadersOrCookies(aResponse.headers, { |
michael@0 | 141 | Referer: /network_requests_iframe\.html/, |
michael@0 | 142 | Cookie: /bug768096/, |
michael@0 | 143 | }); |
michael@0 | 144 | |
michael@0 | 145 | onRequestCookies = onRequestCookies.bind(null, aState); |
michael@0 | 146 | aState.client.getRequestCookies(aState.netActor, |
michael@0 | 147 | onRequestCookies); |
michael@0 | 148 | } |
michael@0 | 149 | |
michael@0 | 150 | function onRequestCookies(aState, aResponse) |
michael@0 | 151 | { |
michael@0 | 152 | info("checking request cookies"); |
michael@0 | 153 | |
michael@0 | 154 | is(aResponse.cookies.length, 3, "request cookies length"); |
michael@0 | 155 | |
michael@0 | 156 | checkHeadersOrCookies(aResponse.cookies, { |
michael@0 | 157 | foobar: "fooval", |
michael@0 | 158 | omgfoo: "bug768096", |
michael@0 | 159 | badcookie: "bug826798=st3fan", |
michael@0 | 160 | }); |
michael@0 | 161 | |
michael@0 | 162 | onRequestPostData = onRequestPostData.bind(null, aState); |
michael@0 | 163 | aState.client.getRequestPostData(aState.netActor, |
michael@0 | 164 | onRequestPostData); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | function onRequestPostData(aState, aResponse) |
michael@0 | 168 | { |
michael@0 | 169 | info("checking request POST data"); |
michael@0 | 170 | |
michael@0 | 171 | ok(!aResponse.postData.text, "no request POST data"); |
michael@0 | 172 | ok(aResponse.postDataDiscarded, "request POST data was discarded"); |
michael@0 | 173 | |
michael@0 | 174 | onResponseHeaders = onResponseHeaders.bind(null, aState); |
michael@0 | 175 | aState.client.getResponseHeaders(aState.netActor, |
michael@0 | 176 | onResponseHeaders); |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | function onResponseHeaders(aState, aResponse) |
michael@0 | 180 | { |
michael@0 | 181 | info("checking response headers"); |
michael@0 | 182 | |
michael@0 | 183 | ok(aResponse.headers.length > 0, "response headers > 0"); |
michael@0 | 184 | ok(aResponse.headersSize > 0, "response headersSize > 0"); |
michael@0 | 185 | |
michael@0 | 186 | checkHeadersOrCookies(aResponse.headers, { |
michael@0 | 187 | "Content-Type": /^application\/(json|octet-stream)$/, |
michael@0 | 188 | "Content-Length": /^\d+$/, |
michael@0 | 189 | }); |
michael@0 | 190 | |
michael@0 | 191 | onResponseCookies = onResponseCookies.bind(null, aState); |
michael@0 | 192 | aState.client.getResponseCookies(aState.netActor, |
michael@0 | 193 | onResponseCookies); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | function onResponseCookies(aState, aResponse) |
michael@0 | 197 | { |
michael@0 | 198 | info("checking response cookies"); |
michael@0 | 199 | |
michael@0 | 200 | is(aResponse.cookies.length, 0, "response cookies length"); |
michael@0 | 201 | |
michael@0 | 202 | onResponseContent = onResponseContent.bind(null, aState); |
michael@0 | 203 | aState.client.getResponseContent(aState.netActor, |
michael@0 | 204 | onResponseContent); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | function onResponseContent(aState, aResponse) |
michael@0 | 208 | { |
michael@0 | 209 | info("checking response content"); |
michael@0 | 210 | |
michael@0 | 211 | ok(!aResponse.content.text, "no response content"); |
michael@0 | 212 | ok(aResponse.contentDiscarded, "response content was discarded"); |
michael@0 | 213 | |
michael@0 | 214 | onEventTimings = onEventTimings.bind(null, aState); |
michael@0 | 215 | aState.client.getEventTimings(aState.netActor, |
michael@0 | 216 | onEventTimings); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | function onEventTimings(aState, aResponse) |
michael@0 | 220 | { |
michael@0 | 221 | info("checking event timings"); |
michael@0 | 222 | |
michael@0 | 223 | checkObject(aResponse, { |
michael@0 | 224 | timings: { |
michael@0 | 225 | blocked: /^-1|\d+$/, |
michael@0 | 226 | dns: /^-1|\d+$/, |
michael@0 | 227 | connect: /^-1|\d+$/, |
michael@0 | 228 | send: /^-1|\d+$/, |
michael@0 | 229 | wait: /^-1|\d+$/, |
michael@0 | 230 | receive: /^-1|\d+$/, |
michael@0 | 231 | }, |
michael@0 | 232 | totalTime: /^\d+$/, |
michael@0 | 233 | }); |
michael@0 | 234 | |
michael@0 | 235 | closeDebugger(aState, function() { |
michael@0 | 236 | SimpleTest.finish(); |
michael@0 | 237 | }); |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | addEventListener("load", startTest); |
michael@0 | 241 | </script> |
michael@0 | 242 | </body> |
michael@0 | 243 | </html> |