test_network_longstring.html 7.7 KB

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