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