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

Unified Diff: Source/core/css/parser/SizesAttributeParserTest.cpp

Issue 224733011: A sizes attribute parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added invalid length layout test Created 6 years, 8 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: Source/core/css/parser/SizesAttributeParserTest.cpp
diff --git a/Source/core/css/parser/SizesAttributeParserTest.cpp b/Source/core/css/parser/SizesAttributeParserTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..26f72e53c2d7912d0560255ba2426d48b00e7cd3
--- /dev/null
+++ b/Source/core/css/parser/SizesAttributeParserTest.cpp
@@ -0,0 +1,80 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/css/parser/SizesAttributeParser.h"
+
+#include "core/css/MediaValuesCached.h"
+
+#include <gtest/gtest.h>
+
+namespace WebCore {
+
+typedef struct {
+ const char* input;
+ const int output;
+} TestCase;
+
+TEST(SizesAttributeParserTest, Basic)
+{
+ // The first string represents the input string.
+ // The second string represents the output string, if present.
+ // Otherwise, the output string is identical to the first string.
+ TestCase testCases[] = {
+ {"screen", 500},
+ {"(min-width:500px)", 500},
+ {"(min-width:500px) 200px", 200},
+ {"(min-width:500px) 50vw", 250},
+ {"(min-width:500px) 200px, 400px", 200},
+ {"400px, (min-width:500px) 200px", 400},
+ {"(min-width:5000px) 200px, 400px", 400},
+ {"(blalbadfsdf) 200px, 400px", 400},
+ {"0", 500},
+ {"-0", 500},
+ {"1", 500},
+ {"300px, 400px", 300},
+ {"(min-width:5000px) 200px, (min-width:500px) 400px", 400},
+ {"", 500},
+ {" /**/ ", 500},
+ {" /**/ 300px", 300},
+ {"300px /**/ ", 300},
+ {" /**/ (min-width:500px) /**/ 300px", 300},
+ {"-100px, 200px", 200},
+ {"-50vw, 20vw", 100},
+ {"50asdf, 200px", 200},
+ {"asdf, 200px", 200},
+ {"(max-width: 3000px) 200w, 400w", 500},
+ {",, , /**/ ,200px", 200},
+ // FIXME - test all other units and calc().
+ {0, 0} // Do not remove the terminator line.
+ };
+
+ MediaValues::MediaValuesInitializer initializer;
+ initializer.viewportWidth = 500;
+ initializer.viewportHeight = 500;
+ initializer.deviceWidth = 500;
+ initializer.deviceHeight = 500;
+ initializer.devicePixelRatio = 2.0;
+ initializer.colorBitsPerComponent = 24;
+ initializer.monochromeBitsPerComponent = 0;
+ initializer.pointer = MediaValues::MousePointer;
+ initializer.defaultFontSize = 16;
+ initializer.computedFontSize = 16;
+ initializer.hasXHeight = true;
+ initializer.xHeight = 16;
+ initializer.zeroWidth = 16;
+ initializer.threeDEnabled = true;
+ initializer.scanMediaType = false;
+ initializer.screenMediaType = true;
+ initializer.printMediaType = false;
+ initializer.strictMode = true;
+ RefPtr<MediaValues> mediaValues = MediaValuesCached::create(initializer);
+
+ for (unsigned i = 0; testCases[i].input; ++i) {
+ int effectiveSize = SizesAttributeParser::findEffectiveSize(testCases[i].input, mediaValues);
+ ASSERT_EQ(testCases[i].output, effectiveSize);
+ }
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698