Commit fd3ea6f0 authored by rajendrant's avatar rajendrant Committed by Commit Bot

Reland "Clear the subresource redirect hints when navigation is started"

This is a reland of 653f075d
(After deflaking the test)

Original change's description:
> Clear the subresource redirect hints when navigation is started
>
> RenderFrames could be reused for same-origin navigations. This causes
> the hints from previous navigations to be used in next navigation
> until the new hints fetch finishes and updates the hints. This CL clears
> the hints.
>
> Unfortunately this causes race conditions between the image fetch and
> the hints update, which causes images to not redirected to compressed
> versions. So the image fetches are delayed a bit to circumvent this.
>
> Bug: 1051283
> Change-Id: Ie9e5351e68c0081ab9dbfe23faed2c3c5e8e4d42
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2056207
> Commit-Queue: rajendrant <rajendrant@chromium.org>
> Reviewed-by: Michael Crouse <mcrouse@chromium.org>
> Reviewed-by: Tarun Bansal <tbansal@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#742326}

TBR=mcrouse@chromium.org

Bug: 1051283
Change-Id: I0336295bc6120c16e02dd28f787f2edcfe37e9fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2065984Reviewed-by: default avatarrajendrant <rajendrant@chromium.org>
Commit-Queue: rajendrant <rajendrant@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743275}
parent 4c376825
......@@ -20,6 +20,7 @@
#include "components/optimization_guide/optimization_guide_constants.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/optimization_guide_service.h"
#include "components/optimization_guide/optimization_guide_switches.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/optimization_guide/test_hints_component_creator.h"
#include "components/ukm/test_ukm_recorder.h"
......@@ -28,6 +29,7 @@
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/network/public/cpp/network_quality_tracker.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
......@@ -92,7 +94,8 @@ class SubresourceRedirectBrowserTest : public InProcessBrowserTest {
{{"enable_lite_page_redirect",
enable_lite_page_redirect_ ? "true" : "false"},
{"lite_page_subresource_origin", compression_url_.spec()}}},
{optimization_guide::features::kOptimizationHints, {}}},
{optimization_guide::features::kOptimizationHints, {}},
{optimization_guide::features::kRemoteOptimizationGuideFetching, {}}},
{});
InProcessBrowserTest::SetUp();
......@@ -118,11 +121,9 @@ class SubresourceRedirectBrowserTest : public InProcessBrowserTest {
bool RunScriptExtractBool(const std::string& script,
content::WebContents* web_contents = nullptr) {
bool result;
if (!web_contents)
web_contents = browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_TRUE(ExecuteScriptAndExtractBool(web_contents, script, &result));
return result;
return EvalJs(web_contents, script).ExtractBool();
}
std::string RunScriptExtractString(
......@@ -137,6 +138,7 @@ class SubresourceRedirectBrowserTest : public InProcessBrowserTest {
// Sets up public image URL hint data.
void SetUpPublicImageURLPaths(
std::string url,
const std::vector<std::string>& public_image_paths) {
std::vector<std::string> public_image_urls;
for (const auto& image_path : public_image_paths) {
......@@ -148,7 +150,7 @@ class SubresourceRedirectBrowserTest : public InProcessBrowserTest {
const optimization_guide::HintsComponentInfo& component_info =
test_hints_component_creator_
.CreateHintsComponentInfoWithPublicImageHints(
{https_server_.GetURL("secure.com", "/").host()}, "*",
{https_server_.GetURL("secure.com", "/").host()}, url,
public_image_urls);
g_browser_process->optimization_guide_service()->MaybeUpdateHintsComponent(
......@@ -178,6 +180,15 @@ class SubresourceRedirectBrowserTest : public InProcessBrowserTest {
return metric_bytes;
}
void WaitForImageCompressionUkmMetrics(size_t count) {
while (ukm_recorder_
->GetEntriesByName(
ukm::builders::PublicImageCompressionDataUse::kEntryName)
.size() < count) {
base::RunLoop().RunUntilIdle();
}
}
void VerifyPublicImageCompressionUkm(uint64_t hash, size_t num_images) {
const auto metrics = GetImageCompressionUkmMetrics();
if (num_images) {
......@@ -333,9 +344,10 @@ IN_PROC_BROWSER_TEST_F(
DISABLE_ON_WIN_MAC_CHROMEOS(TestHTMLLoadRedirectSuccess)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image.html"));
SetUpPublicImageURLPaths("/load_image/image_delayed_load.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
RetryForHistogramUntilCountReached(
histogram_tester(), "SubresourceRedirect.CompressionAttempt.ResponseCode",
......@@ -365,7 +377,8 @@ IN_PROC_BROWSER_TEST_F(
DISABLE_ON_WIN_MAC_CHROMEOS(TestHTMLLoadRedirectBypass)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/private_url_image.png"});
SetUpPublicImageURLPaths("/load_image/private_url_image.html",
{"/load_image/private_url_image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/private_url_image.html"));
......@@ -393,8 +406,8 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
NoTriggerWhenDataSaverOff) {
EnableDataSaver(false);
CreateUkmRecorder();
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image.html"));
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
content::FetchHistogramsFromChildProcesses();
SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
......@@ -418,8 +431,9 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest, NoTriggerInIncognito) {
EnableDataSaver(true);
CreateUkmRecorder();
auto* incognito_browser = CreateIncognitoBrowser();
ui_test_utils::NavigateToURL(incognito_browser,
HttpsURLWithPath("/load_image/image.html"));
ui_test_utils::NavigateToURL(
incognito_browser,
HttpsURLWithPath("/load_image/image_delayed_load.html"));
content::FetchHistogramsFromChildProcesses();
SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
......@@ -452,9 +466,10 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
NoTriggerOnNonSecureSite) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
ui_test_utils::NavigateToURL(browser(),
HttpURLWithPath("/load_image/image.html"));
SetUpPublicImageURLPaths("/load_image/image_delayed_load.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpURLWithPath("/load_image/image_delayed_load.html"));
content::FetchHistogramsFromChildProcesses();
SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
......@@ -480,7 +495,8 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest, NoTriggerOnNonImage) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
SetUpPublicImageURLPaths("/favicon/page_with_favicon.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/favicon/page_with_favicon.html"));
......@@ -508,10 +524,12 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
DISABLE_ON_WIN_MAC_CHROMEOS(FallbackOnServerNotFound)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/fail_image.png"});
SetUpPublicImageURLPaths("/load_image/fail_image.html",
{"/load_image/fail_image.png"});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/fail_image.html"));
EXPECT_TRUE(RunScriptExtractBool("checkImage()"));
content::FetchHistogramsFromChildProcesses();
SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
......@@ -526,8 +544,6 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
"SubresourceRedirect.CompressionAttempt.ResponseCode",
net::HTTP_NOT_FOUND, 1);
EXPECT_TRUE(RunScriptExtractBool("checkImage()"));
EXPECT_EQ(GURL(RunScriptExtractString("imageSrc()")).port(),
https_url().port());
......@@ -544,13 +560,15 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
DISABLE_ON_WIN_MAC_CHROMEOS(FallbackOnServerFailure)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
SetUpPublicImageURLPaths("/load_image/image_delayed_load.html",
{"/load_image/image.png"});
SetCompressionServerToFail();
base::RunLoop().RunUntilIdle();
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image.html"));
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
EXPECT_TRUE(RunScriptExtractBool("checkImage()"));
RetryForHistogramUntilCountReached(
histogram_tester(),
"SubresourceRedirect.CompressionAttempt.ServerResponded", 1);
......@@ -558,8 +576,6 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
histogram_tester()->ExpectBucketCount(
"SubresourceRedirect.CompressionAttempt.ServerResponded", false, 1);
EXPECT_TRUE(RunScriptExtractBool("checkImage()"));
EXPECT_EQ(GURL(RunScriptExtractString("imageSrc()")).port(),
https_url().port());
......@@ -576,6 +592,7 @@ IN_PROC_BROWSER_TEST_F(
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths(
"/load_image/two_images.html",
{"/load_image/image.png", "/load_image/image.png?foo"});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/two_images.html"));
......@@ -607,7 +624,8 @@ IN_PROC_BROWSER_TEST_F(
DISABLE_ON_WIN_MAC_CHROMEOS(TestOnlyPublicImageIsRedirected)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
SetUpPublicImageURLPaths("/load_image/two_images.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/two_images.html"));
......@@ -638,7 +656,8 @@ IN_PROC_BROWSER_TEST_F(
DISABLE_ON_WIN_MAC_CHROMEOS(TestImageURLFragmentAreRemoved)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
SetUpPublicImageURLPaths("/load_image/image_with_fragment.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_with_fragment.html"));
......@@ -669,7 +688,8 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
NoTriggerOnJavaScriptImageRequest) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
SetUpPublicImageURLPaths("/load_image/image_js.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image_js.html"));
......@@ -696,9 +716,9 @@ IN_PROC_BROWSER_TEST_F(
DISABLE_ON_WIN_MAC_CHROMEOS(TestNoRedirectWithEmptyHints)) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image.html"));
SetUpPublicImageURLPaths("/load_image/image_delayed_load.html", {});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
histogram_tester()->ExpectTotalCount(
"SubresourceRedirect.CompressionAttempt.ResponseCode", 0);
......@@ -724,8 +744,8 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
TestNoRedirectWithoutHints) {
EnableDataSaver(true);
CreateUkmRecorder();
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image.html"));
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
histogram_tester()->ExpectTotalCount(
"SubresourceRedirect.CompressionAttempt.ResponseCode", 0);
......@@ -738,6 +758,7 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
EXPECT_EQ(GURL(RunScriptExtractString("imageSrc()")).port(),
https_url().port());
WaitForImageCompressionUkmMetrics(1);
VerifyIneligibleImageHintsUnavailableUkm(1);
VerifyCompressibleImageUkm(0);
VerifyIneligibleMissingInImageHintsUkm(0);
......@@ -760,6 +781,53 @@ IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
histogram_tester()->ExpectTotalCount(
"SubresourceRedirect.DidCompress.CompressionPercent", 0);
EXPECT_TRUE(RunScriptExtractBool("checkBothImagesLoaded()"));
EXPECT_EQ(GURL(RunScriptExtractString("imageSrc()")).port(),
https_url().port());
WaitForImageCompressionUkmMetrics(2);
VerifyCompressibleImageUkm(0);
VerifyIneligibleImageHintsUnavailableUkm(2);
VerifyIneligibleMissingInImageHintsUkm(0);
VerifyIneligibleOtherImageUkm(0);
}
IN_PROC_BROWSER_TEST_F(SubresourceRedirectBrowserTest,
DISABLE_ON_WIN_MAC_CHROMEOS(TestSameOriginNavigation)) {
g_browser_process->network_quality_tracker()
->ReportEffectiveConnectionTypeForTesting(
net::EFFECTIVE_CONNECTION_TYPE_2G);
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths("/load_image/image_delayed_load.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
RetryForHistogramUntilCountReached(
histogram_tester(), "SubresourceRedirect.CompressionAttempt.ResponseCode",
2);
histogram_tester()->ExpectBucketCount(
"SubresourceRedirect.CompressionAttempt.ResponseCode", net::HTTP_OK, 1);
histogram_tester()->ExpectBucketCount(
"SubresourceRedirect.CompressionAttempt.ResponseCode",
net::HTTP_TEMPORARY_REDIRECT, 1);
EXPECT_TRUE(RunScriptExtractBool("checkImage()"));
EXPECT_EQ(request_url().port(), compression_url().port());
VerifyCompressibleImageUkm(1);
VerifyIneligibleImageHintsUnavailableUkm(0);
VerifyIneligibleMissingInImageHintsUkm(0);
VerifyIneligibleOtherImageUkm(0);
CreateUkmRecorder();
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/two_images.html"));
histogram_tester()->ExpectTotalCount(
"SubresourceRedirect.CompressionAttempt.ResponseCode", 2);
EXPECT_TRUE(RunScriptExtractBool("checkBothImagesLoaded()"));
EXPECT_EQ(GURL(RunScriptExtractString("imageSrc()")).port(),
https_url().port());
VerifyCompressibleImageUkm(0);
......@@ -774,9 +842,10 @@ IN_PROC_BROWSER_TEST_F(RedirectDisabledSubresourceRedirectBrowserTest,
ImagesNotRedirected) {
EnableDataSaver(true);
CreateUkmRecorder();
SetUpPublicImageURLPaths({"/load_image/image.png"});
ui_test_utils::NavigateToURL(browser(),
HttpsURLWithPath("/load_image/image.html"));
SetUpPublicImageURLPaths("/load_image/image_delayed_load.html",
{"/load_image/image.png"});
ui_test_utils::NavigateToURL(
browser(), HttpsURLWithPath("/load_image/image_delayed_load.html"));
content::FetchHistogramsFromChildProcesses();
SubprocessMetricsProvider::MergeHistogramDeltasForTesting();
......
......@@ -114,7 +114,7 @@ SubresourceRedirectObserver::SubresourceRedirectObserver(
SubresourceRedirectObserver::~SubresourceRedirectObserver() = default;
void SubresourceRedirectObserver::ReadyToCommitNavigation(
void SubresourceRedirectObserver::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
DCHECK(navigation_handle);
if (!navigation_handle->IsInMainFrame() ||
......
......@@ -34,7 +34,7 @@ class SubresourceRedirectObserver
explicit SubresourceRedirectObserver(content::WebContents* web_contents);
// content::WebContentsObserver.
void ReadyToCommitNavigation(
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
WEB_CONTENTS_USER_DATA_KEY_DECL();
......
......@@ -48,15 +48,16 @@ GURL ResourceLoadingHintsAgent::GetDocumentURL() const {
return render_frame()->GetWebFrame()->GetDocument().Url();
}
void ResourceLoadingHintsAgent::DidStartNavigation(
const GURL& url,
base::Optional<blink::WebNavigationType> navigation_type) {
subresource_redirect_hints_agent_.DidStartNavigation();
}
void ResourceLoadingHintsAgent::DidCreateNewDocument() {
DCHECK(IsMainFrame());
did_create_new_document_ = true;
if (!GetDocumentURL().SchemeIsHTTPOrHTTPS())
return;
if (images_hints_) {
subresource_redirect_hints_agent_.SetCompressPublicImagesHints(
std::move(images_hints_));
}
if (subresource_patterns_to_block_.empty())
return;
......@@ -110,13 +111,8 @@ void ResourceLoadingHintsAgent::SetResourceLoadingHints(
void ResourceLoadingHintsAgent::SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints) {
if (did_create_new_document_) {
subresource_redirect_hints_agent_.SetCompressPublicImagesHints(
std::move(images_hints));
} else {
// Let the hints be sent in DidCreateNewDocument.
images_hints_ = std::move(images_hints);
}
subresource_redirect_hints_agent_.SetCompressPublicImagesHints(
std::move(images_hints));
}
} // namespace previews
......@@ -46,6 +46,9 @@ class ResourceLoadingHintsAgent
private:
// content::RenderFrameObserver:
void DidStartNavigation(
const GURL& url,
base::Optional<blink::WebNavigationType> navigation_type) override;
void DidCreateNewDocument() override;
void OnDestruct() override;
......@@ -63,8 +66,6 @@ class ResourceLoadingHintsAgent
bool IsMainFrame() const;
bool did_create_new_document_ = false;
std::vector<std::string> subresource_patterns_to_block_;
base::Optional<int64_t> ukm_source_id_;
......@@ -73,7 +74,6 @@ class ResourceLoadingHintsAgent
subresource_redirect::SubresourceRedirectHintsAgent
subresource_redirect_hints_agent_;
blink::mojom::CompressPublicImagesHintsPtr images_hints_;
DISALLOW_COPY_AND_ASSIGN(ResourceLoadingHintsAgent);
};
......
......@@ -16,8 +16,17 @@ namespace subresource_redirect {
SubresourceRedirectHintsAgent::SubresourceRedirectHintsAgent() = default;
SubresourceRedirectHintsAgent::~SubresourceRedirectHintsAgent() = default;
void SubresourceRedirectHintsAgent::DidStartNavigation() {
// Clear the hints when a navigation starts, so that hints from previous
// navigation do not apply in case the same renderframe is reused.
public_image_urls_.clear();
public_image_urls_received_ = false;
}
void SubresourceRedirectHintsAgent::SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints) {
DCHECK(public_image_urls_.empty());
DCHECK(!public_image_urls_received_);
public_image_urls_ = images_hints->image_urls;
public_image_urls_received_ = true;
}
......
......@@ -40,6 +40,10 @@ class SubresourceRedirectHintsAgent {
SubresourceRedirectHintsAgent& operator=(
const SubresourceRedirectHintsAgent&) = delete;
// Called when a navigation starts to clear the state from previous
// navigation.
void DidStartNavigation();
void SetCompressPublicImagesHints(
blink::mojom::CompressPublicImagesHintsPtr images_hints);
......
// Copyright (c) 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function checkImage() {
return imageLoadedPromise(document.images[0]);
}
function imageLoadedPromise(img_element) {
return new Promise((resolve, reject) => {
if (img_element.complete && img_element.src) {
console.log("image loaded callback", img_element.src);
resolve(true);
} else {
img_element.addEventListener('load', () => {
console.log("image loaded callback", img_element.src);
resolve(true);
});
}
});
}
function imageSrc() {
sendValueToTest(document.images[0].src);
}
function sendValueToTest(value) {
window.domAutomationController.send(value);
}
<html>
<head></head>
<img alt="long_placeholder_text" src="fail_image.png" />
<img alt="long_placeholder_text"/>
<script src="common.js"></script>
<script>
function checkImage() {
sendValueToTest(document.images[0].complete);
}
function imageSrc() {
sendValueToTest(document.images[0].src);
}
function sendValueToTest(value) {
window.domAutomationController.send(value);
window.onload = () => {
setTimeout(() => {
document.images[0].src = "fail_image.png"
}, 1000);
}
</script>
</html>
<html>
<head></head>
<img alt="long_placeholder_text"/>
<script src="common.js"></script>
<script>
window.onload = () => {
setTimeout(() => {
document.images[0].src = "image.png"
}, 1000);
}
</script>
</html>
<html>
<body>
<div> div tag </div>
<script src="common.js"></script>
<script>
var img = document.createElement("img");
img.src="image.png";
document.getElementsByTagName('div')[0].appendChild(img);
function checkImage() {
sendValueToTest(document.images[0].complete);
}
function imageSrc() {
sendValueToTest(document.images[0].src);
}
function sendValueToTest(value) {
window.domAutomationController.send(value);
}
</script>
</body>
</html>
\ No newline at end of file
</html>
<html>
<head></head>
<img alt="long_placeholder_text" src="image.png#fragment" />
<img alt="long_placeholder_text"/>
<script src="common.js"></script>
<script>
function checkImage() {
sendValueToTest(document.images[0].complete);
}
function imageSrc() {
sendValueToTest(document.images[0].src);
}
function sendValueToTest(value) {
window.domAutomationController.send(value);
window.onload = () => {
setTimeout(() => {
document.images[0].src = "image.png#fragment"
}, 1000)
}
</script>
</html>
<html>
<body>
<img alt="long_placeholder_text" src="private_url_image.png" />
<img alt="long_placeholder_text"/>
<script src="common.js"></script>
<script>
function checkImage() {
sendValueToTest((document.images[0].complete && (document.images[0].naturalWidth > 0)));
}
function imageSrc() {
sendValueToTest(document.images[0].src);
}
function sendValueToTest(value) {
window.domAutomationController.send(value);
window.onload = () => {
setTimeout(() => {
document.images[0].src = "private_url_image.png"
}, 1000)
}
</script>
</body>
</html>
\ No newline at end of file
</html>
<html>
<head></head>
<img src="image.png" />
<img src="image.png?foo" />
<img/>
<img/>
<script src="common.js"></script>
<script>
function checkBothImagesLoaded() {
sendValueToTest(document.images[0].complete && document.images[1].complete);
return new Promise((resolve, reject) => {
Promise.all([imageLoadedPromise(document.images[0]),
imageLoadedPromise(document.images[1])]).then(() => {
resolve(true);
});
});
}
function imageSrc() {
sendValueToTest(document.images[0].src);
}
function sendValueToTest(value) {
window.domAutomationController.send(value);
window.onload = () => {
setTimeout(() => {
document.images[0].src = "image.png"
document.images[1].src = "image.png?foo"
}, 1000)
}
</script>
</html>
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