Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Side by Side Diff: Source/core/css/parser/SizesAttributeParserTest.cpp

Issue 369423002: Have srcset respond to viewport changes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Got rid of assert Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 blink { 13 namespace blink {
14 14
15 typedef struct { 15 typedef struct {
16 const char* input; 16 const char* input;
17 const int output; 17 const unsigned 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 SizesAttributeParser parser(mediaValues, testCases[i].input);
77 ASSERT_EQ(testCases[i].output, effectiveSize); 79 ASSERT_EQ(testCases[i].effectiveSize, parser.length());
80 ASSERT_EQ(testCases[i].viewportDependant, parser.viewportDependant());
78 } 81 }
79 } 82 }
80 83
81 } // namespace 84 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698