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

Side by Side Diff: Source/core/css/MediaQueryEvaluatorTest.cpp

Issue 224733011: A sizes attribute parser (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed rebase 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 unified diff | Download patch
« no previous file with comments | « Source/core/css/MediaQueryEvaluator.cpp ('k') | Source/core/css/MediaQueryExp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/MediaValues.h" 9 #include "core/css/MediaValuesCached.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},
28 {"screen", 1}, 30 {"screen", 1},
29 {"screen and (color)", 1}, 31 {"screen and (color)", 1},
30 {"all and (min-width: 500px)", 1}, 32 {"all and (min-width: 500px)", 1},
31 {"not screen and (color)", 0}, 33 {"not screen and (color)", 0},
32 {"(min-width: 500px)", 1}, 34 {"(min-width: 500px)", 1},
33 {"(min-width: 501px)", 0}, 35 {"(min-width: 501px)", 0},
34 {"(max-width: 500px)", 1}, 36 {"(max-width: 500px)", 1},
35 {"(max-width: 499px)", 0}, 37 {"(max-width: 499px)", 0},
36 {"(width: 500px)", 1}, 38 {"(width: 500px)", 1},
37 {"(width: 501px)", 0}, 39 {"(width: 501px)", 0},
(...skipping 23 matching lines...) Expand all
61 {"(hover: 1)", 1}, 63 {"(hover: 1)", 1},
62 {"(hover: 0)", 0}, 64 {"(hover: 0)", 0},
63 {0, 0} // Do not remove the terminator line. 65 {0, 0} // Do not remove the terminator line.
64 }; 66 };
65 TestCase printTestCases[] = { 67 TestCase printTestCases[] = {
66 {"print and (min-resolution: 1dppx)", 1}, 68 {"print and (min-resolution: 1dppx)", 1},
67 {"print and (min-resolution: 118dpcm)", 0}, 69 {"print and (min-resolution: 118dpcm)", 0},
68 {0, 0} // Do not remove the terminator line. 70 {0, 0} // Do not remove the terminator line.
69 }; 71 };
70 72
71 RefPtr<MediaValues> mediaValues = MediaValues::create(MediaValues::CachingMo de, 73 MediaValuesCached::MediaValuesCachedData data;
72 500, // Viewport Width 74 data.viewportWidth = 500;
73 500, // Viewport height 75 data.viewportHeight = 500;
74 500, // Device Width 76 data.deviceWidth = 500;
75 500, // Device Height 77 data.deviceHeight = 500;
76 2.0, // Device pixel ratio 78 data.devicePixelRatio = 2.0;
77 24, // Color bits per component 79 data.colorBitsPerComponent = 24;
78 0, // Monochrome bits per component 80 data.monochromeBitsPerComponent = 0;
79 MediaValues::MousePointer, // Pointer device 81 data.pointer = MediaValues::MousePointer;
80 16, // Default font size 82 data.defaultFontSize = 16;
81 true, // 3D enabled 83 data.computedFontSize = 16;
82 false, // scan media type 84 data.threeDEnabled = true;
83 true, // screen media type 85 data.scanMediaType = false;
84 false, // print media type 86 data.screenMediaType = true;
85 true // Strict mode 87 data.printMediaType = false;
86 ); 88 data.strictMode = true;
89 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data);
87 90
88 for (unsigned i = 0; screenTestCases[i].input; ++i) { 91 for (unsigned i = 0; screenTestCases[i].input; ++i) {
89 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree nTestCases[i].input); 92 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree nTestCases[i].input);
90 MediaQueryEvaluator mediaQueryEvaluator("screen", *mediaValues); 93 MediaQueryEvaluator mediaQueryEvaluator("screen", *mediaValues);
91 ASSERT_EQ(screenTestCases[i].output, mediaQueryEvaluator.eval(querySet.g et())); 94 ASSERT_EQ(screenTestCases[i].output, mediaQueryEvaluator.eval(querySet.g et()));
92 } 95 }
93 for (unsigned i = 0; printTestCases[i].input; ++i) { 96 for (unsigned i = 0; printTestCases[i].input; ++i) {
94 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print TestCases[i].input); 97 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print TestCases[i].input);
95 MediaQueryEvaluator mediaQueryEvaluator("print", *mediaValues); 98 MediaQueryEvaluator mediaQueryEvaluator("print", *mediaValues);
96 ASSERT_EQ(printTestCases[i].output, mediaQueryEvaluator.eval(querySet.ge t())); 99 ASSERT_EQ(printTestCases[i].output, mediaQueryEvaluator.eval(querySet.ge t()));
97 } 100 }
98 } 101 }
99 102
100 } // namespace 103 } // namespace
OLDNEW
« no previous file with comments | « Source/core/css/MediaQueryEvaluator.cpp ('k') | Source/core/css/MediaQueryExp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698