Skip to content

Commit

Permalink
Append service-worker body size information in BodyDataReceivedImpl
Browse files Browse the repository at this point in the history
In the last CL[1], the size information of the body intercepted by
service-worker was forwareded to navigation timing. However, the total
size is appended in `DocumentLoader::DecodedBodyDataReceived()`, which
is called when the body load is done in the background thread. If the
background thread is not used, `DocumentLoader::BodyDataReceived()` is
called instead, and in that case `total_body_size_from_service_worker_`
is not set at all.

The background thread is used if the mime-type is text/html, but not
used for other mime-type resources. Whether the background thread is
used or not is determined in
`DocumentLoader::MaybeStartLoadingBodyInBackground()`[2].

This CL moves the code from `DecodedBodyDataReceived()` to
`BodyDataReceivedImpl()`, which is called from both `BodyDataReceived()`
and `DecodedBodyDataReceived()`.

https://crbug.com/41494176#comment18 has more context.

[1] crrev.com/c/5463285
[2] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/document_loader.cc;l=3499-3520;drc=b74be264a68fdb02cb216ad60ea610562d2f800d;bpv=1;bpt=1

Bug: 334977808
Change-Id: Ib1ab987a011c5a7cb983dc48d7906b96378f3a88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5526558
Reviewed-by: Kouhei Ueno <kouhei@chromium.org>
Commit-Queue: Kouhei Ueno <kouhei@chromium.org>
Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1298573}
  • Loading branch information
sisidovski authored and chromium-wpt-export-bot committed May 9, 2024
1 parent e14a763 commit 5519d8a
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions service-workers/service-worker/navigation-timing-sizes.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@

}, 'Body sizes in a regular pass-through');

promise_test(async t => {
var script = 'resources/pass-through-worker.js';
var scope = 'resources/simple.txt';

const registration = await service_worker_unregister_and_register(t, script, scope);
t.add_cleanup(() => registration.unregister());
await wait_for_state(t, registration.installing, 'activated');

const iframe = await with_iframe(scope);

// Sanity, to check that we actually loaded the text file.
assert_equals(iframe.contentWindow.document.body.textContent, "a simple text file\n");
t.add_cleanup(() => iframe.remove());
const navigationEntry = iframe.contentWindow.performance.getEntriesByType("navigation")[0];

const main_page_resource_timing = performance.getEntriesByType("resource").filter(
e => e.name.includes('blank'))[0];

assert_greater_than(navigationEntry.encodedBodySize, 0,
'Navigation timing should have encodedBodySize larger than 0.');

assert_equals(navigationEntry.decodedBodySize, navigationEntry.encodedBodySize,
'Navigation timing\'s decodedBodySize and encodedBodySize should be equal.');

assert_greater_than(main_page_resource_timing.encodedBodySize, 0,
'Corresponding resource timing emitted on parent page should have decodedBodySize larger than 0.');

assert_equals(main_page_resource_timing.encodedBodySize, main_page_resource_timing.decodedBodySize,
'Corresponding resource timing emitted on parent page should have equal\
decodedBodySize and encodedBodySize.');

}, 'Body sizes in a pass-through with non html content');

promise_test(async t => {
var script = 'resources/pass-through-worker.js';
var scope = 'resources/blank.html';
Expand Down

0 comments on commit 5519d8a

Please sign in to comment.