| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "content/browser/webui/i18n_source_stream.h" | 7 #include "content/browser/webui/i18n_source_stream.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/test_completion_callback.h" | 9 #include "net/base/test_completion_callback.h" |
| 10 #include "net/filter/mock_source_stream.h" | 10 #include "net/filter/mock_source_stream.h" |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 int result = ReadStream(&actual_output); | 171 int result = ReadStream(&actual_output); |
| 172 EXPECT_EQ(net::OK, result); | 172 EXPECT_EQ(net::OK, result); |
| 173 EXPECT_EQ("i18n", stream()->Description()); | 173 EXPECT_EQ("i18n", stream()->Description()); |
| 174 } | 174 } |
| 175 | 175 |
| 176 TEST_P(I18nSourceStreamTest, NoTranslations) { | 176 TEST_P(I18nSourceStreamTest, NoTranslations) { |
| 177 Init(); | 177 Init(); |
| 178 const char kText[] = "This text has no i18n replacements."; | 178 const char kText[] = "This text has no i18n replacements."; |
| 179 size_t kTextLength = strlen(kText); | 179 size_t kTextLength = strlen(kText); |
| 180 source()->AddReadResult(kText, kTextLength, net::OK, GetParam().mode); | 180 source()->AddReadResult(kText, kTextLength, net::OK, GetParam().mode); |
| 181 source()->AddReadResult(kText + kTextLength, 0, net::OK, GetParam().mode); | 181 source()->AddReadResult(nullptr, 0, net::OK, GetParam().mode); |
| 182 std::string actual_output; | 182 std::string actual_output; |
| 183 int rv = ReadStream(&actual_output); | 183 int rv = ReadStream(&actual_output); |
| 184 EXPECT_EQ(static_cast<int>(kTextLength), rv); | 184 EXPECT_EQ(static_cast<int>(kTextLength), rv); |
| 185 EXPECT_EQ(std::string(kText, kTextLength), actual_output); | 185 EXPECT_EQ(kText, actual_output); |
| 186 EXPECT_EQ("i18n", stream()->Description()); | 186 EXPECT_EQ("i18n", stream()->Description()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 TEST_P(I18nSourceStreamTest, I18nOneRead) { | 189 TEST_P(I18nSourceStreamTest, I18nOneRead) { |
| 190 Init(); | 190 Init(); |
| 191 source()->AddReadResult(source_data(), kSourceSize, net::OK, GetParam().mode); | 191 source()->AddReadResult(source_data(), kSourceSize, net::OK, GetParam().mode); |
| 192 source()->AddReadResult(source_data() + kSourceSize, 0, net::OK, | 192 source()->AddReadResult(nullptr, 0, net::OK, GetParam().mode); |
| 193 GetParam().mode); | |
| 194 std::string actual_output; | 193 std::string actual_output; |
| 195 int rv = ReadStream(&actual_output); | 194 int rv = ReadStream(&actual_output); |
| 196 EXPECT_EQ(static_cast<int>(kResultSize), rv); | 195 EXPECT_EQ(static_cast<int>(kResultSize), rv); |
| 197 EXPECT_EQ(std::string(result_data(), kResultSize), actual_output); | 196 EXPECT_EQ(std::string(result_data(), kResultSize), actual_output); |
| 198 EXPECT_EQ("i18n", stream()->Description()); | 197 EXPECT_EQ("i18n", stream()->Description()); |
| 199 } | 198 } |
| 200 | 199 |
| 201 TEST_P(I18nSourceStreamTest, I18nInMultipleReads) { | 200 TEST_P(I18nSourceStreamTest, I18nInMultipleReads) { |
| 202 Init(); | 201 Init(); |
| 203 size_t chunk_size = 5; | 202 size_t chunk_size = 5; |
| 204 size_t written = 0; | 203 size_t written = 0; |
| 205 while (written + chunk_size < kSourceSize) { | 204 while (written + chunk_size < kSourceSize) { |
| 206 source()->AddReadResult(source_data() + written, chunk_size, net::OK, | 205 source()->AddReadResult(source_data() + written, chunk_size, net::OK, |
| 207 GetParam().mode); | 206 GetParam().mode); |
| 208 written += chunk_size; | 207 written += chunk_size; |
| 209 } | 208 } |
| 210 source()->AddReadResult(source_data() + written, kSourceSize - written, | 209 source()->AddReadResult(source_data() + written, kSourceSize - written, |
| 211 net::OK, GetParam().mode); | 210 net::OK, GetParam().mode); |
| 212 source()->AddReadResult(source_data() + kSourceSize, 0, net::OK, | 211 source()->AddReadResult(nullptr, 0, net::OK, GetParam().mode); |
| 213 GetParam().mode); | |
| 214 std::string actual_output; | 212 std::string actual_output; |
| 215 int rv = ReadStream(&actual_output); | 213 int rv = ReadStream(&actual_output); |
| 216 EXPECT_EQ(static_cast<int>(kResultSize), rv); | 214 EXPECT_EQ(static_cast<int>(kResultSize), rv); |
| 217 EXPECT_EQ(std::string(result_data(), kResultSize), actual_output); | 215 EXPECT_EQ(std::string(result_data(), kResultSize), actual_output); |
| 218 EXPECT_EQ("i18n", stream()->Description()); | 216 EXPECT_EQ("i18n", stream()->Description()); |
| 219 } | 217 } |
| 220 | 218 |
| 219 TEST_P(I18nSourceStreamTest, I18nTagAtEndOfLine) { |
| 220 Init(); |
| 221 const char kSourceData[] = "test with tag at end of line $"; |
| 222 const size_t source_size = strlen(kSourceData); |
| 223 source()->AddReadResult(kSourceData, source_size, net::OK, GetParam().mode); |
| 224 source()->AddReadResult(nullptr, 0, net::OK, GetParam().mode); |
| 225 std::string actual_output; |
| 226 int rv = ReadStream(&actual_output); |
| 227 EXPECT_EQ(static_cast<int>(source_size), rv); |
| 228 EXPECT_EQ(kSourceData, actual_output); |
| 229 EXPECT_EQ("i18n", stream()->Description()); |
| 230 } |
| 231 |
| 221 } // namespace content | 232 } // namespace content |
| OLD | NEW |