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