Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1364)

Unified Diff: third_party/WebKit/LayoutTests/custom-elements/spec/selectors/pseudo-class-defined.html

Issue 1989343002: Implement :defined pseudo-class selector for Custom Elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ce-state
Patch Set: rune and dominicc review, test updated Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSSelector.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/custom-elements/spec/selectors/pseudo-class-defined.html
diff --git a/third_party/WebKit/LayoutTests/custom-elements/spec/selectors/pseudo-class-defined.html b/third_party/WebKit/LayoutTests/custom-elements/spec/selectors/pseudo-class-defined.html
new file mode 100644
index 0000000000000000000000000000000000000000..a248f121b1ae9c9f8e2dc78ff829c16b4af62cdc
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/custom-elements/spec/selectors/pseudo-class-defined.html
@@ -0,0 +1,68 @@
+<!DOCTYPE html>
+<script src="../../../resources/testharness.js"></script>
+<script src="../../../resources/testharnessreport.js"></script>
+<iframe id="iframe"></iframe>
+<script>
+const testList = [
+ { tagName: 'div', defined: true },
+ { tagName: 'a-a', defined: false },
+ { tagName: 'font-face', defined: true },
+];
+
+// Setup iframe to test the parser.
+const neither = 'rgb(255, 0, 0)';
+const defined = 'rgb(255, 165, 0)';
+const not_defined = 'rgb(0, 0, 255)';
+iframe.srcdoc = `<style>
+ * { color:${neither}; }
+ :defined { color:${defined}; }
+ :not(:defined) { color:${not_defined}; }
+</style>`
+ + testList.map(d => `<${d.tagName}></${d.tagName}>`).join('');
+setup({ explicit_done: true });
+iframe.onload = () => {
+ const doc = iframe.contentDocument;
+ const doc_without_browsing_context = doc.implementation.createHTMLDocument();
+ for (const data of testList) {
+ // Test elements inserted by parser.
+ test_defined(data.defined, doc.getElementsByTagName(data.tagName)[0], `<${data.tagName}>`);
+
+ // Test DOM createElement() methods.
+ test_defined_for_createElement(data.defined, doc, data.tagName);
+
+ // Documents without browsing context should be "uncustomized"; i.e., "defined".
+ test_defined_for_createElement(true, doc_without_browsing_context, data.tagName, 'Without browsing context: ');
+ }
+
+ done();
+};
+
+function test_defined_for_createElement(defined, doc, tagName, description = '') {
+ // Test document.createElement().
+ let element = doc.createElement(tagName);
+ doc.body.appendChild(element);
+ test_defined(defined, element, `${description}createElement("${tagName}")`);
+
+ // Test document.createElementNS().
+ element = doc.createElementNS('http://www.w3.org/1999/xhtml', tagName);
+ doc.body.appendChild(element);
+ test_defined(defined, element, `${description}createElementNS("http://www.w3.org/1999/xhtml", "${tagName}")`);
+
+ // If the element namespace is not HTML, it should be "uncustomized"; i.e., "defined".
+ element = doc.createElementNS('http://www.w3.org/2000/svg', tagName);
+ doc.body.appendChild(element);
+ test_defined(true, element, `${description}createElementNS("http://www.w3.org/2000/svg", "${tagName}")`);
+}
+
+function test_defined(expected, element, description) {
+ test(() => {
+ assert_equals(element.matches(':defined'), expected, 'matches(":defined")');
+ assert_equals(element.matches(':not(:defined)'), !expected, 'matches(":not(:defined")');
+ const view = element.ownerDocument.defaultView;
+ if (!view)
+ return;
+ const style = view.getComputedStyle(element);
+ assert_equals(style.color, expected ? defined : not_defined, 'getComputedStyle');
+ }, `${description} should ${expected ? 'be' : 'not be'} :defined`);
+}
+</script>
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/css/CSSSelector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698