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 blink { | 11 namespace blink { |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 float deviceScaleFactor; | 14 float deviceScaleFactor; |
15 int effectiveSize; | 15 float 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 outputDensity; | 19 float outputDensity; |
20 int outputResourceWidth; | 20 int outputResourceWidth; |
21 } TestCase; | 21 } TestCase; |
22 | 22 |
23 TEST(ImageCandidateTest, Basic) | 23 TEST(ImageCandidateTest, Basic) |
24 { | 24 { |
25 ImageCandidate candidate; | 25 ImageCandidate candidate; |
26 ASSERT_EQ(candidate.density(), 1); | 26 ASSERT_EQ(candidate.density(), 1); |
27 ASSERT_EQ(candidate.resourceWidth(), -1); | 27 ASSERT_EQ(candidate.resourceWidth(), -1); |
28 ASSERT_EQ(candidate.srcOrigin(), false); | 28 ASSERT_EQ(candidate.srcOrigin(), false); |
29 | 29 |
30 } | 30 } |
31 | 31 |
32 TEST(HTMLSrcsetParserTest, Basic) | 32 TEST(HTMLSrcsetParserTest, Basic) |
33 { | 33 { |
34 TestCase testCases[] = { | 34 TestCase testCases[] = { |
| 35 {2.0, 0.5, "", "data:,a 1w, data:,b 2x", "data:,a", 2.0, 1}, |
| 36 {2.0, 1, "", "data:,a 2w, data:,b 2x", "data:,a", 2.0, 2}, |
35 {2.0, -1, "", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, | 37 {2.0, -1, "", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, |
36 {2.0, -1, "", "1x.gif 1q, 2x.gif 2x", "2x.gif", 2.0, -1}, | 38 {2.0, -1, "", "1x.gif 1q, 2x.gif 2x", "2x.gif", 2.0, -1}, |
37 {1.0, -1, "", "1x.gif 1q, 2x.gif 2x", "1x.gif", 1.0, -1}, | 39 {1.0, -1, "", "1x.gif 1q, 2x.gif 2x", "1x.gif", 1.0, -1}, |
38 {1.0, -1, "", "1x.gif 1x 100h, 2x.gif 2x", "2x.gif", 2.0, -1}, | 40 {1.0, -1, "", "1x.gif 1x 100h, 2x.gif 2x", "2x.gif", 2.0, -1}, |
39 {1.0, -1, "", "1x.gif 1x 100w, 2x.gif 2x", "2x.gif", 2.0, -1}, | 41 {1.0, -1, "", "1x.gif 1x 100w, 2x.gif 2x", "2x.gif", 2.0, -1}, |
40 {1.0, -1, "", "1x.gif 1x 100h 100w, 2x.gif 2x", "2x.gif", 2.0, -1}, | 42 {1.0, -1, "", "1x.gif 1x 100h 100w, 2x.gif 2x", "2x.gif", 2.0, -1}, |
41 {2.0, -1, "", "1x.gif 1x, 2x.gif -2x", "1x.gif", 1.0, -1}, | 43 {2.0, -1, "", "1x.gif 1x, 2x.gif -2x", "1x.gif", 1.0, -1}, |
42 {2.0, -1, "", "0x.gif 0x", "0x.gif", 0.0, -1}, | 44 {2.0, -1, "", "0x.gif 0x", "0x.gif", 0.0, -1}, |
43 {2.0, -1, "", "0x.gif -0x", "0x.gif", 0.0, -1}, | 45 {2.0, -1, "", "0x.gif -0x", "0x.gif", 0.0, -1}, |
44 {2.0, -1, "", "neg.gif -2x", "", 1.0, -1}, | 46 {2.0, -1, "", "neg.gif -2x", "", 1.0, -1}, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 for (unsigned i = 0; testCases[i].srcInput; ++i) { | 102 for (unsigned i = 0; testCases[i].srcInput; ++i) { |
101 TestCase test = testCases[i]; | 103 TestCase test = testCases[i]; |
102 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc
aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); | 104 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc
aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); |
103 ASSERT_EQ(test.outputDensity, candidate.density()); | 105 ASSERT_EQ(test.outputDensity, candidate.density()); |
104 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); | 106 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); |
105 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); | 107 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); |
106 } | 108 } |
107 } | 109 } |
108 | 110 |
109 } // namespace | 111 } // namespace |
OLD | NEW |