1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "core/css/parser/SizesAttributeParser.h"
8 #include "core/MediaTypeNames.h"
9 #include "core/css/MediaValuesCached.h"
11 #include <gtest/gtest.h>
17 const float effectiveSize;
20 TEST(SizesAttributeParserTest, Basic)
22 TestCase testCases[] = {
24 {"(min-width:500px)", 500},
25 {"(min-width:500px) 200px", 200},
26 {"(min-width:500px) 50vw", 250},
27 {"(min-width:500px) 200px, 400px", 200},
28 {"400px, (min-width:500px) 200px", 400},
29 {"40vw, (min-width:500px) 201px", 200},
30 {"(min-width:500px) 201px, 40vw", 201},
31 {"(min-width:5000px) 40vw, 201px", 201},
32 {"(min-width:500px) calc(201px), calc(40vw)", 201},
33 {"(min-width:5000px) calc(40vw), calc(201px)", 201},
34 {"(min-width:5000px) 200px, 400px", 400},
35 {"(blalbadfsdf) 200px, 400px", 400},
39 {"300px, 400px", 300},
40 {"(min-width:5000px) 200px, (min-width:500px) 400px", 400},
46 {" /**/ (min-width:500px) /**/ 300px", 300},
47 {"-100px, 200px", 200},
49 {"50asdf, 200px", 200},
51 {"(max-width: 3000px) 200w, 400w", 500},
52 {",, , /**/ ,200px", 200},
59 {"calc(40vw*2)", 400},
60 {"(min-width:5000px) calc(5000px/10), (min-width:500px) calc(1200px/3)", 400},
61 {"(min-width:500px) calc(1200/3)", 500},
62 {"(min-width:500px) calc(1200px/(0px*14))", 500},
63 {"(max-width: 3000px) 200px, 400px", 200},
64 {"(max-width: 3000px) 20em, 40em", 320},
65 {"(max-width: 3000px) 0, 40em", 0},
66 {"(max-width: 3000px) 0px, 40em", 0},
67 {"(max-width: 3000px) 50vw, 40em", 250},
68 {"(max-width: 3000px) 50px, 40vw", 50},
73 {"(max-width: 3000px) 50.5px, 40vw", 50.5},
74 {"not (blabla) 50px, 40vw", 200},
75 {"not (max-width: 100px) 50px, 40vw", 50},
76 {0, 0} // Do not remove the terminator line.
79 MediaValuesCached::MediaValuesCachedData data;
80 data.viewportWidth = 500;
81 data.viewportHeight = 600;
82 data.deviceWidth = 500;
83 data.deviceHeight = 500;
84 data.devicePixelRatio = 2.0;
85 data.colorBitsPerComponent = 24;
86 data.monochromeBitsPerComponent = 0;
87 data.primaryPointerType = PointerTypeFine;
88 data.defaultFontSize = 16;
89 data.threeDEnabled = true;
90 data.mediaType = MediaTypeNames::screen;
91 data.strictMode = true;
92 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data);
94 for (unsigned i = 0; testCases[i].input; ++i) {
95 SizesAttributeParser parser(mediaValues, testCases[i].input);
96 ASSERT_EQ(testCases[i].effectiveSize, parser.length());