OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(beaudoin): What is really needed here? | 5 // TODO(beaudoin): What is really needed here? |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h" | 14 #include "chrome/browser/ui/webui/ntp/suggestions_combiner.h" |
15 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" | 15 #include "chrome/browser/ui/webui/ntp/suggestions_page_handler.h" |
16 #include "chrome/browser/ui/webui/ntp/suggestions_source.h" | 16 #include "chrome/browser/ui/webui/ntp/suggestions_source.h" |
17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/test/test_browser_thread_bundle.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 struct SourceInfo { | 23 struct SourceInfo { |
23 int weight; | 24 int weight; |
24 const char* source_name; | 25 const char* source_name; |
25 int number_of_suggestions; | 26 int number_of_suggestions; |
26 }; | 27 }; |
27 | 28 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 int number_of_suggestions_; | 201 int number_of_suggestions_; |
201 bool debug_; | 202 bool debug_; |
202 | 203 |
203 // Keep the results of the db query here. | 204 // Keep the results of the db query here. |
204 std::deque<base::DictionaryValue*> items_; | 205 std::deque<base::DictionaryValue*> items_; |
205 | 206 |
206 DISALLOW_COPY_AND_ASSIGN(SuggestionsSourceStub); | 207 DISALLOW_COPY_AND_ASSIGN(SuggestionsSourceStub); |
207 }; | 208 }; |
208 | 209 |
209 class SuggestionsCombinerTest : public testing::Test { | 210 class SuggestionsCombinerTest : public testing::Test { |
210 public: | 211 protected: |
211 SuggestionsCombinerTest() { | 212 virtual void SetUp() { |
| 213 thread_bundle_.reset(new content::TestBrowserThreadBundle()); |
| 214 profile_.reset(new TestingProfile()); |
| 215 suggestions_handler_.reset(new SuggestionsHandler()); |
| 216 Reset(); |
212 } | 217 } |
213 | 218 |
214 protected: | |
215 Profile* profile_; | |
216 SuggestionsHandler* suggestions_handler_; | |
217 SuggestionsCombiner* combiner_; | |
218 | |
219 void Reset() { | 219 void Reset() { |
220 delete combiner_; | 220 combiner_.reset( |
221 combiner_ = new SuggestionsCombiner(suggestions_handler_, profile_); | 221 new SuggestionsCombiner(suggestions_handler_.get(), profile_.get())); |
222 } | 222 } |
223 | 223 |
224 private: | 224 scoped_ptr<content::TestBrowserThreadBundle> thread_bundle_; |
225 virtual void SetUp() { | 225 scoped_ptr<Profile> profile_; |
226 profile_ = new TestingProfile(); | 226 scoped_ptr<SuggestionsHandler> suggestions_handler_; |
227 suggestions_handler_ = new SuggestionsHandler(); | 227 scoped_ptr<SuggestionsCombiner> combiner_; |
228 combiner_ = new SuggestionsCombiner(suggestions_handler_, profile_); | |
229 } | |
230 | |
231 virtual void TearDown() { | |
232 delete combiner_; | |
233 delete suggestions_handler_; | |
234 delete profile_; | |
235 } | |
236 | |
237 DISALLOW_COPY_AND_ASSIGN(SuggestionsCombinerTest); | |
238 }; | 228 }; |
239 | 229 |
240 TEST_F(SuggestionsCombinerTest, NoSource) { | 230 TEST_F(SuggestionsCombinerTest, NoSource) { |
241 combiner_->FetchItems(NULL); | 231 combiner_->FetchItems(NULL); |
242 EXPECT_EQ(0UL, combiner_->GetPageValues()->GetSize()); | 232 EXPECT_EQ(0UL, combiner_->GetPageValues()->GetSize()); |
243 } | 233 } |
244 | 234 |
245 TEST_F(SuggestionsCombinerTest, SourcesAreNotDoneFetching) { | 235 TEST_F(SuggestionsCombinerTest, SourcesAreNotDoneFetching) { |
246 combiner_->AddSource(new SuggestionsSourceStub(1, "sourceA", 10)); | 236 combiner_->AddSource(new SuggestionsSourceStub(1, "sourceA", 10)); |
247 combiner_->AddSource(new SuggestionsSourceStub(1, "sourceB", 10)); | 237 combiner_->AddSource(new SuggestionsSourceStub(1, "sourceB", 10)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 } else { | 285 } else { |
296 EXPECT_EQ(description.results[j], static_cast<const char*>(NULL)) << | 286 EXPECT_EQ(description.results[j], static_cast<const char*>(NULL)) << |
297 " test index:" << i; | 287 " test index:" << i; |
298 } | 288 } |
299 } | 289 } |
300 | 290 |
301 Reset(); | 291 Reset(); |
302 } | 292 } |
303 } | 293 } |
304 | 294 |
OLD | NEW |