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

Side by Side Diff: Source/core/html/parser/HTMLSrcsetParserTest.cpp

Issue 667763004: Srcset resource selection use a geometric mean to determine resource. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review nits Created 6 years, 2 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
« no previous file with comments | « Source/core/html/parser/HTMLSrcsetParser.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/html/parser/HTMLSrcsetParser.h" 6 #include "core/html/parser/HTMLSrcsetParser.h"
7 7
8 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9 #include <limits.h> 9 #include <limits.h>
10 10
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 {2.0, -1, "", "1x.gif , 2x.gif 2q", "1x.gif", 1.0, -1}, 49 {2.0, -1, "", "1x.gif , 2x.gif 2q", "1x.gif", 1.0, -1},
50 {2.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, 50 {2.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
51 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1}, 51 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
52 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "", "1x.gif 1x, 2x.gif 2x", 1.0, -1}, 52 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "", "1x.gif 1x, 2x.gif 2x", 1.0, -1},
53 {2.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, 53 {2.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
54 {1.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1}, 54 {1.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
55 {1.0, -1, "src.gif", "2x.gif 2x", "src.gif", 1.0, -1}, 55 {1.0, -1, "src.gif", "2x.gif 2x", "src.gif", 1.0, -1},
56 {2.0, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, 56 {2.0, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
57 {2.0, -1, "src.gif", "2x.gif 2px", "src.gif", 1.0, -1}, 57 {2.0, -1, "src.gif", "2x.gif 2px", "src.gif", 1.0, -1},
58 {2.0, -1, "src.gif", "2x.gif 2ex", "src.gif", 1.0, -1}, 58 {2.0, -1, "src.gif", "2x.gif 2ex", "src.gif", 1.0, -1},
59 {2.0, -1, "src.gif", "2x.gif 2e1x", "2x.gif", 20.0, -1}, 59 {10.0, -1, "src.gif", "2x.gif 2e1x", "2x.gif", 20.0, -1},
60 {2.0, -1, "src.gif", "2x.gif 2e1x", "src.gif", 1.0, -1},
60 {2.0, -1, "src.gif", "2x.gif +2x", "src.gif", 1.0, -1}, 61 {2.0, -1, "src.gif", "2x.gif +2x", "src.gif", 1.0, -1},
61 {1.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, 62 {1.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
62 {2.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, 63 {2.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
63 {2.5, -1, "src.gif", "2x.gif 2x, 3x.gif 3x", "3x.gif", 3.0, -1}, 64 {2.5, -1, "src.gif", "2x.gif 2x, 3x.gif 3x", "3x.gif", 3.0, -1},
64 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1}, 65 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1},
65 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1}, 66 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1},
66 {2.0, -1, "", ",,1x,, , x ,2x ", "1x", 1.0, -1}, 67 {2.0, -1, "", ",,1x,, , x ,2x ", "1x", 1.0, -1},
67 {2.0, -1, "", ",,1x,,", "1x", 1.0, -1}, 68 {2.0, -1, "", ",,1x,,", "1x", 1.0, -1},
68 {2.0, -1, "", ",1x,", "1x", 1.0, -1}, 69 {2.0, -1, "", ",1x,", "1x", 1.0, -1},
69 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 1x, 2x.gif 2 x", "2x.gif", 2.0, -1}, 70 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 1x, 2x.gif 2 x", "2x.gif", 2.0, -1},
70 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 2x, 1x.gif 1 x", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg", 2.0, -1}, 71 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 2x, 1x.gif 1 x", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg", 2.0, -1},
71 {2.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1}, 72 {2.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1},
72 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100h, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1}, 73 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100h, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1},
73 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1}, 74 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1},
74 {1.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "1x", 1.0, -1}, 75 {1.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "1x", 1.0, -1},
75 {5.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1}, 76 {5.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "2x.gif", 2.0, -1},
76 {2.0, -1, "", "1x.gif 1x, data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0 cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIj4KCTxyZWN0IHdp ZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiIvPgo8L3N2Zz4K 2x", "data:image/sv g+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDA iIGhlaWdodD0iMTAwIj4KCTxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiI vPgo8L3N2Zz4K", 2.0, -1 }, 77 {2.0, -1, "", "1x.gif 1x, data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0 cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIj4KCTxyZWN0IHdp ZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiIvPgo8L3N2Zz4K 2x", "data:image/sv g+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDA iIGhlaWdodD0iMTAwIj4KCTxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiI vPgo8L3N2Zz4K", 2.0, -1 },
77 {2.0, -1, "1x.gif", "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL 3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIj4KCTxyZWN0IHdpZHRoP SIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiIvPgo8L3N2Zz4K 2x", "data:image/svg+xml ;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhl aWdodD0iMTAwIj4KCTxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiIvPgo8 L3N2Zz4K", 2.0, -1 }, 78 {2.0, -1, "1x.gif", "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL 3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIj4KCTxyZWN0IHdpZHRoP SIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiIvPgo8L3N2Zz4K 2x", "data:image/svg+xml ;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAiIGhl aWdodD0iMTAwIj4KCTxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iMTAwIiBmaWxsPSJncmVlbiIvPgo8 L3N2Zz4K", 2.0, -1 },
78 {2.0, -1, "1x.svg#red", "1x.svg#green 2x", "1x.svg#green", 2.0, -1}, 79 {2.0, -1, "1x.svg#red", "1x.svg#green 2x", "1x.svg#green", 2.0, -1},
79 {2.0, -1, "", "1x.svg#red 1x, 1x.svg#green 2x", "1x.svg#green", 2.0, -1} , 80 {2.0, -1, "", "1x.svg#red 1x, 1x.svg#green 2x", "1x.svg#green", 2.0, -1} ,
80 {1.0, 400, "", "400.gif 400w, 6000.gif 6000w", "400.gif", 1.0, 400}, 81 {1.0, 400, "", "400.gif 400w, 6000.gif 6000w", "400.gif", 1.0, 400},
81 {1.0, 400, "", "400.gif 400pw, 6000.gif 6000w", "6000.gif", 15.0, 6000}, 82 {1.0, 400, "", "400.gif 400pw, 6000.gif 6000w", "6000.gif", 15.0, 6000},
82 {1.0, 400, "fallback.gif", "400.gif 400pw", "fallback.gif", 1.0, -1}, 83 {1.0, 400, "fallback.gif", "400.gif 400pw", "fallback.gif", 1.0, -1},
83 {1.0, 400, "fallback.gif", "400.gif +400w", "fallback.gif", 1.0, -1}, 84 {1.0, 400, "fallback.gif", "400.gif +400w", "fallback.gif", 1.0, -1},
84 {1.0, 400, "", "400.gif 400w 400h, 6000.gif 6000w", "400.gif", 1.0, 400} , 85 {1.0, 400, "", "400.gif 400w 400h, 6000.gif 6000w", "400.gif", 1.0, 400} ,
85 {2.0, 400, "", "400.gif 400w, 6000.gif 6000w", "6000.gif", 15.0, 6000}, 86 {4.0, 400, "", "400.gif 400w, 6000.gif 6000w", "6000.gif", 15.0, 6000},
87 {3.8, 400, "", "400.gif 400w, 6000.gif 6000w", "400.gif", 1.0, 400},
88 {0.9, 800, "src.gif", "400.gif 400w", "400.gif", 0.5, 400},
89 {0.9, 800, "src.gif", "1x.gif 1x, 400.gif 400w", "1x.gif", 1.0, -1},
90 {0.9, 800, "src.gif", "1x.gif 0.6x, 400.gif 400w", "1x.gif", 0.6, -1},
91 {2.0, 800, "src.gif", "400.gif 400w", "400.gif", 0.5, 400},
86 {1.0, 400, "src.gif", "800.gif 800w", "800.gif", 2.0, 800}, 92 {1.0, 400, "src.gif", "800.gif 800w", "800.gif", 2.0, 800},
87 {1.0, 400, "src.gif", "0.gif 0w, 800.gif 800w", "800.gif", 2.0, 800}, 93 {1.0, 400, "src.gif", "0.gif 0w, 800.gif 800w", "800.gif", 2.0, 800},
88 {1.0, 400, "src.gif", "0.gif 0w, 2x.gif 2x", "src.gif", 1.0, -1}, 94 {1.0, 400, "src.gif", "0.gif 0w, 2x.gif 2x", "src.gif", 1.0, -1},
89 {1.0, 400, "src.gif", "800.gif 2x, 1600.gif 1600w", "800.gif", 2.0, -1}, 95 {1.0, 400, "src.gif", "800.gif 2x, 1600.gif 1600w", "800.gif", 2.0, -1},
90 {1.0, 400, "", "400.gif 400w, 2x.gif 2x", "400.gif", 1.0, 400}, 96 {1.0, 400, "", "400.gif 400w, 2x.gif 2x", "400.gif", 1.0, 400},
91 {2.0, 400, "", "400.gif 400w, 2x.gif 2x", "2x.gif", 2.0, -1}, 97 {2.0, 400, "", "400.gif 400w, 2x.gif 2x", "2x.gif", 2.0, -1},
92 {1.0, 0, "", "400.gif 400w, 6000.gif 6000w", "400.gif", std::numeric_lim its<float>::infinity(), 400}, 98 {1.0, 0, "", "400.gif 400w, 6000.gif 6000w", "400.gif", std::numeric_lim its<float>::infinity(), 400},
93 {2.0, -1, "", ", 1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, 99 {2.0, -1, "", ", 1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
94 {1.0, -1, "", ",1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1}, 100 {1.0, -1, "", ",1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
95 {1.2, -1, "", ",1x.gif 1x, 1.4x.gif 1.4x, 2x.gif 2x", "1.4x.gif", 1.4, - 1}, 101 {1.2, -1, "", ",1x.gif 1x, 1.4x.gif 1.4x, 2x.gif 2x", "1.4x.gif", 1.4, - 1},
96 {1.0, -1, "", "inf.gif 0.00000000001x", "inf.gif", 1e-11, -1}, 102 {1.0, -1, "", "inf.gif 0.00000000001x", "inf.gif", 1e-11, -1},
97 {1.0, -1, "", "data:,a ( , data:,b 1x, ), data:,c", "data:,c", 1.0, -1}, 103 {1.0, -1, "", "data:,a ( , data:,b 1x, ), data:,c", "data:,c", 1.0, -1},
98 {1.0, 1, "", "data:,a 1w 1h", "data:,a", 1.0, 1}, 104 {1.0, 1, "", "data:,a 1w 1h", "data:,a", 1.0, 1},
99 {1.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "2x.gif", 2.0, -1}, 105 {1.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "2x.gif", 2.0, -1},
100 {2.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "2x.gif", 2.0, -1}, 106 {2.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "2x.gif", 2.0, -1},
101 {1.0, -1, "", "data:,a 1 w", "", 1.0, -1}, 107 {1.0, -1, "", "data:,a 1 w", "", 1.0, -1},
102 {1.0, -1, "", "data:,a 1 w", "", 1.0, -1}, 108 {1.0, -1, "", "data:,a 1 w", "", 1.0, -1},
103 {1.0, -1, "", "data:,a +1x", "", 1.0, -1}, 109 {1.0, -1, "", "data:,a +1x", "", 1.0, -1},
104 {1.0, -1, "", "data:,a +1x", "", 1.0, -1}, 110 {1.0, -1, "", "data:,a +1x", "", 1.0, -1},
105 {1.0, -1, "", "data:,a 1.0x", "data:,a", 1.0, -1}, 111 {1.0, -1, "", "data:,a 1.0x", "data:,a", 1.0, -1},
106 {1.0, -1, "", "1%20and%202.gif 1x", "1%20and%202.gif", 1.0, -1}, 112 {1.0, -1, "", "1%20and%202.gif 1x", "1%20and%202.gif", 1.0, -1},
113 {1.0, 700, "", "data:,a 0.5x, data:,b 1400w", "data:,b", 2.0, 1400},
107 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line. 114 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line.
108 }; 115 };
109 116
110 for (unsigned i = 0; testCases[i].srcInput; ++i) { 117 for (unsigned i = 0; testCases[i].srcInput; ++i) {
111 TestCase test = testCases[i]; 118 TestCase test = testCases[i];
112 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); 119 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput);
113 ASSERT_EQ(test.outputDensity, candidate.density()); 120 ASSERT_EQ(test.outputDensity, candidate.density());
114 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); 121 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth());
115 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); 122 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data());
116 } 123 }
117 } 124 }
118 125
119 } // namespace 126 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/parser/HTMLSrcsetParser.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698