Chromium Code Reviews| 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/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 Loading... | |
| 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 MediaValues::MediaValuesInitializer initializer; |
|
eseidel
2014/04/14 22:55:32
This is sooooo much easier to read /less error pro
| |
| 72 500, // Viewport Width | 74 initializer.viewportWidth = 500; |
| 73 500, // Viewport height | 75 initializer.viewportHeight = 500; |
| 74 500, // Device Width | 76 initializer.deviceWidth = 500; |
| 75 500, // Device Height | 77 initializer.deviceHeight = 500; |
| 76 2.0, // Device pixel ratio | 78 initializer.devicePixelRatio = 2.0; |
| 77 24, // Color bits per component | 79 initializer.colorBitsPerComponent = 24; |
| 78 0, // Monochrome bits per component | 80 initializer.monochromeBitsPerComponent = 0; |
| 79 MediaValues::MousePointer, // Pointer device | 81 initializer.pointer = MediaValues::MousePointer; |
| 80 16, // Default font size | 82 initializer.defaultFontSize = 16; |
| 81 true, // 3D enabled | 83 initializer.computedFontSize = 16; |
| 82 false, // scan media type | 84 initializer.hasXHeight = true; |
| 83 true, // screen media type | 85 initializer.xHeight = 16; |
| 84 false, // print media type | 86 initializer.zeroWidth = 16; |
| 85 true // Strict mode | 87 initializer.threeDEnabled = true; |
| 86 ); | 88 initializer.scanMediaType = false; |
| 89 initializer.screenMediaType = true; | |
| 90 initializer.printMediaType = false; | |
| 91 initializer.strictMode = true; | |
| 92 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(initializer); | |
| 87 | 93 |
| 88 for (unsigned i = 0; screenTestCases[i].input; ++i) { | 94 for (unsigned i = 0; screenTestCases[i].input; ++i) { |
| 89 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree nTestCases[i].input); | 95 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree nTestCases[i].input); |
| 90 MediaQueryEvaluator mediaQueryEvaluator("screen", *mediaValues); | 96 MediaQueryEvaluator mediaQueryEvaluator("screen", *mediaValues); |
| 91 ASSERT_EQ(screenTestCases[i].output, mediaQueryEvaluator.eval(querySet.g et())); | 97 ASSERT_EQ(screenTestCases[i].output, mediaQueryEvaluator.eval(querySet.g et())); |
| 92 } | 98 } |
| 93 for (unsigned i = 0; printTestCases[i].input; ++i) { | 99 for (unsigned i = 0; printTestCases[i].input; ++i) { |
| 94 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print TestCases[i].input); | 100 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print TestCases[i].input); |
| 95 MediaQueryEvaluator mediaQueryEvaluator("print", *mediaValues); | 101 MediaQueryEvaluator mediaQueryEvaluator("print", *mediaValues); |
| 96 ASSERT_EQ(printTestCases[i].output, mediaQueryEvaluator.eval(querySet.ge t())); | 102 ASSERT_EQ(printTestCases[i].output, mediaQueryEvaluator.eval(querySet.ge t())); |
| 97 } | 103 } |
| 98 } | 104 } |
| 99 | 105 |
| 100 } // namespace | 106 } // namespace |
| OLD | NEW |