OLD | NEW |
1 // Copyright (C) 2013 Google Inc. | 1 // Copyright (C) 2013 Google Inc. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 const char kKey[] = "data/CA"; | 38 const char kKey[] = "data/CA"; |
39 | 39 |
40 // Empty data that the downloader can return. | 40 // Empty data that the downloader can return. |
41 const char kEmptyData[] = "{}"; | 41 const char kEmptyData[] = "{}"; |
42 | 42 |
43 // The MD5 checksum for kEmptyData. Retriever uses MD5 to validate data | 43 // The MD5 checksum for kEmptyData. Retriever uses MD5 to validate data |
44 // integrity. | 44 // integrity. |
45 const char kEmptyDataChecksum[] = "99914b932bd37a50b983c5e7c90ae93b"; | 45 const char kEmptyDataChecksum[] = "99914b932bd37a50b983c5e7c90ae93b"; |
46 | 46 |
47 std::string Wrap(const std::string& data, | 47 scoped_ptr<std::string> Wrap(const std::string& data, |
48 const std::string& checksum, | 48 const std::string& checksum, |
49 const std::string& timestamp) { | 49 const std::string& timestamp) { |
50 return data + "\n" + "checksum=" + checksum + "\n" + "timestamp=" + timestamp; | 50 return make_scoped_ptr(new std::string( |
| 51 data + "\n" + "checksum=" + checksum + "\n" + "timestamp=" + timestamp)); |
51 } | 52 } |
52 | 53 |
53 } // namespace | 54 } // namespace |
54 | 55 |
55 // Tests for Retriever object. | 56 // Tests for Retriever object. |
56 class RetrieverTest : public testing::Test { | 57 class RetrieverTest : public testing::Test { |
57 protected: | 58 protected: |
58 RetrieverTest() | 59 RetrieverTest() |
59 : storage_(NULL), | 60 : storage_(NULL), |
60 retriever_(), | 61 retriever_(), |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 const char kFallbackDataKey[] = "data/US"; | 164 const char kFallbackDataKey[] = "data/US"; |
164 bad_retriever.Retrieve(kFallbackDataKey, BuildCallback()); | 165 bad_retriever.Retrieve(kFallbackDataKey, BuildCallback()); |
165 | 166 |
166 EXPECT_TRUE(success_); | 167 EXPECT_TRUE(success_); |
167 EXPECT_EQ(kFallbackDataKey, key_); | 168 EXPECT_EQ(kFallbackDataKey, key_); |
168 EXPECT_FALSE(data_.empty()); | 169 EXPECT_FALSE(data_.empty()); |
169 EXPECT_NE(kEmptyData, data_); | 170 EXPECT_NE(kEmptyData, data_); |
170 } | 171 } |
171 | 172 |
172 TEST_F(RetrieverTest, NoChecksumAndTimestampWillRedownload) { | 173 TEST_F(RetrieverTest, NoChecksumAndTimestampWillRedownload) { |
173 storage_->Put(kKey, kEmptyData); | 174 storage_->Put(kKey, make_scoped_ptr(new std::string(kEmptyData))); |
174 retriever_->Retrieve(kKey, BuildCallback()); | 175 retriever_->Retrieve(kKey, BuildCallback()); |
175 EXPECT_TRUE(success_); | 176 EXPECT_TRUE(success_); |
176 EXPECT_EQ(kKey, key_); | 177 EXPECT_EQ(kKey, key_); |
177 EXPECT_FALSE(data_.empty()); | 178 EXPECT_FALSE(data_.empty()); |
178 EXPECT_NE(kEmptyData, data_); | 179 EXPECT_NE(kEmptyData, data_); |
179 } | 180 } |
180 | 181 |
181 TEST_F(RetrieverTest, ChecksumAndTimestampWillNotRedownload) { | 182 TEST_F(RetrieverTest, ChecksumAndTimestampWillNotRedownload) { |
182 storage_->Put(kKey, | 183 storage_->Put(kKey, |
183 Wrap(kEmptyData, kEmptyDataChecksum, TimeToString(time(NULL)))); | 184 Wrap(kEmptyData, kEmptyDataChecksum, TimeToString(time(NULL)))); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 265 |
265 TEST_F(RetrieverTest, NullCallbackNoCrash) { | 266 TEST_F(RetrieverTest, NullCallbackNoCrash) { |
266 ASSERT_NO_FATAL_FAILURE( | 267 ASSERT_NO_FATAL_FAILURE( |
267 retriever_->Retrieve(kKey, scoped_ptr<Retriever::Callback>())); | 268 retriever_->Retrieve(kKey, scoped_ptr<Retriever::Callback>())); |
268 ASSERT_NO_FATAL_FAILURE( | 269 ASSERT_NO_FATAL_FAILURE( |
269 retriever_->Retrieve(kKey, scoped_ptr<Retriever::Callback>())); | 270 retriever_->Retrieve(kKey, scoped_ptr<Retriever::Callback>())); |
270 } | 271 } |
271 | 272 |
272 } // namespace addressinput | 273 } // namespace addressinput |
273 } // namespace i18n | 274 } // namespace i18n |
OLD | NEW |