Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/browser/search/suggestions/suggestions_service_unittest.cc

Issue 392983007: [Suggestions] Make ThumbnailManager implement ImageManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/search/suggestions/suggestions_service.h" 5 #include "chrome/browser/search/suggestions/suggestions_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/prefs/pref_service.h" 14 #include "base/prefs/pref_service.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/search/suggestions/blacklist_store.h" 16 #include "chrome/browser/search/suggestions/blacklist_store.h"
17 #include "chrome/browser/search/suggestions/image_manager.h"
17 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h" 18 #include "chrome/browser/search/suggestions/proto/suggestions.pb.h"
18 #include "chrome/browser/search/suggestions/suggestions_service_factory.h" 19 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
19 #include "chrome/browser/search/suggestions/suggestions_store.h" 20 #include "chrome/browser/search/suggestions/suggestions_store.h"
20 #include "components/variations/entropy_provider.h" 21 #include "components/variations/entropy_provider.h"
21 #include "components/variations/variations_associated_data.h" 22 #include "components/variations/variations_associated_data.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 23 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "net/http/http_response_headers.h" 24 #include "net/http/http_response_headers.h"
24 #include "net/http/http_status_code.h" 25 #include "net/http/http_status_code.h"
25 #include "net/url_request/test_url_fetcher_factory.h" 26 #include "net/url_request/test_url_fetcher_factory.h"
26 #include "net/url_request/url_request_status.h" 27 #include "net/url_request/url_request_status.h"
27 #include "net/url_request/url_request_test_util.h" 28 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 using testing::DoAll; 32 using testing::DoAll;
32 using ::testing::Eq; 33 using ::testing::Eq;
33 using ::testing::Return; 34 using ::testing::Return;
34 using testing::SetArgPointee; 35 using testing::SetArgPointee;
36 using ::testing::NiceMock;
35 using ::testing::StrictMock; 37 using ::testing::StrictMock;
36 using ::testing::_; 38 using ::testing::_;
37 39
38 namespace { 40 namespace {
39 41
40 const char kFakeSuggestionsURL[] = "https://mysuggestions.com/proto"; 42 const char kFakeSuggestionsURL[] = "https://mysuggestions.com/proto";
41 const char kFakeSuggestionsCommonParams[] = "foo=bar"; 43 const char kFakeSuggestionsCommonParams[] = "foo=bar";
42 const char kFakeBlacklistPath[] = "/blacklist"; 44 const char kFakeBlacklistPath[] = "/blacklist";
43 const char kFakeBlacklistUrlParam[] = "baz"; 45 const char kFakeBlacklistUrlParam[] = "baz";
44 46
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return profile.Pass(); 95 return profile.Pass();
94 } 96 }
95 97
96 class MockSuggestionsStore : public suggestions::SuggestionsStore { 98 class MockSuggestionsStore : public suggestions::SuggestionsStore {
97 public: 99 public:
98 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*)); 100 MOCK_METHOD1(LoadSuggestions, bool(SuggestionsProfile*));
99 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&)); 101 MOCK_METHOD1(StoreSuggestions, bool(const SuggestionsProfile&));
100 MOCK_METHOD0(ClearSuggestions, void()); 102 MOCK_METHOD0(ClearSuggestions, void());
101 }; 103 };
102 104
103 class MockThumbnailManager : public suggestions::ThumbnailManager { 105 class MockImageManager : public suggestions::ImageManager {
104 public: 106 public:
105 MockThumbnailManager() {} 107 MockImageManager() {}
106 virtual ~MockThumbnailManager() {} 108 virtual ~MockImageManager() {}
107 MOCK_METHOD1(InitializeThumbnailMap, void(const SuggestionsProfile&)); 109 MOCK_METHOD1(InitializeImageMap, void(const SuggestionsProfile&));
huangs 2014/07/16 22:22:24 Note that InitializeImageMap() is never used.
Mathieu 2014/07/17 16:06:35 Changed to Initialize per discussion
108 MOCK_METHOD2(GetPageThumbnail, 110 MOCK_METHOD2(GetImageForURL,
109 void(const GURL&, 111 void(const GURL&,
110 base::Callback<void(const GURL&, const SkBitmap*)>)); 112 base::Callback<void(const GURL&, const SkBitmap*)>));
111 }; 113 };
112 114
113 class MockBlacklistStore : public suggestions::BlacklistStore { 115 class MockBlacklistStore : public suggestions::BlacklistStore {
114 public: 116 public:
115 MOCK_METHOD1(BlacklistUrl, bool(const GURL&)); 117 MOCK_METHOD1(BlacklistUrl, bool(const GURL&));
116 MOCK_METHOD1(GetFirstUrlFromBlacklist, bool(GURL*)); 118 MOCK_METHOD1(GetFirstUrlFromBlacklist, bool(GURL*));
117 MOCK_METHOD1(RemoveUrl, bool(const GURL&)); 119 MOCK_METHOD1(RemoveUrl, bool(const GURL&));
118 MOCK_METHOD1(FilterSuggestions, void(SuggestionsProfile*)); 120 MOCK_METHOD1(FilterSuggestions, void(SuggestionsProfile*));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 "Group1", params); 179 "Group1", params);
178 field_trial_ = base::FieldTrialList::CreateFieldTrial( 180 field_trial_ = base::FieldTrialList::CreateFieldTrial(
179 kSuggestionsFieldTrialName, "Group1"); 181 kSuggestionsFieldTrialName, "Group1");
180 field_trial_->group(); 182 field_trial_->group();
181 } 183 }
182 184
183 // Should not be called more than once per test since it stashes the 185 // Should not be called more than once per test since it stashes the
184 // SuggestionsStore in |mock_suggestions_store_|. 186 // SuggestionsStore in |mock_suggestions_store_|.
185 SuggestionsService* CreateSuggestionsServiceWithMocks() { 187 SuggestionsService* CreateSuggestionsServiceWithMocks() {
186 mock_suggestions_store_ = new StrictMock<MockSuggestionsStore>(); 188 mock_suggestions_store_ = new StrictMock<MockSuggestionsStore>();
187 mock_thumbnail_manager_ = new StrictMock<MockThumbnailManager>(); 189 mock_thumbnail_manager_ = new NiceMock<MockImageManager>();
188 mock_blacklist_store_ = new MockBlacklistStore(); 190 mock_blacklist_store_ = new MockBlacklistStore();
189 return new SuggestionsService( 191 return new SuggestionsService(
190 request_context_, scoped_ptr<SuggestionsStore>(mock_suggestions_store_), 192 request_context_, scoped_ptr<SuggestionsStore>(mock_suggestions_store_),
191 scoped_ptr<ThumbnailManager>(mock_thumbnail_manager_), 193 scoped_ptr<ImageManager>(mock_thumbnail_manager_),
192 scoped_ptr<BlacklistStore>(mock_blacklist_store_)); 194 scoped_ptr<BlacklistStore>(mock_blacklist_store_));
193 } 195 }
194 196
195 void FetchSuggestionsDataNoTimeoutHelper(bool interleaved_requests) { 197 void FetchSuggestionsDataNoTimeoutHelper(bool interleaved_requests) {
196 // Field trial enabled with a specific suggestions URL. 198 // Field trial enabled with a specific suggestions URL.
197 EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams, 199 EnableFieldTrial(kFakeSuggestionsURL, kFakeSuggestionsCommonParams,
198 kFakeBlacklistPath, kFakeBlacklistUrlParam, false); 200 kFakeBlacklistPath, kFakeBlacklistUrlParam, false);
199 scoped_ptr<SuggestionsService> suggestions_service( 201 scoped_ptr<SuggestionsService> suggestions_service(
200 CreateSuggestionsServiceWithMocks()); 202 CreateSuggestionsServiceWithMocks());
201 EXPECT_TRUE(suggestions_service != NULL); 203 EXPECT_TRUE(suggestions_service != NULL);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 base::MessageLoop::current()->RunUntilIdle(); 243 base::MessageLoop::current()->RunUntilIdle();
242 244
243 // Ensure that CheckSuggestionsData() ran twice. 245 // Ensure that CheckSuggestionsData() ran twice.
244 EXPECT_EQ(2, suggestions_data_check_count_); 246 EXPECT_EQ(2, suggestions_data_check_count_);
245 } 247 }
246 248
247 protected: 249 protected:
248 net::FakeURLFetcherFactory factory_; 250 net::FakeURLFetcherFactory factory_;
249 // Only used if the SuggestionsService is built with mocks. Not owned. 251 // Only used if the SuggestionsService is built with mocks. Not owned.
250 MockSuggestionsStore* mock_suggestions_store_; 252 MockSuggestionsStore* mock_suggestions_store_;
251 MockThumbnailManager* mock_thumbnail_manager_; 253 MockImageManager* mock_thumbnail_manager_;
252 MockBlacklistStore* mock_blacklist_store_; 254 MockBlacklistStore* mock_blacklist_store_;
253 scoped_refptr<net::TestURLRequestContextGetter> request_context_; 255 scoped_refptr<net::TestURLRequestContextGetter> request_context_;
254 256
255 private: 257 private:
256 content::TestBrowserThreadBundle thread_bundle_; 258 content::TestBrowserThreadBundle thread_bundle_;
257 scoped_ptr<base::FieldTrialList> field_trial_list_; 259 scoped_ptr<base::FieldTrialList> field_trial_list_;
258 scoped_refptr<base::FieldTrial> field_trial_; 260 scoped_refptr<base::FieldTrial> field_trial_;
259 261
260 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceTest); 262 DISALLOW_COPY_AND_ASSIGN(SuggestionsServiceTest);
261 }; 263 };
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 // Delay increases on failure. 488 // Delay increases on failure.
487 suggestions_service->UpdateBlacklistDelay(false); 489 suggestions_service->UpdateBlacklistDelay(false);
488 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay); 490 EXPECT_GT(suggestions_service->blacklist_delay(), initial_delay);
489 491
490 // Delay resets on success. 492 // Delay resets on success.
491 suggestions_service->UpdateBlacklistDelay(true); 493 suggestions_service->UpdateBlacklistDelay(true);
492 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay()); 494 EXPECT_EQ(initial_delay, suggestions_service->blacklist_delay());
493 } 495 }
494 496
495 } // namespace suggestions 497 } // namespace suggestions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698