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

[Gecko Bug 1607268] Implement replaceSync() Functionality #21176

Merged
merged 1 commit into from
Jan 16, 2020
Merged
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
36 changes: 35 additions & 1 deletion css/cssom/CSSStyleSheet-constructable.html
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,19 @@
return shadowDiv;
}

test(() => {
const sheet = new CSSStyleSheet();
assert_equals(sheet.cssRules.length, 0);

sheet.replaceSync(redStyleTexts[0])
assert_equals(sheet.cssRules.length, 1);
assert_equals(redStyleTexts[0], sheet.cssRules[0].cssText);

sheet.replaceSync(redStyleTexts[1]);
assert_equals(sheet.cssRules.length, 1);
assert_equals(redStyleTexts[1], sheet.cssRules[0].cssText);
}, 'CSSStyleSheet.replaceSync replaces stylesheet text synchronously');

test(() => {
// Attach a div inside a shadow root with the class ".red".
const span = document.createElement("span");
Expand All @@ -485,7 +498,7 @@
sheet.insertRule(redStyleTexts[1]);
assert_equals(sheet.cssRules.length, 2);
assert_equals(sheet.cssRules[0].cssText, redStyleTexts[1]);
}, 'CSSStyleSheet.replaceSync replaces stylesheet text synchronously');
}, 'CSSStyleSheet.replaceSync correctly updates the style of its adopters synchronously');

const import_text = '@import url("support/constructable-import.css");';

Expand All @@ -497,6 +510,27 @@
assert_throws("NotAllowedError", () => { (new CSSStyleSheet).insertRule(import_text) });
}, 'Inserting an @import rule through insertRule on a constructed stylesheet throws an exception');

async_test(t => {
const importUrl = "support/constructable-import.css";
const sheet = new CSSStyleSheet();

assert_throws("NotAllowedError", () => { sheet.replaceSync(`@import url("${importUrl}");`) });

const timeAfterReplaceSync = performance.now();
let link = document.createElement("link");
link.rel = "stylesheet";
link.href = importUrl;

link.addEventListener("error", t.unreached_func("Load shouldn't fail"));
link.addEventListener("load", t.step_func_done(event => {
let entries = window.performance.getEntriesByType('resource').filter(entry => entry.name.includes(importUrl));
assert_equals(entries.length, 1, "There should be only one entry for the import URL");
assert_greater_than_equal(entries[0].startTime, timeAfterReplaceSync, "The entry's start time should be after replaceSync threw");
link.remove();
}));
document.body.appendChild(link);
}, "CSSStyleSheet.replaceSync should not trigger any loads from @import rules")

promise_test(() => {
const span = document.createElement("span");
thirdSection.appendChild(span);
Expand Down