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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 TestCase printTestCases[] = { | 78 TestCase printTestCases[] = { |
79 {"print and (min-resolution: 1dppx)", 1}, | 79 {"print and (min-resolution: 1dppx)", 1}, |
80 {"print and (min-resolution: 118dpcm)", 1}, | 80 {"print and (min-resolution: 118dpcm)", 1}, |
81 {"print and (min-resolution: 119dpcm)", 0}, | 81 {"print and (min-resolution: 119dpcm)", 0}, |
82 {0, 0} // Do not remove the terminator line. | 82 {0, 0} // Do not remove the terminator line. |
83 }; | 83 }; |
84 | 84 |
85 void testMQEvaluator(TestCase* testCases, const MediaQueryEvaluator& mediaQueryE
valuator) | 85 void testMQEvaluator(TestCase* testCases, const MediaQueryEvaluator& mediaQueryE
valuator) |
86 { | 86 { |
| 87 RefPtrWillBePersistent<MediaQuerySet> querySet = nullptr; |
87 for (unsigned i = 0; testCases[i].input; ++i) { | 88 for (unsigned i = 0; testCases[i].input; ++i) { |
88 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create(testC
ases[i].input); | 89 querySet = MediaQuerySet::create(testCases[i].input); |
89 ASSERT_EQ(testCases[i].output, mediaQueryEvaluator.eval(querySet.get()))
; | 90 ASSERT_EQ(testCases[i].output, mediaQueryEvaluator.eval(querySet.get()))
; |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 TEST(MediaQueryEvaluatorTest, Cached) | 94 TEST(MediaQueryEvaluatorTest, Cached) |
94 { | 95 { |
95 MediaValuesCached::MediaValuesCachedData data; | 96 MediaValuesCached::MediaValuesCachedData data; |
96 data.viewportWidth = 500; | 97 data.viewportWidth = 500; |
97 data.viewportHeight = 500; | 98 data.viewportHeight = 500; |
98 data.deviceWidth = 500; | 99 data.deviceWidth = 500; |
(...skipping 26 matching lines...) Expand all Loading... |
125 | 126 |
126 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); | 127 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); |
127 testMQEvaluator(viewportTestCases, mediaQueryEvaluator); | 128 testMQEvaluator(viewportTestCases, mediaQueryEvaluator); |
128 pageHolder->frameView().setMediaType(MediaTypeNames::print); | 129 pageHolder->frameView().setMediaType(MediaTypeNames::print); |
129 testMQEvaluator(printTestCases, mediaQueryEvaluator); | 130 testMQEvaluator(printTestCases, mediaQueryEvaluator); |
130 } | 131 } |
131 | 132 |
132 TEST(MediaQueryEvaluatorTest, DynamicNoView) | 133 TEST(MediaQueryEvaluatorTest, DynamicNoView) |
133 { | 134 { |
134 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSize(500, 50
0)); | 135 OwnPtr<DummyPageHolder> pageHolder = DummyPageHolder::create(IntSize(500, 50
0)); |
135 RefPtr<FrameView> view = pageHolder->frame().view(); | 136 RefPtrWillBePersistent<FrameView> view = pageHolder->frame().view(); |
136 pageHolder->frame().setView(nullptr); | 137 pageHolder->frame().setView(nullptr); |
137 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); | 138 MediaQueryEvaluator mediaQueryEvaluator(&pageHolder->frame()); |
138 RefPtrWillBeRawPtr<MediaQuerySet> querySet = MediaQuerySet::create("foobar")
; | 139 RefPtrWillBePersistent<MediaQuerySet> querySet = MediaQuerySet::create("foob
ar"); |
139 bool output = false; | 140 bool output = false; |
140 ASSERT_EQ(output, mediaQueryEvaluator.eval(querySet.get())); | 141 ASSERT_EQ(output, mediaQueryEvaluator.eval(querySet.get())); |
141 pageHolder->frame().setView(view); | 142 pageHolder->frame().setView(view); |
142 } | 143 } |
143 | 144 |
144 } // namespace | 145 } // namespace |
OLD | NEW |