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

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

Issue 355953003: Fixed srcset descriptor parsing bug and added tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 {2.0, -1, "", "1x.gif 1x, 2x.gif 2q", "1x.gif", 1.0, -1}, 45 {2.0, -1, "", "1x.gif 1x, 2x.gif 2q", "1x.gif", 1.0, -1},
46 {2.0, -1, "", "1x.gif, 2x.gif 2q", "1x.gif", 1.0, -1}, 46 {2.0, -1, "", "1x.gif, 2x.gif 2q", "1x.gif", 1.0, -1},
47 {2.0, -1, "", "1x.gif , 2x.gif 2q", "1x.gif", 1.0, -1}, 47 {2.0, -1, "", "1x.gif , 2x.gif 2q", "1x.gif", 1.0, -1},
48 {2.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, 48 {2.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
49 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1}, 49 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
50 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "", "1x.gif 1x, 2x.gif 2x", 1.0, -1}, 50 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "", "1x.gif 1x, 2x.gif 2x", 1.0, -1},
51 {2.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, 51 {2.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
52 {1.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1}, 52 {1.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
53 {1.0, -1, "src.gif", "2x.gif 2x", "src.gif", 1.0, -1}, 53 {1.0, -1, "src.gif", "2x.gif 2x", "src.gif", 1.0, -1},
54 {2.0, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, 54 {2.0, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
55 {2.0, -1, "src.gif", "2x.gif 2px", "src.gif", 1.0, -1},
56 {2.0, -1, "src.gif", "2x.gif 2ex", "src.gif", 1.0, -1},
57 {2.0, -1, "src.gif", "2x.gif 2e1x", "2x.gif", 20.0, -1},
58 {2.0, -1, "src.gif", "2x.gif +2x", "2x.gif", 2.0, -1},
55 {1.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, 59 {1.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
56 {2.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, 60 {2.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
57 {2.5, -1, "src.gif", "2x.gif 2x, 3x.gif 3x", "3x.gif", 3.0, -1}, 61 {2.5, -1, "src.gif", "2x.gif 2x, 3x.gif 3x", "3x.gif", 3.0, -1},
58 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1}, 62 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1},
59 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1}, 63 {2.0, -1, "", "1x,, , x ,2x ", "1x", 1.0, -1},
60 {2.0, -1, "", ",,1x,, , x ,2x ", "1x", 1.0, -1}, 64 {2.0, -1, "", ",,1x,, , x ,2x ", "1x", 1.0, -1},
61 {2.0, -1, "", ",,1x,,", "1x", 1.0, -1}, 65 {2.0, -1, "", ",,1x,,", "1x", 1.0, -1},
62 {2.0, -1, "", ",1x,", "1x", 1.0, -1}, 66 {2.0, -1, "", ",1x,", "1x", 1.0, -1},
63 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 1x, 2x.gif 2 x", "2x.gif", 2.0, -1}, 67 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 1x, 2x.gif 2 x", "2x.gif", 2.0, -1},
64 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 2x, 1x.gif 1 x", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg", 2.0, -1}, 68 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 2x, 1x.gif 1 x", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg", 2.0, -1},
65 {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}, 69 {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},
66 {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}, 70 {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},
67 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "4x.gif", 4.0, -1}, 71 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "4x.gif", 4.0, -1},
68 {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}, 72 {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},
69 {5.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "4x.gif", 4.0, -1}, 73 {5.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100z, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "4x.gif", 4.0, -1},
70 {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 }, 74 {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 },
71 {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 }, 75 {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 },
72 {2.0, -1, "1x.svg#red", "1x.svg#green 2x", "1x.svg#green", 2.0, -1 }, 76 {2.0, -1, "1x.svg#red", "1x.svg#green 2x", "1x.svg#green", 2.0, -1},
73 {2.0, -1, "", "1x.svg#red 1x, 1x.svg#green 2x", "1x.svg#green", 2.0, -1 }, 77 {2.0, -1, "", "1x.svg#red 1x, 1x.svg#green 2x", "1x.svg#green", 2.0, -1} ,
74 {1.0, 400, "", "400.gif 400w, 6000.gif 6000w", "400.gif", 1.0, 400}, 78 {1.0, 400, "", "400.gif 400w, 6000.gif 6000w", "400.gif", 1.0, 400},
79 {1.0, 400, "", "400.gif 400pw, 6000.gif 6000w", "6000.gif", 15.0, 6000},
80 {1.0, 400, "fallback.gif", "400.gif 400pw", "fallback.gif", 1.0, -1},
81 {1.0, 400, "fallback.gif", "400.gif +400w", "400.gif", 1.0, 400},
75 {1.0, 400, "", "400.gif 400w 400h, 6000.gif 6000w", "400.gif", 1.0, 400} , 82 {1.0, 400, "", "400.gif 400w 400h, 6000.gif 6000w", "400.gif", 1.0, 400} ,
76 {2.0, 400, "", "400.gif 400w, 6000.gif 6000w", "6000.gif", 15.0, 6000}, 83 {2.0, 400, "", "400.gif 400w, 6000.gif 6000w", "6000.gif", 15.0, 6000},
77 {1.0, 400, "src.gif", "800.gif 800w", "800.gif", 2.0, 800}, 84 {1.0, 400, "src.gif", "800.gif 800w", "800.gif", 2.0, 800},
78 {1.0, 400, "src.gif", "0.gif 0w, 800.gif 800w", "800.gif", 2.0, 800}, 85 {1.0, 400, "src.gif", "0.gif 0w, 800.gif 800w", "800.gif", 2.0, 800},
79 {1.0, 400, "src.gif", "0.gif 0w, 2x.gif 2x", "src.gif", 1.0, -1}, 86 {1.0, 400, "src.gif", "0.gif 0w, 2x.gif 2x", "src.gif", 1.0, -1},
80 {1.0, 400, "src.gif", "800.gif 2x, 1600.gif 1600w", "800.gif", 2.0, -1}, 87 {1.0, 400, "src.gif", "800.gif 2x, 1600.gif 1600w", "800.gif", 2.0, -1},
81 {1.0, 400, "", "400.gif 400w, 2x.gif 2x", "400.gif", 1.0, 400}, 88 {1.0, 400, "", "400.gif 400w, 2x.gif 2x", "400.gif", 1.0, 400},
82 {2.0, 400, "", "400.gif 400w, 2x.gif 2x", "2x.gif", 2.0, -1}, 89 {2.0, 400, "", "400.gif 400w, 2x.gif 2x", "2x.gif", 2.0, -1},
83 {1.0, 0, "", "400.gif 400w, 6000.gif 6000w", "400.gif", std::numeric_lim its<float>::infinity(), 400}, 90 {1.0, 0, "", "400.gif 400w, 6000.gif 6000w", "400.gif", std::numeric_lim its<float>::infinity(), 400},
84 {2.0, -1, "", ", 1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, 91 {2.0, -1, "", ", 1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
85 {1.0, -1, "", ",1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1}, 92 {1.0, -1, "", ",1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
86 {1.2, -1, "", ",1x.gif 1x, 1.4x.gif 1.4x, 2x.gif 2x", "1.4x.gif", 1.4, - 1}, 93 {1.2, -1, "", ",1x.gif 1x, 1.4x.gif 1.4x, 2x.gif 2x", "1.4x.gif", 1.4, - 1},
87 {1.0, -1, "", "inf.gif 0.00000000001x", "inf.gif", 1e-11, -1}, 94 {1.0, -1, "", "inf.gif 0.00000000001x", "inf.gif", 1e-11, -1},
88 {1.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "1x.gif", 1.0, -1}, 95 {1.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "1x.gif", 1.0, -1},
89 {2.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "2x.gif", 2.0, -1}, 96 {2.0, -1, "", ",1x.gif 1x future-descriptor(3x, 4h, whatever), 2x.gif 2x ", "2x.gif", 2.0, -1},
90 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line. 97 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line.
91 }; 98 };
92 99
93 for (unsigned i = 0; testCases[i].srcInput; ++i) { 100 for (unsigned i = 0; testCases[i].srcInput; ++i) {
94 TestCase test = testCases[i]; 101 TestCase test = testCases[i];
95 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); 102 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput);
96 ASSERT_EQ(test.outputDensity, candidate.density()); 103 ASSERT_EQ(test.outputDensity, candidate.density());
97 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); 104 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth());
98 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); 105 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data());
99 } 106 }
100 } 107 }
101 108
102 } // namespace 109 } // 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