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

Unified Diff: LayoutTests/http/tests/serviceworker/current-on-reload.html

Issue 265943003: Add blink-side binding code for navigator.serviceWorker.current (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 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
Index: LayoutTests/http/tests/serviceworker/current-on-reload.html
diff --git a/LayoutTests/http/tests/serviceworker/current-on-reload.html b/LayoutTests/http/tests/serviceworker/current-on-reload.html
new file mode 100644
index 0000000000000000000000000000000000000000..71a7cc8c9b60e915cdfd75140188c5984d17a947
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/current-on-reload.html
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<title>Service Worker: Current on reload</title>
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="resources/testutils.js"></script>
+<body>
+<script>
+var t = async_test('current is set upon reload after registration');
+t.step(function() {
+ var reloaded = false;
+ var scope = 'resources/blank.html';
+ navigator.serviceWorker.unregister(scope).then(doTest, doTest);
+
+ function doTest() {
+ withIframe(scope, t.step_func(onIframeLoad));
+ }
+
+ function onIframeLoad(frame) {
+ var w = frame.contentWindow;
+
+ function onActive(event) {
+ assert_equals(w.navigator.serviceWorker.current, null,
+ 'current should be null until the document is reloaded');
+ reloaded = true;
+ w.location.reload();
+ }
+
+ function onRegister(worker) {
+ worker.addEventListener('statechange', function(event) {
+ if (event.target.state == 'active')
+ t.step(onActive);
+ });
+ }
+
+ if (reloaded) {
+
+ // FIXME: Why instanceof doesn't work?
+ // assert_true(w.navigator.serviceWorker.current instanceof ServiceWorker,
kinuko 2014/05/02 12:26:13 Somehow I can't make it work for .current. I'm lik
jsbell 2014/05/02 17:55:03 w.navigator.serviceWorker.current is reaching into
kinuko 2014/05/05 14:20:27 Very cool, thanks!
+ assert_true(w.navigator.serviceWorker.current.constructor.name == 'ServiceWorker',
+ 'current should be a ServiceWorker object upon reload');
+ t.done();
+ return;
+ }
+
+ w.navigator.serviceWorker.register(
+ 'worker-no-op.js', {scope: 'blank.html'}
+ ).then(t.step_func(onRegister), t.step_func(function(reason) {
+ assert_unreached('Registration should succeed, but failed: ' + reason.name);
+ }));
+ }
+});
+</script>
+</body>

Powered by Google App Engine
This is Rietveld 408576698