Skip to content

Commit

Permalink
re-import css/cssom WPT
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265237
rdar://118710238

Reviewed by Tim Nguyen.

This re-imports WPT css/cssom tests.
Upstream commit: web-platform-tests/wpt@73d59dc

* LayoutTests/imported/w3c/web-platform-tests/css/cssom/HTMLLinkElement-load-event-002-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/HTMLLinkElement-load-event-002.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/HTMLLinkElement-load-event-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/HTMLLinkElement-load-event.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/HTMLStyleElement-load-event-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/HTMLStyleElement-load-event.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/caretPositionFromPoint-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/caretPositionFromPoint-with-transformation.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/caretPositionFromPoint.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/change-rule-with-layers-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssimportrule.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssom-pagerule-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/cssom-pagerule.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/delete-namespace-rule-when-child-rule-exists-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/delete-namespace-rule-when-child-rule-exists.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-absolute-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-absolute-logical-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-absolute-roundtrip-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-absolute-roundtrip.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-grid-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-grid.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-multicol-absolute-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-relpos-inline-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-relpos-inline.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-margins-roundtrip-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-margins-roundtrip.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-pseudo-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-pseudo.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/insert-dir-rule-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/insert-dir-rule-in-iframe-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/insert-invalid-where-rule-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/selectorSerialize.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/serialize-values-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/serialize-values.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/shorthand-values-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/shorthand-values.html:
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/stylesheet-dom-mutation-event-crash.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/cssom/w3c-import.log:
* LayoutTests/platform/glib/imported/w3c/web-platform-tests/css/cssom/getComputedStyle-insets-relpos-inline-expected.txt: Added.

Canonical link: https://commits.webkit.org/271070@main
  • Loading branch information
karlcow authored and nt1m committed Nov 23, 2023
1 parent ac24f06 commit dff9be7
Show file tree
Hide file tree
Showing 39 changed files with 729 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

PASS Load event doesn't fire on removed link
PASS Load event doesn't fire for removed sheet

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<meta charset="utf-8">
<title>Link element load event doesn't block the parser.</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://html.spec.whatwg.org/#link-type-stylesheet">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
let NUM_LOADS = 0;

function sheetUrl(token) {
return "stylesheet-same-origin.css?" + token;
}

function createLink(token) {
let link = document.createElement("link");
link.rel = "stylesheet";
link.href = sheetUrl(token);
return link;
}

function waitForEnoughTimeToLoadSheet(token) {
return new Promise(resolve => {
let link = createLink(token);
link.onload = resolve;
document.head.appendChild(link);
});
}

promise_test(async function (t) {
let link = createLink("removed");
link.addEventListener("load", t.unreached_func("got unexpected load event"));
link.addEventListener("error", t.unreached_func("got unexpected error event"));
document.head.appendChild(link);
link.remove();

await waitForEnoughTimeToLoadSheet("removed-wait");
}, "Load event doesn't fire on removed link");

promise_test(async function (t) {
let link = createLink("changed-initial");
let sawLoad = false;
let load = new Promise(resolve => {
link.addEventListener("load", function(e) {
assert_false(sawLoad, "Should only see load event once");
sawLoad = true;
resolve();
});
});
link.addEventListener("error", t.unreached_func("got unexpected error event"));
document.head.appendChild(link);
link.href = sheetUrl("changed-change");

await waitForEnoughTimeToLoadSheet("changed-wait");
await load;

assert_true(sawLoad, "Should've seen the load event only once");
}, "Load event doesn't fire for removed sheet");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS Link element load event doesn't block the parser.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!doctype html>
<meta charset="utf-8">
<title>Link element load event doesn't block the parser.</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://html.spec.whatwg.org/#link-type-stylesheet">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
let NUM_LOADS = 0;
</script>
<link rel="stylesheet" href="data:text/css,*{}" onload="++NUM_LOADS">
<script>
let t = async_test(document.title);
window.addEventListener("load", t.step_func_done(() => {
assert_equals(NUM_LOADS, 2, "Load event should've fired for all links");
}));
t.step(function() {
assert_equals(document.styleSheets.length, 1, "Should expose the sheet to the OM before running script");
// We can't quite assert that NUM_LOADS is zero (even though it almost-always
// should be the case), in case the parser yields just before executing the
// script but after parsing the link load.
let loadsBefore = NUM_LOADS;
// Intentionally the same href as above, to test caching behavior.
document.write(`
<link rel="stylesheet" href="data:text/css,*{}" onload="++NUM_LOADS">
`);
assert_equals(document.styleSheets.length, 2, "Should expose both sheets to the OM before running second script");
assert_equals(NUM_LOADS, loadsBefore, "Shouldn't fire the load event sync");
assert_not_equals(document.styleSheets[0], document.styleSheets[1], "Should be different sheets");
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

PASS style elements fire load events properly

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!doctype html>
<meta charset="utf-8">
<title>style elements fire load events properly</title>
<link rel="author" title="Emilio Cobos Álvarez" href="mailto:emilio@crisal.io">
<link rel="author" title="Mozilla" href="https://mozilla.org">
<link rel="help" href="https://html.spec.whatwg.org/#update-a-style-block">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
let NUM_LOADS = 0;
</script>
<style onload="++NUM_LOADS"></style>
<style onload="++NUM_LOADS">:root { background-color: lime }</style>
<style onload="++NUM_LOADS">:root { background-color: lime }</style> <!-- Intentionally the same -->
<script>
async_test(function(t) {
assert_equals(document.styleSheets.length, 3, "Should expose the three stylesheets to the OM sync");
assert_equals(NUM_LOADS, 0, "Should not fire load event sync");
window.addEventListener("load", t.step_func_done(() => {
assert_equals(NUM_LOADS, 3, "Load event should've fired for all nodes");
}));
});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
aaa

PASS document.caretPositionFromPoint() throws when called without the correct parameters
FAIL document.caretPositionFromPoint() should return null for a document with no viewport doc.caretPositionFromPoint is not a function. (In 'doc.caretPositionFromPoint(0, 0)', 'doc.caretPositionFromPoint' is undefined)
FAIL document.caretPositionFromPoint() should return null if given coordinates outside of the viewport document.caretPositionFromPoint is not a function. (In 'document.caretPositionFromPoint(-5, 5)', 'document.caretPositionFromPoint' is undefined)
FAIL document.caretPositionFromPoint() should return a CaretPosition at the specified location document.caretPositionFromPoint is not a function. (In 'document.caretPositionFromPoint(x, y)', 'document.caretPositionFromPoint' is undefined)
FAIL CaretRange.getClientRect() should return a DOMRect that matches one obtained from a manually constructed Range document.caretPositionFromPoint is not a function. (In 'document.caretPositionFromPoint(x, y)', 'document.caretPositionFromPoint' is undefined)

Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,18 @@
return [rect.x + rect.width / 2, rect.y + rect.height / 2];
};

return new Promise(resolve => {
return new Promise((resolve, reject) => {
frame.srcdoc = source;
frame.onload = () => {
const frameDoc = frame.contentDocument;
const {offset} = frameDoc.caretPositionFromPoint(
...elementCenter(frameDoc.querySelector("h1"))
);
resolve(offset);
try {
const frameDoc = frame.contentDocument;
const {offset} = frameDoc.caretPositionFromPoint(
...elementCenter(frameDoc.querySelector("h1"))
);
resolve(offset);
} catch (error) {
reject(error);
}
};
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!doctype html>
<meta charset="utf-8">
<title>document.caretPositionFromPoint()</title>
<link rel="help" href="https://drafts.csswg.org/cssom-view-1/#dom-document-caretpositionfrompoint">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
#textDiv {
display: inline-block;
}
</style>
<div id="textDiv">aaa</div>
<script>
test(() => {
assert_throws_js(TypeError, () => { document.caretPositionFromPoint(); });
assert_throws_js(TypeError, () => { document.caretPositionFromPoint(5); });
assert_throws_js(TypeError, () => { document.caretPositionFromPoint("foo", 5); });
}, "document.caretPositionFromPoint() throws when called without the correct parameters");

test(() => {
const doc = document.implementation.createHTMLDocument("");
assert_equals(doc.caretPositionFromPoint(0, 0), null);
}, "document.caretPositionFromPoint() should return null for a document with no viewport");

test(() => {
assert_equals(document.caretPositionFromPoint(-5, 5), null);
assert_equals(document.caretPositionFromPoint(5, -5), null);
assert_equals(document.caretPositionFromPoint(document.documentElement.clientWidth * 2, 5), null);
assert_equals(document.caretPositionFromPoint(5, document.documentElement.clientHeight * 2), null);
}, "document.caretPositionFromPoint() should return null if given coordinates outside of the viewport");

test(() => {
const textDiv = document.getElementById("textDiv");
const rect = textDiv.getBoundingClientRect();
const characterWidth = rect.width / textDiv.textContent.length;
const characterIndex = 2
const x = rect.left + characterWidth * characterIndex;
const y = rect.top + rect.height / 2;
const caretPosition = document.caretPositionFromPoint(x, y);
assert_true(caretPosition instanceof CaretPosition);
assert_true(caretPosition.offsetNode instanceof Text);
assert_equals(typeof(caretPosition.offset), "number");
assert_equals(caretPosition.offsetNode, textDiv.firstChild);
assert_equals(caretPosition.offset, characterIndex);
}, "document.caretPositionFromPoint() should return a CaretPosition at the specified location");

test(() => {
const textDiv = document.getElementById("textDiv");
const rect = textDiv.getBoundingClientRect();
const characterWidth = rect.width / textDiv.textContent.length;
const characterIndex = 2
const x = rect.left + characterWidth * characterIndex;
const y = rect.top + rect.height / 2;
const caretPosition = document.caretPositionFromPoint(x, y);
const caretRangeExpected = new Range();
caretRangeExpected.setStart(textDiv.firstChild, characterIndex);
caretRectExpected = caretRangeExpected.getBoundingClientRect();
assert_true(caretPosition.getClientRect instanceof Function);
const caretRectActual = caretPosition.getClientRect();
assert_true(caretRectActual instanceof DOMRect);
assert_not_equals(caretRectActual, caretPosition.getClientRect(), "CaretPosition.getClientRect() should return a new DOMRect every time");
assert_equals(caretRectActual.x, caretRectExpected.x);
assert_equals(caretRectActual.y, caretRectExpected.y);
assert_equals(caretRectActual.width, 0, "Caret range should be collapsed");
assert_equals(caretRectActual.height, caretRectExpected.height);
}, "CaretRange.getClientRect() should return a DOMRect that matches one obtained from a manually constructed Range");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<title>CSSOM Test: Chrome crash when modifying rules with @layer</title>
<link rel="help" href="https://crbug.com/1499277">
<link rel="author" title="Steinar H. Gunderson" href="mailto:sesse@chromium.org">
<style id="s">
.x {
transition: color 0.5s;
@layer warning {
:first-child { }
:last-child { }
}
}
</style>
<p>Test passes if it does not crash.</p>
<script>
document.body.offsetTop;
s.sheet.cssRules[0].style.transitionDuration = '1s';
</script>

Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@
@import url("support/a-green.css") screen;
@import url("support/a-green.css") all;
@import url("support/a-green") supports((display: flex) or (display: block));
@import url('quote"quote');
@page { background-color: red; }
</style>
</head>
<body>
<div id="log"></div>

<script type="text/javascript">
var styleSheet, ruleList, rule, ruleWithMedia, ruleWithMediaAll, ruleWithSupports;
var styleSheet, ruleList, rule, ruleWithMedia, ruleWithMediaAll, ruleWithSupports, ruleWithQuote;
setup(function() {
styleSheet = document.getElementById("styleElement").sheet;
ruleList = styleSheet.cssRules;
rule = ruleList[0];
ruleWithMedia = ruleList[1];
ruleWithMediaAll = ruleList[2];
ruleWithSupports = ruleList[3];
ruleWithQuote = ruleList[4];
});

test(function() {
Expand Down Expand Up @@ -71,6 +73,7 @@
assert_equals(ruleWithMedia.cssText, '@import url("support/a-green.css") screen;');
assert_equals(ruleWithMediaAll.cssText, '@import url("support/a-green.css") all;');
assert_equals(ruleWithSupports.cssText, '@import url("support/a-green") supports((display: flex) or (display: block));');
assert_equals(ruleWithQuote.cssText, '@import url("quote\\\"quote");');
assert_equals(rule.parentRule, null);
assert_true(rule.parentStyleSheet instanceof CSSStyleSheet);
}, "Values of CSSRule attributes");
Expand Down Expand Up @@ -99,7 +102,7 @@
}, "CSSImportRule : MediaList mediaText attribute should be updated due to [PutForwards]");

test(function() {
var ruleWithPage = ruleList[4];
var ruleWithPage = ruleList[5];
ruleWithPage.style = "margin-top: 10px;"
assert_equals(ruleWithPage.style.cssText, "margin-top: 10px;");
}, "CSSStyleDeclaration cssText attribute should be updated due to [PutForwards]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ FAIL Page selector is initially the empty string assert_equals: expected "" but
FAIL Set selectorText to :left pseudo page assert_equals: expected ":left" but got "@page"
FAIL Set selectorText to named page assert_equals: expected "named" but got "@page named"
FAIL Set selectorText to named page with :first pseudo page assert_equals: expected "named:first" but got "@page named"
FAIL Set selectorText to named page with case insensitive :first pseudo page assert_equals: expected "named:first" but got "@page named"
FAIL Set selectorText to named page with two :first pseudo page assert_equals: expected "named:first:first" but got "@page named"
FAIL Set selectorText to named page with pseudo pages of :first, :left, :right, :first in order. assert_equals: expected "named:first:left:right:first" but got "@page named"
FAIL Cannot set selectorText to named page with pseudo, whitespace between assert_equals: expected "" but got "@page named"
FAIL Cannot set selectorText to two pseudos, whitespace between assert_equals: expected "" but got "@page named"
FAIL Cannot set selectorText to invalid pseudo page assert_equals: expected "" but got "@page named"
PASS Set selectorText to named page after rule was removed

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@
assert_equals(rule.selectorText, "named:first");
}, "Set selectorText to named page with :first pseudo page");

test(() => {
rule.selectorText = "named:First";
assert_equals(rule.selectorText, "named:first");
}, "Set selectorText to named page with case insensitive :first pseudo page");

test(() => {
rule.selectorText = "named:first:first";
assert_equals(rule.selectorText, "named:first:first");
}, "Set selectorText to named page with two :first pseudo page");

test(() => {
rule.selectorText = "named:first:left:right:first";
assert_equals(rule.selectorText, "named:first:left:right:first");
}, "Set selectorText to named page with pseudo pages of " +
":first, :left, :right, :first in order.");

test(() => {
rule.selectorText = "";
rule.selectorText = "named :first";
assert_equals(rule.selectorText, "");
}, "Cannot set selectorText to named page with pseudo, whitespace between");

test(() => {
rule.selectorText = "";
rule.selectorText = ":first :left";
assert_equals(rule.selectorText, "");
}, "Cannot set selectorText to two pseudos, whitespace between");

test(() => {
rule.selectorText = "";
rule.selectorText = ":notapagepseudo";
assert_equals(rule.selectorText, "");
}, "Cannot set selectorText to invalid pseudo page");

test(() => {
assert_equals(rule.parentStyleSheet, sheet);
sheet.deleteRule(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

FAIL Deleting a @namespace rule when list contains anything other than @import or @namespace rules should throw InvalidStateError. assert_throws_dom: function "() => styleSheet.deleteRule(0)" did not throw

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<title>Deleting a @namespace rule when list contains anything other than @import or @namespace rules should throw InvalidStateError.</title>
<link rel="help" href="https://drafts.csswg.org/cssom-1/#remove-a-css-rule">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@namespace a url();
</style>
<script>
test(function () {
let styleSheet = document.styleSheets[0];
styleSheet.cssRules[0];
styleSheet.insertRule(`b {}`, 1);
assert_throws_dom("InvalidStateError", () => styleSheet.deleteRule(0));
}, "Deleting a @namespace rule when list contains anything other than @import or @namespace rules should throw InvalidStateError.");
</script>
Loading

0 comments on commit dff9be7

Please sign in to comment.