Commit d132447c authored by Kunihiko Sakamoto's avatar Kunihiko Sakamoto Committed by Commit Bot

Subresource WebBundle: Do not reload bundle on resources attribute change

Bug: 1082020
Change-Id: Ib3acbd01711ea781f751714fd0854437b9647896
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332148Reviewed-by: default avatarTsuyoshi Horo <horo@chromium.org>
Reviewed-by: default avatarHayato Ito <hayato@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Kunihiko Sakamoto <ksakamoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794372}
parent a44bbb14
......@@ -23,8 +23,8 @@ class WebBundleLoader : public GarbageCollected<WebBundleLoader>,
ExecutionContext& execution_context,
const KURL& url)
: link_web_bundle_(&link_web_bundle),
pending_factory_receiver_(
loader_factory_.BindNewPipeAndPassReceiver()) {
pending_factory_receiver_(loader_factory_.BindNewPipeAndPassReceiver()),
url_(url) {
ResourceRequest request(url);
request.SetUseStreamOnResponse(true);
// TODO(crbug.com/1082020): Revisit these once the fetch and process the
......@@ -77,6 +77,8 @@ class WebBundleLoader : public GarbageCollected<WebBundleLoader>,
void DidFail(const ResourceError&) override { DidFailInternal(); }
void DidFailRedirectCheck() override { DidFailInternal(); }
const KURL& url() const { return url_; }
private:
void DidFailInternal() {
if (pending_factory_receiver_) {
......@@ -97,6 +99,7 @@ class WebBundleLoader : public GarbageCollected<WebBundleLoader>,
mojo::PendingReceiver<network::mojom::blink::URLLoaderFactory>
pending_factory_receiver_;
bool failed_ = false;
KURL url_;
};
LinkWebBundle::LinkWebBundle(HTMLLinkElement* owner) : LinkResource(owner) {}
......@@ -123,8 +126,10 @@ void LinkWebBundle::Process() {
if (!resource_fetcher)
return;
bundle_loader_ = MakeGarbageCollected<WebBundleLoader>(
*this, *owner_->GetDocument().GetExecutionContext(), owner_->Href());
if (!bundle_loader_ || bundle_loader_->url() != owner_->Href()) {
bundle_loader_ = MakeGarbageCollected<WebBundleLoader>(
*this, *owner_->GetDocument().GetExecutionContext(), owner_->Href());
}
resource_fetcher->AddSubresourceWebBundle(*this);
}
......
......@@ -7,7 +7,7 @@
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<link rel="webbundle" href="../resources/wbn/subresource.wbn"
<link id="link-web-bundle" rel="webbundle" href="../resources/wbn/subresource.wbn"
resources="https://subresource-wbn.example/root.js https://subresource-wbn.example/submodule.js" />
<script>
promise_test(async () => {
......@@ -41,25 +41,43 @@
}, 'Dynamically adding / updating / removing "<link rel=webbundle>"');
promise_test(() => {
return addLinkAndWaitForLoad("../resources/wbn/dynamic1.wbn?test-event");
}, '<link rel="webbundle"> fires a load event on load success');
promise_test((t) => {
return addLinkAndWaitForError("../resources/wbn/nonexistent.wbn");
}, '<link rel="webbundle"> fires an error event on load failure');
promise_test(async () => {
const wbn_url = 'http://web-platform.test:8001/web-bundle/resources/wbn/subresource.wbn?test-resources-update';
const resource_url = 'https://subresource-wbn.example/submodule.js';
const link = await addLinkAndWaitForLoad(wbn_url);
link.resources.add(resource_url);
const resp = await fetch(resource_url, {cache: 'no-store'});
assert_true(resp.ok);
assert_equals(performance.getEntriesByName(wbn_url).length, 1);
}, 'Updating resource= attribute should not reload the bundle');
function addLinkAndWaitForLoad(url) {
return new Promise((resolve, reject) => {
const link = document.createElement("link");
link.rel = "webbundle";
link.href = "../resources/wbn/dynamic1.wbn?test-event";
link.onload = resolve;
link.href = url;
link.onload = () => resolve(link);
link.onerror = reject;
document.body.appendChild(link);
});
}, '<link rel="webbundle"> fires a load event on load success');
}
promise_test(() => {
function addLinkAndWaitForError(url) {
return new Promise((resolve, reject) => {
const link = document.createElement("link");
link.rel = "webbundle";
link.href = "../resources/wbn/nonexistent.wbn";
link.href = url;
link.onload = reject;
link.onerror = resolve;
link.onerror = () => resolve(link);
document.body.appendChild(link);
});
}, '<link rel="webbundle"> fires an error event on load failure');
}
</script>
</body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment