Index: LayoutTests/http/tests/serviceworker/chromium/memory-cache.html |
diff --git a/LayoutTests/http/tests/serviceworker/chromium/memory-cache.html b/LayoutTests/http/tests/serviceworker/chromium/memory-cache.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..20dbb4be5244a8bb19a57e2bdebdc61fce93eb0e |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/chromium/memory-cache.html |
@@ -0,0 +1,71 @@ |
+<!DOCTYPE html> |
+<html> |
+<title>Service Worker: Memory Cache</title> |
+<script src="../../resources/testharness.js"></script> |
+<script src="../../resources/testharnessreport.js"></script> |
+<script src="../resources/test-helpers.js"></script> |
+<script> |
+var callback; |
horo
2014/10/10 02:25:12
Please write comments about |callback|.
"This call
nhiroki
2014/10/10 06:20:37
Done.
|
+ |
+function getJSON(url) { |
+ var sc = document.createElement('script'); |
+ sc.src = url; |
+ document.body.appendChild(sc); |
+ return new Promise(function(resolve) { |
+ callback = function(data) { resolve(data); } |
+ }); |
+} |
+ |
+async_test(function(t) { |
+ var scope = 'resources/memory-cache-controlled.html'; |
+ var worker = 'resources/memory-cache-worker.js'; |
+ var json_url = '/serviceworker/chromium/resources/memory-cache.json'; |
+ var registration; |
+ var frame; |
+ var promises = []; |
+ |
+ service_worker_unregister_and_register(t, worker, scope) |
+ .then(function(r) { |
+ registration = r; |
+ return wait_for_activated(t, registration); |
+ }) |
+ .then(function() { return with_iframe(scope); }) |
+ .then(function(f) { |
+ frame = f; |
+ var messageChannel = new MessageChannel(); |
jsbell
2014/10/09 16:47:51
Is this "ack" step actually necessary for the test
nhiroki
2014/10/10 06:20:37
This messaging mechanism seems no longer necessary
|
+ var promise = new Promise(function (resolve) { |
+ messageChannel.port1.onmessage = function(e) { |
+ resolve(e); |
+ } |
+ }); |
+ registration.active.postMessage( |
+ {port: messageChannel.port2}, [messageChannel.port2]); |
+ // Request a json file from controlled page. |
+ promises.push(frame.contentWindow.getJSON(json_url)); |
+ return promise; |
+ }) |
+ .then(function(e) { |
+ assert_equals(e.data, 'ack'); |
+ // Request a json file from non-controlled page. |
+ promises.push(getJSON(json_url)); |
+ registration.active.postMessage({ ping: true }); |
+ return Promise.all(promises); |
+ }) |
+ .then(function(results) { |
+ assert_equals( |
+ results[0].src, |
+ 'service worker', |
+ 'Response for controlled page should be served by Service Worker'); |
+ assert_equals( |
+ results[1].src, |
+ 'network', |
+ 'Response for non-controlled page should be served by network'); |
+ unload_iframe(frame); |
+ return registration.unregister(); |
+ }) |
+ .then(function() { |
+ t.done(); |
+ }) |
+ .catch(unreached_rejection(t)); |
+ }, 'Non-controlled page should not use a cache filled by Service Worker'); |
+</script> |