Test for bug 1214752 - verify that the network monitor shows CORS preflights properly. r=Honza
authorJarda Snajdr <jsnajdr@gmail.com>
Thu, 26 May 2016 20:36:09 -0400
changeset 340259 1f3bc3649264c8bf2dd5c19cf3790faa2fb7b1d1
parent 340258 baee93983a1a83785879dc990d45030388e7854f
child 340260 69c675c22f86edad3830fcef5decabc2add794ba
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1214752
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Test for bug 1214752 - verify that the network monitor shows CORS preflights properly. r=Honza
devtools/client/netmonitor/test/browser.ini
devtools/client/netmonitor/test/browser_net_cors_requests.js
devtools/client/netmonitor/test/head.js
devtools/client/netmonitor/test/html_cors-test-page.html
devtools/client/netmonitor/test/sjs_cors-test-server.sjs
--- a/devtools/client/netmonitor/test/browser.ini
+++ b/devtools/client/netmonitor/test/browser.ini
@@ -1,16 +1,17 @@
 [DEFAULT]
 tags = devtools
 subsuite = devtools
 support-files =
   dropmarker.svg
   head.js
   html_content-type-test-page.html
   html_content-type-without-cache-test-page.html
+  html_cors-test-page.html
   html_custom-get-page.html
   html_single-get-page.html
   html_cyrillic-test-page.html
   html_filter-test-page.html
   html_infinite-get-page.html
   html_json-custom-mime-test-page.html
   html_json-long-test-page.html
   html_json-malformed-test-page.html
@@ -68,16 +69,17 @@ subsuite = clipboard
 subsuite = clipboard
 [browser_net_copy_response.js]
 subsuite = clipboard
 [browser_net_copy_headers.js]
 subsuite = clipboard
 [browser_net_copy_as_curl.js]
 subsuite = clipboard
 skip-if = e10s # Bug 1091596
+[browser_net_cors_requests.js]
 [browser_net_cyrillic-01.js]
 [browser_net_cyrillic-02.js]
 [browser_net_details-no-duplicated-content.js]
 skip-if = (os == 'linux' && e10s && debug) # Bug 1242204
 [browser_net_filter-01.js]
 [browser_net_filter-02.js]
 [browser_net_filter-03.js]
 [browser_net_filter-04.js]
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/browser_net_cors_requests.js
@@ -0,0 +1,29 @@
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+"use strict";
+
+/**
+ * Test that CORS preflight requests are displayed by network monitor
+ */
+
+add_task(function* () {
+  let [, debuggee, monitor] = yield initNetMonitor(CORS_URL);
+  let { RequestsMenu } = monitor.panelWin.NetMonitorView;
+  RequestsMenu.lazyUpdate = false;
+
+  info("Performing a CORS request");
+  let url = "http://test1.example.com" + CORS_SJS_PATH;
+  debuggee.performRequests(url, "triggering/preflight", "post-data");
+
+  info("Waiting until the requests appear in netmonitor");
+  yield waitForNetworkEvents(monitor, 1, 1);
+
+  info("Checking the preflight and flight methods");
+  ["OPTIONS", "POST"].forEach((method, i) => {
+    verifyRequestItemTarget(RequestsMenu.getItemAtIndex(i), method, url);
+  });
+
+  yield teardown(monitor);
+  finish();
+});
--- a/devtools/client/netmonitor/test/head.js
+++ b/devtools/client/netmonitor/test/head.js
@@ -37,16 +37,17 @@ const SORTING_URL = EXAMPLE_URL + "html_
 const FILTERING_URL = EXAMPLE_URL + "html_filter-test-page.html";
 const INFINITE_GET_URL = EXAMPLE_URL + "html_infinite-get-page.html";
 const CUSTOM_GET_URL = EXAMPLE_URL + "html_custom-get-page.html";
 const SINGLE_GET_URL = EXAMPLE_URL + "html_single-get-page.html";
 const STATISTICS_URL = EXAMPLE_URL + "html_statistics-test-page.html";
 const CURL_URL = EXAMPLE_URL + "html_copy-as-curl.html";
 const CURL_UTILS_URL = EXAMPLE_URL + "html_curl-utils.html";
 const SEND_BEACON_URL = EXAMPLE_URL + "html_send-beacon.html";
+const CORS_URL = EXAMPLE_URL + "html_cors-test-page.html";
 
 const SIMPLE_SJS = EXAMPLE_URL + "sjs_simple-test-server.sjs";
 const CONTENT_TYPE_SJS = EXAMPLE_URL + "sjs_content-type-test-server.sjs";
 const STATUS_CODES_SJS = EXAMPLE_URL + "sjs_status-codes-test-server.sjs";
 const SORTING_SJS = EXAMPLE_URL + "sjs_sorting-test-server.sjs";
 const HTTPS_REDIRECT_SJS = EXAMPLE_URL + "sjs_https-redirect-test-server.sjs";
 const CORS_SJS_PATH = "/browser/devtools/client/netmonitor/test/sjs_cors-test-server.sjs";
 
new file mode 100644
--- /dev/null
+++ b/devtools/client/netmonitor/test/html_cors-test-page.html
@@ -0,0 +1,31 @@
+<!-- Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+  <head>
+    <meta charset="utf-8"/>
+    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
+    <meta http-equiv="Pragma" content="no-cache" />
+    <meta http-equiv="Expires" content="0" />
+    <title>Network Monitor test page</title>
+  </head>
+
+  <body>
+    <p>POST with CORS test page</p>
+
+    <script type="text/javascript">
+      function post(url, contentType, postData) {
+        var xhr = new XMLHttpRequest();
+        xhr.open("POST", url, true);
+        xhr.setRequestHeader("Content-Type", contentType);
+        xhr.send(postData);
+      }
+
+      function performRequests(url, contentType, postData) {
+        post(url, contentType, postData);
+      }
+    </script>
+  </body>
+
+</html>
--- a/devtools/client/netmonitor/test/sjs_cors-test-server.sjs
+++ b/devtools/client/netmonitor/test/sjs_cors-test-server.sjs
@@ -4,13 +4,14 @@
 function handleRequest(request, response) {
   response.setStatusLine(request.httpVersion, 200, "Och Aye");
 
   response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
   response.setHeader("Pragma", "no-cache");
   response.setHeader("Expires", "0");
 
   response.setHeader("Access-Control-Allow-Origin", "*", false);
+  response.setHeader("Access-Control-Allow-Headers", "content-type", false);
 
   response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
 
   response.write("Access-Control-Allow-Origin: *");
 }