Commit 22d5b10d authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Add internals.setIsAdSubframe and simplify web tests accordingly

Currently, many subresource_filter/ web_tests rely on the behavior that
Frames are tagged as ads immediately when they are created if ad script
is on the stack. This flow requires that first the script's URL is set
as disallowed, then the script is loaded and then the frame can be
created. This new call allows for web tests to more simply create ad
frames by setting their ad status directly.

We adapt existing web_tests to use this new functionality. We remove the
ad script creation and onload setting boilerplate that is no longer
necessary, also converting affected promise_tests to async_tests to
further simplify them.

These changes will additionally allow for an upcoming refactor that
defers ad status calculation until the frame has navigated to access
additional information. As this logic is in the subresource_filter/
component, it cannot be used in web-tests.

Bug: 1119476
Change-Id: Id2fc2faa392f06c3b1845981f06f19a0650461d6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2364956
Commit-Queue: Alex Turner <alexmt@chromium.org>
Reviewed-by: default avatarCharlie Harrison <csharrison@chromium.org>
Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807540}
parent 0d0a9bac
......@@ -3526,4 +3526,19 @@ void Internals::generateTestReport(const String& message) {
ReportingContext::From(document_->domWindow())->QueueReport(report);
}
void Internals::setIsAdSubframe(HTMLIFrameElement* iframe,
ExceptionState& exception_state) {
if (!iframe->ContentFrame() || !iframe->ContentFrame()->IsLocalFrame()) {
exception_state.ThrowDOMException(DOMExceptionCode::kNotSupportedError,
"Frame cannot be accessed.");
return;
}
LocalFrame* parent_frame = iframe->GetDocument().GetFrame();
LocalFrame* child_frame = To<LocalFrame>(iframe->ContentFrame());
bool parent_is_ad = parent_frame && parent_frame->IsAdSubframe();
child_frame->SetIsAdSubframe(parent_is_ad
? blink::mojom::AdFrameType::kChildAd
: blink::mojom::AdFrameType::kRootAd);
}
} // namespace blink
......@@ -611,6 +611,9 @@ class Internals final : public ScriptWrappable {
void generateTestReport(const String& message);
void setIsAdSubframe(HTMLIFrameElement* iframe,
ExceptionState& exception_state);
private:
Document* ContextDocument() const;
Vector<String> IconURLs(Document*, int icon_types_mask) const;
......
......@@ -450,4 +450,6 @@
// Request generation of a Reporting report.
void generateTestReport(DOMString message);
[RaisesException] void setIsAdSubframe(HTMLIFrameElement iframe);
};
......@@ -4,24 +4,21 @@
await dp.Page.enable();
session.evaluate(`
if (window.testRunner) {
// Inject a subresource filter to mark 'ad-iframe-writer.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["ad-iframe-writer.js"], false /* block_subresources */);
testRunner.setHighlightAds();
}
// Script must be loaded after disallowed paths are set to be marked as an ad.
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "../resources/ad-iframe-writer.js";
ad_script.onload = function () {
ad_frame = createAdFrame();
ad_frame.width = 100;
ad_frame.height = 200;
};
document.body.appendChild(ad_script);
let ad_frame = document.createElement('iframe');
document.body.appendChild(ad_frame);
internals.setIsAdSubframe(ad_frame);
ad_frame.width = 100;
ad_frame.height = 200;
ad_frame.src = "about:blank";
`);
// The first navigation will occur before the frame is set as an ad subframe.
// So, we wait for the second navigation before logging the adFrameType.
await dp.Page.onceFrameNavigated();
const { params } = await dp.Page.onceFrameNavigated();
testRunner.log({ adFrameType: params.frame.adFrameType });
testRunner.completeTest();
})
// Creates and iframe and appends it to the body element. Make sure the caller
// has a body element!
function createAdFrame() {
let ad_frame = document.createElement('iframe');
document.body.appendChild(ad_frame);
return ad_frame;
}
......@@ -7,35 +7,27 @@ body {
margin: 0;
}
</style>
<script src="resources/ad-iframe-writer.js"></script>
</head>
<body>
<script type="text/javascript">
if (window.testRunner) {
// Inject a subresource filter to mark 'ad-iframe-writer.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["ad-iframe-writer.js"], false /* block_subresources */);
testRunner.setHighlightAds();
}
// Script must be loaded after disallowed paths are set to be marked as an ad.
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/ad-iframe-writer.js";
ad_script.onload = function () {
ad_frame = createAdFrame();
ad_frame.style.borderWidth = 0;
ad_frame.width = 100;
ad_frame.height = 1000;
// Scroll down to verify that the overlay is drawn correctly for the portion of the
// frame that is larger than the viewport.
window.scrollTo(0, 400);
// Finish the test once the ad frame is loaded.
ad_frame.onload = function () {
if (window.testRunner)
testRunner.notifyDone();
}
ad_frame.src = "about:blank";
};
document.body.appendChild(ad_script);
ad_frame = createAdFrame();
ad_frame.style.borderWidth = 0;
ad_frame.width = 100;
ad_frame.height = 1000;
// Scroll down to verify that the overlay is drawn correctly for the portion of the
// frame that is larger than the viewport.
window.scrollTo(0, 400);
// Finish the test once the ad frame is loaded.
ad_frame.onload = function () {
if (window.testRunner)
testRunner.notifyDone();
}
ad_frame.src = "about:blank";
if (window.testRunner)
testRunner.waitUntilDone();
......
<!DOCTYPE html>
<html>
<head><script src="resources/ad-iframe-writer.js"></script></head>
<body>
<script type="text/javascript">
if (window.testRunner) {
// Inject a subresource filter to mark 'ad-iframe-writer.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["ad-iframe-writer.js"], false /* block_subresources */);
testRunner.setHighlightAds();
}
// Script must be loaded after disallowed paths are set to be marked as an ad.
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/ad-iframe-writer.js";
ad_script.onload = function () {
ad_frame = createAdFrame();
ad_frame.width = 100;
ad_frame.height = 200;
// Finish the test once the ad frame is loaded.
ad_frame.onload = function () {
// Resize the frame to verify that the highlight is also resized.
ad_frame.width = 300;
if (window.testRunner)
testRunner.notifyDone();
}
ad_frame.src = "about:blank";
};
document.body.appendChild(ad_script);
ad_frame = createAdFrame();
ad_frame.width = 100;
ad_frame.height = 200;
// Finish the test once the ad frame is loaded.
ad_frame.onload = function () {
// Resize the frame to verify that the highlight is also resized.
ad_frame.width = 300;
if (window.testRunner)
testRunner.notifyDone();
}
ad_frame.src = "about:blank";
if (window.testRunner)
testRunner.waitUntilDone();
......
<!DOCTYPE html>
<html>
<head><script src="resources/ad-iframe-writer.js"></script></head>
<body>
<script type="text/javascript">
if (window.testRunner) {
// Inject a subresource filter to mark 'ad-iframe-writer.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["ad-iframe-writer.js"], false /* block_subresources */);
testRunner.setHighlightAds();
}
// Script must be loaded after disallowed paths are set to be marked as an ad.
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/ad-iframe-writer.js";
ad_script.onload = function () {
ad_frame = createAdFrame();
ad_frame.width = 100;
ad_frame.height = 200;
// Finish the test once the ad frame is loaded.
ad_frame.onload = function () {
if (window.testRunner)
testRunner.notifyDone();
}
ad_frame.src = "about:blank";
};
document.body.appendChild(ad_script);
ad_frame = createAdFrame();
ad_frame.width = 100;
ad_frame.height = 200;
// Finish the test once the ad frame is loaded.
ad_frame.onload = function () {
if (window.testRunner)
testRunner.notifyDone();
}
ad_frame.src = "about:blank";
if (window.testRunner)
testRunner.waitUntilDone();
......
......@@ -23,6 +23,7 @@ p {
</style>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/large-sticky-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
<!-- To trigger the first contentful paint at the very start -->
......@@ -30,58 +31,43 @@ p {
<!-- To be positioned further down in the main page to make the page scrollable -->
<div class="bottom"></div>
<script>
async_test(async function(t) {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
if (window.testRunner) {
// Inject a subresource filter to mark 'large-sticky-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["large-sticky-ad-testharness.js"], false /* block_subresources */);
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/large-sticky-ad-testharness.js";
ad_script.onload = async() => {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
// After 1500ms, force a layout update so that the sticky ad detector is
// aware of the sticky ad candidate.
await timeout(1500);
await forceLayoutUpdate();
// After 1500ms, force a layout update so that the sticky ad detector is
// aware of the sticky ad candidate.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 1px.
window.scrollTo(0, 1);
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
// After 1500ms, force a layout update. At this point the scrolling
// position hasn't changed much since the detector first saw the
// candidate, so we expect no use counter for kLargeStickyAd.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 1px.
window.scrollTo(0, 1);
// Scroll down to 5000px.
window.scrollTo(0, 5000);
// After 1500ms, force a layout update. At this point the scrolling
// position hasn't changed much since the detector first saw the
// candidate, so we expect no use counter for kLargeStickyAd.
await timeout(1500);
await forceLayoutUpdate();
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
// After 1500ms, force a layout update. At this point the scrolling
// position has changed by a distance greater than the candidate's height,
// so the use counter kLargeStickyAd should be recorded.
await timeout(1500);
await forceLayoutUpdate();
if (!internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 5000px.
window.scrollTo(0, 5000);
resolve();
};
document.body.appendChild(ad_script);
// After 1500ms, force a layout update. At this point the scrolling
// position has changed by a distance greater than the candidate's height,
// so the use counter kLargeStickyAd should be recorded.
await timeout(1500);
await forceLayoutUpdate();
t.step(function () {
assert_true(internals.isUseCounted(document, kLargeStickyAd));
});
t.done();
}, "Test UseCounter for large-sticky-ad at the bottom when the frame itself has a fixed position.");
</script>
</body>
......
......@@ -23,6 +23,7 @@ p {
</style>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/large-sticky-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
<!-- To trigger the first contentful paint at the very start -->
......@@ -30,51 +31,36 @@ p {
<!-- To be positioned further down in the main page to make the page scrollable -->
<div class="bottom"></div>
<script>
async_test(async function(t) {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
if (window.testRunner) {
// Inject a subresource filter to mark 'large-sticky-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["large-sticky-ad-testharness.js"], false /* block_subresources */);
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/large-sticky-ad-testharness.js";
ad_script.onload = async() => {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
let ad_candidate = document.getElementsByTagName("iframe")[0];
let initial_margin_top = parseInt(window.getComputedStyle(ad_candidate).marginTop, 10);
let ad_candidate = document.getElementsByTagName("iframe")[0];
let initial_margin_top = parseInt(window.getComputedStyle(ad_candidate).marginTop, 10);
// After 1500ms, force a layout update so that the sticky ad detector is
// aware of the sticky ad candidate.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 5000px. Reset the frame's position w.r.t. the viewport
// to its initial position.
window.scrollTo(0, 5000);
ad_candidate.style.marginTop = initial_margin_top + window.scrollY + 'px';
// After 1500ms, force a layout update so that the sticky ad detector is
// aware of the sticky ad candidate.
await timeout(1500);
await forceLayoutUpdate();
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
// After 1500ms, force a layout update. At this point the scrolling
// position has changed by a distance greater than the candidate's height,
// so the use counter kLargeStickyAd should be recorded.
await timeout(1500);
await forceLayoutUpdate();
if (!internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 5000px. Reset the frame's position w.r.t. the viewport
// to its initial position.
window.scrollTo(0, 5000);
ad_candidate.style.marginTop = initial_margin_top + window.scrollY + 'px';
resolve();
};
document.body.appendChild(ad_script);
// After 1500ms, force a layout update. At this point the scrolling
// position has changed by a distance greater than the candidate's height,
// so the use counter kLargeStickyAd should be recorded.
await timeout(1500);
await forceLayoutUpdate();
t.step(function() {
assert_true(internals.isUseCounted(document, kLargeStickyAd));
});
t.done();
}, "Test UseCounter for large-sticky-ad at the bottom when the frame itself has an absolute position, and along with scrolling the ad's position w.r.t. the browser viewport gets frequently reset to the initial postion.");
</script>
</body>
......
......@@ -23,6 +23,7 @@ p {
</style>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/large-sticky-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
<!-- To trigger the first contentful paint at the very start -->
......@@ -30,45 +31,30 @@ p {
<!-- To be positioned further down in the main page to make the page scrollable -->
<div class="bottom"></div>
<script>
async_test(async function(t) {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
if (window.testRunner) {
// Inject a subresource filter to mark 'large-sticky-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["large-sticky-ad-testharness.js"], false /* block_subresources */);
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/large-sticky-ad-testharness.js";
ad_script.onload = async() => {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
// After 1500ms, force a layout update.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 5000px.
window.scrollTo(0, 5000);
// After 1500ms, force a layout update.
await timeout(1500);
await forceLayoutUpdate();
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
// After 1500ms, force a layout update. At this point the scrolling
// position has changed by a distance greater than the candidate's height.
// We expect no kLargeStickyAd use counter.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// Scroll down to 5000px.
window.scrollTo(0, 5000);
resolve();
};
document.body.appendChild(ad_script);
// After 1500ms, force a layout update. At this point the scrolling
// position has changed by a distance greater than the candidate's height.
// We expect no kLargeStickyAd use counter.
await timeout(1500);
await forceLayoutUpdate();
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
t.done();
}, "Test a large-sticky-ad at the center. In this case, we expect no use counter for kLargeStickyAd.");
</script>
</body>
......
......@@ -20,6 +20,7 @@ p {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0" overflow="hidden">
......@@ -31,43 +32,32 @@ p {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
document.body.style.overflow = "hidden";
document.body.style.overflow = "hidden";
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Expect the OverlayPopupAd UseCounter.
if (!internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect the OverlayPopupAd UseCounter.
t.step(function () {
assert_true(internals.isUseCounted(document, kOverlayPopupAd));
});
}, "Test UseCounter for overlay-popup-ad when the frame has position:absolute and the <body> has overflow:hidden.");
t.done();
}, "Test UseCounter for overlay-popup-ad when the frame has position:absolute and the <body> has overflow:hidden.");
</script>
</body>
</html>
......@@ -27,6 +27,7 @@ div.bottom {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -41,54 +42,44 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Ensure a user gesture happened in the main frame.
if (window.eventSender) {
eventSender.mouseMoveTo(1, 1);
eventSender.mouseDown(1, 1);
eventSender.mouseUp(1, 1);
}
// Ensure a user gesture happened in the main frame.
if (window.eventSender) {
eventSender.mouseMoveTo(1, 1);
eventSender.mouseDown(1, 1);
eventSender.mouseUp(1, 1);
}
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Expect no OverlayPopupAd UseCounter as the popup was created with user
// gesture.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect no OverlayPopupAd UseCounter as the popup was created with user
// gesture.
t.step(function() {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test overlay-popup-ad when the frame itself has a fixed position and it's created with user gesture. In this case, we expect no use counter for kOverlayPopupAd.");
</script>
......
......@@ -27,6 +27,7 @@ div.bottom {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -41,46 +42,36 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Expect the OverlayPopupAd UseCounter.
if (!internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect the OverlayPopupAd UseCounter.
t.step(function() {
assert_true(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test UseCounter for overlay-popup-ad when the frame itself has a fixed position.");
</script>
......
......@@ -27,6 +27,7 @@ div.bottom {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -41,46 +42,36 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Expect the OverlayPopupAd UseCounter.
if (!internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect the OverlayPopupAd UseCounter.
t.step(function() {
assert_true(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test UseCounter for overlay-popup-ad when the frame's outer div has a fixed position.");
</script>
......
......@@ -27,6 +27,7 @@ div.bottom {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -41,47 +42,37 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Expect that the use counter kOverlayPopupAd is not recorded, as the
// ad size is too small relative to the viewport size.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect that the use counter kOverlayPopupAd is not recorded, as the
// ad size is too small relative to the viewport size.
t.step(function() {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test overlay-popup-ad when the frame itself has a fixed position and the size is less than 10% of the viewport size. In this case, we expect no use counter for kOverlayPopupAd.");
</script>
......
......@@ -28,6 +28,7 @@ div.bottom {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -42,50 +43,40 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// would have been aware of the first meaningful paint (hadn't we skipped
// the detection in fullscreen video scenario).
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// would have been aware of the first meaningful paint (hadn't we skipped
// the detection in fullscreen video scenario).
await timeout(1500);
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.body);
// Create the overlay pop-up ad.
appendAdFrameTo(document.body);
// Force a layout update, so that the interstitial detector would have
// been aware of the overlay candidate (hadn't we skipped the detection in
// fullscreen video scenario).
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector would have
// been aware of the overlay candidate (hadn't we skipped the detection in
// fullscreen video scenario).
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector would have
// been aware of the overlay candidate's dismissal (hadn't we skipped the
// detection in fullscreen video scenario).
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector would have
// been aware of the overlay candidate's dismissal (hadn't we skipped the
// detection in fullscreen video scenario).
await forceLayoutUpdate();
// Expect that the use counter kOverlayPopupAd is not recorded, as we
// skipped all previous detection due to there was a fullscreen video
// element.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect that the use counter kOverlayPopupAd is not recorded, as we
// skipped all previous detection due to there was a fullscreen video
// element.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test that we will skip the overlay-popup-ad detection if there's a dominant video element in the page.");
</script>
......
......@@ -26,6 +26,7 @@ div.bottom {
</style>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -38,81 +39,71 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Make the page unscrollable so that future overlay candidates can be
// determined immediately rather than at dismissal time.
document.body.style.overflow = "hidden";
// Force a layout update, so that the interstitial detector is aware of
// the current viewport size.
await forceLayoutUpdate();
// Expect no OverlayPopupAd usage, as the ad frame is not in the center of
// the viewport.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
// Resize the window to to make the overlay iframe centered and large
// relative to the viewport.
testRunner.useUnfortunateSynchronousResizeMode();
testRunner.waitUntilDone();
window.resizeTo(150, 150);
// Force a layout update, so that the interstitial detector
// is aware of the updated viewport size, and the overlay ad iframe.
await forceLayoutUpdate();
// Expect no OverlayPopupAd usage, as the viewport has just been resized
// so we have skipped this detection.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
// Force a layout update, to trigger another detection event.
await forceLayoutUpdate();
// Expect no OverlayPopupAd usage, as the overlay has been marked
// unqualified.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
// Create another overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update so that the interstitial detector is aware of
// the new overlay ad iframe.
await forceLayoutUpdate();
// Expect OverlayPopupAd usage due to the appearance of the new overlay.
if (!internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Make the page unscrollable so that future overlay candidates can be
// determined immediately rather than at dismissal time.
document.body.style.overflow = "hidden";
// Force a layout update, so that the interstitial detector is aware of
// the current viewport size.
await forceLayoutUpdate();
// Expect no OverlayPopupAd usage, as the ad frame is not in the center of
// the viewport.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
// Resize the window to to make the overlay iframe centered and large
// relative to the viewport.
testRunner.useUnfortunateSynchronousResizeMode();
testRunner.waitUntilDone();
window.resizeTo(150, 150);
// Force a layout update, so that the interstitial detector
// is aware of the updated viewport size, and the overlay ad iframe.
await forceLayoutUpdate();
// Expect no OverlayPopupAd usage, as the viewport has just been resized
// so we have skipped this detection.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
// Force a layout update, to trigger another detection event.
await forceLayoutUpdate();
// Expect no OverlayPopupAd usage, as the overlay has been marked
// unqualified.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
// Create another overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Force a layout update so that the interstitial detector is aware of
// the new overlay ad iframe.
await forceLayoutUpdate();
// Expect OverlayPopupAd usage due to the appearance of the new overlay.
t.step(function () {
assert_true(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test overlay-popup-ad when the ad appears before (no use counter) & after (use counter) resizing the viewport.");
</script>
</body>
......
......@@ -33,6 +33,7 @@ div.bottom {
</style>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -45,71 +46,61 @@ div.bottom {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create a overlay pop-up <form> element.
let form = document.createElement('form');
document.getElementsByTagName('div')[0].appendChild(form);
// Create a overlay pop-up <form> element.
let form = document.createElement('form');
document.getElementsByTagName('div')[0].appendChild(form);
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate.
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('form')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('form')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay candidate's dismissal.
await forceLayoutUpdate();
// Expect use counter kOverlayPopup.
if (!internals.isUseCounted(document, kOverlayPopup)) {
reject();
}
// Expect use counter kOverlayPopupAd is NOT recorded.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
// Expect use counter kOverlayPopup.
t.step(function () {
assert_true(internals.isUseCounted(document, kOverlayPopup));
});
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Expect use counter kOverlayPopupAd is NOT recorded.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate.
await forceLayoutUpdate();
// Create the overlay pop-up ad.
appendAdFrameTo(document.getElementsByTagName('div')[0]);
// Hide the pop-up ad.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate's dismissal.
await forceLayoutUpdate();
// Hide the pop-up ad.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Expect use counter kOverlayPopupAd.
if (!internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate's dismissal.
await forceLayoutUpdate();
resolve();
};
document.body.appendChild(ad_script);
// Expect use counter kOverlayPopupAd.
t.step(function () {
assert_true(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test UseCounter for overlay-popup non-ad element followed by an ad element.");
</script>
</body>
......
......@@ -16,6 +16,7 @@ p {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -24,46 +25,36 @@ p {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// Create the overlay pop-up ad.
let ad_frame = appendAdFrameTo(document.body);
async_test(async function(t) {
// Create the overlay pop-up ad.
let ad_frame = appendAdFrameTo(document.body);
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint and the prestitial.
await timeout(1500);
await forceLayoutUpdate();
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint and the prestitial.
await timeout(1500);
await forceLayoutUpdate();
// Ensure the detection is triggered at least once after the first
// meaningful paint is seen.
await forceLayoutUpdate();
// Ensure the detection is triggered at least once after the first
// meaningful paint is seen.
await forceLayoutUpdate();
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Hide the pop-up.
document.getElementsByTagName('iframe')[0].style.display = 'none';
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate's dismissal.
await forceLayoutUpdate();
// Expect no kOverlayPopupAd UseCounter as the candidate is considered to
// be 'prestitial' instead of 'pop-up'.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect no kOverlayPopupAd UseCounter as the candidate is considered to
// be 'prestitial' instead of 'pop-up'.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test overlay-prestitial-ad when the frame itself has a fixed position. In this case we expect no use counter for kOverlayPopupAd.");
</script>
......
......@@ -40,6 +40,7 @@ p {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/large-sticky-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -51,50 +52,37 @@ p {
<div class="content2">some content</div>
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["large-sticky-ad-testharness.js"], false /* block_subresources */);
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/large-sticky-ad-testharness.js";
ad_script.onload = async() => {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
async_test(async function(t) {
// Create the large-sticky-ad.
appendAdFrameTo(document.body);
// Scroll down to the position where the parallax-ad is no longer
// covered by "content1" and becomes visible.
window.scrollTo(0, window.innerHeight);
// Scroll down to the position where the parallax-ad is no longer
// covered by "content1" and becomes visible.
window.scrollTo(0, window.innerHeight);
// After 1500ms, force a layout update so that the large-sticky-ad
// detector is aware of the candidate.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// After 1500ms, force a layout update so that the large-sticky-ad
// detector is aware of the candidate.
await timeout(1500);
await forceLayoutUpdate();
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
// Scroll further down to the position where the parallax-ad is covered by
// "content2" and becomes invisible again.
window.scrollTo(0, window.innerHeight * 2);
// Scroll further down to the position where the parallax-ad is covered by
// "content2" and becomes invisible again.
window.scrollTo(0, window.innerHeight * 2);
// After 1500ms, force a layout update so that the large-sticky-ad
// detector is aware of the dismissal of the candidate. We expect no use
// counter for kLargeStickyAd.
await timeout(1500);
await forceLayoutUpdate();
if (internals.isUseCounted(document, kLargeStickyAd)) {
reject();
}
// After 1500ms, force a layout update so that the large-sticky-ad
// detector is aware of the dismissal of the candidate. We expect no use
// counter for kLargeStickyAd.
await timeout(1500);
await forceLayoutUpdate();
resolve();
};
document.body.appendChild(ad_script);
t.step(function () {
assert_false(internals.isUseCounted(document, kLargeStickyAd));
});
t.done();
}, "Test parallax-ad while scrolling over the page. In this case, we expect no use counter for kLargeStickyAd.");
</script>
......
......@@ -40,6 +40,7 @@ p {
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/overlay-interstitial-ad-testharness.js"></script>
</head>
<body marginwidth="0" marginheight="0">
......@@ -52,53 +53,43 @@ p {
<script>
if (window.testRunner) {
// Inject a subresource filter to mark 'overlay-interstitial-ad-testharness.js' as a would be disallowed resource.
testRunner.setDisallowedSubresourcePathSuffixes(["overlay-interstitial-ad-testharness.js"], false /* block_subresources */);
internals.DisableFrequencyCappingForOverlayPopupDetection();
}
promise_test(() => {
return new Promise((resolve, reject) => {
let ad_script = document.createElement("script");
ad_script.async = false;
ad_script.src = "resources/overlay-interstitial-ad-testharness.js";
ad_script.onload = async() => {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
async_test(async function(t) {
// After 1500ms, force a layout update so that the interstitial detector
// is aware of the first meaningful paint, and future overlay candidates
// will be considered for pop-ups rather than for prestitials.
await timeout(1500);
await forceLayoutUpdate();
// Create the parallax-ad, which is below the "content" div and above the
// "empty" div.
appendAdFrameTo(document.body);
// Create the parallax-ad, which is below the "content" div and above the
// "empty" div.
appendAdFrameTo(document.body);
// Scroll down to the position where the parallax-ad is no longer covered
// by "content1" and becomes visible.
window.scrollTo(0, document.documentElement.clientHeight);
// Scroll down to the position where the parallax-ad is no longer covered
// by "content1" and becomes visible.
window.scrollTo(0, document.documentElement.clientHeight);
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate.
await forceLayoutUpdate();
// Scroll further down to the position where the parallax-ad is covered by
// "content2" and becomes invisible again.
window.scrollTo(0, document.documentElement.clientHeight * 2);
// Scroll further down to the position where the parallax-ad is covered by
// "content2" and becomes invisible again.
window.scrollTo(0, document.documentElement.clientHeight * 2);
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate's dismissal.
await forceLayoutUpdate();
// Force a layout update, so that the interstitial detector is aware of
// the overlay ad candidate's dismissal.
await forceLayoutUpdate();
// Expect no kOverlayPopupAd UseCounter as the scroll offset has changed
// since the candidate's appearance.
if (internals.isUseCounted(document, kOverlayPopupAd)) {
reject();
}
resolve();
};
document.body.appendChild(ad_script);
// Expect no kOverlayPopupAd UseCounter as the scroll offset has changed
// since the candidate's appearance.
t.step(function () {
assert_false(internals.isUseCounted(document, kOverlayPopupAd));
});
t.done();
}, "Test parallax-ad while scrolling over the page. In this case, we expect no use counter for kOverlayPopupAd.");
</script>
......
......@@ -3,5 +3,6 @@
function createAdFrame() {
let ad_frame = document.createElement('iframe');
document.body.appendChild(ad_frame);
internals.setIsAdSubframe(ad_frame);
return ad_frame;
}
......@@ -12,4 +12,5 @@ function forceLayoutUpdate() {
function appendAdFrameTo(parent) {
let ad_frame = document.createElement('iframe');
parent.appendChild(ad_frame);
internals.setIsAdSubframe(ad_frame);
}
......@@ -15,5 +15,6 @@ function forceLayoutUpdate() {
function appendAdFrameTo(parent) {
let ad_frame = document.createElement('iframe');
parent.appendChild(ad_frame);
internals.setIsAdSubframe(ad_frame);
return ad_frame;
}
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