Bug 1444680: Part 4: Convert test_ext_webRequest_webSocket to xpcshell. r?mixedpuppy draft
authorKris Maglione <maglione.k@gmail.com>
Sat, 10 Mar 2018 18:49:38 -0800
changeset 765938 f19da1c1bffea4c5f894b6bc04c9636c96e830a2
parent 765937 27188a28141f967aa14e32acfe7b7f6a6261a624
child 765939 28198b6b577b98fd2f358c2dcba5538b85094620
push id102183
push usermaglione.k@gmail.com
push dateSun, 11 Mar 2018 06:57:39 +0000
reviewersmixedpuppy
bugs1444680
milestone60.0a1
Bug 1444680: Part 4: Convert test_ext_webRequest_webSocket to xpcshell. r?mixedpuppy MozReview-Commit-ID: Ck0vyHoqPV9
toolkit/components/extensions/test/mochitest/mochitest-common.ini
toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
toolkit/components/extensions/test/xpcshell/test_ext_webRequest_webSocket.js
toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
--- a/toolkit/components/extensions/test/mochitest/mochitest-common.ini
+++ b/toolkit/components/extensions/test/mochitest/mochitest-common.ini
@@ -160,12 +160,11 @@ skip-if = os == 'android' && debug # bug
 [test_ext_webrequest_filter.html]
 [test_ext_webrequest_frameId.html]
 [test_ext_webrequest_hsts.html]
 [test_ext_webrequest_responseBody.html]
 skip-if = os == 'android' || os == 'linux' # linux, bug 1398120
 [test_ext_webrequest_upgrade.html]
 [test_ext_webrequest_upload.html]
 skip-if = os == 'android' # Currently fails in emulator tests
-[test_ext_webrequest_websocket.html]
 [test_ext_webrequest_redirect_data_uri.html]
 [test_ext_window_postMessage.html]
 [test_ext_xhr_capabilities.html]
rename from toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
rename to toolkit/components/extensions/test/xpcshell/test_ext_webRequest_webSocket.js
--- a/toolkit/components/extensions/test/mochitest/test_ext_webrequest_websocket.html
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_webRequest_webSocket.js
@@ -1,56 +1,53 @@
-<!DOCTYPE HTML>
-<html>
-<!--
--->
-<head>
-  <title>Basic websocket test</title>
-  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
-  <script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
-  <script type="text/javascript" src="head.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+"use strict";
+
+const HOSTS = new Set([
+  "example.com",
+]);
 
-<script class="testbody" type="text/javascript">
-"use strict";
+const server = createHttpServer({hosts: HOSTS});
+
+server.registerPathHandler("/dummy", (request, response) => {
+  response.setStatusLine(request.httpVersion, 200, "OK");
+  response.write("ok");
+});
 
 add_task(async function test_webSocket() {
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "permissions": [
         "webRequest",
         "webRequestBlocking",
         "<all_urls>",
       ],
     },
     background() {
       browser.webRequest.onBeforeRequest.addListener(details => {
         browser.test.assertEq("ws:", new URL(details.url).protocol, "ws protocol worked");
         browser.test.notifyPass("websocket");
-      }, {urls: ["ws://mochi.test/*"]}, ["blocking"]);
+      }, {urls: ["ws://example.com/*"]}, ["blocking"]);
 
       browser.test.onMessage.addListener(msg => {
-        let ws = new WebSocket("ws://mochi.test:8888/tests/dom/base/test/file_websocket_hello");
+        let ws = new WebSocket("ws://example.com/dummy");
         ws.onopen = (e) => {
           ws.send("data");
         };
         ws.onclose = (e) => {};
         ws.onerror = (e) => {};
         ws.onmessage = (e) => {
           ws.close();
         };
       });
       browser.test.sendMessage("ready");
     },
   });
   await extension.startup();
   await extension.awaitMessage("ready");
   extension.sendMessage("go");
   await extension.awaitFinish("websocket");
+
+  // Wait until the next tick so that listener responses are processed
+  // before we unload.
+  await new Promise(executeSoon);
+
   await extension.unload();
 });
-
-</script>
-</head>
-<body>
-</body>
-</html>
--- a/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
+++ b/toolkit/components/extensions/test/xpcshell/xpcshell-common.ini
@@ -79,16 +79,17 @@ skip-if = os == "android"
 [test_ext_storage_telemetry.js]
 skip-if = os == "android" # checking for telemetry needs to be updated: 1384923
 [test_ext_trustworthy_origin.js]
 [test_ext_topSites.js]
 skip-if = os == "android"
 [test_ext_webRequest_filterResponseData.js]
 [test_ext_webRequest_permission.js]
 [test_ext_webRequest_suspend.js]
+[test_ext_webRequest_webSocket.js]
 [test_native_manifests.js]
 subprocess = true
 skip-if = os == "android"
 [test_ext_permissions.js]
 skip-if = os == "android" # Bug 1350559
 [test_proxy_listener.js]
 [test_proxy_scripts.js]
 [test_proxy_scripts_results.js]