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

Move more methods from resources-impl to owners-impl #24222

Merged
merged 10 commits into from
Aug 30, 2019
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
10 changes: 3 additions & 7 deletions build-system/tasks/presubmit-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,13 +611,9 @@ const forbiddenTerms = {
'src/service/viewer-impl.js',
],
},
'\\.findResourcesInElements\\(': {
message: 'findResourcesInElements is a restricted API.',
whitelist: ['src/service/owners-impl.js'],
},
'\\.measureAndTryScheduleLayout\\(': {
message: 'measureAndTryScheduleLayout is a restricted API.',
whitelist: ['src/service/owners-impl.js'],
'\\.scheduleLayoutOrPreload\\(': {
message: 'scheduleLayoutOrPreload is a restricted API.',
whitelist: ['src/service/owners-impl.js', 'src/service/resources-impl.js'],
},
'(win|Win)(dow)?(\\(\\))?\\.open\\W': {
message: 'Use dom.openWindowDialog',
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-a4a/0.1/amp-a4a.js
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ export class AmpA4A extends AMP.BaseElement {
Services.viewerForDoc(this.getAmpDoc())
.whenNextVisible()
.then(() => {
Services.resourcesForDoc(this.getAmpDoc())./*OK*/ requireLayout(
Services.ownersForDoc(this.getAmpDoc())./*OK*/ requireLayout(
this.element
);
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-animation/0.1/amp-animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export class AmpAnimation extends AMP.BaseElement {
this.getRootNode_(),
baseUrl,
this.getVsync(),
this.element.getResources()
Services.ownersForDoc(this.element.getAmpDoc())
);
return builder.createRunner(configJson, args, opt_positionObserverData);
});
Expand Down
27 changes: 12 additions & 15 deletions extensions/amp-animation/0.1/test/test-web-animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
import {Builder} from '../web-animations';
import {NativeWebAnimationRunner} from '../runners/native-web-animation-runner';
import {Services} from '../../../../src/services';
import {WebAnimationPlayState} from '../web-animation-types';
import {isArray, isObject} from '../../../../src/types';
import {poll} from '../../../../testing/iframe';
Expand All @@ -24,6 +25,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
let win, doc;
let vsync;
let resources;
let owners;
let requireLayoutSpy;
let target1, target2;
let warnStub;
Expand Down Expand Up @@ -54,12 +56,13 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
});
warnStub = sandbox.stub(user(), 'warn');

vsync = win.__AMP_SERVICES.vsync.obj;
vsync = Services.vsyncFor(win);
sandbox.stub(vsync, 'measurePromise').callsFake(callback => {
return Promise.resolve(callback());
});
resources = win.__AMP_SERVICES.resources.obj;
requireLayoutSpy = sandbox.spy(resources, 'requireLayout');
resources = Services.resourcesForDoc(env.ampdoc);
owners = Services.ownersForDoc(env.ampdoc);
requireLayoutSpy = sandbox.spy(owners, 'requireLayout');

target1 = doc.createElement('div');
target1.id = 'target1';
Expand All @@ -82,7 +85,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
doc,
'https://acme.org/',
/* vsync */ null,
/* resources */ null
/* owners */ null
);
sandbox.stub(builder, 'requireLayout');
const scanner = builder.createScanner_([]);
Expand Down Expand Up @@ -796,7 +799,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
doc,
'https://acme.org/',
vsync,
/* resources */ null
/* owners */ null
);
const cssContext = builder.css_;
expect(cssContext.supports('supported: 0')).to.be.false;
Expand Down Expand Up @@ -975,7 +978,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
doc,
'https://acme.org/',
vsync,
/* resources */ null
/* owners */ null
);
sandbox.stub(builder, 'requireLayout');
const spec = {target: target1, delay: 101, keyframes: {}};
Expand Down Expand Up @@ -1010,7 +1013,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
animation2.id = 'animation2';
doc.body.appendChild(animation2);

builder = new Builder(win, doc, 'https://acme.org/', vsync, resources);
builder = new Builder(win, doc, 'https://acme.org/', vsync, owners);
sandbox.stub(builder, 'requireLayout');
scanner = builder.createScanner_([]);
});
Expand Down Expand Up @@ -1255,7 +1258,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
doc,
'https://acme.org/',
/* vsync */ null,
/* resources */ null
/* owners */ null
);
css = builder.css_;
parseSpy = sandbox.spy(css, 'resolveAsNode_');
Expand Down Expand Up @@ -1557,13 +1560,7 @@ describes.realWin('MeasureScanner', {amp: 1}, env => {
}

function createRunner(spec) {
const builder = new Builder(
win,
doc,
'https://acme.org/',
vsync,
resources
);
const builder = new Builder(win, doc, 'https://acme.org/', vsync, owners);
return builder.createRunner(spec);
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/amp-animation/0.1/web-animation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class WebAnimationService {
this.vsync_ = Services.vsyncFor(ampdoc.win);

/** @private @const */
this.resources_ = Services.resourcesForDoc(ampdoc);
this.owners_ = Services.ownersForDoc(ampdoc);
}

/**
Expand All @@ -43,7 +43,7 @@ export class WebAnimationService {
this.ampdoc_.getRootNode(),
this.ampdoc_.getUrl(),
this.vsync_,
this.resources_
this.owners_
);
}
}
8 changes: 4 additions & 4 deletions extensions/amp-animation/0.1/web-animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ export class Builder {
* @param {!Document|!ShadowRoot} rootNode
* @param {string} baseUrl
* @param {!../../../src/service/vsync-impl.Vsync} vsync
* @param {!../../../src/service/resources-impl.ResourcesDef} resources
* @param {!../../../src/service/owners-impl.OwnersDef} owners
*/
constructor(win, rootNode, baseUrl, vsync, resources) {
constructor(win, rootNode, baseUrl, vsync, owners) {
/** @const @private */
this.win_ = win;

Expand All @@ -164,7 +164,7 @@ export class Builder {
this.vsync_ = vsync;

/** @const @private */
this.resources_ = resources;
this.owners_ = owners;

/** @const @private {!Array<!Element>} */
this.targets_ = [];
Expand Down Expand Up @@ -231,7 +231,7 @@ export class Builder {
requireLayout(target) {
if (!this.targets_.includes(target)) {
this.targets_.push(target);
this.loaders_.push(this.resources_.requireLayout(target));
this.loaders_.push(this.owners_.requireLayout(target));
}
}

Expand Down
Loading