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 1 commit
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
@@ -1,4 +1,4 @@
@font-face {
font-family: "Ostrich";
src: url("./font/ostrich-sans-regular.ttf") format("TrueType");
font-family: "Open Sans";
caalador marked this conversation as resolved.
Show resolved Hide resolved
src: url("./font/OpenSans-Light.ttf") format("TrueType");
}
Binary file not shown.
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 @@ -88,4 +88,43 @@ 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_fontsAreAppliedInDocumentRoot() {
open();

Long adoptedStyles = (Long) getCommandExecutor().executeScript(
"return document.adoptedStyleSheets !== undefined ? document"
+ ".adoptedStyleSheets.length : 0");

Assert.assertTrue(
"Expected the document root to have the adopted styles",
adoptedStyles > 0);

Object openSansFontStylesFound = getCommandExecutor().executeScript(
"return document.adoptedStyleSheets.map(styleSheet => styleSheet"
caalador marked this conversation as resolved.
Show resolved Hide resolved
+ ".cssRules[0].cssText).filter(cssText => cssText"
+ ".indexOf('Open Sans') > 0).length > 0;");

Assert.assertEquals(
"Expected Open Sans font to be applied to document root element",
Boolean.TRUE, openSansFontStylesFound);
}

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

Object openSansFontStylesNotFoundForEmbedded = getCommandExecutor()
.executeScript(
"return document.getElementsByTagName('themed-component')[0]"
+ ".shadowRoot.adoptedStyleSheets.map(styleSheet => "
+ "styleSheet.cssRules[0].cssText).filter(cssText => "
+ "cssText.indexOf('Open Sans') > 0).length === 0;");

Assert.assertEquals(
"Expected no font-face from document.css has been applied to "
+ "embedded element",
Boolean.TRUE, openSansFontStylesNotFoundForEmbedded);
}
}