OLD | NEW |
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 |
11 namespace WebCore { | 11 namespace WebCore { |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 float deviceScaleFactor; | 14 float deviceScaleFactor; |
15 int effectiveSize; | 15 int effectiveSize; |
16 const char* srcInput; | 16 const char* srcInput; |
17 const char* srcsetInput; | 17 const char* srcsetInput; |
18 const char* outputURL; | 18 const char* outputURL; |
19 float outputScaleFactor; | 19 float outputScaleFactor; |
20 int outputResourceWidth; | 20 int outputResourceWidth; |
21 } TestCase; | 21 } TestCase; |
22 | 22 |
23 TEST(HTMLSrcsetParserTest, Basic) | 23 TEST(HTMLSrcsetParserTest, Basic) |
24 { | 24 { |
25 TestCase testCases[] = { | 25 TestCase testCases[] = { |
26 {2.0, -1, "", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, | 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}, | 27 {2.0, -1, "", "1x.gif 1x, 2x.gif -2x", "1x.gif", 1.0, -1}, |
| 28 {2.0, -1, "", "0x.gif 0x", "0x.gif", 0.0, -1}, |
| 29 {2.0, -1, "", "0x.gif -0x", "0x.gif", 0.0, -1}, |
| 30 {2.0, -1, "", "neg.gif -2x", "", 1.0, -1}, |
28 {2.0, -1, "", "1x.gif 1x, 2x.gif 2q", "1x.gif", 1.0, -1}, | 31 {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}, | 32 {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}, | 33 {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}, | 34 {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}, | 35 {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}, | 36 {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}, | 37 {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}, | 38 {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}, | 39 {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}, | 40 {2.5, -1, "src.gif", "2x.gif 2x", "2x.gif", 2.0, -1}, |
(...skipping 25 matching lines...) Expand all Loading... |
63 for (unsigned i = 0; testCases[i].srcInput; ++i) { | 66 for (unsigned i = 0; testCases[i].srcInput; ++i) { |
64 TestCase test = testCases[i]; | 67 TestCase test = testCases[i]; |
65 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc
aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); | 68 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc
aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); |
66 ASSERT_EQ(test.outputScaleFactor, candidate.scaleFactor()); | 69 ASSERT_EQ(test.outputScaleFactor, candidate.scaleFactor()); |
67 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); | 70 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); |
68 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); | 71 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); |
69 } | 72 } |
70 } | 73 } |
71 | 74 |
72 } // namespace | 75 } // namespace |
OLD | NEW |