MCPcopy
hub / github.com/ampproject/amphtml / testAmpComponentsBTF

Function testAmpComponentsBTF

test/integration/test-amphtml-ads.js:444–472  ·  view source on GitHub ↗
(win)

Source from the content-addressed store, hash-verified

442}
443
444function testAmpComponentsBTF(win) {
445 // The iframe starts BTF. "visible" trigger should be after scroll.
446 // We will record scrolling time for comparison.
447 let scrollTime = Infinity;
448 const imgPromise = RequestBank.withdraw('image').then((req) => {
449 expect(Date.now()).to.be.below(scrollTime);
450 expect(req.url).to.equal('/');
451 });
452 const pixelPromise = RequestBank.withdraw('pixel').then((req) => {
453 expect(Date.now()).to.be.below(scrollTime);
454 expect(req.url).to.equal('/foo?cid=');
455 });
456 const analyticsPromise = RequestBank.withdraw('analytics').then((req) => {
457 expect(req.url).to.match(/^\/bar\?/);
458 const queries = parseQueryString(req.url.substr('/bar'.length));
459 expect(queries['cid']).to.equal('');
460 expect(Date.now()).to.be.above(scrollTime);
461 expect(parseInt(queries['timestamp'], 10)).to.be.above(scrollTime);
462 });
463 setTimeout(() => {
464 scrollTime = Date.now();
465 win.scrollTo(0, 1000);
466 // Scroll the top frame by 1 pixel manually because the observer lives
467 // there so it will only fire the position changed event if the top window
468 // itself is scrolled.
469 window.top.scrollBy(0, 1);
470 }, 2000);
471 return Promise.all([imgPromise, pixelPromise, analyticsPromise]);
472}
473
474/**
475 * Returns a promise that fetches the content of the AMP ad at the amp4test url.

Callers 1

Calls 7

parseQueryStringFunction · 0.90
expectFunction · 0.85
withdrawMethod · 0.80
nowMethod · 0.80
scrollByMethod · 0.80
thenMethod · 0.45
scrollToMethod · 0.45

Tested by

no test coverage detected