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

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: rebase 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 {"40vw, (min-width:500px) 201px", 200, true},
30 {"(blalbadfsdf) 200px, 400px", 400}, 31 {"(min-width:500px) 201px, 40vw", 201, false},
31 {"0", 0}, 32 {"(min-width:5000px) 40vw, 201px", 201, false},
32 {"-0", 0}, 33 {"(min-width:500px) calc(201px), calc(40vw)", 201, false},
33 {"1", 500}, 34 {"(min-width:5000px) calc(40vw), calc(201px)", 201, false},
34 {"300px, 400px", 300}, 35 {"(min-width:5000px) 200px, 400px", 400, false},
35 {"(min-width:5000px) 200px, (min-width:500px) 400px", 400}, 36 {"(blalbadfsdf) 200px, 400px", 400, false},
36 {"", 500}, 37 {"0", 0, false},
37 {" ", 500}, 38 {"-0", 0, false},
38 {" /**/ ", 500}, 39 {"1", 500, true},
39 {" /**/ 300px", 300}, 40 {"300px, 400px", 300, false},
40 {"300px /**/ ", 300}, 41 {"(min-width:5000px) 200px, (min-width:500px) 400px", 400, false},
41 {" /**/ (min-width:500px) /**/ 300px", 300}, 42 {"", 500, true},
42 {"-100px, 200px", 200}, 43 {" ", 500, true},
43 {"-50vw, 20vw", 100}, 44 {" /**/ ", 500, true},
44 {"50asdf, 200px", 200}, 45 {" /**/ 300px", 300, false},
45 {"asdf, 200px", 200}, 46 {"300px /**/ ", 300, false},
46 {"(max-width: 3000px) 200w, 400w", 500}, 47 {" /**/ (min-width:500px) /**/ 300px", 300, false},
47 {",, , /**/ ,200px", 200}, 48 {"-100px, 200px", 200, false},
48 {"50vw", 250}, 49 {"-50vw, 20vw", 100, true},
49 {"5em", 80}, 50 {"50asdf, 200px", 200, false},
50 {"5rem", 80}, 51 {"asdf, 200px", 200, false},
51 {"calc(40vw*2)", 400}, 52 {"(max-width: 3000px) 200w, 400w", 500, true},
52 {"(min-width:5000px) calc(5000px/10), (min-width:500px) calc(1200px/3)", 400}, 53 {",, , /**/ ,200px", 200, false},
53 {"(min-width:500px) calc(1200/3)", 500}, 54 {"50vw", 250, true},
54 {"(min-width:500px) calc(1200px/(0px*14))", 500}, 55 {"5em", 80, false},
55 {"(max-width: 3000px) 200px, 400px", 200}, 56 {"5rem", 80, false},
56 {"(max-width: 3000px) 20em, 40em", 320}, 57 {"calc(40vw*2)", 400, true},
57 {"(max-width: 3000px) 0, 40em", 0}, 58 {"(min-width:5000px) calc(5000px/10), (min-width:500px) calc(1200px/3)", 400, false},
58 {"(max-width: 3000px) 50vw, 40em", 250}, 59 {"(min-width:500px) calc(1200/3)", 500, true},
59 {0, 0} // Do not remove the terminator line. 60 {"(min-width:500px) calc(1200px/(0px*14))", 500, true},
61 {"(max-width: 3000px) 200px, 400px", 200, false},
62 {"(max-width: 3000px) 20em, 40em", 320, false},
63 {"(max-width: 3000px) 0, 40em", 0, false},
64 {"(max-width: 3000px) 50vw, 40em", 250, true},
65 {"(max-width: 3000px) 50px, 40vw", 50, false},
66 {0, 0, false} // Do not remove the terminator line.
60 }; 67 };
61 68
62 MediaValuesCached::MediaValuesCachedData data; 69 MediaValuesCached::MediaValuesCachedData data;
63 data.viewportWidth = 500; 70 data.viewportWidth = 500;
64 data.viewportHeight = 500; 71 data.viewportHeight = 500;
65 data.deviceWidth = 500; 72 data.deviceWidth = 500;
66 data.deviceHeight = 500; 73 data.deviceHeight = 500;
67 data.devicePixelRatio = 2.0; 74 data.devicePixelRatio = 2.0;
68 data.colorBitsPerComponent = 24; 75 data.colorBitsPerComponent = 24;
69 data.monochromeBitsPerComponent = 0; 76 data.monochromeBitsPerComponent = 0;
70 data.pointer = MediaValues::MousePointer; 77 data.pointer = MediaValues::MousePointer;
71 data.defaultFontSize = 16; 78 data.defaultFontSize = 16;
72 data.threeDEnabled = true; 79 data.threeDEnabled = true;
73 data.mediaType = MediaTypeNames::screen; 80 data.mediaType = MediaTypeNames::screen;
74 data.strictMode = true; 81 data.strictMode = true;
75 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data); 82 RefPtr<MediaValues> mediaValues = MediaValuesCached::create(data);
76 83
77 for (unsigned i = 0; testCases[i].input; ++i) { 84 for (unsigned i = 0; testCases[i].input; ++i) {
78 int effectiveSize = SizesAttributeParser::findEffectiveSize(testCases[i] .input, mediaValues); 85 SizesAttributeParser parser(mediaValues, testCases[i].input);
79 ASSERT_EQ(testCases[i].output, effectiveSize); 86 ASSERT_EQ(testCases[i].effectiveSize, parser.length());
87 ASSERT_EQ(testCases[i].viewportDependant, parser.viewportDependant());
80 } 88 }
81 } 89 }
82 90
83 } // namespace 91 } // namespace
OLDNEW
« no previous file with comments | « Source/core/css/parser/SizesAttributeParser.cpp ('k') | Source/core/css/parser/SizesCalcParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698