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 "core/html/parser/HTMLSrcsetParser.h" | 5 #include "core/html/parser/HTMLSrcsetParser.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include <limits.h> | 8 #include <limits.h> |
9 | 9 |
10 namespace blink { | 10 namespace blink { |
11 | 11 |
12 typedef struct { | 12 typedef struct { |
13 float deviceScaleFactor; | 13 float deviceScaleFactor; |
14 float effectiveSize; | 14 float effectiveSize; |
15 const char* srcInput; | 15 const char* srcInput; |
16 const char* srcsetInput; | 16 const char* srcsetInput; |
17 const char* outputURL; | 17 const char* outputURL; |
18 float outputDensity; | 18 float outputDensity; |
19 int outputResourceWidth; | 19 int outputResourceWidth; |
20 } TestCase; | 20 } TestCase; |
21 | 21 |
22 TEST(ImageCandidateTest, Basic) | 22 TEST(ImageCandidateTest, Basic) |
23 { | 23 { |
24 ImageCandidate candidate; | 24 ImageCandidate candidate; |
25 ASSERT_EQ(candidate.density(), 1); | 25 ASSERT_EQ(candidate.density(), 1); |
26 ASSERT_EQ(candidate.resourceWidth(), -1); | 26 ASSERT_EQ(candidate.getResourceWidth(), -1); |
27 ASSERT_EQ(candidate.srcOrigin(), false); | 27 ASSERT_EQ(candidate.srcOrigin(), false); |
28 | 28 |
29 } | 29 } |
30 | 30 |
31 TEST(HTMLSrcsetParserTest, Basic) | 31 TEST(HTMLSrcsetParserTest, Basic) |
32 { | 32 { |
33 TestCase testCases[] = { | 33 TestCase testCases[] = { |
34 {2.0, 0.5, "", "data:,a 1w, data:,b 2x", "data:,a", 2.0, 1}, | 34 {2.0, 0.5, "", "data:,a 1w, data:,b 2x", "data:,a", 2.0, 1}, |
35 {2.0, 1, "", "data:,a 2w, data:,b 2x", "data:,a", 2.0, 2}, | 35 {2.0, 1, "", "data:,a 2w, data:,b 2x", "data:,a", 2.0, 2}, |
36 {2.0, -1, "", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, | 36 {2.0, -1, "", "1x.gif 1x, 2x.gif 2x", "2x.gif", 2.0, -1}, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 {1.0, -1, "", "data:,a 1.0x", "data:,a", 1.0, -1}, | 113 {1.0, -1, "", "data:,a 1.0x", "data:,a", 1.0, -1}, |
114 {1.0, -1, "", "1%20and%202.gif 1x", "1%20and%202.gif", 1.0, -1}, | 114 {1.0, -1, "", "1%20and%202.gif 1x", "1%20and%202.gif", 1.0, -1}, |
115 {1.0, 700, "", "data:,a 0.5x, data:,b 1400w", "data:,b", 2.0, 1400}, | 115 {1.0, 700, "", "data:,a 0.5x, data:,b 1400w", "data:,b", 2.0, 1400}, |
116 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line. | 116 {0, 0, 0, 0, 0, 0} // Do not remove the terminator line. |
117 }; | 117 }; |
118 | 118 |
119 for (unsigned i = 0; testCases[i].srcInput; ++i) { | 119 for (unsigned i = 0; testCases[i].srcInput; ++i) { |
120 TestCase test = testCases[i]; | 120 TestCase test = testCases[i]; |
121 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc
aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); | 121 ImageCandidate candidate = bestFitSourceForImageAttributes(test.deviceSc
aleFactor, test.effectiveSize, test.srcInput, test.srcsetInput); |
122 ASSERT_EQ(test.outputDensity, candidate.density()); | 122 ASSERT_EQ(test.outputDensity, candidate.density()); |
123 ASSERT_EQ(test.outputResourceWidth, candidate.resourceWidth()); | 123 ASSERT_EQ(test.outputResourceWidth, candidate.getResourceWidth()); |
124 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); | 124 ASSERT_STREQ(test.outputURL, candidate.toString().ascii().data()); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 } // namespace blink | 128 } // namespace blink |
OLD | NEW |