OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #include "config.h" |
| 6 #include "core/css/MediaQueryEvaluator.h" |
| 7 |
| 8 #include "core/css/MediaList.h" |
| 9 #include "core/css/MediaValues.h" |
| 10 #include "wtf/PassOwnPtr.h" |
| 11 #include "wtf/text/StringBuilder.h" |
| 12 |
| 13 #include <gtest/gtest.h> |
| 14 |
| 15 namespace WebCore { |
| 16 |
| 17 typedef struct { |
| 18 const char* input; |
| 19 const bool output; |
| 20 } TestCase; |
| 21 |
| 22 TEST(MediaQueryEvaluatorTest, Basic) |
| 23 { |
| 24 // The first string represents the input string. |
| 25 // The second string represents the output string, if present. |
| 26 // Otherwise, the output string is identical to the first string. |
| 27 TestCase screenTestCases[] = { |
| 28 {"screen", 1}, |
| 29 {"screen and (color)", 1}, |
| 30 {"all and (min-width: 500px)", 1}, |
| 31 {"not screen and (color)", 0}, |
| 32 {"(min-width: 500px)", 1}, |
| 33 {"(min-width: 501px)", 0}, |
| 34 {"(max-width: 500px)", 1}, |
| 35 {"(max-width: 499px)", 0}, |
| 36 {"(width: 500px)", 1}, |
| 37 {"(width: 501px)", 0}, |
| 38 {"(min-height: 500px)", 1}, |
| 39 {"(min-height: 501px)", 0}, |
| 40 {"(max-height: 500px)", 1}, |
| 41 {"(max-height: 499px)", 0}, |
| 42 {"(height: 500px)", 1}, |
| 43 {"(height: 501px)", 0}, |
| 44 {"screen and (min-width: 400px) and (max-width: 700px)", 1}, |
| 45 {"screen and (device-aspect-ratio: 16/9)", 0}, |
| 46 {"screen and (device-aspect-ratio: 1/1)", 1}, |
| 47 {"all and (min-color: 2)", 1}, |
| 48 {"all and (min-color: 32)", 0}, |
| 49 {"all and (min-color-index: 0)", 1}, |
| 50 {"all and (min-color-index: 1)", 0}, |
| 51 {"all and (monochrome)", 0}, |
| 52 {"all and (min-monochrome: 0)", 1}, |
| 53 {"all and (grid: 0)", 1}, |
| 54 {"(resolution: 2dppx)", 1}, |
| 55 {"(resolution: 1dppx)", 0}, |
| 56 {"(orientation: portrait)", 1}, |
| 57 {"(orientation: landscape)", 0}, |
| 58 {"tv and (scan: progressive)", 0}, |
| 59 {"(pointer: coarse)", 0}, |
| 60 {"(pointer: fine)", 1}, |
| 61 {"(hover: 1)", 1}, |
| 62 {"(hover: 0)", 0}, |
| 63 {0, 0} // Do not remove the terminator line. |
| 64 }; |
| 65 TestCase printTestCases[] = { |
| 66 {"print and (min-resolution: 1dppx)", 1}, |
| 67 {"print and (min-resolution: 118dpcm)", 0}, |
| 68 {0, 0} // Do not remove the terminator line. |
| 69 }; |
| 70 |
| 71 MediaValues mediaValues(MediaValues::CachingMode, |
| 72 500, // Viewport Width |
| 73 500, // Viewport height |
| 74 500, // Device Width |
| 75 500, // Device Height |
| 76 2.0, // Device pixel ratio |
| 77 24, // Color bits per component |
| 78 0, // Monochrome bits per component |
| 79 MediaValues::MousePointer, // Pointer device |
| 80 16, // Default font size |
| 81 true, // 3D enabled |
| 82 false, // scan media type |
| 83 true, // screen media type |
| 84 false, // print media type |
| 85 true // Strict mode |
| 86 ); |
| 87 |
| 88 for (unsigned i = 0; screenTestCases[i].input; ++i) { |
| 89 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(scree
nTestCases[i].input); |
| 90 MediaQueryEvaluator mediaQueryEvaluator("screen", mediaValues); |
| 91 ASSERT_EQ(mediaQueryEvaluator.eval(querySet.get()), screenTestCases[i].o
utput); |
| 92 } |
| 93 for (unsigned i = 0; printTestCases[i].input; ++i) { |
| 94 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(print
TestCases[i].input); |
| 95 MediaQueryEvaluator mediaQueryEvaluator("print", mediaValues); |
| 96 ASSERT_EQ(mediaQueryEvaluator.eval(querySet.get()), printTestCases[i].ou
tput); |
| 97 } |
| 98 } |
| 99 |
| 100 } // namespace |
OLD | NEW |