-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
316 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
extensions/amp-story/1.0/test/test-amp-story-grid-layer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/** | ||
* Copyright 2018 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import {Action, AmpStoryStoreService} from '../amp-story-store-service'; | ||
import {AmpDocSingle} from '../../../../src/service/ampdoc-impl'; | ||
import {AmpStoryGridLayer} from '../amp-story-grid-layer'; | ||
import {AmpStoryPage} from '../amp-story-page'; | ||
import {LocalizationService} from '../../../../src/service/localization'; | ||
import {MediaType} from '../media-pool'; | ||
import {Services} from '../../../../src/services'; | ||
import {registerServiceBuilder} from '../../../../src/service'; | ||
|
||
describes.realWin('amp-story-grid-layer', {amp: true}, env => { | ||
let win; | ||
let element; | ||
let gridLayerEl; | ||
let page; | ||
let grid; | ||
let storeService; | ||
|
||
beforeEach(() => { | ||
win = env.win; | ||
|
||
env.sandbox | ||
.stub(Services, 'vsyncFor') | ||
.callsFake(() => ({mutate: task => task()})); | ||
|
||
const mediaPoolRoot = { | ||
getElement: () => win.document.createElement('div'), | ||
getMaxMediaElementCounts: () => ({ | ||
[MediaType.VIDEO]: 8, | ||
[MediaType.AUDIO]: 8, | ||
}), | ||
}; | ||
|
||
storeService = new AmpStoryStoreService(win); | ||
registerServiceBuilder(win, 'story-store', function() { | ||
return storeService; | ||
}); | ||
|
||
const localizationService = new LocalizationService(win); | ||
registerServiceBuilder(win, 'localization', function() { | ||
return localizationService; | ||
}); | ||
|
||
registerServiceBuilder(win, 'performance', function() { | ||
return { | ||
isPerformanceTrackingOn: () => false, | ||
}; | ||
}); | ||
|
||
const story = win.document.createElement('amp-story'); | ||
story.getImpl = () => Promise.resolve(mediaPoolRoot); | ||
|
||
element = win.document.createElement('amp-story-page'); | ||
gridLayerEl = win.document.createElement('amp-story-grid-layer'); | ||
element.getAmpDoc = () => new AmpDocSingle(win); | ||
element.appendChild(gridLayerEl); | ||
story.appendChild(element); | ||
win.document.body.appendChild(story); | ||
|
||
page = new AmpStoryPage(element); | ||
env.sandbox.stub(page, 'mutateElement').callsFake(fn => fn()); | ||
|
||
grid = new AmpStoryGridLayer(gridLayerEl); | ||
}); | ||
|
||
afterEach(() => { | ||
element.remove(); | ||
}); | ||
|
||
async function buildGridLayer() { | ||
page.buildCallback(); | ||
await page.layoutCallback(); | ||
grid.buildCallback(); | ||
await grid.layoutCallback(); | ||
} | ||
|
||
it('should set the vertical aspect-ratio', async () => { | ||
gridLayerEl.setAttribute('aspect-ratio', '9:16'); | ||
await buildGridLayer(); | ||
|
||
storeService.dispatch(Action.SET_PAGE_SIZE, {width: 1000, height: 1000}); | ||
|
||
expect(gridLayerEl).to.have.class('i-amphtml-story-grid-template-aspect'); | ||
expect( | ||
parseInt( | ||
gridLayerEl.style.getPropertyValue('--i-amphtml-story-layer-width'), | ||
10 | ||
) | ||
).to.equal(562); | ||
expect( | ||
parseInt( | ||
gridLayerEl.style.getPropertyValue('--i-amphtml-story-layer-height'), | ||
10 | ||
) | ||
).to.equal(1000); | ||
}); | ||
|
||
it('should set the horizontal aspect-ratio', async () => { | ||
gridLayerEl.setAttribute('aspect-ratio', '16:9'); | ||
await buildGridLayer(); | ||
|
||
storeService.dispatch(Action.SET_PAGE_SIZE, {width: 1000, height: 1000}); | ||
|
||
expect(gridLayerEl).to.have.class('i-amphtml-story-grid-template-aspect'); | ||
expect( | ||
parseInt( | ||
gridLayerEl.style.getPropertyValue('--i-amphtml-story-layer-width'), | ||
10 | ||
) | ||
).to.equal(1000); | ||
expect( | ||
parseInt( | ||
gridLayerEl.style.getPropertyValue('--i-amphtml-story-layer-height'), | ||
10 | ||
) | ||
).to.equal(562); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
extensions/amp-story/1.0/test/validator-amp-story-grid-layer-error.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- | ||
Copyright 2019 The AMP HTML Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS-IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the license. | ||
--> | ||
<!-- | ||
Test Description: | ||
Tests for the live story functionality inside amp-story. | ||
--> | ||
<!doctype html> | ||
<html amp lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script async src="https://cdn.ampproject.org/v0.js"></script> | ||
<script async custom-element="amp-story" | ||
src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script> | ||
<title>amp-story-grid-layer</title> | ||
<meta name="viewport" | ||
content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> | ||
<link rel="canonical" href="index.html"> | ||
</head> | ||
|
||
<body> | ||
<amp-story standalone> | ||
<amp-story-page> | ||
<amp-story-grid-layer aspect-ratio="a:b" template="vertical"> | ||
</amp-story-grid-layer> | ||
</amp-story-page> | ||
</amp-story> | ||
</body> | ||
|
||
</html> |
43 changes: 43 additions & 0 deletions
43
extensions/amp-story/1.0/test/validator-amp-story-grid-layer-error.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
FAIL | ||
| <!-- | ||
| Copyright 2019 The AMP HTML Authors. All Rights Reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS-IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the license. | ||
| --> | ||
| <!-- | ||
| Test Description: | ||
| Tests for the live story functionality inside amp-story. | ||
| --> | ||
| <!doctype html> | ||
| <html amp lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <script async src="https://cdn.ampproject.org/v0.js"></script> | ||
| <script async custom-element="amp-story" | ||
| src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script> | ||
| <title>amp-story-grid-layer</title> | ||
| <meta name="viewport" | ||
| content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
| <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> | ||
| <link rel="canonical" href="index.html"> | ||
| </head> | ||
| | ||
| <body> | ||
| <amp-story standalone> | ||
| <amp-story-page> | ||
| <amp-story-grid-layer aspect-ratio="a:b" template="vertical"> | ||
>> ^~~~~~~~~ | ||
amp-story/1.0/test/validator-amp-story-grid-layer-error.html:35:6 The attribute 'aspec-ratio' in tag 'amp-story-grid-layer' is set to the invalid value 'a:b'. (see https://amp.dev/documentation/components/amp-story) | ||
| </amp-story-grid-layer> | ||
| </amp-story-page> | ||
| </amp-story> | ||
| </body> | ||
| | ||
| </html> |
40 changes: 40 additions & 0 deletions
40
extensions/amp-story/1.0/test/validator-amp-story-grid-layer.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- | ||
Copyright 2019 The AMP HTML Authors. All Rights Reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS-IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the license. | ||
--> | ||
<!-- | ||
Test Description: | ||
Tests for the live story functionality inside amp-story. | ||
--> | ||
<!doctype html> | ||
<html amp lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<script async src="https://cdn.ampproject.org/v0.js"></script> | ||
<script async custom-element="amp-story" | ||
src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script> | ||
<title>amp-story-grid-layer</title> | ||
<meta name="viewport" | ||
content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> | ||
<link rel="canonical" href="index.html"> | ||
</head> | ||
|
||
<body> | ||
<amp-story standalone> | ||
<amp-story-page> | ||
<amp-story-grid-layer aspect-ratio="9:16" template="vertical"> | ||
</amp-story-grid-layer> | ||
</amp-story-page> | ||
</amp-story> | ||
</body> | ||
|
||
</html> |
41 changes: 41 additions & 0 deletions
41
extensions/amp-story/1.0/test/validator-amp-story-grid-layer.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
PASS | ||
| <!-- | ||
| Copyright 2019 The AMP HTML Authors. All Rights Reserved. | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS-IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the license. | ||
| --> | ||
| <!-- | ||
| Test Description: | ||
| Tests for the live story functionality inside amp-story. | ||
| --> | ||
| <!doctype html> | ||
| <html amp lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <script async src="https://cdn.ampproject.org/v0.js"></script> | ||
| <script async custom-element="amp-story" | ||
| src="https://cdn.ampproject.org/v0/amp-story-1.0.js"></script> | ||
| <title>amp-story-grid-layer</title> | ||
| <meta name="viewport" | ||
| content="width=device-width,minimum-scale=1,initial-scale=1"> | ||
| <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> | ||
| <link rel="canonical" href="index.html"> | ||
| </head> | ||
| | ||
| <body> | ||
| <amp-story standalone> | ||
| <amp-story-page> | ||
| <amp-story-grid-layer aspect-ratio="9:16" template="vertical"> | ||
| </amp-story-grid-layer> | ||
| </amp-story-page> | ||
| </amp-story> | ||
| </body> | ||
| | ||
| </html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters