Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup INTERSECTION_OBSERVER_POLYFILL experiment #28929

Merged
merged 8 commits into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build-system/global-configs/experiments-const.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{
"INTERSECTION_OBSERVER_POLYFILL": true,
"INTERSECTION_OBSERVER_POLYFILL_INABOX": true,
"STRICT_COMPILATION": false
}
10 changes: 5 additions & 5 deletions build-system/tasks/check-sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const sourcemapUrlMatcher =
'https://raw.githubusercontent.com/ampproject/amphtml/\\d{13}/';

// Mapping related constants
const expectedFirstLineFile = 'src/internal-version.js';
const expectedFirstLineCode = 'export function internalRuntimeVersion() {';
const expectedFirstLineFile = 'src/polyfills/array-includes.js';
const expectedFirstLineCode = 'function includes(value, opt_fromIndex) {';

/**
* Throws an error with the given message
Expand Down Expand Up @@ -114,9 +114,9 @@ function checkSourcemapSources(sourcemapJson) {
* Performs a sanity check on the mappings field in the sourcemap file.
*
* Today, the first line of amp.js after resolving imports comes from
* src/internal-version.js. (The import chain is src/amp.js -> src/polyfills.js
* -> src/mode.js -> src/internal-version.js.) This sequence is unlikely to
* change, so we can use it as a sentinel value. Here is the process:
* src/polyfills/array-includes.js. (The import chain is src/amp.js -> src/polyfills.js
* -> src/polyfills/array-includes.js.) This sequence changes rarely, so we can
* use it as a sentinel value. Here is the process:
*
* 1. Decode the 'mappings' field into a 3d array using 'sourcemap-codec'.
* 2. Extract the mapping for the first line of code in minified v0.js.
Expand Down

This file was deleted.

16 changes: 5 additions & 11 deletions extensions/amp-a4a/0.1/refresh-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import {RefreshIntersectionObserverPolyfillWrapper} from './refresh-intersection-observer-polyfill-wrapper';
import {Services} from '../../../src/services';
import {devAssert, user, userAssert} from '../../../src/log';
import {dict} from '../../../src/utils/object';
Expand Down Expand Up @@ -132,7 +131,7 @@ const RefreshLifecycleState = {
* Each IO is configured to a different threshold, and all elements that
* share the same visiblePercentageMin will be monitored by the same IO.
*
* @const {!Object<string, (!IntersectionObserver|!RefreshIntersectionObserverPolyfillWrapper)>}
* @const {!Object<string, (!IntersectionObserver)>}
*/
const observers = {};

Expand Down Expand Up @@ -226,20 +225,15 @@ export class RefreshManager {
* one if one does not yet exist.
*
* @param {number} threshold
* @return {(!IntersectionObserver|!RefreshIntersectionObserverPolyfillWrapper)}
* @return {!IntersectionObserver}
*/
getIntersectionObserverWithThreshold_(threshold) {
const thresholdString = String(threshold);
return (
observers[thresholdString] ||
(observers[thresholdString] =
'IntersectionObserver' in this.win_
? new this.win_['IntersectionObserver'](this.ioCallback_, {threshold})
: new RefreshIntersectionObserverPolyfillWrapper(
this.ioCallback_,
this.a4a_,
{threshold}
))
(observers[
thresholdString
] = new this.win_.IntersectionObserver(this.ioCallback_, {threshold}))
);
}

Expand Down
107 changes: 0 additions & 107 deletions extensions/amp-a4a/0.1/test/test-refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
RefreshManager,
getPublisherSpecifiedRefreshInterval,
} from '../refresh-manager';
import {RefreshIntersectionObserverPolyfillWrapper} from '../refresh-intersection-observer-polyfill-wrapper';
import {Services} from '../../../../src/services';

describe('refresh', () => {
Expand Down Expand Up @@ -187,110 +186,4 @@ describe('refresh', () => {
});
});
});

describe('RefreshIntersectionObserverPolyfillWrapper', () => {
let callback;
let callbackPromise;
let getRect;
let observerWrapper;

beforeEach(() => {
getRect = () => ({
top: 0,
bottom: 10,
left: 0,
right: 10,
width: 10,
height: 10,
x: 0,
y: 0,
});

window.sandbox.stub(Services, 'viewportForDoc').callsFake(() => {
return {
getRect,
};
});
window.sandbox.stub(Services, 'ampdoc').callsFake(() => {
return {
getRootNode: () => {
return window.document;
},
win: window,
isSingleDoc: () => {
return true;
},
};
});

mockA4a.element.setAttribute(DATA_MANAGER_ID_NAME, '0');
mockA4a.element.viewportCallback = () => {};
mockA4a.element.getLayoutBox = getRect;
mockA4a.element.getOwner = () => mockA4a.element;
mockA4a.getViewport = () => ({getRect});

let resolver;
callbackPromise = new Promise((resolve) => {
resolver = resolve;
});
callback = (entries) => resolver(entries);
observerWrapper = new RefreshIntersectionObserverPolyfillWrapper(
callback,
mockA4a,
{threshold: 0.5}
);
});

it('should invoke callback with intersection ratio 1', () => {
observerWrapper.observe(mockA4a.element);
return callbackPromise.then((entries) => {
expect(entries).to.be.ok;
expect(entries[0]).to.be.ok;
expect(entries[0].intersectionRatio).to.equal(1);
});
});

it('should invoke callback with intersection ratio 0.5', () => {
observerWrapper.viewport_ = {
getRect: () => ({
top: 0,
bottom: 5,
left: 0,
right: 10,
width: 10,
height: 5,
x: 0,
y: 0,
}),
};
observerWrapper.observe(mockA4a.element);
return callbackPromise.then((entries) => {
expect(entries).to.be.ok;
expect(entries[0]).to.be.ok;
expect(entries[0].intersectionRatio).to.equal(0.5);
});
});

it('should not invoke callback', () => {
const callbackSpy = window.sandbox.spy(callback);
observerWrapper.viewport_ = {
getRect: () => ({
top: 10,
bottom: 5,
left: 0,
right: 10,
width: 10,
height: 5,
x: 0,
y: 0,
}),
};
observerWrapper.observe(mockA4a.element);
return Services.timerFor(window)
.promise(500)
.then(() => {
expect(callbackSpy).to.not.be.called;
});
});
});
});
3 changes: 0 additions & 3 deletions extensions/amp-ad/0.1/amp-ad-xorigin-iframe-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,6 @@ export class AmpAdXOriginIframeHandler {
* @param {boolean} inViewport
*/
viewportCallback(inViewport) {
if (this.intersectionObserverHost_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likely the removal of this code might have caused issue: #29759
@dvoytenko was it intended to remove this?

this.intersectionObserverHost_.onViewportCallback(inViewport);
}
this.sendEmbedInfo_(inViewport);
}

Expand Down
Loading