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 23 matching lines...) Expand all Loading... |
34 const char kKey[] = "data/CA/AB--fr"; | 34 const char kKey[] = "data/CA/AB--fr"; |
35 | 35 |
36 // Empty data that the downloader can return. | 36 // Empty data that the downloader can return. |
37 const char kEmptyData[] = "{}"; | 37 const char kEmptyData[] = "{}"; |
38 | 38 |
39 // Tests for Retriever object. | 39 // Tests for Retriever object. |
40 class RetrieverTest : public testing::Test { | 40 class RetrieverTest : public testing::Test { |
41 protected: | 41 protected: |
42 RetrieverTest() | 42 RetrieverTest() |
43 : retriever_(FakeDownloader::kFakeDataUrl, | 43 : retriever_(FakeDownloader::kFakeDataUrl, |
44 scoped_ptr<const Downloader>(new FakeDownloader), | 44 scoped_ptr<Downloader>(new FakeDownloader), |
45 scoped_ptr<Storage>(new FakeStorage)), | 45 scoped_ptr<Storage>(new FakeStorage)), |
46 success_(false), | 46 success_(false), |
47 key_(), | 47 key_(), |
48 data_() {} | 48 data_() {} |
49 | 49 |
50 virtual ~RetrieverTest() {} | 50 virtual ~RetrieverTest() {} |
51 | 51 |
52 scoped_ptr<Retriever::Callback> BuildCallback() { | 52 scoped_ptr<Retriever::Callback> BuildCallback() { |
53 return ::i18n::addressinput::BuildCallback( | 53 return ::i18n::addressinput::BuildCallback( |
54 this, &RetrieverTest::OnDataReady); | 54 this, &RetrieverTest::OnDataReady); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 | 100 |
101 // The downloader that always fails. | 101 // The downloader that always fails. |
102 class FaultyDownloader : public Downloader { | 102 class FaultyDownloader : public Downloader { |
103 public: | 103 public: |
104 FaultyDownloader() {} | 104 FaultyDownloader() {} |
105 virtual ~FaultyDownloader() {} | 105 virtual ~FaultyDownloader() {} |
106 | 106 |
107 // Downloader implementation. | 107 // Downloader implementation. |
108 virtual void Download(const std::string& url, | 108 virtual void Download(const std::string& url, |
109 scoped_ptr<Callback> downloaded) const { | 109 scoped_ptr<Callback> downloaded) { |
110 (*downloaded)(false, url, "garbage"); | 110 (*downloaded)(false, url, "garbage"); |
111 } | 111 } |
112 }; | 112 }; |
113 | 113 |
114 TEST_F(RetrieverTest, FaultyDownloader) { | 114 TEST_F(RetrieverTest, FaultyDownloader) { |
115 Retriever bad_retriever(FakeDownloader::kFakeDataUrl, | 115 Retriever bad_retriever(FakeDownloader::kFakeDataUrl, |
116 scoped_ptr<const Downloader>(new FaultyDownloader), | 116 scoped_ptr<Downloader>(new FaultyDownloader), |
117 scoped_ptr<Storage>(new FakeStorage)); | 117 scoped_ptr<Storage>(new FakeStorage)); |
118 bad_retriever.Retrieve(kKey, BuildCallback()); | 118 bad_retriever.Retrieve(kKey, BuildCallback()); |
119 | 119 |
120 EXPECT_FALSE(success_); | 120 EXPECT_FALSE(success_); |
121 EXPECT_EQ(kKey, key_); | 121 EXPECT_EQ(kKey, key_); |
122 EXPECT_TRUE(data_.empty()); | 122 EXPECT_TRUE(data_.empty()); |
123 } | 123 } |
124 | 124 |
125 // The downloader that doesn't get back to you. | 125 // The downloader that doesn't get back to you. |
126 class HangingDownloader : public Downloader { | 126 class HangingDownloader : public Downloader { |
127 public: | 127 public: |
128 HangingDownloader() {} | 128 HangingDownloader() {} |
129 virtual ~HangingDownloader() {} | 129 virtual ~HangingDownloader() {} |
130 | 130 |
131 // Downloader implementation. | 131 // Downloader implementation. |
132 virtual void Download(const std::string& url, | 132 virtual void Download(const std::string& url, |
133 scoped_ptr<Callback> downloaded) const {} | 133 scoped_ptr<Callback> downloaded) {} |
134 }; | 134 }; |
135 | 135 |
136 TEST_F(RetrieverTest, RequestsDontStack) { | 136 TEST_F(RetrieverTest, RequestsDontStack) { |
137 Retriever slow_retriever(FakeDownloader::kFakeDataUrl, | 137 Retriever slow_retriever(FakeDownloader::kFakeDataUrl, |
138 scoped_ptr<const Downloader>(new HangingDownloader), | 138 scoped_ptr<Downloader>(new HangingDownloader), |
139 scoped_ptr<Storage>(new FakeStorage)); | 139 scoped_ptr<Storage>(new FakeStorage)); |
140 | 140 |
141 slow_retriever.Retrieve(kKey, BuildCallback()); | 141 slow_retriever.Retrieve(kKey, BuildCallback()); |
142 EXPECT_FALSE(success_); | 142 EXPECT_FALSE(success_); |
143 EXPECT_TRUE(key_.empty()); | 143 EXPECT_TRUE(key_.empty()); |
144 | 144 |
145 #if !defined(NDEBUG) | 145 #if !defined(NDEBUG) |
146 // This request should cause an assert. | 146 // This request should cause an assert. |
147 ASSERT_DEATH(slow_retriever.Retrieve(kKey, BuildCallback()), ""); | 147 ASSERT_DEATH(slow_retriever.Retrieve(kKey, BuildCallback()), ""); |
148 #endif | 148 #endif |
149 } | 149 } |
150 | 150 |
151 } // namespace | 151 } // namespace |
152 | 152 |
153 } // namespace addressinput | 153 } // namespace addressinput |
154 } // namespace i18n | 154 } // namespace i18n |
OLD | NEW |