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

Unified Diff: third_party/WebKit/LayoutTests/typedcssom/inlinestyle/tokenStreamValue.html

Issue 2251663002: [Typed-OM] Get CSSTokenStreamValue from StyleMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify functions, add test Created 4 years, 4 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
Index: third_party/WebKit/LayoutTests/typedcssom/inlinestyle/tokenStreamValue.html
diff --git a/third_party/WebKit/LayoutTests/typedcssom/inlinestyle/tokenStreamValue.html b/third_party/WebKit/LayoutTests/typedcssom/inlinestyle/tokenStreamValue.html
new file mode 100644
index 0000000000000000000000000000000000000000..851ee7088101328429ce7c3a7e6a0c53cbda4e6c
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/typedcssom/inlinestyle/tokenStreamValue.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+
+<div id="testElement1"></div>
+<div id="testElement2"></div>
+<div id="testElement3"></div>
+<div id="testElement4"></div>
+
+<script>
+
+function compareTokenStreamValueWithArray(tokenStreamValue, expectedTokenStreamValue) {
meade_UTC10 2016/08/25 01:00:01 Don't forget to address my previous comments on th
anthonyhkf 2016/08/25 03:48:31 Oh, sorry, I didn't see it.
+ if (tokenStreamValue == null) {
+ return expectedTokenStreamValue == null;
+ }
+ assert_true(tokenStreamValue instanceof CSSTokenStreamValue);
+ var iterator = tokenStreamValue.values();
+ var correct = true, i, j;
+ for (i = iterator.next(), j = 0; j < expectedTokenStreamValue.length; i = iterator.next(), ++j) {
+ if (i.done) return false;
+ if (typeof(i.value) == 'string') {
+ if (i.value != expectedTokenStreamValue[j]) {
+ return false;
+ }
+ } else if (i.value instanceof CSSVariableReferenceValue) {
+ if (i.value.variable != expectedTokenStreamValue[j].variable) {
+ return false;
+ }
+ correct = correct && compareTokenStreamValueWithArray(i.value.fallback, expectedTokenStreamValue[j].fallback);
+ } else return false;
+ }
+ return correct && i.done;
+}
+
+test(function() {
+ testElement1.style.width = "calc(42px + var(--foo, 15em) + var(--bar, var(--far) + 15px))";
+ var expectedTokenStreamValue =
+ ["calc(42px + "
+ , { variable: "--foo", fallback: [" 15em"] }
+ , " + "
+ , { variable: "--bar", fallback: [" ", { variable: "--far", fallback: undefined }, " + 15px"] }
+ , ")"];
+ assert_true(compareTokenStreamValueWithArray(testElement1.styleMap.get("width"), expectedTokenStreamValue));
+}, "Can get CSSTokenStreamValue from StyleMap with correct normalization");
+
+test(function() {
+ testElement2.style.width = "var(--a)";
+ var expectedTokenStreamValue = [{ variable: "--a", fallback: undefined }];
+ assert_true(compareTokenStreamValueWithArray(testElement2.styleMap.get("width"), expectedTokenStreamValue));
+}, "Only has variable");
+
+test(function() {
+ testElement3.style.width = "var(--a, 10px, 20px, 30em)";
+ var expectedTokenStreamValue = [{ variable: "--a", fallback: [" 10px, 20px, 30em"] }];
+ assert_true(compareTokenStreamValueWithArray(testElement3.styleMap.get("width"), expectedTokenStreamValue));
+}, "Has several values");
+
+test(function() {
+ testElement4.style.width = " var( --a , 5px ) ";
+ var expectedTokenStreamValue = [{ variable: "--a", fallback: [" 5px "] }, " "];
+ assert_true(compareTokenStreamValueWithArray(testElement4.styleMap.get("width"), expectedTokenStreamValue));
+}, "Can handle spaces");
+
+</script>

Powered by Google App Engine
This is Rietveld 408576698