navigation-timing-sizes.https.html (5294B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Service Worker Navigation Timing</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 8 <body> 9 <script> 10 11 promise_test(async t => { 12 var script = 'resources/pass-through-worker.js'; 13 var scope = 'resources/blank.html'; 14 15 const registration = await service_worker_unregister_and_register(t, script, scope); 16 t.add_cleanup(() => registration.unregister()); 17 await wait_for_state(t, registration.installing, 'activated'); 18 19 const iframe = await with_iframe(scope); 20 21 // Sanity, to check that we actually loaded the document. 22 assert_equals(iframe.contentWindow.document.title, "Empty doc"); 23 t.add_cleanup(() => iframe.remove()); 24 const navigationEntry = iframe.contentWindow.performance.getEntriesByType("navigation")[0]; 25 26 const main_page_resource_timing = performance.getEntriesByType("resource").filter( 27 e => e.name.includes('blank'))[0]; 28 29 assert_greater_than(navigationEntry.encodedBodySize, 0, 30 'Navigation timing should have encodedBodySize larger than 0.'); 31 32 assert_equals(navigationEntry.decodedBodySize, navigationEntry.encodedBodySize, 33 'Navigation timing\'s decodedBodySize and encodedBodySize should be equal.'); 34 35 assert_greater_than(main_page_resource_timing.encodedBodySize, 0, 36 'Corresponding resource timing emitted on parent page should have decodedBodySize larger than 0.'); 37 38 assert_equals(main_page_resource_timing.encodedBodySize, main_page_resource_timing.decodedBodySize, 39 'Corresponding resource timing emitted on parent page should have equal\ 40 decodedBodySize and encodedBodySize.'); 41 42 }, 'Body sizes in a regular pass-through'); 43 44 promise_test(async t => { 45 var script = 'resources/pass-through-worker.js'; 46 var scope = 'resources/simple.txt'; 47 48 const registration = await service_worker_unregister_and_register(t, script, scope); 49 t.add_cleanup(() => registration.unregister()); 50 await wait_for_state(t, registration.installing, 'activated'); 51 52 const iframe = await with_iframe(scope); 53 54 // Sanity, to check that we actually loaded the text file. 55 assert_equals(iframe.contentWindow.document.body.textContent, "a simple text file\n"); 56 t.add_cleanup(() => iframe.remove()); 57 const navigationEntry = iframe.contentWindow.performance.getEntriesByType("navigation")[0]; 58 59 const main_page_resource_timing = performance.getEntriesByType("resource").filter( 60 e => e.name.includes('blank'))[0]; 61 62 assert_greater_than(navigationEntry.encodedBodySize, 0, 63 'Navigation timing should have encodedBodySize larger than 0.'); 64 65 assert_equals(navigationEntry.decodedBodySize, navigationEntry.encodedBodySize, 66 'Navigation timing\'s decodedBodySize and encodedBodySize should be equal.'); 67 68 assert_greater_than(main_page_resource_timing.encodedBodySize, 0, 69 'Corresponding resource timing emitted on parent page should have decodedBodySize larger than 0.'); 70 71 assert_equals(main_page_resource_timing.encodedBodySize, main_page_resource_timing.decodedBodySize, 72 'Corresponding resource timing emitted on parent page should have equal\ 73 decodedBodySize and encodedBodySize.'); 74 75 }, 'Body sizes in a pass-through with non html content'); 76 77 promise_test(async t => { 78 var script = 'resources/pass-through-worker.js'; 79 var scope = 'resources/blank.html'; 80 81 const registration = await service_worker_unregister_and_register(t, script, scope); 82 t.add_cleanup(() => registration.unregister()); 83 await wait_for_state(t, registration.installing, 'activated'); 84 85 const iframe = await with_iframe(scope + "?pipe=gzip"); 86 // Sanity, to check that we actually loaded the document. 87 assert_equals(iframe.contentWindow.document.title, "Empty doc"); 88 t.add_cleanup(() => iframe.remove()); 89 90 const navigationEntry = iframe.contentWindow.performance.getEntriesByType("navigation")[0]; 91 92 const main_page_resource_timing = performance.getEntriesByType("resource").filter( 93 e => e.name.includes('blank'))[0]; 94 95 assert_greater_than(navigationEntry.decodedBodySize, 0, 96 'Navigation timing should have decodedBodySize larger than 0.'); 97 98 // The response body that comes from a service worker respondWith promise 99 // should have identical encoded and decoded body sizes, regardless of what 100 // the service worker itself saw, according to the spec. 101 assert_equals(navigationEntry.encodedBodySize, navigationEntry.decodedBodySize, 102 'Navigation timing should have equal decodedBodySize and encodedBodySize.'); 103 104 assert_greater_than(main_page_resource_timing.decodedBodySize, 0, 105 'Corresponding resource timing emitted on parent page should have decodedBodySize larger than 0.'); 106 107 assert_equals(main_page_resource_timing.encodedBodySize, navigationEntry.decodedBodySize, 108 'Corresponding resource timing emitted on parent page should have equal decodedBodySize and \ 109 encodedBodySize.'); 110 111 }, 'Body sizes in a regular pass-through with gzip'); 112 </script> 113 </body>