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

Side by Side Diff: chrome/browser/google/google_url_tracker_unittest.cc

Issue 10581012: Move test_url_fetcher_factory.* from content/ to net/url_request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove export annotations Created 8 years, 6 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 (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 #include "chrome/browser/google/google_url_tracker.h" 5 #include "chrome/browser/google/google_url_tracker.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "chrome/browser/google/google_url_tracker_factory.h" 11 #include "chrome/browser/google/google_url_tracker_factory.h"
12 #include "chrome/browser/infobars/infobar_delegate.h" 12 #include "chrome/browser/infobars/infobar_delegate.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 16 #include "chrome/test/base/testing_profile.h"
17 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
18 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
19 #include "content/public/test/test_url_fetcher_factory.h" 19 #include "net/url_request/test_url_fetcher_factory.h"
20 #include "net/url_request/url_fetcher.h" 20 #include "net/url_request/url_fetcher.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 class TabContents; 23 class TabContents;
24 24
25 // TestNotificationObserver --------------------------------------------------- 25 // TestNotificationObserver ---------------------------------------------------
26 26
27 namespace { 27 namespace {
28 28
29 class TestNotificationObserver : public content::NotificationObserver { 29 class TestNotificationObserver : public content::NotificationObserver {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 class GoogleURLTrackerTest : public testing::Test { 115 class GoogleURLTrackerTest : public testing::Test {
116 protected: 116 protected:
117 GoogleURLTrackerTest(); 117 GoogleURLTrackerTest();
118 virtual ~GoogleURLTrackerTest(); 118 virtual ~GoogleURLTrackerTest();
119 119
120 // testing::Test 120 // testing::Test
121 virtual void SetUp(); 121 virtual void SetUp();
122 virtual void TearDown(); 122 virtual void TearDown();
123 123
124 TestURLFetcher* GetFetcher(); 124 net::TestURLFetcher* GetFetcher();
125 void MockSearchDomainCheckResponse(const std::string& domain); 125 void MockSearchDomainCheckResponse(const std::string& domain);
126 void RequestServerCheck(); 126 void RequestServerCheck();
127 void FinishSleep(); 127 void FinishSleep();
128 void NotifyIPAddressChanged(); 128 void NotifyIPAddressChanged();
129 GURL fetched_google_url() const { 129 GURL fetched_google_url() const {
130 return google_url_tracker_->fetched_google_url_; 130 return google_url_tracker_->fetched_google_url_;
131 } 131 }
132 void set_google_url(const GURL& url) { 132 void set_google_url(const GURL& url) {
133 google_url_tracker_->google_url_ = url; 133 google_url_tracker_->google_url_ = url;
134 } 134 }
135 GURL google_url() const { return google_url_tracker_->google_url_; } 135 GURL google_url() const { return google_url_tracker_->google_url_; }
136 void SetLastPromptedGoogleURL(const GURL& url); 136 void SetLastPromptedGoogleURL(const GURL& url);
137 GURL GetLastPromptedGoogleURL(); 137 GURL GetLastPromptedGoogleURL();
138 void SetSearchPending(const GURL& search_url, int unique_id); 138 void SetSearchPending(const GURL& search_url, int unique_id);
139 void CommitSearch(int unique_id); 139 void CommitSearch(int unique_id);
140 void CloseTab(int unique_id); 140 void CloseTab(int unique_id);
141 TestInfoBarDelegate* GetInfoBar(int unique_id); 141 TestInfoBarDelegate* GetInfoBar(int unique_id);
142 void ExpectDefaultURLs(); 142 void ExpectDefaultURLs();
143 143
144 scoped_ptr<TestNotificationObserver> observer_; 144 scoped_ptr<TestNotificationObserver> observer_;
145 145
146 private: 146 private:
147 // These are required by the TestURLFetchers GoogleURLTracker will create (see 147 // These are required by the TestURLFetchers GoogleURLTracker will create (see
148 // test_url_fetcher_factory.h). 148 // test_url_fetcher_factory.h).
149 MessageLoop message_loop_; 149 MessageLoop message_loop_;
150 content::TestBrowserThread io_thread_; 150 content::TestBrowserThread io_thread_;
151 // Creating this allows us to call 151 // Creating this allows us to call
152 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). 152 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
153 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 153 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
154 TestURLFetcherFactory fetcher_factory_; 154 net::TestURLFetcherFactory fetcher_factory_;
155 content::NotificationRegistrar registrar_; 155 content::NotificationRegistrar registrar_;
156 TestingProfile profile_; 156 TestingProfile profile_;
157 scoped_ptr<GoogleURLTracker> google_url_tracker_; 157 scoped_ptr<GoogleURLTracker> google_url_tracker_;
158 // This tracks the different "tabs" a test has "opened", so we can close them 158 // This tracks the different "tabs" a test has "opened", so we can close them
159 // properly before shutting down |google_url_tracker_|, which expects that. 159 // properly before shutting down |google_url_tracker_|, which expects that.
160 std::set<int> unique_ids_seen_; 160 std::set<int> unique_ids_seen_;
161 }; 161 };
162 162
163 GoogleURLTrackerTest::GoogleURLTrackerTest() 163 GoogleURLTrackerTest::GoogleURLTrackerTest()
164 : observer_(new TestNotificationObserver), 164 : observer_(new TestNotificationObserver),
(...skipping 13 matching lines...) Expand all
178 } 178 }
179 179
180 void GoogleURLTrackerTest::TearDown() { 180 void GoogleURLTrackerTest::TearDown() {
181 while (!unique_ids_seen_.empty()) 181 while (!unique_ids_seen_.empty())
182 CloseTab(*unique_ids_seen_.begin()); 182 CloseTab(*unique_ids_seen_.begin());
183 183
184 google_url_tracker_.reset(); 184 google_url_tracker_.reset();
185 network_change_notifier_.reset(); 185 network_change_notifier_.reset();
186 } 186 }
187 187
188 TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { 188 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
189 // This will return the last fetcher created. If no fetchers have been 189 // This will return the last fetcher created. If no fetchers have been
190 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. 190 // created, we'll pass GetFetcherByID() "-1", and it will return NULL.
191 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); 191 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1);
192 } 192 }
193 193
194 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( 194 void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
195 const std::string& domain) { 195 const std::string& domain) {
196 TestURLFetcher* fetcher = GetFetcher(); 196 net::TestURLFetcher* fetcher = GetFetcher();
197 if (!fetcher) 197 if (!fetcher)
198 return; 198 return;
199 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); 199 fetcher_factory_.RemoveFetcherFromMap(fetcher->id());
200 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); 200 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL));
201 fetcher->set_response_code(200); 201 fetcher->set_response_code(200);
202 fetcher->SetResponseString(domain); 202 fetcher->SetResponseString(domain);
203 fetcher->delegate()->OnURLFetchComplete(fetcher); 203 fetcher->delegate()->OnURLFetchComplete(fetcher);
204 // At this point, |fetcher| is deleted. 204 // At this point, |fetcher| is deleted.
205 } 205 }
206 206
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 EXPECT_FALSE(observer_->notified()); 825 EXPECT_FALSE(observer_->notified());
826 826
827 infobar4->Accept(); 827 infobar4->Accept();
828 EXPECT_TRUE(GetInfoBar(1) == NULL); 828 EXPECT_TRUE(GetInfoBar(1) == NULL);
829 EXPECT_TRUE(GetInfoBar(3) == NULL); 829 EXPECT_TRUE(GetInfoBar(3) == NULL);
830 EXPECT_TRUE(GetInfoBar(4) == NULL); 830 EXPECT_TRUE(GetInfoBar(4) == NULL);
831 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); 831 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
832 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 832 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
833 EXPECT_TRUE(observer_->notified()); 833 EXPECT_TRUE(observer_->notified());
834 } 834 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698