New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ServiceWorkerContainer::Promise #13419
Merged
+83
−51
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Add Promises to Service Worker Container
The purpose of the code changes is to enable the use of promises in the Service Worker container. I also modified the Service Worker test in order to support the promises.
- Loading branch information
commit e6b879048fa7224885605cd695ca5b853799f55a
| @@ -14,39 +14,39 @@ | ||
| assert_true('serviceWorker' in navigator); | ||
| }, "Test: Asserts ServiceWorkerContainer in Navigator"); | ||
|
|
||
| test(function() { | ||
| var sw_reg = register_sw('sw.js'); | ||
| assert_class_string(sw_reg, "ServiceWorkerRegistration"); | ||
| assert_class_string(sw_reg.active, "ServiceWorker"); | ||
| assert_class_string(navigator.serviceWorker.controller, "ServiceWorker"); | ||
| promise_test(function() { | ||
| return register_sw('sw.js').then(function(sw_reg) { | ||
| assert_class_string(sw_reg, "ServiceWorkerRegistration"); | ||
| assert_class_string(sw_reg.active, "ServiceWorker"); | ||
| assert_class_string(navigator.serviceWorker.controller, "ServiceWorker"); | ||
| }); | ||
| }, "Test: Asserts Active Service Worker and its Registration"); | ||
|
|
||
| test(function() { | ||
| var sw_reg = register_sw('resources/sw.js', './'); | ||
| assert_equals(sw_reg.scope, location.href.replace("service-worker-registration.html", "")); | ||
| promise_test(function() { | ||
| return register_sw('resources/sw.js', './').then(function(sw_reg) { | ||
| assert_equals(sw_reg.scope, location.href.replace("service-worker-registration.html", "")); | ||
| }); | ||
| }, "Test: Service Worker Registration property scope Url when no scope"); | ||
|
|
||
| test(function() { | ||
| var sw_reg = register_sw('resources/sw.js', '/some/nested/cache/directory'); | ||
| var expected_scope_url = location.protocol + '//' + location.host + '/some/nested/cache/directory'; | ||
| assert_equals(sw_reg.scope, expected_scope_url); | ||
| promise_test(function() { | ||
| return register_sw('resources/sw.js', '/some/nested/cache/directory').then(function(sw_reg) { | ||
| var expected_scope_url = location.protocol + '//' + location.host + '/some/nested/cache/directory'; | ||
| assert_equals(sw_reg.scope, expected_scope_url); | ||
| }); | ||
| }, "Test: Service Worker Registration property scope when provided a scope"); | ||
|
|
||
| test(function () { | ||
| assert_throws(new TypeError(), | ||
| function() { var sw_reg = register_sw('./in%5Csome%5fdir/sw.js'); }, | ||
| "Invalid URL Path"); | ||
| promise_test(function (p) { | ||
| promise_rejects(p, new TypeError(), register_sw('./in%5Csome%5fdir/sw.js')); | ||
Coder206
Author
Contributor
|
||
| }, "Test: Throws Error when Invalid Url Path"); | ||
|
|
||
| test(function () { | ||
| assert_throws(new TypeError(), | ||
| function() { var sw_reg = register_sw('sw.js', './mal%5fformed/sco%5Cpe/'); }, | ||
| "Invalid URL Path"); | ||
| promise_test(function (p) { | ||
| return promise_rejects(p, new TypeError(), register_sw('sw.js', './mal%5fformed/sco%5Cpe/')); | ||
|
||
| }, "Test: Throws Error when Invalid Scope"); | ||
|
|
||
| test(function() { | ||
| var sw_reg = register_sw('resources/sw.js'); | ||
| assert_equals(sw_reg.active.scriptURL, location.href.replace("service-worker-registration.html", "resources/sw.js")); | ||
| promise_test(function() { | ||
| return register_sw('resources/sw.js').then(function(sw_reg) { | ||
| assert_equals(sw_reg.active.scriptURL, location.href.replace("service-worker-registration.html", "resources/sw.js")); | ||
| }); | ||
| }, "Test: Active Service Worker ScriptURL property"); | ||
|
|
||
| </script> | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
@jdm I don't fancy an inline code like this but the code below would fail: