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/MediaQueryEvaluator.h" | 6 #include "core/css/MediaQueryEvaluator.h" |
7 | 7 |
8 #include "core/css/MediaList.h" | 8 #include "core/css/MediaList.h" |
9 #include "core/css/MediaValuesCached.h" | 9 #include "core/css/MediaValues.h" |
10 #include "wtf/PassOwnPtr.h" | 10 #include "wtf/PassOwnPtr.h" |
11 #include "wtf/text/StringBuilder.h" | 11 #include "wtf/text/StringBuilder.h" |
12 | 12 |
13 #include <gtest/gtest.h> | 13 #include <gtest/gtest.h> |
14 | 14 |
15 namespace WebCore { | 15 namespace WebCore { |
16 | 16 |
17 typedef struct { | 17 typedef struct { |
18 const char* input; | 18 const char* input; |
19 const bool output; | 19 const bool output; |
20 } TestCase; | 20 } TestCase; |
21 | 21 |
22 TEST(MediaQueryEvaluatorTest, Basic) | 22 TEST(MediaQueryEvaluatorTest, Basic) |
23 { | 23 { |
24 // The first string represents the input string. | 24 // The first string represents the input string. |
25 // The second string represents the output string, if present. | 25 // The second string represents the output string, if present. |
26 // Otherwise, the output string is identical to the first string. | 26 // Otherwise, the output string is identical to the first string. |
27 TestCase screenTestCases[] = { | 27 TestCase screenTestCases[] = { |
28 {"", 1}, | |
29 {" ", 1}, | |
30 {"screen", 1}, | 28 {"screen", 1}, |
31 {"screen and (color)", 1}, | 29 {"screen and (color)", 1}, |
32 {"all and (min-width: 500px)", 1}, | 30 {"all and (min-width: 500px)", 1}, |
33 {"not screen and (color)", 0}, | 31 {"not screen and (color)", 0}, |
34 {"(min-width: 500px)", 1}, | 32 {"(min-width: 500px)", 1}, |
35 {"(min-width: 501px)", 0}, | 33 {"(min-width: 501px)", 0}, |
36 {"(max-width: 500px)", 1}, | 34 {"(max-width: 500px)", 1}, |
37 {"(max-width: 499px)", 0}, | 35 {"(max-width: 499px)", 0}, |
38 {"(width: 500px)", 1}, | 36 {"(width: 500px)", 1}, |
39 {"(width: 501px)", 0}, | 37 {"(width: 501px)", 0}, |
(...skipping 23 matching lines...) Expand all Loading... |
63 {"(hover: 1)", 1}, | 61 {"(hover: 1)", 1}, |
64 {"(hover: 0)", 0}, | 62 {"(hover: 0)", 0}, |
65 {0, 0} // Do not remove the terminator line. | 63 {0, 0} // Do not remove the terminator line. |
66 }; | 64 }; |
67 TestCase printTestCases[] = { | 65 TestCase printTestCases[] = { |
68 {"print and (min-resolution: 1dppx)", 1}, | 66 {"print and (min-resolution: 1dppx)", 1}, |
69 {"print and (min-resolution: 118dpcm)", 0}, | 67 {"print and (min-resolution: 118dpcm)", 0}, |
70 {0, 0} // Do not remove the terminator line. | 68 {0, 0} // Do not remove the terminator line. |
71 }; | 69 }; |
72 | 70 |
73 MediaValuesCached::MediaValuesCachedData data; | 71 RefPtr<MediaValues> mediaValues = MediaValues::create(MediaValues::CachingMo
de, |
74 data.viewportWidth = 500; | 72 500, // Viewport Width |
75 data.viewportHeight = 500; | 73 500, // Viewport height |
76 data.deviceWidth = 500; | 74 500, // Device Width |
77 data.deviceHeight = 500; | 75 500, // Device Height |
78 data.devicePixelRatio = 2.0; | 76 2.0, // Device pixel ratio |
79 data.colorBitsPerComponent = 24; | 77 24, // Color bits per component |
80 data.monochromeBitsPerComponent = 0; | 78 0, // Monochrome bits per component |
81 data.pointer = MediaValues::MousePointer; | 79 MediaValues::MousePointer, // Pointer device |
82 data.defaultFontSize = 16; | 80 16, // Default font size |
83 data.computedFontSize = 16; | 81 true, // 3D enabled |
84 data.hasXHeight = true; | 82 false, // scan media type |
85 data.xHeight = 16; | 83 true, // screen media type |
86 data.zeroWidth = 16; | 84 false, // print media type |
87 data.threeDEnabled = true; | 85 true // Strict mode |
88 data.scanMediaType = false; | 86 ); |
89 data.screenMediaType = true; | |
90 data.printMediaType = false; | |
91 data.strictMode = true; | |
92 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data); | |
93 | 87 |
94 for (unsigned i = 0; screenTestCases[i].input; ++i) { | 88 for (unsigned i = 0; screenTestCases[i].input; ++i) { |
95 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree
nTestCases[i].input); | 89 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree
nTestCases[i].input); |
96 MediaQueryEvaluator mediaQueryEvaluator("screen", *mediaValues); | 90 MediaQueryEvaluator mediaQueryEvaluator("screen", *mediaValues); |
97 ASSERT_EQ(screenTestCases[i].output, mediaQueryEvaluator.eval(querySet.g
et())); | 91 ASSERT_EQ(screenTestCases[i].output, mediaQueryEvaluator.eval(querySet.g
et())); |
98 } | 92 } |
99 for (unsigned i = 0; printTestCases[i].input; ++i) { | 93 for (unsigned i = 0; printTestCases[i].input; ++i) { |
100 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print
TestCases[i].input); | 94 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print
TestCases[i].input); |
101 MediaQueryEvaluator mediaQueryEvaluator("print", *mediaValues); | 95 MediaQueryEvaluator mediaQueryEvaluator("print", *mediaValues); |
102 ASSERT_EQ(printTestCases[i].output, mediaQueryEvaluator.eval(querySet.ge
t())); | 96 ASSERT_EQ(printTestCases[i].output, mediaQueryEvaluator.eval(querySet.ge
t())); |
103 } | 97 } |
104 } | 98 } |
105 | 99 |
106 } // namespace | 100 } // namespace |
OLD | NEW |