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

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

Issue 233213003: Extend srcset's syntax to include 'w' descriptors (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed nits and modified multiple descriptor layout test Created 6 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/html/parser/HTMLSrcsetParser.h"
7
8 #include <gtest/gtest.h>
9 #include <limits.h>
10
11 namespace WebCore {
12
13 typedef struct {
14 float deviceScaleFactor;
15 int effectiveSize;
16 const char* srcInput;
17 const char* srcsetInput;
18 const char* outputURL;
19 float outputScaleFactor;
20 int outputResourceWidth;
21 } TestCase;
22
23 TEST(HTMLSrcsetParserTest, Basic)
24 {
25 TestCase testCases[] = {
26 {2.0, -1, "", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
27 {2.0, -1, "", "1x.gif 1x, 2x.gif -2x", "1x.gif", 1.0, -1},
28 {2.0, -1, "", "1x.gif 1x, 2x.gif 2q", "1x.gif", 1.0, -1},
29 {2.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
30 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
31 {1.0, -1, "1x.gif 1x, 2x.gif 2x", "", "1x.gif 1x, 2x.gif 2x", 1.0, -1},
32 {2.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1},
33 {1.0, -1, "src.gif", "1x.gif 1x, 2x.gif 2x", "1x.gif", 1.0, -1},
34 {1.0, -1, "src.gif", "2x.gif 2x", "src.gif", 1.0, -1},
35 {2.0, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
36 {1.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
37 {2.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1},
38 {2.5, -1, "src.gif", "2x.gif 2x, 3x.gif 3x", "3x.gif", 3.0, -1},
39 {2.0, -1, "", "1x,, , x ,2x ", "1x,", 1.0, -1},
40 {2.0, -1, "", "1x,, , x ,2x ", "1x,", 1.0, -1},
41 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 1x, 2x.gif 2 x", "2x.gif", 2.0, -1},
42 {2.0, -1, "", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg 2x, 1x.gif 1 x", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUg", 2.0, -1},
43 {2.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},
44 {4.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100h, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "4x.gif", 4.0, -1},
45 {1.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100h, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "1x,", 1.0, -1},
46 {5.0, -1, "", "1x,, , x ,2x , 1x.gif, 3x, 4x.gif 4x 100h, 5x.gif 5, dx.gif dx, 2x.gif 2x ,", "4x.gif", 4.0, -1},
47 {1.0, 400, "", "400.gif 400w, 6000.gif 6000w", "400.gif", 1.0, 400},
48 {2.0, 400, "", "400.gif 400w, 6000.gif 6000w", "6000.gif", 15.0, 6000},
49 {1.0, 0, "", "400.gif 400w, 6000.gif 6000w", "400.gif", std::numeric_lim its<float>::infinity(), 400},
50 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line.
51 };
52
53 for (unsigned i = 0; testCases[i].srcInput; ++i) {
54 TestCase test = testCases[i];
55 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput);
56 ASSERT_EQ(test.outputScaleFactor, candidate.scaleFactor());
57 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth());
58 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data());
59 }
60 }
61
62 } // 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