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

test: add document.css level styles tests #9646

Merged
merged 3 commits into from
Dec 15, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@

<themed-component></themed-component>


</body>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@

public class ApplicationThemeComponentIT extends ChromeBrowserTest {

private static final String FIND_FONT_FACE_RULE_SCRIPT =
//@formatter:off
"let found = false;"
+ "for (let as = 0; as < target.adoptedStyleSheets.length; ++as) {"
+ " let styleSheetRules = target.adoptedStyleSheets[as].rules;"
+ " for (var ss = 0; ss < styleSheetRules.length; ++ss) {"
+ " let cssRule = styleSheetRules[ss];"
+ " if (cssRule instanceof CSSFontFaceRule && cssRule.cssText.startsWith(\"@font-face { font-family: Ostrich;\")) {"
+ " found = true;"
+ " }"
+ " }"
+ "}"
+ "return found;";
//@formatter:on

@Override
protected String getTestPath() {
return "/index.html";
Expand Down Expand Up @@ -88,4 +103,30 @@ public void componentThemeIsApplied_forPolymerAndLit() {
Assert.assertEquals("Lit radiobutton should have red background",
"rgba(255, 0, 0, 1)", radio.getCssValue("background-color"));
}

@Test
public void documentCssFonts_fromLocalCssFile_fontAppliedToDocumentRoot() {
open();

Object ostrichFontStylesFound = getCommandExecutor().executeScript(
"let target = document;" + FIND_FONT_FACE_RULE_SCRIPT);

Assert.assertTrue(
"Expected Ostrich font to be applied to document root element",
(Boolean) ostrichFontStylesFound);
}

@Test
public void documentCssFonts_fromLocalCssFile_fontNotAppliedToEmbeddedComponent() {
open();

Object ostrichFontStylesFoundForEmbedded = getCommandExecutor()
.executeScript("let target = document.getElementsByTagName"
+ "('themed-component')[0].shadowRoot;"
+ FIND_FONT_FACE_RULE_SCRIPT);

Assert.assertFalse(
"Expected no Ostrich font to be applied to embedded component",
(Boolean) ostrichFontStylesFoundForEmbedded);
}
}