Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Last active May 29, 2017 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugglinmike/55f7de63032befeb16175d607c51fe7d to your computer and use it in GitHub Desktop.
Save jugglinmike/55f7de63032befeb16175d607c51fe7d to your computer and use it in GitHub Desktop.
sw-migration-http-to-https.diff
$ git show -M10
commit f26ecde6736594ae0463f4f251f8c97650098a02
Author: Mike Pennisi <mike@mikepennisi.com>
Date: Mon May 29 16:27:29 2017 -0400
Upstream service wrkr "respond with" tests to WPT
**http-to-https-redirect-and-register**
The Web Platform Tests project's infrastructure can only provide secure
contexts through the use of the HTTPS protocol. This restriction
precludes the strategy used by this test because an HTTPS-origin page
cannot load an HTTP-origin iframe.
Introduce a related test that may run in the WPT infrastructure: one
that creates browsing contexts via `window.open`. Update the surrounding
logic to accomodate this alteration. Additionally, update URLs to
suitable values for the WPT project, using the `base_path` utility
function as per convention there.
Because the new version differs substantially, the original version
cannot be removed without decreasing test coverage. Persist the original
version of the test within the Chromium project, and document the
rational for doing so.
Update both versions to include "use strict" directives for all script
bodies and to avoid including unnecessary script resources.
BUG=688116
R=falken@chromium.org
diff --git a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/http-to-https-redirect-and-register.https.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/http-to-https-redirect-and-register.https.html
new file mode 100644
index 0000000..d78b23a
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/http-to-https-redirect-and-register.https.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<title>register on a secure page after redirect from an non-secure url</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="resources/test-helpers.sub.js"></script>
+<body>
+<script>
+'use strict';
+
+// Loads a non-secure url in a new window, which redirects to |target_url|.
+// That page then registers a service worker, and messages back with the result.
+// Returns a promise that resolves with the result.
+function redirect_and_register(target_url) {
+ var redirect_url = get_host_info()['UNAUTHENTICATED_ORIGIN'] + base_path() +
+ 'resources/redirect.py?Redirect=';
+ var child = window.open(redirect_url + encodeURIComponent(target_url));
+ return new Promise(resolve => {
+ window.addEventListener('message', e => resolve(e.data));
+ })
+ .then(function(result) {
+ child.close();
+ return result;
+ });
+}
+
+promise_test(function(t) {
+ var target_url = window.location.origin + base_path() +
+ 'resources/http-to-https-redirect-and-register-iframe.html';
+
+ return redirect_and_register(target_url)
+ .then(result => {
+ assert_equals(result, 'OK');
+ });
+ }, 'register on a secure page after redirect from an non-secure url');
+
+promise_test(function(t) {
+ var target_url = get_host_info()['UNAUTHENTICATED_ORIGIN'] + base_path() +
+ 'resources/http-to-https-redirect-and-register-iframe.html';
+
+ return redirect_and_register(target_url)
+ .then(result => {
+ assert_equals(result, 'FAIL: SecurityError');
+ });
+ }, 'register on a non-secure page after redirect from an non-secure url');
+</script>
+</body>
diff --git a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/http-to-https-redirect-and-register-iframe.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/http-to-https-redirect-and-register-iframe.html
new file mode 100644
index 0000000..8c48a18
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/http-to-https-redirect-and-register-iframe.html
@@ -0,0 +1,21 @@
+<!doctype html>
+<title>register, unregister, and report result to opener</title>
+<body>
+<script>
+'use strict';
+
+navigator.serviceWorker.register('empty-worker.js', {scope: 'scope-register'})
+ .then(
+ registration => {
+ registration.unregister().then(() => {
+ window.opener.postMessage('OK', '*');
+ });
+ },
+ error => {
+ window.opener.postMessage('FAIL: ' + error.name, '*');
+ })
+ .catch(error => {
+ window.opener.postMessage('ERROR: ' + error.name, '*');
+ });
+</script>
+</body>
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/http-to-https-redirect-and-register.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.http-to-https-redirect-and-register-iframe.html
similarity index 79%
rename from third_party/WebKit/LayoutTests/http/tests/serviceworker/http-to-https-redirect-and-register.html
rename to third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.http-to-https-redirect-and-register-iframe.html
index af07905..209c819 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/http-to-https-redirect-and-register.html
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/chromium.http-to-https-redirect-and-register-iframe.html
@@ -1,4 +1,10 @@
<!DOCTYPE html>
+<!-- This test's file name is prefixed with `chromium.` because while a roughly
+ equivalent version is available in the Web Platform Tests project, the
+ limitations of the WPT infrastructure precludes the use of iframes for this
+ purpose. This version should be maintained only insofar as the functionality
+ under test concerns iframe contexts specifically; otherwise, modifications
+ should be contributed to the shared version. -->
<title>register on a secure page after redirect from an non-secure url</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
@@ -6,6 +12,7 @@
<script src="resources/test-helpers.js"></script>
<body>
<script>
+'use strict';
// Loads a non-secure url in an iframe, which redirects to |target_url|.
// That page then registers a service worker, and messages back with the result.
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register.html
index e8713dd..e954067 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register.html
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/register.html
@@ -1,8 +1,9 @@
<!doctype html>
<title>register</title>
-<script src="test-helpers.js"></script>
<body>
<script>
+'use strict';
+
navigator.serviceWorker.register('empty-worker.js', {scope: 'scope-register'})
.then(
registration => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment