-
-
Save jugglinmike/a67f822f9f42343d6b422d000fbb2b39 to your computer and use it in GitHub Desktop.
sw-migration-update.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/update.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/update.https.html | |
index 82db192..213b72a 100644 | |
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/update.html | |
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/update.https.html | |
@@ -1,14 +1,16 @@ | |
<!DOCTYPE html> | |
<title>Service Worker: Registration update()</title> | |
-<script src="../resources/testharness.js"></script> | |
-<script src="../resources/testharnessreport.js"></script> | |
-<script src="resources/test-helpers.js"></script> | |
+<script src="/resources/testharness.js"></script> | |
+<script src="/resources/testharnessreport.js"></script> | |
+<script src="resources/testharness-helpers.js"></script> | |
+<script src="resources/test-helpers.sub.js"></script> | |
<script> | |
promise_test(function(t) { | |
- var scope = 'resources/scope/update'; | |
- var worker_url = 'resources/update-worker.php'; | |
+ var scope = 'resources/simple.txt'; | |
+ var worker_url = 'resources/update-worker.py'; | |
var expected_url = normalizeURL(worker_url); | |
var registration; | |
+ var iframe; | |
return service_worker_unregister_and_register(t, worker_url, scope) | |
.then(function(r) { | |
registration = r; | |
@@ -21,8 +23,7 @@ promise_test(function(t) { | |
'waiting should be null in the initial state.'); | |
assert_equals(registration.active.scriptURL, expected_url, | |
'active should exist in the initial state.'); | |
- | |
- // A new worker (generated by update-worker.php) should be found. | |
+ // A new worker (generated by update-worker.py) should be found. | |
// The returned promise should resolve when a new worker script is | |
// fetched and starts installing. | |
return Promise.all([registration.update(), | |
@@ -40,11 +41,13 @@ promise_test(function(t) { | |
.then(function() { | |
assert_equals(registration.installing, null, | |
'installing should be null after installing.'); | |
- assert_equals(registration.waiting.scriptURL, expected_url, | |
- 'waiting should be set after installing.'); | |
- assert_equals(registration.active.scriptURL, expected_url, | |
- 'active should still exist after installing.'); | |
- return wait_for_state(t, registration.waiting, 'activated'); | |
+ if (registration.waiting) { | |
+ assert_equals(registration.waiting.scriptURL, expected_url, | |
+ 'waiting should be set after installing.'); | |
+ assert_equals(registration.active.scriptURL, expected_url, | |
+ 'active should still exist after installing.'); | |
+ return wait_for_state(t, registration.waiting, 'activated'); | |
+ } | |
}) | |
.then(function() { | |
assert_equals(registration.installing, null, | |
@@ -55,8 +58,8 @@ promise_test(function(t) { | |
'new worker should be promoted to active.'); | |
}) | |
.then(function() { | |
- // A new worker(generated by update-worker.php) should be found. | |
- // The returned promise should reject as update-worker.php sets the | |
+ // A new worker(generated by update-worker.py) should be found. | |
+ // The returned promise should reject as update-worker.py sets the | |
// mimetype to a disallowed value for this attempt. | |
return registration.update(); | |
}) | |
@@ -92,11 +95,11 @@ promise_test(function(t) { | |
}) | |
.then(function() { | |
assert_equals(registration.installing.scriptURL, expected_url, | |
- 'installing should be set after update resolves (throw-install).'); | |
+ 'new installing should be set after update resolves.'); | |
assert_equals(registration.waiting, null, | |
- 'waiting should still be null after update resolves (throw-install).'); | |
+ 'waiting should be null after activated.'); | |
assert_equals(registration.active.scriptURL, expected_url, | |
- 'active should still exist after update found (throw-install).'); | |
+ 'active should still exist after update found.'); | |
// We need to hold a client alive so that unregister() below doesn't | |
// remove the registration before update() has had a chance to look | |
@@ -104,16 +107,17 @@ promise_test(function(t) { | |
return with_iframe(scope); | |
}) | |
.then(function(frame) { | |
- return Promise.all([registration.unregister(), | |
- registration.update()]); | |
+ iframe = frame; | |
+ | |
+ return assert_promise_rejects( | |
+ Promise.all([registration.unregister(), registration.update()]), | |
+ new TypeError(), | |
+ 'Calling update() while the uninstalling flag is set ' + | |
+ 'should return a promise that rejects with a TypeError.'); | |
}) | |
- .then( | |
- function() { assert_unreached("update() should reject."); }, | |
- function(e) { | |
- assert_throws({name: 'TypeError'}, function () { throw e; }, | |
- 'Calling update() while the uninstalling flag is ' + | |
- 'set should return a promise that rejects with an ' + | |
- 'TypeError.'); | |
+ .then(function() { | |
+ iframe.remove(); | |
+ return t.done(); | |
}); | |
}, 'Update a registration.'); | |
</script> | |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/update-worker.php b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/update-worker.py | |
index 81bdd1b..bc9b32a 100644 | |
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/update-worker.php | |
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/update-worker.py | |
@@ -1,42 +1,46 @@ | |
-<?php | |
-if(!isset($_COOKIE['mode'])) | |
- $mode = 'init'; // Set mode to 'init' for initial fetch. | |
-else | |
- $mode = $_COOKIE['mode']; // $_COOKIE['mode'] is either 'normal' or 'error'. | |
+import time | |
-// no-cache itself to ensure the user agent finds a new version for each update. | |
-header("Cache-Control: no-cache, must-revalidate"); | |
-header("Pragma: no-cache"); | |
+def main(request, response): | |
+ # Set mode to 'init' for initial fetch. | |
+ mode = 'init' | |
+ if 'mode' in request.cookies: | |
+ mode = request.cookies['mode'].value | |
-$extra_body = ''; | |
+ # no-cache itself to ensure the user agent finds a new version for each update. | |
+ headers = [('Cache-Control', 'no-cache, must-revalidate'), | |
+ ('Pragma', 'no-cache')] | |
+ | |
+ content_type = '' | |
+ extra_body = '' | |
+ | |
+ if mode == 'init': | |
+ # Set a normal mimetype. | |
+ # Set cookie value to 'normal' so the next fetch will work in 'normal' mode. | |
+ content_type = 'application/javascript' | |
+ response.set_cookie('mode', 'normal') | |
+ elif mode == 'normal': | |
+ # Set a normal mimetype. | |
+ # Set cookie value to 'error' so the next fetch will work in 'error' mode. | |
+ content_type = 'application/javascript' | |
+ response.set_cookie('mode', 'error'); | |
+ elif mode == 'error': | |
+ # Set a disallowed mimetype. | |
+ # Set cookie value to 'syntax-error' so the next fetch will work in 'syntax-error' mode. | |
+ content_type = 'text/html' | |
+ response.set_cookie('mode', 'syntax-error'); | |
+ elif mode == 'syntax-error': | |
+ # Set cookie value to 'throw-install' so the next fetch will work in 'throw-install' mode. | |
+ content_type = 'application/javascript' | |
+ response.set_cookie('mode', 'throw-install'); | |
+ extra_body = 'badsyntax(isbad;' | |
+ elif mode == 'throw-install': | |
+ # Unset and delete cookie to clean up the test setting. | |
+ content_type = 'application/javascript' | |
+ response.delete_cookie('mode') | |
+ extra_body = "addEventListener('install', function(e) { throw new Error('boom'); });" | |
+ | |
+ headers.append(('Content-Type', content_type)) | |
+ # Return a different script for each access. Use .time() and .clock() for | |
+ # best time resolution across different platforms. | |
+ return headers, '/* %s %s */ %s' % (time.time(), time.clock(), extra_body) | |
-if ($mode == 'init') { | |
- // Set a normal mimetype. | |
- // Set cookie value to 'normal' so the next fetch will work in 'normal' mode. | |
- header('Content-Type:application/javascript'); | |
- setcookie('mode', 'normal'); | |
-} else if ($mode == 'normal') { | |
- // Set a normal mimetype. | |
- // Set cookie value to 'error' so the next fetch will work in 'error' mode. | |
- header('Content-Type:application/javascript'); | |
- setcookie('mode', 'error'); | |
-} else if ($mode == 'error') { | |
- // Set a disallowed mimetype. | |
- // Set cookie value to 'syntax-error' so the next fetch will work in 'syntax-error' mode. | |
- header('Content-Type:text/html'); | |
- setcookie('mode', 'syntax-error'); | |
-} else if ($mode == 'syntax-error') { | |
- // Set cookie value to 'throw-install' so the next fetch will work in 'throw-install' mode. | |
- header('Content-Type:application/javascript'); | |
- setcookie('mode', 'throw-install'); | |
- $extra_body = 'badsyntax(isbad;'; | |
-} else if ($mode == 'throw-install') { | |
- // Unset and delete cookie to clean up the test setting. | |
- header('Content-Type:application/javascript'); | |
- unset($_COOKIE['mode']); | |
- setcookie('mode', '', time() - 3600); | |
- $extra_body = "addEventListener('install', function(e) { throw new Error('boom'); });"; | |
-} | |
-// Return a different script for each access. | |
-echo '/* ', microtime(), ' */ ', $extra_body; | |
-?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment