Skip to content

Commit

Permalink
Validator rules/test for amp-action-macro (#20928)
Browse files Browse the repository at this point in the history
  • Loading branch information
alabiaga committed Feb 25, 2019
1 parent 45371fd commit 56a8b0f
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 0 deletions.
41 changes: 41 additions & 0 deletions extensions/amp-action-macro/validator-amp-action-macro.protoascii
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# 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.
#
tags: { # amp-action-macro
html_format: AMP
html_format: ACTIONS
tag_name: "SCRIPT"
extension_spec: {
name: "amp-action-macro"
version: "0.1"
version: "latest"
}
attr_lists: "common-extension-attrs"
}
tags: { # <amp-action-macro>
html_format: AMP
html_format: ACTIONS
tag_name: "AMP-ACTION-MACRO"
requires_extension: "amp-action-macro"
attrs: {
name: "arguments"
}
attrs: {
name: "execute"
mandatory: true
}
attr_lists: "mandatory-id-attr"
spec_url: "https://www.ampproject.org/docs/reference/components/amp-action-macro"
}
54 changes: 54 additions & 0 deletions validator/testdata/feature_tests/amp-action-macro.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!--
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.
-->
<!doctype html>
<html >
<head>
<meta charset="utf-8">
<link rel="canonical" href="./regular-html-version.html" />
<meta name="viewport" content="width=device-width,minimum-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>
<script async custom-element="amp-action-macro" src="https://cdn.ampproject.org/v0/amp-action-macro-0.1.js"></script>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<style amp-custom>
.red {
color: red;
}
.green {
color: green;
}
</style>
</head>
<body>

<!-- Valid -->
<amp-action-macro id="action-macro-id" execute="amp-component.doSomething()">
</amp-action-macro>

<!-- Valid, optional arguments -->
<amp-action-macro id="action-macro-id" execute="amp-component.doSomething(foo=x,bar=y)"
arguments="x,y">
</amp-action-macro>

<!-- Invalid, requires ID -->
<amp-action-macro execute="amp-component.doSomething()">
</amp-action-macro>

<!-- Invalid, requires execute -->
<amp-action-macro id="action-macro-id">
</amp-action-macro>

</body>
</html>
60 changes: 60 additions & 0 deletions validator/testdata/feature_tests/amp-action-macro.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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.
| -->
| <!doctype html>
| <html ⚡>
| <head>
| <meta charset="utf-8">
| <link rel="canonical" href="./regular-html-version.html" />
| <meta name="viewport" content="width=device-width,minimum-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>
| <script async custom-element="amp-action-macro" src="https://cdn.ampproject.org/v0/amp-action-macro-0.1.js"></script>
| <script async src="https://cdn.ampproject.org/v0.js"></script>
| <style amp-custom>
| .red {
| color: red;
| }
| .green {
| color: green;
| }
| </style>
| </head>
| <body>
|
| <!-- Valid -->
| <amp-action-macro id="action-macro-id" execute="amp-component.doSomething()">
| </amp-action-macro>
|
| <!-- Valid, optional arguments -->
| <amp-action-macro id="action-macro-id" execute="amp-component.doSomething(foo=x,bar=y)"
| arguments="x,y">
| </amp-action-macro>
|
| <!-- Invalid, requires ID -->
| <amp-action-macro execute="amp-component.doSomething()">
>> ^~~~~~~~~
feature_tests/amp-action-macro.html:46:2 The mandatory attribute 'id' is missing in tag 'amp-action-macro'. (see https://www.ampproject.org/docs/reference/components/amp-action-macro) [AMP_TAG_PROBLEM]
| </amp-action-macro>
|
| <!-- Invalid, requires execute -->
| <amp-action-macro id="action-macro-id">
>> ^~~~~~~~~
feature_tests/amp-action-macro.html:50:2 The mandatory attribute 'execute' is missing in tag 'amp-action-macro'. (see https://www.ampproject.org/docs/reference/components/amp-action-macro) [AMP_TAG_PROBLEM]
| </amp-action-macro>
|
| </body>
| </html>

0 comments on commit 56a8b0f

Please sign in to comment.