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/parser/SizesAttributeParser.h" |
| 7 |
| 8 #include "core/css/MediaValuesCached.h" |
| 9 |
| 10 #include <gtest/gtest.h> |
| 11 |
| 12 namespace WebCore { |
| 13 |
| 14 typedef struct { |
| 15 const char* input; |
| 16 const int output; |
| 17 } TestCase; |
| 18 |
| 19 TEST(SizesAttributeParserTest, Basic) |
| 20 { |
| 21 // The first string represents the input string. |
| 22 // The second string represents the output string, if present. |
| 23 // Otherwise, the output string is identical to the first string. |
| 24 TestCase testCases[] = { |
| 25 {"screen", 500}, |
| 26 {"(min-width:500px)", 500}, |
| 27 {"(min-width:500px) 200px", 200}, |
| 28 {"(min-width:500px) 50vw", 250}, |
| 29 {"(min-width:500px) 200px, 400px", 200}, |
| 30 {"400px, (min-width:500px) 200px", 400}, |
| 31 {"(min-width:5000px) 200px, 400px", 400}, |
| 32 {"(blalbadfsdf) 200px, 400px", 400}, |
| 33 {"0", 500}, |
| 34 {"-0", 500}, |
| 35 {"1", 500}, |
| 36 {"300px, 400px", 300}, |
| 37 {"(min-width:5000px) 200px, (min-width:500px) 400px", 400}, |
| 38 {"", 500}, |
| 39 {" /**/ ", 500}, |
| 40 {" /**/ 300px", 300}, |
| 41 {"300px /**/ ", 300}, |
| 42 {" /**/ (min-width:500px) /**/ 300px", 300}, |
| 43 {"-100px, 200px", 200}, |
| 44 {"-50vw, 20vw", 100}, |
| 45 {"50asdf, 200px", 200}, |
| 46 {"asdf, 200px", 200}, |
| 47 {"(max-width: 3000px) 200w, 400w", 500}, |
| 48 {",, , /**/ ,200px", 200}, |
| 49 // FIXME - test all other units and calc(). |
| 50 {0, 0} // Do not remove the terminator line. |
| 51 }; |
| 52 |
| 53 MediaValues::MediaValuesInitializer initializer; |
| 54 initializer.viewportWidth = 500; |
| 55 initializer.viewportHeight = 500; |
| 56 initializer.deviceWidth = 500; |
| 57 initializer.deviceHeight = 500; |
| 58 initializer.devicePixelRatio = 2.0; |
| 59 initializer.colorBitsPerComponent = 24; |
| 60 initializer.monochromeBitsPerComponent = 0; |
| 61 initializer.pointer = MediaValues::MousePointer; |
| 62 initializer.defaultFontSize = 16; |
| 63 initializer.computedFontSize = 16; |
| 64 initializer.hasXHeight = true; |
| 65 initializer.xHeight = 16; |
| 66 initializer.zeroWidth = 16; |
| 67 initializer.threeDEnabled = true; |
| 68 initializer.scanMediaType = false; |
| 69 initializer.screenMediaType = true; |
| 70 initializer.printMediaType = false; |
| 71 initializer.strictMode = true; |
| 72 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(initializer); |
| 73 |
| 74 for (unsigned i = 0; testCases[i].input; ++i) { |
| 75 int effectiveSize = SizesAttributeParser::findEffectiveSize(testCases[i]
.input, mediaValues); |
| 76 ASSERT_EQ(testCases[i].output, effectiveSize); |
| 77 } |
| 78 } |
| 79 |
| 80 } // namespace |
OLD | NEW |