Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: LayoutTests/http/tests/serviceworker/unregister-controller.html

Issue 358553003: Service Worker: add layout tests for behavior of controller after unregister (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/serviceworker/unregister-controller.html
diff --git a/LayoutTests/http/tests/serviceworker/unregister-controller.html b/LayoutTests/http/tests/serviceworker/unregister-controller.html
new file mode 100644
index 0000000000000000000000000000000000000000..a3be77e691fa702905d7dc10943e2d6624be57b9
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/unregister-controller.html
@@ -0,0 +1,71 @@
+<!DOCTYPE html>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.js"></script>
+<script>
+var worker_url = 'resources/hello-world-worker.js';
+
+async_test(function(t) {
+ var scope = 'unregister-existing-controller';
+ var w = null;
+
+ service_worker_unregister_and_register(t, worker_url, scope).then(t.step_func(function(worker) {
+ worker.addEventListener('statechange', t.step_func(on_state_change));
+ }));
+
+ function on_state_change(event) {
+ if (event.target.state != 'active')
+ return;
+ with_iframe(scope, t.step_func(function(frame) {
michaeln 2014/06/26 00:41:15 how is 'scope' used by with_iframe?
falken 2014/06/26 03:03:16 with_iframe makes an iframe with src=scope. The id
+ w = frame.contentWindow;
+ assert_true(w.navigator.serviceWorker.controller instanceof w.ServiceWorker,
+ 'document should load with a controller');
+ document_loaded();
+ }));
+ }
+
+ function document_loaded() {
+ navigator.serviceWorker.unregister(scope).then(t.step_func(function() {
+ assert_true(w.navigator.serviceWorker.controller instanceof w.ServiceWorker,
+ 'controller should remain after unregister');
+ var xhr = new w.XMLHttpRequest();
michaeln 2014/06/26 00:41:15 On my first reading, i didn't notice you were new'
falken 2014/06/26 03:03:16 Yeah I agree this is confusing though it seems to
+ xhr.addEventListener('readystatechange', t.step_func(function(event) {
+ if (event.target.readyState == 4) {
+ assert_equals(xhr.response, 'hello, world', 'controller should intercept requests');
michaeln 2014/06/26 00:41:15 hello world is generated by the script, right? may
falken 2014/06/26 03:03:16 Done.
+ t.done();
+ }
+ }));
+ xhr.open('GET', 'resources/simple.html');
+ xhr.send();
+ }));
+ }
+}, 'Unregister does not affect existing controller');
+
+async_test(function(t) {
michaeln 2014/06/26 00:41:15 does this next async_test() get queued up and wait
falken 2014/06/26 03:03:16 They run concurrently. That's why we have to be ca
+ var scope = 'no-control-after-unregister';
+
+ service_worker_unregister_and_register(t, worker_url, scope).then(t.step_func(function(worker) {
+ worker.addEventListener('statechange', t.step_func(on_state_change));
+ }));
+
+ function on_state_change(event) {
+ if (event.target.state != 'active')
+ return;
+ navigator.serviceWorker.unregister(scope).then(t.step_func(function() {
+ with_iframe(scope, t.step_func(function(frame) {
+ var w = frame.contentWindow;
+ assert_equals(w.navigator.serviceWorker.controller, null, 'document should not have a controller');
+ var xhr = new w.XMLHttpRequest();
+ xhr.addEventListener('readystatechange', t.step_func(function(event) {
+ if (event.target.readyState == 4) {
+ assert_equals(xhr.response, '<!DOCTYPE html>\n<title>Simple</title>\nHere\'s a simple html file.\n', 'requests should not be intercepted');
michaeln 2014/06/26 00:41:15 a simple text file would be even simpler (and make
falken 2014/06/26 03:03:16 Done.
+ t.done();
+ }
+ }));
+ xhr.open('GET', 'resources/simple.html');
+ xhr.send();
+ }));
+ }));
+ }
+}, 'Unregister prevents control of subsequent navigations');
+</script>
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698