Skip to content

Commit

Permalink
Sync for validator cpp engine and cpp htmlparser (#35885)
Browse files Browse the repository at this point in the history
* Make no-js case valid. The basic structure of the change is to set up a series of requires/satisfies pairs:
- Extension js requires v0.js (this is the only code change).
- amp-pixel, amp-img, and amp-layout, which have no extension js, likewise require v0.js
- non-transformed v0.js requires style boilerplate and the noscript variant (transformed does not).

Then we remove the mandatory bits on all of these tags. They are no longer globally mandatory, they are only conditionally mandatory.

PiperOrigin-RevId: 393187930

* Remove notice for CSS/Doc length tests.

PiperOrigin-RevId: 393885470

Co-authored-by: Greg Grothaus <greggrothaus@google.com>
Co-authored-by: honeybadgerdontcare <sedano@google.com>
  • Loading branch information
3 people committed Aug 31, 2021
1 parent e97558b commit 107ec60
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 32 deletions.
2 changes: 2 additions & 0 deletions validator/cpp/engine/validator-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4847,6 +4847,8 @@ void ParsedValidatorRules::ExpandExtensionSpec(ValidatorRules* rules) const {
if (!tagspec->has_descriptive_name())
tagspec->set_descriptive_name(tagspec->spec_name());
tagspec->set_mandatory_parent("HEAD");
// This is satisfied by any of the `v0.js` variants:
tagspec->add_requires("amphtml javascript runtime (v0.js)");

if (extension_spec.deprecated_allow_duplicates()) {
tagspec->set_unique_warning(true);
Expand Down
64 changes: 32 additions & 32 deletions validator/cpp/engine/validator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ TEST(ValidatorTest, TestDocSizeAmpEmail) {
// 200000 bytes in the tested document.
{
std::string test_case_name = StrCat(test_case.name, "[MaxBytesTest]");
std::string body = RepeatString(valid_body_content, /*n_times=*/9944);
std::string body = RepeatString(valid_body_content, /*n_times=*/9974);
std::string test_html = TestWithDocSize(test_case.input_content, body);
EXPECT_EQ(200000, test_html.length());
EXPECT_EQ(
Expand All @@ -199,15 +199,15 @@ TEST(ValidatorTest, TestDocSizeAmpEmail) {
{
std::string test_case_name = StrCat(test_case.name, "[OffByOneTest]");
std::string body =
StrCat(RepeatString(valid_body_content, /*n_times=*/9944), " ");
StrCat(RepeatString(valid_body_content, /*n_times=*/9974), " ");
std::string test_html = TestWithDocSize(test_case.input_content, body);
EXPECT_EQ(200001, test_html.length());
std::string output = RenderResult(
/*filename=*/test_case_name,
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":9977:6 "
":9993:6 "
"Document exceeded 200000 bytes limit. Actual size 200001 bytes. "
"(see https://amp.dev/documentation/guides-and-tutorials/learn/"
"email-spec/amp-email-format/?format=email)");
Expand Down Expand Up @@ -257,7 +257,7 @@ TEST(ValidatorTest, TestScriptLengthAmp) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":35:2 The inline script is 10001 bytes, which exceeds the limit of "
":20:2 The inline script is 10001 bytes, which exceeds the limit of "
"10000 bytes. (see https://amp.dev/documentation/components/"
"amp-script/#faq)");
EXPECT_EQ(expected_output, output) << "test case " << test_case_name;
Expand Down Expand Up @@ -312,7 +312,7 @@ TEST(ValidatorTest, TestCssLengthAmp) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' is "
":13:2 The author stylesheet specified in tag 'style amp-custom' is "
"too long - document contains 75001 bytes whereas the limit is 75000 "
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
"spec/amphtml/#maximum-size)");
Expand All @@ -332,7 +332,7 @@ TEST(ValidatorTest, TestCssLengthAmp) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' is "
":13:2 The author stylesheet specified in tag 'style amp-custom' is "
"too long - document contains 75002 bytes whereas the limit is 75000 "
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
"spec/amphtml/#maximum-size)");
Expand Down Expand Up @@ -364,7 +364,7 @@ TEST(ValidatorTest, TestCssLengthAmp) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":36:6 The author stylesheet specified in tag 'style amp-custom' "
":21:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75010 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand All @@ -384,7 +384,7 @@ TEST(ValidatorTest, TestCssLengthAmp) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":7536:6 The author stylesheet specified in tag 'style amp-custom' "
":7521:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75010 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand Down Expand Up @@ -418,7 +418,7 @@ TEST(ValidatorTest, TestCssLengthAmp) {
amp::validator::Validate(test_html));
std::string expected_output =
StrCat("FAIL\n", test_case_name,
":34:2 The inline style specified in tag 'div' is too long - "
":19:2 The inline style specified in tag 'div' is too long - "
"it contains 1001 bytes whereas the limit is 1000 bytes. "
"(see https://amp.dev/documentation/guides-and-tutorials/learn/"
"spec/amphtml/#maximum-size)");
Expand Down Expand Up @@ -450,7 +450,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"PASS\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)");
Expand All @@ -470,12 +470,12 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)\n",
test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' "
":13:2 The author stylesheet specified in tag 'style amp-custom' "
"is too long - document contains 75001 bytes whereas the "
"limit is 75000 "
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
Expand All @@ -494,7 +494,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"PASS\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)");
Expand All @@ -516,12 +516,12 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
// to make the transition.
std::string expected_output = StrCat(
"PASS\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)\n",
test_case_name,
":34:6 The author stylesheet specified in tag 'style amp-custom' "
":19:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75010 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand All @@ -544,12 +544,12 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
// to make the transition.
std::string expected_output = StrCat(
"PASS\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)\n",
test_case_name,
":7534:6 The author stylesheet specified in tag 'style amp-custom' "
":7519:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75014 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand All @@ -568,7 +568,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"PASS\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)");
Expand All @@ -591,12 +591,12 @@ TEST(ValidatorTest, TestCssLengthAmpEmail) {
// value should be.
std::string expected_output = StrCat(
"PASS\n", test_case_name,
":23:0 Tag 'html' marked with attribute 'amp4email' is missing the "
":8:0 Tag 'html' marked with attribute 'amp4email' is missing the "
"corresponding attribute 'data-css-strict' for enabling strict "
"CSS validation. This may become an error in the future. "
"(see https://github.com/ampproject/amphtml/issues/32587)\n",
test_case_name,
":32:2 The inline style specified in tag 'div' is too long - it "
":17:2 The inline style specified in tag 'div' is too long - it "
"contains 1001 bytes whereas the limit is 1000 bytes. (see "
"https://amp.dev/documentation/guides-and-tutorials/learn/spec/"
"amphtml/#maximum-size)");
Expand Down Expand Up @@ -643,7 +643,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' "
":13:2 The author stylesheet specified in tag 'style amp-custom' "
"is too long - document contains 75001 bytes whereas the "
"limit is 75000 "
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
Expand Down Expand Up @@ -675,7 +675,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":34:6 The author stylesheet specified in tag 'style amp-custom' "
":19:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75010 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand All @@ -695,7 +695,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":3784:6 The author stylesheet specified in tag 'style amp-custom' "
":3769:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75014 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand Down Expand Up @@ -729,7 +729,7 @@ TEST(ValidatorTest, TestCssLengthAmpEmailStrict) {
amp::validator::Validate(test_html, HtmlFormat::AMP4EMAIL));
std::string expected_output =
StrCat("FAIL\n", test_case_name,
":32:2 The inline style specified in tag 'div' is too long - it "
":17:2 The inline style specified in tag 'div' is too long - it "
"contains 1001 bytes whereas the limit is 1000 bytes. (see "
"https://amp.dev/documentation/guides-and-tutorials/learn/spec/"
"amphtml/#maximum-size)");
Expand Down Expand Up @@ -762,7 +762,7 @@ TEST(ValidatorTest, TestCssLengthAmpAds) {
amp::validator::Validate(test_html, HtmlFormat::AMP4ADS));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":29:2 The author stylesheet specified in tag 'style amp-custom' "
":14:2 The author stylesheet specified in tag 'style amp-custom' "
"is too long - document contains 20001 bytes whereas the "
"limit is 20000 "
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
Expand Down Expand Up @@ -846,7 +846,7 @@ TEST(ValidatorTest, TestCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' "
":13:2 The author stylesheet specified in tag 'style amp-custom' "
"is too long - document contains 75010 bytes whereas the limit is "
"75000 bytes. (see https://amp.dev/documentation/guides-and-tutorials/"
"learn/spec/amphtml/#maximum-size)");
Expand All @@ -872,7 +872,7 @@ TEST(ValidatorTest, TestCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' "
":13:2 The author stylesheet specified in tag 'style amp-custom' "
"is too long - document contains 75010 bytes whereas the limit is "
"75000 bytes. (see https://amp.dev/documentation/guides-and-tutorials/"
"learn/spec/amphtml/#maximum-size)");
Expand All @@ -898,7 +898,7 @@ TEST(ValidatorTest, TestCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":28:2 The author stylesheet specified in tag 'style amp-custom' is "
":13:2 The author stylesheet specified in tag 'style amp-custom' is "
"too long - document contains 75010 bytes whereas the limit is 75000 "
"bytes. (see https://amp.dev/documentation/guides-and-tutorials/learn/"
"spec/amphtml/#maximum-size)");
Expand All @@ -921,7 +921,7 @@ TEST(ValidatorTest, TestCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":36:6 The author stylesheet specified in tag 'style amp-custom' "
":21:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75009 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand All @@ -945,7 +945,7 @@ TEST(ValidatorTest, TestCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":36:6 The author stylesheet specified in tag 'style amp-custom' "
":21:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains 75009 "
"bytes whereas the limit is 75000 bytes. (see https://amp.dev/"
"documentation/guides-and-tutorials/learn/spec/amphtml/#maximum-size)");
Expand Down Expand Up @@ -1024,7 +1024,7 @@ TEST(ValidatorTest, TestTransformedAmpCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":29:2 The author stylesheet specified in tag 'style amp-custom' "
":14:2 The author stylesheet specified in tag 'style amp-custom' "
"is too long - document contains 75010 bytes whereas "
"the limit is 75000 bytes. (see "
"https://amp.dev/documentation/guides-and-tutorials/learn/"
Expand Down Expand Up @@ -1066,7 +1066,7 @@ TEST(ValidatorTest, TestTransformedAmpCssLengthWithUrls) {
amp::validator::Validate(test_html));
std::string expected_output = StrCat(
"FAIL\n", test_case_name,
":36:6 The author stylesheet specified in tag 'style amp-custom' "
":21:6 The author stylesheet specified in tag 'style amp-custom' "
"and the combined inline styles is too large - document contains "
"112530 bytes whereas the limit is 112500 bytes. (see "
"https://amp.dev/documentation/guides-and-tutorials/learn/spec/"
Expand Down

0 comments on commit 107ec60

Please sign in to comment.