OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/css/parser/SizesAttributeParser.h" | 6 #include "core/css/parser/SizesAttributeParser.h" |
7 | 7 |
8 #include "core/MediaTypeNames.h" | 8 #include "core/MediaTypeNames.h" |
9 #include "core/css/MediaValuesCached.h" | 9 #include "core/css/MediaValuesCached.h" |
10 | 10 |
11 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 | 14 |
15 typedef struct { | 15 typedef struct { |
16 const char* input; | 16 const char* input; |
17 const unsigned effectiveSize; | 17 const float effectiveSize; |
18 const bool viewportDependant; | 18 const bool viewportDependant; |
19 } TestCase; | 19 } TestCase; |
20 | 20 |
21 TEST(SizesAttributeParserTest, Basic) | 21 TEST(SizesAttributeParserTest, Basic) |
22 { | 22 { |
23 TestCase testCases[] = { | 23 TestCase testCases[] = { |
24 {"screen", 500, true}, | 24 {"screen", 500, true}, |
25 {"(min-width:500px)", 500, true}, | 25 {"(min-width:500px)", 500, true}, |
26 {"(min-width:500px) 200px", 200, false}, | 26 {"(min-width:500px) 200px", 200, false}, |
27 {"(min-width:500px) 50vw", 250, true}, | 27 {"(min-width:500px) 50vw", 250, true}, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 {"(max-width: 3000px) 200px, 400px", 200, false}, | 61 {"(max-width: 3000px) 200px, 400px", 200, false}, |
62 {"(max-width: 3000px) 20em, 40em", 320, false}, | 62 {"(max-width: 3000px) 20em, 40em", 320, false}, |
63 {"(max-width: 3000px) 0, 40em", 0, false}, | 63 {"(max-width: 3000px) 0, 40em", 0, false}, |
64 {"(max-width: 3000px) 0px, 40em", 0, false}, | 64 {"(max-width: 3000px) 0px, 40em", 0, false}, |
65 {"(max-width: 3000px) 50vw, 40em", 250, true}, | 65 {"(max-width: 3000px) 50vw, 40em", 250, true}, |
66 {"(max-width: 3000px) 50px, 40vw", 50, false}, | 66 {"(max-width: 3000px) 50px, 40vw", 50, false}, |
67 {"((),1px", 500, true}, | 67 {"((),1px", 500, true}, |
68 {"{{},1px", 500, true}, | 68 {"{{},1px", 500, true}, |
69 {"[[],1px", 500, true}, | 69 {"[[],1px", 500, true}, |
70 {"x(x(),1px", 500, true}, | 70 {"x(x(),1px", 500, true}, |
| 71 {"(max-width: 3000px) 50.5px, 40vw", 50.5, false}, |
71 {0, 0, false} // Do not remove the terminator line. | 72 {0, 0, false} // Do not remove the terminator line. |
72 }; | 73 }; |
73 | 74 |
74 MediaValuesCached::MediaValuesCachedData data; | 75 MediaValuesCached::MediaValuesCachedData data; |
75 data.viewportWidth = 500; | 76 data.viewportWidth = 500; |
76 data.viewportHeight = 500; | 77 data.viewportHeight = 500; |
77 data.deviceWidth = 500; | 78 data.deviceWidth = 500; |
78 data.deviceHeight = 500; | 79 data.deviceHeight = 500; |
79 data.devicePixelRatio = 2.0; | 80 data.devicePixelRatio = 2.0; |
80 data.colorBitsPerComponent = 24; | 81 data.colorBitsPerComponent = 24; |
81 data.monochromeBitsPerComponent = 0; | 82 data.monochromeBitsPerComponent = 0; |
82 data.primaryPointerType = PointerTypeFine; | 83 data.primaryPointerType = PointerTypeFine; |
83 data.defaultFontSize = 16; | 84 data.defaultFontSize = 16; |
84 data.threeDEnabled = true; | 85 data.threeDEnabled = true; |
85 data.mediaType = MediaTypeNames::screen; | 86 data.mediaType = MediaTypeNames::screen; |
86 data.strictMode = true; | 87 data.strictMode = true; |
87 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data); | 88 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data); |
88 | 89 |
89 for (unsigned i = 0; testCases[i].input; ++i) { | 90 for (unsigned i = 0; testCases[i].input; ++i) { |
90 SizesAttributeParser parser(mediaValues, testCases[i].input); | 91 SizesAttributeParser parser(mediaValues, testCases[i].input); |
91 ASSERT_EQ(testCases[i].effectiveSize, parser.length()); | 92 ASSERT_EQ(testCases[i].effectiveSize, parser.length()); |
92 ASSERT_EQ(testCases[i].viewportDependant, parser.viewportDependant()); | 93 ASSERT_EQ(testCases[i].viewportDependant, parser.viewportDependant()); |
93 } | 94 } |
94 } | 95 } |
95 | 96 |
96 } // namespace | 97 } // namespace |
OLD | NEW |