Index: LayoutTests/http/tests/serviceworker/fetch-event.html |
diff --git a/LayoutTests/http/tests/serviceworker/fetch-event.html b/LayoutTests/http/tests/serviceworker/fetch-event.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e5b9735f16e7dc8d614bc0c4c3a56c62bf8d3065 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/fetch-event.html |
@@ -0,0 +1,89 @@ |
+<!DOCTYPE html> |
+<script src="../resources/testharness.js"></script> |
+<script src="../resources/testharnessreport.js"></script> |
+<script src="resources/test-helpers.js"></script> |
+<body> |
+<script> |
+var worker = 'resources/fetch-event-test-worker.js'; |
+ |
+(function() { |
+ var t = async_test('Service Worker responds to fetch event with blob body'); |
+ var scope = 'helloworld'; |
+ service_worker_unregister_and_register(t, worker, scope, onRegister); |
+ |
+ function onRegister(sw) { |
+ sw.addEventListener('statechange', t.step_func(onStateChange)); |
+ } |
+ |
+ function onStateChange(event) { |
+ if (event.target.state != 'active') |
+ return; |
+ with_iframe(scope, t.step_func(function(frame) { |
+ assert_equals(frame.contentDocument.body.textContent, 'hello, world', |
+ 'Service Worker should respond to fetch with a fixed-string body'); |
+ service_worker_unregister_and_done(t, scope); |
+ })); |
+ } |
+}()); |
+ |
+(function() { |
+ var t = async_test('Service Worker does not respond to fetch event'); |
+ var scope = 'resources/simple.html?ignore'; |
+ service_worker_unregister_and_register(t, worker, scope, onRegister); |
+ |
+ function onRegister(sw) { |
+ sw.addEventListener('statechange', t.step_func(onStateChange)); |
+ } |
+ |
+ function onStateChange(event) { |
+ if (event.target.state != 'active') |
+ return; |
+ with_iframe(scope, t.step_func(function(frame) { |
+ assert_equals(frame.contentDocument.body.textContent, 'Here\'s a simple html file.\n', |
+ 'Response should come from fallback to native fetch'); |
+ service_worker_unregister_and_done(t, scope); |
+ })); |
+ } |
+}()); |
+ |
+(function() { |
+ var t = async_test('Service Worker responds to fetch event with null response body'); |
+ var scope = 'resources/simple.html?null'; |
+ service_worker_unregister_and_register(t, worker, scope, onRegister); |
+ |
+ function onRegister(sw) { |
+ sw.addEventListener('statechange', t.step_func(onStateChange)); |
+ } |
+ |
+ function onStateChange(event) { |
+ if (event.target.state != 'active') |
+ return; |
+ with_iframe(scope, t.step_func(function(frame) { |
+ assert_equals(frame.contentDocument.body.textContent, '', |
+ 'Response should be the empty string'); |
+ service_worker_unregister_and_done(t, scope); |
+ })); |
+ } |
+}()); |
+ |
+(function() { |
+ var t = async_test('Service Worker rejects fetch event'); |
+ var scope = 'resources/simple.html?ignore'; |
+ service_worker_unregister_and_register(t, worker, scope, onRegister); |
+ |
+ function onRegister(sw) { |
+ sw.addEventListener('statechange', t.step_func(onStateChange)); |
+ } |
+ |
+ function onStateChange(event) { |
+ if (event.target.state != 'active') |
+ return; |
+ with_iframe(scope, t.step_func(function(frame) { |
+ assert_equals(frame.contentDocument.body.textContent, 'Here\'s a simple html file.\n', |
+ 'Response should come from fallback to native fetch'); |
+ service_worker_unregister_and_done(t, scope); |
+ })); |
+ } |
+}()); |
+</script> |
+</body> |