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