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

Sync for validator/cpp/engine #34534

Merged
merged 3 commits into from
May 25, 2021
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
8 changes: 8 additions & 0 deletions validator/cpp/engine/parse-layout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,16 @@ bool IsLayoutSizeDefined(AmpLayout::Layout layout) {
layout == AmpLayout::INTRINSIC);
}

bool IsLayoutAwaitingSize(AmpLayout::Layout layout) {
return layout == AmpLayout::FLUID;
}

std::string GetLayoutSizeDefinedClass() {
return "i-amphtml-layout-size-defined";
}

std::string GetLayoutAwaitingSizeClass() {
return "i-amphtml-layout-awaiting-size";
}

} // namespace amp::validator::parse_layout
6 changes: 6 additions & 0 deletions validator/cpp/engine/parse-layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ std::string GetSizerStyle(amp::validator::AmpLayout::Layout layout,
// https://github.com/ampproject/amphtml/blob/main/src/layout.js.
bool IsLayoutSizeDefined(amp::validator::AmpLayout::Layout layout);

// Returns whether the given AmpLayout waits on a runtime size.
bool IsLayoutAwaitingSize(amp::validator::AmpLayout::Layout layout);

// Returns the CSS class name for AmpLayouts with defined sizes.
std::string GetLayoutSizeDefinedClass();

// Returns the CSS class name for AmpLayouts which wait on a runtime size.
std::string GetLayoutAwaitingSizeClass();

} // namespace amp::validator::parse_layout

#endif // AMPVALIDATOR__PARSE_LAYOUT_H_
25 changes: 6 additions & 19 deletions validator/cpp/engine/validator-internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,6 @@ class ParsedValidatorRules {
}
const vector<ParsedDocCssSpec>& css() const { return parsed_css_; }

int32_t SpecFileRevision() const { return rules_.spec_file_revision(); }

const ParsedTagSpec* GetTagSpec(int id) const { return &tagspec_by_id_[id]; }

const TagSpecDispatch& DispatchForTagName(const std::string& tagname) const {
Expand Down Expand Up @@ -3602,6 +3600,10 @@ void ValidateSsrLayout(const TagSpec& spec,
// i-amphtml-layout-size-defined
valid_internal_classes.push_back(
amp::validator::parse_layout::GetLayoutSizeDefinedClass());
if (amp::validator::parse_layout::IsLayoutAwaitingSize(layout))
// i-amphtml-layout-awaiting-size
valid_internal_classes.push_back(
amp::validator::parse_layout::GetLayoutAwaitingSizeClass());
for (const string_view class_token :
StrSplit(class_attr.value(), ByAnyChar("\t\n\f\r "))) {
if (StartsWith(class_token, "i-amphtml-") &&
Expand Down Expand Up @@ -5575,14 +5577,6 @@ void ReferencePointMatcher::ExitParentTag(const Context& context,
}
}

// This is a prototype from which new validation result messages get
// copied from for initialization.
ValidationResult CreateResultPrototype(const ParsedValidatorRules& rules) {
ValidationResult prototype;
prototype.set_spec_file_revision(rules.SpecFileRevision());
return prototype;
}

// Makes Singleton ParsedValidatorRules non destructible.
// TSAN throw race condition errors when ~ParsedValidatorRules destructor is
// called.
Expand Down Expand Up @@ -5626,8 +5620,7 @@ class Validator {
Validator(const ParsedValidatorRules* rules, int max_errors = -1)
: rules_(rules),
max_errors_(max_errors),
context_(rules_, max_errors_),
result_prototype_(CreateResultPrototype(*rules_)) {}
context_(rules_, max_errors_) {}

ValidationResult Validate(std::string_view html) {
Clear();
Expand Down Expand Up @@ -5853,7 +5846,7 @@ class Validator {
// to parse multiple documents, so in case a new document arrives
// we clear out the state.
void Clear() {
result_ = result_prototype_;
result_.Clear();
context_ = Context(rules_, max_errors_);
}

Expand Down Expand Up @@ -5969,7 +5962,6 @@ class Validator {
Context context_;
htmlparser::ParseAccounting parse_accounting_;
ValidationResult result_;
const ValidationResult result_prototype_;
Validator(const Validator&) = delete;
Validator& operator=(const Validator&) = delete;
};
Expand All @@ -5983,9 +5975,4 @@ ValidationResult Validate(std::string_view html, HtmlFormat_Code html_format,
return validator.Validate(html);
}

int RulesSpecVersion() {
auto rules = ParsedValidatorRulesProvider::Get(HtmlFormat::AMP);
return rules->SpecFileRevision();
}

} // namespace amp::validator
3 changes: 0 additions & 3 deletions validator/cpp/engine/validator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ TEST(ValidatorTest, Testdata_ValidatorTest_TestCases) {
output = RenderInlineResult(
/*filename=*/test_case.name, test_case.input_content, result);

// If this fails, then an integrate command into a branch probably
// went wrong.
EXPECT_LE(55, result.spec_file_revision());
MaybeGenerateFailuresFor(output, test_case.output_content,
test_case.output_file);
}
Expand Down