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/MediaTypeNames.h" | 8 #include "core/MediaTypeNames.h" |
9 #include "core/css/MediaList.h" | 9 #include "core/css/MediaList.h" |
10 #include "core/css/MediaValuesCached.h" | 10 #include "core/css/MediaValuesCached.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 TestCase printTestCases[] = { | 71 TestCase printTestCases[] = { |
72 {"print and (min-resolution: 1dppx)", 1}, | 72 {"print and (min-resolution: 1dppx)", 1}, |
73 {"print and (min-resolution: 118dpcm)", 1}, | 73 {"print and (min-resolution: 118dpcm)", 1}, |
74 {"print and (min-resolution: 119dpcm)", 0}, | 74 {"print and (min-resolution: 119dpcm)", 0}, |
75 {0, 0} // Do not remove the terminator line. | 75 {0, 0} // Do not remove the terminator line. |
76 }; | 76 }; |
77 | 77 |
78 void testMQEvaluator(TestCase* testCases, const MediaQueryEvaluator& mediaQueryE
valuator) | 78 void testMQEvaluator(TestCase* testCases, const MediaQueryEvaluator& mediaQueryE
valuator) |
79 { | 79 { |
| 80 RefPtrWillBePersistent<MediaQuerySet> querySet = nullptr; |
80 for (unsigned i = 0; testCases[i].input; ++i) { | 81 for (unsigned i = 0; testCases[i].input; ++i) { |
81 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(testC
ases[i].input); | 82 querySet = MediaQuerySet::create(testCases[i].input); |
82 ASSERT_EQ(testCases[i].output, mediaQueryEvaluator.eval(querySet.get()))
; | 83 ASSERT_EQ(testCases[i].output, mediaQueryEvaluator.eval(querySet.get()))
; |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 TEST(MediaQueryEvaluatorTest, Cached) | 87 TEST(MediaQueryEvaluatorTest, Cached) |
87 { | 88 { |
88 MediaValuesCached::MediaValuesCachedData data; | 89 MediaValuesCached::MediaValuesCachedData data; |
89 data.viewportWidth = 500; | 90 data.viewportWidth = 500; |
90 data.viewportHeight = 500; | 91 data.viewportHeight = 500; |
91 data.deviceWidth = 500; | 92 data.deviceWidth = 500; |
(...skipping 26 matching lines...) Expand all Loading... |
118 | 119 |
119 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); | 120 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); |
120 testMQEvaluator(viewportTestCases, mediaQueryEvaluator); | 121 testMQEvaluator(viewportTestCases, mediaQueryEvaluator); |
121 pageHolder->frameView().setMediaType(MediaTypeNames::print); | 122 pageHolder->frameView().setMediaType(MediaTypeNames::print); |
122 testMQEvaluator(printTestCases, mediaQueryEvaluator); | 123 testMQEvaluator(printTestCases, mediaQueryEvaluator); |
123 } | 124 } |
124 | 125 |
125 TEST(MediaQueryEvaluatorTest, DynamicNoView) | 126 TEST(MediaQueryEvaluatorTest, DynamicNoView) |
126 { | 127 { |
127 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSize(500, 50
0)); | 128 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSize(500, 50
0)); |
128 RefPtr<FrameView> view = pageHolder->frame().view(); | 129 RefPtrWillBePersistent<FrameView> view = pageHolder->frame().view(); |
129 pageHolder->frame().setView(nullptr); | 130 pageHolder->frame().setView(nullptr); |
130 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); | 131 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); |
131 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create("foobar")
; | 132 RefPtrWillBePersistent<MediaQuerySet> querySet = MediaQuerySet::create("foob
ar"); |
132 bool output = false; | 133 bool output = false; |
133 ASSERT_EQ(output, mediaQueryEvaluator.eval(querySet.get())); | 134 ASSERT_EQ(output, mediaQueryEvaluator.eval(querySet.get())); |
134 pageHolder->frame().setView(view); | 135 pageHolder->frame().setView(view); |
135 } | 136 } |
136 | 137 |
137 } // namespace | 138 } // namespace |
OLD | NEW |