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

Unified Diff: LayoutTests/http/tests/serviceworker/fetch-event.html

Issue 304233017: ServiceWorker: Add layout tests for fetch event response (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: patch for landing 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 | LayoutTests/http/tests/serviceworker/fetch-event-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
« no previous file with comments | « no previous file | LayoutTests/http/tests/serviceworker/fetch-event-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698