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

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

Issue 290453005: Remove Infobars notifications from GoogleURLTrackerMapEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review comments Created 6 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
« no previous file with comments | « chrome/browser/google/google_url_tracker_map_entry.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/google/google_url_tracker_factory.h" 13 #include "chrome/browser/google/google_url_tracker_factory.h"
14 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" 14 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
15 #include "chrome/browser/google/google_url_tracker_navigation_helper.h" 15 #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
18 #include "components/google/core/browser/google_url_tracker_client.h" 18 #include "components/google/core/browser/google_url_tracker_client.h"
19 #include "components/infobars/core/infobar.h" 19 #include "components/infobars/core/infobar.h"
20 #include "components/infobars/core/infobar_delegate.h" 20 #include "components/infobars/core/infobar_delegate.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "net/url_request/test_url_fetcher_factory.h" 22 #include "net/url_request/test_url_fetcher_factory.h"
24 #include "net/url_request/url_fetcher.h" 23 #include "net/url_request/url_fetcher.h"
25 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
26 25
27 class GoogleURLTrackerTest;
28
29 namespace { 26 namespace {
30 27
31 // TestInfoBarDelegate --------------------------------------------------------
32
33 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate {
34 public:
35 // Creates a test infobar and delegate and returns the infobar. Unlike the
36 // parent class, this does not add the infobar to |infobar_manager|, since
37 // that "pointer" is really just a magic number. Thus there is no
38 // InfoBarManager ownership of the returned object; and since the caller
39 // doesn't own the returned object, we rely on |test_harness| cleaning this
40 // up eventually in GoogleURLTrackerTest::OnInfoBarClosed() to avoid leaks.
41 static infobars::InfoBar* Create(
42 GoogleURLTrackerTest* test_harness,
43 infobars::InfoBarManager* infobar_manager,
44 GoogleURLTracker* google_url_tracker,
45 const GURL& search_url);
46
47 private:
48 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness,
49 infobars::InfoBarManager* infobar_manager,
50 GoogleURLTracker* google_url_tracker,
51 const GURL& search_url);
52 virtual ~TestInfoBarDelegate();
53
54 // GoogleURLTrackerInfoBarDelegate:
55 virtual void Update(const GURL& search_url) OVERRIDE;
56 virtual void Close(bool redo_search) OVERRIDE;
57
58 GoogleURLTrackerTest* test_harness_;
59 infobars::InfoBarManager* infobar_manager_;
60
61 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate);
62 };
63
64 // The member function definitions come after the declaration of
65 // GoogleURLTrackerTest, so they can call members on it.
66
67
68 // TestCallbackListener --------------------------------------------------- 28 // TestCallbackListener ---------------------------------------------------
69 29
70 class TestCallbackListener { 30 class TestCallbackListener {
71 public: 31 public:
72 TestCallbackListener(); 32 TestCallbackListener();
73 virtual ~TestCallbackListener(); 33 virtual ~TestCallbackListener();
74 34
75 bool HasRegisteredCallback(); 35 bool HasRegisteredCallback();
76 void RegisterCallback(GoogleURLTracker* google_url_tracker); 36 void RegisterCallback(GoogleURLTracker* google_url_tracker);
77 37
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() { 154 bool TestGoogleURLTrackerNavigationHelper::IsListeningForTabDestruction() {
195 return listening_for_tab_destruction_; 155 return listening_for_tab_destruction_;
196 } 156 }
197 157
198 void TestGoogleURLTrackerNavigationHelper::OpenURL( 158 void TestGoogleURLTrackerNavigationHelper::OpenURL(
199 GURL url, 159 GURL url,
200 WindowOpenDisposition disposition, 160 WindowOpenDisposition disposition,
201 bool user_clicked_on_link) { 161 bool user_clicked_on_link) {
202 } 162 }
203 163
164 // TestInfoBarManager ---------------------------------------------------------
165
166 class TestInfoBarManager : public infobars::InfoBarManager {
167 public:
168 explicit TestInfoBarManager(int unique_id);
169 virtual ~TestInfoBarManager();
170 virtual int GetActiveEntryID() OVERRIDE;
171
172 private:
173 int unique_id_;
174 DISALLOW_COPY_AND_ASSIGN(TestInfoBarManager);
175 };
176
177 TestInfoBarManager::TestInfoBarManager(int unique_id) : unique_id_(unique_id) {
178 }
179
180 TestInfoBarManager::~TestInfoBarManager() {
181 ShutDown();
182 }
183
184 int TestInfoBarManager::GetActiveEntryID() {
185 return unique_id_;
186 }
187
204 } // namespace 188 } // namespace
205 189
206
207 // GoogleURLTrackerTest ------------------------------------------------------- 190 // GoogleURLTrackerTest -------------------------------------------------------
208 191
209 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more
210 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions
211 // are carefully written so that many of the functions which take
212 // NavigationController* or infobars::InfoBarManager* do not actually
213 // dereference the
214 // objects, merely use them for comparisons and lookups, e.g. in |entry_map_|.
215 // This then allows the test code here to not create any of these objects, and
216 // instead supply "pointers" that are actually reinterpret_cast<>()ed magic
217 // numbers. Then we write the necessary stubs/hooks, here and in
218 // TestInfoBarDelegate above, to make everything continue to work.
219 //
220 // Technically, the C++98 spec defines the result of casting
221 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what
222 // we use here) is "implementation-defined". Since I've never seen a compiler
223 // break this, though, and the result would simply be a failing test rather than
224 // a bug in Chrome, we'll use it anyway.
225 class GoogleURLTrackerTest : public testing::Test { 192 class GoogleURLTrackerTest : public testing::Test {
226 public:
227 // Called by TestInfoBarDelegate::Close().
228 void OnInfoBarClosed(scoped_ptr<infobars::InfoBar> infobar,
229 infobars::InfoBarManager* infobar_manager);
230
231 protected: 193 protected:
232 GoogleURLTrackerTest(); 194 GoogleURLTrackerTest();
233 virtual ~GoogleURLTrackerTest(); 195 virtual ~GoogleURLTrackerTest();
234 196
235 // testing::Test 197 // testing::Test
236 virtual void SetUp() OVERRIDE; 198 virtual void SetUp() OVERRIDE;
237 virtual void TearDown() OVERRIDE; 199 virtual void TearDown() OVERRIDE;
238 200
239 net::TestURLFetcher* GetFetcher(); 201 net::TestURLFetcher* GetFetcher();
240 void MockSearchDomainCheckResponse(const std::string& domain); 202 void MockSearchDomainCheckResponse(const std::string& domain);
241 void RequestServerCheck(); 203 void RequestServerCheck();
242 void FinishSleep(); 204 void FinishSleep();
243 void NotifyIPAddressChanged(); 205 void NotifyIPAddressChanged();
244 GURL fetched_google_url() const { 206 GURL fetched_google_url() const {
245 return google_url_tracker_->fetched_google_url(); 207 return google_url_tracker_->fetched_google_url();
246 } 208 }
247 void set_google_url(const GURL& url) { 209 void set_google_url(const GURL& url) {
248 google_url_tracker_->google_url_ = url; 210 google_url_tracker_->google_url_ = url;
249 } 211 }
250 GURL google_url() const { return google_url_tracker_->google_url(); } 212 GURL google_url() const { return google_url_tracker_->google_url(); }
251 void SetLastPromptedGoogleURL(const GURL& url); 213 void SetLastPromptedGoogleURL(const GURL& url);
252 GURL GetLastPromptedGoogleURL(); 214 GURL GetLastPromptedGoogleURL();
253 void SetNavigationPending(intptr_t unique_id, bool is_search); 215 void SetNavigationPending(infobars::InfoBarManager* infobar_manager,
254 void CommitNonSearch(intptr_t unique_id); 216 bool is_search);
255 void CommitSearch(intptr_t unique_id, const GURL& search_url); 217 void CommitNonSearch(infobars::InfoBarManager* infobar_manager);
256 void CloseTab(intptr_t unique_id); 218 void CommitSearch(infobars::InfoBarManager* infobar_manager,
257 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); 219 const GURL& search_url);
258 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(intptr_t unique_id); 220 void CloseTab(infobars::InfoBarManager* infobar_manager);
259 GoogleURLTrackerNavigationHelper* GetNavigationHelper(intptr_t unique_id); 221 GoogleURLTrackerMapEntry* GetMapEntry(
222 infobars::InfoBarManager* infobar_manager);
223 GoogleURLTrackerInfoBarDelegate* GetInfoBarDelegate(
224 infobars::InfoBarManager* infobar_manager);
225 GoogleURLTrackerNavigationHelper* GetNavigationHelper(
226 infobars::InfoBarManager* infobar_manager);
260 void ExpectDefaultURLs() const; 227 void ExpectDefaultURLs() const;
261 void ExpectListeningForCommit(intptr_t unique_id, bool listening); 228 void ExpectListeningForCommit(infobars::InfoBarManager* infobar_manager,
229 bool listening);
262 bool listener_notified() const { return listener_.notified(); } 230 bool listener_notified() const { return listener_.notified(); }
263 void clear_listener_notified() { listener_.clear_notified(); } 231 void clear_listener_notified() { listener_.clear_notified(); }
264 232
265 private: 233 private:
266 // Since |infobar_manager| is really a magic number rather than an actual
267 // object, we don't add the created infobar to it. Instead we will simulate
268 // any helper<->infobar interaction necessary. The returned object will be
269 // cleaned up in OnInfoBarClosed().
270 infobars::InfoBar* CreateTestInfoBar(
271 infobars::InfoBarManager* infobar_manager,
272 GoogleURLTracker* google_url_tracker,
273 const GURL& search_url);
274
275 // These are required by the TestURLFetchers GoogleURLTracker will create (see 234 // These are required by the TestURLFetchers GoogleURLTracker will create (see
276 // test_url_fetcher_factory.h). 235 // test_url_fetcher_factory.h).
277 content::TestBrowserThreadBundle thread_bundle_; 236 content::TestBrowserThreadBundle thread_bundle_;
237
278 // Creating this allows us to call 238 // Creating this allows us to call
279 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). 239 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests().
280 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; 240 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_;
281 net::TestURLFetcherFactory fetcher_factory_; 241 net::TestURLFetcherFactory fetcher_factory_;
282 GoogleURLTrackerClient* client_; 242 GoogleURLTrackerClient* client_;
283 TestingProfile profile_; 243 TestingProfile profile_;
284 scoped_ptr<GoogleURLTracker> google_url_tracker_; 244 scoped_ptr<GoogleURLTracker> google_url_tracker_;
285 TestCallbackListener listener_; 245 TestCallbackListener listener_;
286 // This tracks the different "tabs" a test has "opened", so we can close them 246 // This tracks the different "tabs" a test has "opened", so we can close them
287 // properly before shutting down |google_url_tracker_|, which expects that. 247 // properly before shutting down |google_url_tracker_|, which expects that.
288 std::set<int> unique_ids_seen_; 248 std::set<infobars::InfoBarManager*> infobar_managers_seen_;
289 }; 249 };
290 250
291 void GoogleURLTrackerTest::OnInfoBarClosed(
292 scoped_ptr<infobars::InfoBar> infobar,
293 infobars::InfoBarManager* infobar_manager) {
294 // First, simulate the InfoBarManager firing INFOBAR_REMOVED.
295 // TODO(droger): Replace this flow with a call to the observer method once
296 // the map entry is observing InfoBarManager. crbug.com/373243
297 infobars::InfoBar::RemovedDetails removed_details(infobar.get(), false);
298 GoogleURLTracker::EntryMap::const_iterator i =
299 google_url_tracker_->entry_map_.find(infobar_manager);
300 ASSERT_FALSE(i == google_url_tracker_->entry_map_.end());
301 GoogleURLTrackerMapEntry* map_entry = i->second;
302 ASSERT_EQ(infobar->delegate(), map_entry->infobar_delegate());
303 map_entry->Observe(
304 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
305 content::Source<infobars::InfoBarManager>(infobar_manager),
306 content::Details<infobars::InfoBar::RemovedDetails>(&removed_details));
307
308 // Second, simulate the infobar container closing the infobar in response.
309 // This happens automatically as |infobar| goes out of scope.
310 }
311
312 GoogleURLTrackerTest::GoogleURLTrackerTest() 251 GoogleURLTrackerTest::GoogleURLTrackerTest()
313 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 252 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
314 GoogleURLTrackerFactory::GetInstance()-> 253 GoogleURLTrackerFactory::GetInstance()->
315 RegisterUserPrefsOnBrowserContextForTest(&profile_); 254 RegisterUserPrefsOnBrowserContextForTest(&profile_);
316 } 255 }
317 256
318 GoogleURLTrackerTest::~GoogleURLTrackerTest() { 257 GoogleURLTrackerTest::~GoogleURLTrackerTest() {
319 } 258 }
320 259
321 void GoogleURLTrackerTest::SetUp() { 260 void GoogleURLTrackerTest::SetUp() {
322 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); 261 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
323 // Ownership is passed to google_url_tracker_, but a weak pointer is kept; 262 // Ownership is passed to google_url_tracker_, but a weak pointer is kept;
324 // this is safe since GoogleURLTracker keeps the client for its lifetime. 263 // this is safe since GoogleURLTracker keeps the client for its lifetime.
325 client_ = new TestGoogleURLTrackerClient(); 264 client_ = new TestGoogleURLTrackerClient();
326 scoped_ptr<GoogleURLTrackerClient> client(client_); 265 scoped_ptr<GoogleURLTrackerClient> client(client_);
327 google_url_tracker_.reset(new GoogleURLTracker( 266 google_url_tracker_.reset(new GoogleURLTracker(
328 &profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE)); 267 &profile_, client.Pass(), GoogleURLTracker::UNIT_TEST_MODE));
329 google_url_tracker_->infobar_creator_ = base::Bind(
330 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this));
331 } 268 }
332 269
333 void GoogleURLTrackerTest::TearDown() { 270 void GoogleURLTrackerTest::TearDown() {
334 while (!unique_ids_seen_.empty()) 271 while (!infobar_managers_seen_.empty())
335 CloseTab(*unique_ids_seen_.begin()); 272 CloseTab(*infobar_managers_seen_.begin());
336 google_url_tracker_->Shutdown(); 273 google_url_tracker_->Shutdown();
337 } 274 }
338 275
339 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { 276 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() {
340 // This will return the last fetcher created. If no fetchers have been 277 // This will return the last fetcher created. If no fetchers have been
341 // created, we'll pass GetFetcherByID() "-1", and it will return NULL. 278 // created, we'll pass GetFetcherByID() "-1", and it will return NULL.
342 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1); 279 return fetcher_factory_.GetFetcherByID(google_url_tracker_->fetcher_id_ - 1);
343 } 280 }
344 281
345 void GoogleURLTrackerTest::MockSearchDomainCheckResponse( 282 void GoogleURLTrackerTest::MockSearchDomainCheckResponse(
(...skipping 27 matching lines...) Expand all
373 } 310 }
374 311
375 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { 312 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) {
376 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); 313 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec());
377 } 314 }
378 315
379 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { 316 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() {
380 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); 317 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL));
381 } 318 }
382 319
383 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, 320 void GoogleURLTrackerTest::SetNavigationPending(
384 bool is_search) { 321 infobars::InfoBarManager* infobar_manager,
322 bool is_search) {
385 if (is_search) { 323 if (is_search) {
386 google_url_tracker_->SearchCommitted(); 324 google_url_tracker_->SearchCommitted();
387 // Note that the call above might not have actually registered a listener 325 // Note that the call above might not have actually registered a listener
388 // for navigation starts if the searchdomaincheck response was bogus. 326 // for navigation starts if the searchdomaincheck response was bogus.
389 } 327 }
390 unique_ids_seen_.insert(unique_id); 328 infobar_managers_seen_.insert(infobar_manager);
391 if (client_->IsListeningForNavigationStart()) { 329 if (client_->IsListeningForNavigationStart()) {
392 google_url_tracker_->OnNavigationPending( 330 google_url_tracker_->OnNavigationPending(
393 scoped_ptr<GoogleURLTrackerNavigationHelper>( 331 scoped_ptr<GoogleURLTrackerNavigationHelper>(
394 new TestGoogleURLTrackerNavigationHelper( 332 new TestGoogleURLTrackerNavigationHelper(
395 google_url_tracker_.get())), 333 google_url_tracker_.get())),
396 reinterpret_cast<infobars::InfoBarManager*>(unique_id), 334 infobar_manager,
397 unique_id); 335 infobar_manager->GetActiveEntryID());
398 } 336 }
399 } 337 }
400 338
401 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { 339 void GoogleURLTrackerTest::CommitNonSearch(
402 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 340 infobars::InfoBarManager* infobar_manager) {
341 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager);
403 if (!map_entry) 342 if (!map_entry)
404 return; 343 return;
405 344
406 ExpectListeningForCommit(unique_id, false); 345 ExpectListeningForCommit(infobar_manager, false);
407 346
408 // The infobar should be showing; otherwise the pending non-search should 347 // The infobar should be showing; otherwise the pending non-search should
409 // have closed it. 348 // have closed it.
410 ASSERT_TRUE(map_entry->has_infobar_delegate()); 349 ASSERT_TRUE(map_entry->has_infobar_delegate());
411 350
412 // The pending_id should have been reset to 0 when the non-search became 351 // The pending_id should have been reset to 0 when the non-search became
413 // pending. 352 // pending.
414 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id()); 353 EXPECT_EQ(0, map_entry->infobar_delegate()->pending_id());
415 354
416 // Committing the navigation would close the infobar. 355 // Committing the navigation would close the infobar.
417 map_entry->infobar_delegate()->Close(false); 356 map_entry->infobar_delegate()->Close(false);
418 } 357 }
419 358
420 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, 359 void GoogleURLTrackerTest::CommitSearch(
421 const GURL& search_url) { 360 infobars::InfoBarManager* infobar_manager,
361 const GURL& search_url) {
422 DCHECK(search_url.is_valid()); 362 DCHECK(search_url.is_valid());
423 GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); 363 GoogleURLTrackerNavigationHelper* nav_helper =
364 GetNavigationHelper(infobar_manager);
424 if (nav_helper && nav_helper->IsListeningForNavigationCommit()) { 365 if (nav_helper && nav_helper->IsListeningForNavigationCommit()) {
425 google_url_tracker_->OnNavigationCommitted( 366 google_url_tracker_->OnNavigationCommitted(infobar_manager, search_url);
426 reinterpret_cast<infobars::InfoBarManager*>(unique_id), search_url);
427 } 367 }
428 } 368 }
429 369
430 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { 370 void GoogleURLTrackerTest::CloseTab(infobars::InfoBarManager* infobar_manager) {
431 unique_ids_seen_.erase(unique_id); 371 infobar_managers_seen_.erase(infobar_manager);
432 GoogleURLTrackerNavigationHelper* nav_helper = GetNavigationHelper(unique_id); 372 GoogleURLTrackerNavigationHelper* nav_helper =
373 GetNavigationHelper(infobar_manager);
433 if (nav_helper && nav_helper->IsListeningForTabDestruction()) { 374 if (nav_helper && nav_helper->IsListeningForTabDestruction()) {
434 google_url_tracker_->OnTabClosed(nav_helper); 375 google_url_tracker_->OnTabClosed(nav_helper);
435 } else { 376 } else {
436 // Closing a tab with an infobar showing would close the infobar. 377 // Closing a tab with an infobar showing would close the infobar.
437 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(unique_id); 378 GoogleURLTrackerInfoBarDelegate* delegate =
379 GetInfoBarDelegate(infobar_manager);
438 if (delegate) 380 if (delegate)
439 delegate->Close(false); 381 delegate->Close(false);
440 } 382 }
441 } 383 }
442 384
443 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( 385 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry(
444 intptr_t unique_id) { 386 infobars::InfoBarManager* infobar_manager) {
445 GoogleURLTracker::EntryMap::const_iterator i = 387 GoogleURLTracker::EntryMap::const_iterator i =
446 google_url_tracker_->entry_map_.find( 388 google_url_tracker_->entry_map_.find(infobar_manager);
447 reinterpret_cast<infobars::InfoBarManager*>(unique_id));
448 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second; 389 return (i == google_url_tracker_->entry_map_.end()) ? NULL : i->second;
449 } 390 }
450 391
451 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate( 392 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBarDelegate(
452 intptr_t unique_id) { 393 infobars::InfoBarManager* infobar_manager) {
453 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 394 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager);
454 return map_entry ? map_entry->infobar_delegate() : NULL; 395 return map_entry ? map_entry->infobar_delegate() : NULL;
455 } 396 }
456 397
457 GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper( 398 GoogleURLTrackerNavigationHelper* GoogleURLTrackerTest::GetNavigationHelper(
458 intptr_t unique_id) { 399 infobars::InfoBarManager* infobar_manager) {
459 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 400 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager);
460 return map_entry ? map_entry->navigation_helper() : NULL; 401 return map_entry ? map_entry->navigation_helper() : NULL;
461 } 402 }
462 403
463 void GoogleURLTrackerTest::ExpectDefaultURLs() const { 404 void GoogleURLTrackerTest::ExpectDefaultURLs() const {
464 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 405 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
465 EXPECT_EQ(GURL(), fetched_google_url()); 406 EXPECT_EQ(GURL(), fetched_google_url());
466 } 407 }
467 408
468 void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, 409 void GoogleURLTrackerTest::ExpectListeningForCommit(
469 bool listening) { 410 infobars::InfoBarManager* infobar_manager,
470 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); 411 bool listening) {
412 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(infobar_manager);
471 if (map_entry) { 413 if (map_entry) {
472 EXPECT_EQ(listening, 414 EXPECT_EQ(listening,
473 map_entry->navigation_helper()->IsListeningForNavigationCommit()); 415 map_entry->navigation_helper()->IsListeningForNavigationCommit());
474 } else { 416 } else {
475 EXPECT_FALSE(listening); 417 EXPECT_FALSE(listening);
476 } 418 }
477 } 419 }
478 420
479 infobars::InfoBar* GoogleURLTrackerTest::CreateTestInfoBar(
480 infobars::InfoBarManager* infobar_manager,
481 GoogleURLTracker* google_url_tracker,
482 const GURL& search_url) {
483 return TestInfoBarDelegate::Create(
484 this, infobar_manager, google_url_tracker, search_url);
485 }
486
487
488 // TestInfoBarDelegate --------------------------------------------------------
489
490 namespace {
491
492 // static
493 infobars::InfoBar* TestInfoBarDelegate::Create(
494 GoogleURLTrackerTest* test_harness,
495 infobars::InfoBarManager* infobar_manager,
496 GoogleURLTracker* google_url_tracker,
497 const GURL& search_url) {
498 return ConfirmInfoBarDelegate::CreateInfoBar(
499 scoped_ptr<ConfirmInfoBarDelegate>(new TestInfoBarDelegate(
500 test_harness,
501 infobar_manager,
502 google_url_tracker,
503 search_url))).release();
504 }
505
506 TestInfoBarDelegate::TestInfoBarDelegate(
507 GoogleURLTrackerTest* test_harness,
508 infobars::InfoBarManager* infobar_manager,
509 GoogleURLTracker* google_url_tracker,
510 const GURL& search_url)
511 : GoogleURLTrackerInfoBarDelegate(google_url_tracker,
512 search_url),
513 test_harness_(test_harness),
514 infobar_manager_(infobar_manager) {
515 }
516
517 TestInfoBarDelegate::~TestInfoBarDelegate() {
518 }
519
520 void TestInfoBarDelegate::Update(const GURL& search_url) {
521 set_search_url(search_url);
522 set_pending_id(0);
523 }
524
525 void TestInfoBarDelegate::Close(bool redo_search) {
526 test_harness_->OnInfoBarClosed(scoped_ptr<infobars::InfoBar>(infobar()),
527 infobar_manager_);
528 // WARNING: At this point |this| has been deleted!
529 }
530
531 } // namespace
532
533
534 // Tests ---------------------------------------------------------------------- 421 // Tests ----------------------------------------------------------------------
535 422
536 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { 423 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) {
537 ExpectDefaultURLs(); 424 ExpectDefaultURLs();
538 FinishSleep(); 425 FinishSleep();
539 // No one called RequestServerCheck() so nothing should have happened. 426 // No one called RequestServerCheck() so nothing should have happened.
540 EXPECT_FALSE(GetFetcher()); 427 EXPECT_FALSE(GetFetcher());
541 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 428 MockSearchDomainCheckResponse("http://www.google.co.uk/");
542 ExpectDefaultURLs(); 429 ExpectDefaultURLs();
543 EXPECT_FALSE(listener_notified()); 430 EXPECT_FALSE(listener_notified());
(...skipping 24 matching lines...) Expand all
568 FinishSleep(); 455 FinishSleep();
569 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 456 MockSearchDomainCheckResponse("http://www.google.co.uk/");
570 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 457 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
571 // GoogleURL should not be updated, because the fetched and prompted URLs 458 // GoogleURL should not be updated, because the fetched and prompted URLs
572 // match. 459 // match.
573 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 460 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
574 EXPECT_FALSE(listener_notified()); 461 EXPECT_FALSE(listener_notified());
575 } 462 }
576 463
577 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { 464 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) {
465 TestInfoBarManager infobar_manager(1);
578 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 466 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
579 467
580 RequestServerCheck(); 468 RequestServerCheck();
581 EXPECT_FALSE(GetFetcher()); 469 EXPECT_FALSE(GetFetcher());
582 ExpectDefaultURLs(); 470 ExpectDefaultURLs();
583 EXPECT_FALSE(listener_notified()); 471 EXPECT_FALSE(listener_notified());
584 472
585 // Old-style domain string. 473 // Old-style domain string.
586 FinishSleep(); 474 FinishSleep();
587 MockSearchDomainCheckResponse(".google.co.in"); 475 MockSearchDomainCheckResponse(".google.co.in");
588 EXPECT_EQ(GURL(), fetched_google_url()); 476 EXPECT_EQ(GURL(), fetched_google_url());
589 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 477 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
590 EXPECT_FALSE(listener_notified()); 478 EXPECT_FALSE(listener_notified());
591 SetNavigationPending(1, true); 479 SetNavigationPending(&infobar_manager, true);
592 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 480 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
593 EXPECT_TRUE(GetMapEntry(1) == NULL); 481 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
594 482
595 // Bad subdomain. 483 // Bad subdomain.
596 NotifyIPAddressChanged(); 484 NotifyIPAddressChanged();
597 MockSearchDomainCheckResponse("http://mail.google.com/"); 485 MockSearchDomainCheckResponse("http://mail.google.com/");
598 EXPECT_EQ(GURL(), fetched_google_url()); 486 EXPECT_EQ(GURL(), fetched_google_url());
599 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 487 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
600 EXPECT_FALSE(listener_notified()); 488 EXPECT_FALSE(listener_notified());
601 SetNavigationPending(1, true); 489 SetNavigationPending(&infobar_manager, true);
602 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 490 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
603 EXPECT_TRUE(GetMapEntry(1) == NULL); 491 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
604 492
605 // Non-empty path. 493 // Non-empty path.
606 NotifyIPAddressChanged(); 494 NotifyIPAddressChanged();
607 MockSearchDomainCheckResponse("http://www.google.com/search"); 495 MockSearchDomainCheckResponse("http://www.google.com/search");
608 EXPECT_EQ(GURL(), fetched_google_url()); 496 EXPECT_EQ(GURL(), fetched_google_url());
609 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 497 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
610 EXPECT_FALSE(listener_notified()); 498 EXPECT_FALSE(listener_notified());
611 SetNavigationPending(1, true); 499 SetNavigationPending(&infobar_manager, true);
612 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 500 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
613 EXPECT_TRUE(GetMapEntry(1) == NULL); 501 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
614 502
615 // Non-empty query. 503 // Non-empty query.
616 NotifyIPAddressChanged(); 504 NotifyIPAddressChanged();
617 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); 505 MockSearchDomainCheckResponse("http://www.google.com/?q=foo");
618 EXPECT_EQ(GURL(), fetched_google_url()); 506 EXPECT_EQ(GURL(), fetched_google_url());
619 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 507 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
620 EXPECT_FALSE(listener_notified()); 508 EXPECT_FALSE(listener_notified());
621 SetNavigationPending(1, true); 509 SetNavigationPending(&infobar_manager, true);
622 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 510 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
623 EXPECT_TRUE(GetMapEntry(1) == NULL); 511 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
624 512
625 // Non-empty ref. 513 // Non-empty ref.
626 NotifyIPAddressChanged(); 514 NotifyIPAddressChanged();
627 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); 515 MockSearchDomainCheckResponse("http://www.google.com/#anchor");
628 EXPECT_EQ(GURL(), fetched_google_url()); 516 EXPECT_EQ(GURL(), fetched_google_url());
629 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 517 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
630 EXPECT_FALSE(listener_notified()); 518 EXPECT_FALSE(listener_notified());
631 SetNavigationPending(1, true); 519 SetNavigationPending(&infobar_manager, true);
632 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 520 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
633 EXPECT_TRUE(GetMapEntry(1) == NULL); 521 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
634 522
635 // Complete garbage. 523 // Complete garbage.
636 NotifyIPAddressChanged(); 524 NotifyIPAddressChanged();
637 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); 525 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1");
638 EXPECT_EQ(GURL(), fetched_google_url()); 526 EXPECT_EQ(GURL(), fetched_google_url());
639 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 527 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
640 EXPECT_FALSE(listener_notified()); 528 EXPECT_FALSE(listener_notified());
641 SetNavigationPending(1, true); 529 SetNavigationPending(&infobar_manager, true);
642 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 530 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
643 EXPECT_TRUE(GetMapEntry(1) == NULL); 531 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
644 } 532 }
645 533
646 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { 534 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) {
647 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); 535 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/"));
648 set_google_url(GURL("http://www.google.co.uk/")); 536 set_google_url(GURL("http://www.google.co.uk/"));
649 RequestServerCheck(); 537 RequestServerCheck();
650 FinishSleep(); 538 FinishSleep();
651 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 539 MockSearchDomainCheckResponse("http://www.google.co.uk/");
652 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 540 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
653 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 541 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 RequestServerCheck(); 622 RequestServerCheck();
735 // The second request should be ignored. 623 // The second request should be ignored.
736 EXPECT_FALSE(GetFetcher()); 624 EXPECT_FALSE(GetFetcher());
737 MockSearchDomainCheckResponse("http://www.google.co.in/"); 625 MockSearchDomainCheckResponse("http://www.google.co.in/");
738 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 626 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
739 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 627 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
740 EXPECT_FALSE(listener_notified()); 628 EXPECT_FALSE(listener_notified());
741 } 629 }
742 630
743 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { 631 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) {
632 TestInfoBarManager infobar_manager(1);
744 RequestServerCheck(); 633 RequestServerCheck();
745 FinishSleep(); 634 FinishSleep();
746 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 635 MockSearchDomainCheckResponse("http://www.google.co.uk/");
747 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 636 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
748 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 637 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
749 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 638 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
750 EXPECT_TRUE(listener_notified()); 639 EXPECT_TRUE(listener_notified());
751 clear_listener_notified(); 640 clear_listener_notified();
752 641
753 SetNavigationPending(1, true); 642 SetNavigationPending(&infobar_manager, true);
754 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 643 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
755 EXPECT_TRUE(GetMapEntry(1) == NULL); 644 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
756 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 645 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
757 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); 646 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url());
758 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 647 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
759 EXPECT_FALSE(listener_notified()); 648 EXPECT_FALSE(listener_notified());
760 } 649 }
761 650
762 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { 651 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) {
652 TestInfoBarManager infobar_manager(1);
763 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 653 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
764 RequestServerCheck(); 654 RequestServerCheck();
765 FinishSleep(); 655 FinishSleep();
766 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 656 MockSearchDomainCheckResponse("http://www.google.co.jp/");
767 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 657 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
768 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); 658 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url());
769 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 659 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
770 EXPECT_FALSE(listener_notified()); 660 EXPECT_FALSE(listener_notified());
771 661
772 SetNavigationPending(1, true); 662 SetNavigationPending(&infobar_manager, true);
773 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); 663 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(&infobar_manager);
774 ASSERT_FALSE(map_entry == NULL); 664 ASSERT_FALSE(map_entry == NULL);
775 EXPECT_FALSE(map_entry->has_infobar_delegate()); 665 EXPECT_FALSE(map_entry->has_infobar_delegate());
776 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 666 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
777 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 667 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
778 EXPECT_FALSE(listener_notified()); 668 EXPECT_FALSE(listener_notified());
779 669
780 CloseTab(1); 670 CloseTab(&infobar_manager);
781 EXPECT_TRUE(GetMapEntry(1) == NULL); 671 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
782 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 672 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
783 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 673 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
784 EXPECT_FALSE(listener_notified()); 674 EXPECT_FALSE(listener_notified());
785 } 675 }
786 676
787 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { 677 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) {
678 TestInfoBarManager infobar_manager(1);
788 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 679 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
789 RequestServerCheck(); 680 RequestServerCheck();
790 FinishSleep(); 681 FinishSleep();
791 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 682 MockSearchDomainCheckResponse("http://www.google.co.jp/");
792 683
793 SetNavigationPending(1, true); 684 SetNavigationPending(&infobar_manager, true);
794 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 685 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
795 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 686 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
796 687
797 CloseTab(1); 688 CloseTab(&infobar_manager);
798 EXPECT_TRUE(GetMapEntry(1) == NULL); 689 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
799 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 690 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
800 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 691 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
801 EXPECT_FALSE(listener_notified()); 692 EXPECT_FALSE(listener_notified());
802 } 693 }
803 694
804 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { 695 TEST_F(GoogleURLTrackerTest, InfoBarClosed) {
696 TestInfoBarManager infobar_manager(1);
805 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 697 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
806 RequestServerCheck(); 698 RequestServerCheck();
807 FinishSleep(); 699 FinishSleep();
808 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 700 MockSearchDomainCheckResponse("http://www.google.co.jp/");
809 701
810 SetNavigationPending(1, true); 702 SetNavigationPending(&infobar_manager, true);
811 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 703 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
812 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); 704 GoogleURLTrackerInfoBarDelegate* infobar =
705 GetInfoBarDelegate(&infobar_manager);
813 ASSERT_FALSE(infobar == NULL); 706 ASSERT_FALSE(infobar == NULL);
814 707
815 infobar->Close(false); 708 infobar->Close(false);
816 EXPECT_TRUE(GetMapEntry(1) == NULL); 709 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
817 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 710 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
818 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 711 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
819 EXPECT_FALSE(listener_notified()); 712 EXPECT_FALSE(listener_notified());
820 } 713 }
821 714
822 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { 715 TEST_F(GoogleURLTrackerTest, InfoBarRefused) {
716 TestInfoBarManager infobar_manager(1);
823 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 717 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
824 RequestServerCheck(); 718 RequestServerCheck();
825 FinishSleep(); 719 FinishSleep();
826 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 720 MockSearchDomainCheckResponse("http://www.google.co.jp/");
827 721
828 SetNavigationPending(1, true); 722 SetNavigationPending(&infobar_manager, true);
829 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 723 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
830 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); 724 GoogleURLTrackerInfoBarDelegate* infobar =
725 GetInfoBarDelegate(&infobar_manager);
831 ASSERT_FALSE(infobar == NULL); 726 ASSERT_FALSE(infobar == NULL);
832 727
833 infobar->Cancel(); 728 infobar->Cancel();
834 EXPECT_TRUE(GetMapEntry(1) == NULL); 729 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
835 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 730 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
836 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 731 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
837 EXPECT_FALSE(listener_notified()); 732 EXPECT_FALSE(listener_notified());
838 } 733 }
839 734
840 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { 735 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) {
736 TestInfoBarManager infobar_manager(1);
841 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 737 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
842 RequestServerCheck(); 738 RequestServerCheck();
843 FinishSleep(); 739 FinishSleep();
844 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 740 MockSearchDomainCheckResponse("http://www.google.co.jp/");
845 741
846 SetNavigationPending(1, true); 742 SetNavigationPending(&infobar_manager, true);
847 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 743 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
848 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBarDelegate(1); 744 GoogleURLTrackerInfoBarDelegate* infobar =
745 GetInfoBarDelegate(&infobar_manager);
849 ASSERT_FALSE(infobar == NULL); 746 ASSERT_FALSE(infobar == NULL);
850 747
851 infobar->Accept(); 748 infobar->Accept();
852 EXPECT_TRUE(GetMapEntry(1) == NULL); 749 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
853 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); 750 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
854 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 751 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
855 EXPECT_TRUE(listener_notified()); 752 EXPECT_TRUE(listener_notified());
856 } 753 }
857 754
858 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { 755 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) {
756 TestInfoBarManager infobar_manager(1);
859 RequestServerCheck(); 757 RequestServerCheck();
860 FinishSleep(); 758 FinishSleep();
861 MockSearchDomainCheckResponse(google_url().spec()); 759 MockSearchDomainCheckResponse(google_url().spec());
862 760
863 // Re-fetching the accepted URL after showing an infobar for another URL 761 // Re-fetching the accepted URL after showing an infobar for another URL
864 // should close the infobar. 762 // should close the infobar.
865 NotifyIPAddressChanged(); 763 NotifyIPAddressChanged();
866 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 764 MockSearchDomainCheckResponse("http://www.google.co.uk/");
867 SetNavigationPending(1, true); 765 SetNavigationPending(&infobar_manager, true);
868 CommitSearch(1, GURL("http://www.google.com/search?q=test")); 766 CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test"));
869 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 767 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
870 NotifyIPAddressChanged(); 768 NotifyIPAddressChanged();
871 MockSearchDomainCheckResponse(google_url().spec()); 769 MockSearchDomainCheckResponse(google_url().spec());
872 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); 770 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL());
873 EXPECT_TRUE(GetMapEntry(1) == NULL); 771 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
874 772
875 // As should fetching a URL that differs from the accepted only by the scheme. 773 // As should fetching a URL that differs from the accepted only by the scheme.
876 NotifyIPAddressChanged(); 774 NotifyIPAddressChanged();
877 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 775 MockSearchDomainCheckResponse("http://www.google.co.uk/");
878 SetNavigationPending(1, true); 776 SetNavigationPending(&infobar_manager, true);
879 CommitSearch(1, GURL("http://www.google.com/search?q=test")); 777 CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test"));
880 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 778 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
881 NotifyIPAddressChanged(); 779 NotifyIPAddressChanged();
882 url::Replacements<char> replacements; 780 url::Replacements<char> replacements;
883 const std::string& scheme("https"); 781 const std::string& scheme("https");
884 replacements.SetScheme(scheme.data(), url::Component(0, scheme.length())); 782 replacements.SetScheme(scheme.data(), url::Component(0, scheme.length()));
885 GURL new_google_url(google_url().ReplaceComponents(replacements)); 783 GURL new_google_url(google_url().ReplaceComponents(replacements));
886 MockSearchDomainCheckResponse(new_google_url.spec()); 784 MockSearchDomainCheckResponse(new_google_url.spec());
887 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); 785 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL());
888 EXPECT_TRUE(GetMapEntry(1) == NULL); 786 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
889 787
890 // As should re-fetching the last prompted URL. 788 // As should re-fetching the last prompted URL.
891 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 789 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
892 NotifyIPAddressChanged(); 790 NotifyIPAddressChanged();
893 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 791 MockSearchDomainCheckResponse("http://www.google.co.jp/");
894 SetNavigationPending(1, true); 792 SetNavigationPending(&infobar_manager, true);
895 CommitSearch(1, GURL("http://www.google.com/search?q=test")); 793 CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test"));
896 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 794 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
897 NotifyIPAddressChanged(); 795 NotifyIPAddressChanged();
898 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 796 MockSearchDomainCheckResponse("http://www.google.co.uk/");
899 EXPECT_EQ(new_google_url, google_url()); 797 EXPECT_EQ(new_google_url, google_url());
900 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 798 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
901 EXPECT_TRUE(GetMapEntry(1) == NULL); 799 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
902 800
903 // And one that differs from the last prompted URL only by the scheme. 801 // And one that differs from the last prompted URL only by the scheme.
904 NotifyIPAddressChanged(); 802 NotifyIPAddressChanged();
905 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 803 MockSearchDomainCheckResponse("http://www.google.co.jp/");
906 SetNavigationPending(1, true); 804 SetNavigationPending(&infobar_manager, true);
907 CommitSearch(1, GURL("http://www.google.com/search?q=test")); 805 CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test"));
908 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 806 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
909 NotifyIPAddressChanged(); 807 NotifyIPAddressChanged();
910 MockSearchDomainCheckResponse("https://www.google.co.uk/"); 808 MockSearchDomainCheckResponse("https://www.google.co.uk/");
911 EXPECT_EQ(new_google_url, google_url()); 809 EXPECT_EQ(new_google_url, google_url());
912 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); 810 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
913 EXPECT_TRUE(GetMapEntry(1) == NULL); 811 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
914 812
915 // And fetching a different URL entirely. 813 // And fetching a different URL entirely.
916 NotifyIPAddressChanged(); 814 NotifyIPAddressChanged();
917 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 815 MockSearchDomainCheckResponse("http://www.google.co.jp/");
918 SetNavigationPending(1, true); 816 SetNavigationPending(&infobar_manager, true);
919 CommitSearch(1, GURL("http://www.google.com/search?q=test")); 817 CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test"));
920 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 818 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
921 NotifyIPAddressChanged(); 819 NotifyIPAddressChanged();
922 MockSearchDomainCheckResponse("https://www.google.co.in/"); 820 MockSearchDomainCheckResponse("https://www.google.co.in/");
923 EXPECT_EQ(new_google_url, google_url()); 821 EXPECT_EQ(new_google_url, google_url());
924 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); 822 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL());
925 EXPECT_TRUE(GetMapEntry(1) == NULL); 823 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
926 } 824 }
927 825
928 TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) { 826 TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) {
827 TestInfoBarManager infobar_manager(1);
929 RequestServerCheck(); 828 RequestServerCheck();
930 FinishSleep(); 829 FinishSleep();
931 MockSearchDomainCheckResponse(google_url().spec()); 830 MockSearchDomainCheckResponse(google_url().spec());
932 831
933 NotifyIPAddressChanged(); 832 NotifyIPAddressChanged();
934 MockSearchDomainCheckResponse("http://www.google.co.uk/"); 833 MockSearchDomainCheckResponse("http://www.google.co.uk/");
935 SetNavigationPending(1, true); 834 SetNavigationPending(&infobar_manager, true);
936 CommitSearch(1, GURL("http://www.google.com/search?q=test")); 835 CommitSearch(&infobar_manager, GURL("http://www.google.com/search?q=test"));
937 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); 836 GoogleURLTrackerInfoBarDelegate* delegate =
837 GetInfoBarDelegate(&infobar_manager);
938 ASSERT_FALSE(delegate == NULL); 838 ASSERT_FALSE(delegate == NULL);
939 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); 839 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url());
940 840
941 // If while an infobar is showing we fetch a new URL that differs from the 841 // If while an infobar is showing we fetch a new URL that differs from the
942 // infobar's only by scheme, the infobar should stay showing. 842 // infobar's only by scheme, the infobar should stay showing.
943 NotifyIPAddressChanged(); 843 NotifyIPAddressChanged();
944 MockSearchDomainCheckResponse("https://www.google.co.uk/"); 844 MockSearchDomainCheckResponse("https://www.google.co.uk/");
945 EXPECT_EQ(delegate, GetInfoBarDelegate(1)); 845 EXPECT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
946 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); 846 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url());
947 } 847 }
948 848
949 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { 849 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) {
850 TestInfoBarManager infobar_manager(1);
950 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 851 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
951 RequestServerCheck(); 852 RequestServerCheck();
952 FinishSleep(); 853 FinishSleep();
953 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 854 MockSearchDomainCheckResponse("http://www.google.co.jp/");
954 855
955 // A pending non-search after a pending search should delete the map entry. 856 // A pending non-search after a pending search should delete the map entry.
956 SetNavigationPending(1, true); 857 SetNavigationPending(&infobar_manager, true);
957 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); 858 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(&infobar_manager);
958 ASSERT_FALSE(map_entry == NULL); 859 ASSERT_FALSE(map_entry == NULL);
959 EXPECT_FALSE(map_entry->has_infobar_delegate()); 860 EXPECT_FALSE(map_entry->has_infobar_delegate());
960 SetNavigationPending(1, false); 861 SetNavigationPending(&infobar_manager, false);
961 EXPECT_TRUE(GetMapEntry(1) == NULL); 862 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
962 863
963 // A pending search after a pending search should leave the map entry alive. 864 // A pending search after a pending search should leave the map entry alive.
964 SetNavigationPending(1, true); 865 SetNavigationPending(&infobar_manager, true);
965 map_entry = GetMapEntry(1); 866 map_entry = GetMapEntry(&infobar_manager);
966 ASSERT_FALSE(map_entry == NULL); 867 ASSERT_FALSE(map_entry == NULL);
967 EXPECT_FALSE(map_entry->has_infobar_delegate()); 868 EXPECT_FALSE(map_entry->has_infobar_delegate());
968 SetNavigationPending(1, true); 869 SetNavigationPending(&infobar_manager, true);
969 ASSERT_EQ(map_entry, GetMapEntry(1)); 870 ASSERT_EQ(map_entry, GetMapEntry(&infobar_manager));
970 EXPECT_FALSE(map_entry->has_infobar_delegate()); 871 EXPECT_FALSE(map_entry->has_infobar_delegate());
971 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 872 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true));
972 873
973 // Committing this search should show an infobar. 874 // Committing this search should show an infobar.
974 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); 875 CommitSearch(&infobar_manager,
876 GURL("http://www.google.co.uk/search?q=test2"));
975 EXPECT_TRUE(map_entry->has_infobar_delegate()); 877 EXPECT_TRUE(map_entry->has_infobar_delegate());
976 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 878 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
977 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 879 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
978 EXPECT_FALSE(listener_notified()); 880 EXPECT_FALSE(listener_notified());
979 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 881 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
980 } 882 }
981 883
982 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { 884 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) {
885 TestInfoBarManager infobar_manager(1);
983 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 886 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
984 RequestServerCheck(); 887 RequestServerCheck();
985 FinishSleep(); 888 FinishSleep();
986 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 889 MockSearchDomainCheckResponse("http://www.google.co.jp/");
987 SetNavigationPending(1, true); 890 SetNavigationPending(&infobar_manager, true);
988 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 891 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
989 GoogleURLTrackerInfoBarDelegate* delegate = GetInfoBarDelegate(1); 892 GoogleURLTrackerInfoBarDelegate* delegate =
893 GetInfoBarDelegate(&infobar_manager);
990 ASSERT_FALSE(delegate == NULL); 894 ASSERT_FALSE(delegate == NULL);
991 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 895 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
992 896
993 // A pending non-search on a visible infobar should basically do nothing. 897 // A pending non-search on a visible infobar should basically do nothing.
994 SetNavigationPending(1, false); 898 SetNavigationPending(&infobar_manager, false);
995 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 899 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
996 EXPECT_EQ(0, delegate->pending_id()); 900 EXPECT_EQ(0, delegate->pending_id());
997 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 901 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
998 902
999 // As should another pending non-search after the first. 903 // As should another pending non-search after the first.
1000 SetNavigationPending(1, false); 904 SetNavigationPending(&infobar_manager, false);
1001 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 905 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
1002 EXPECT_EQ(0, delegate->pending_id()); 906 EXPECT_EQ(0, delegate->pending_id());
1003 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 907 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
1004 908
1005 // Committing this non-search should close the infobar. The control flow in 909 // Committing this non-search should close the infobar. The control flow in
1006 // these tests is not really comparable to in the real browser, but at least a 910 // these tests is not really comparable to in the real browser, but at least a
1007 // few sanity-checks will be performed. 911 // few sanity-checks will be performed.
1008 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); 912 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(&infobar_manager));
1009 EXPECT_TRUE(GetMapEntry(1) == NULL); 913 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
1010 914
1011 // A pending search on a visible infobar should cause the infobar to listen 915 // A pending search on a visible infobar should cause the infobar to listen
1012 // for the search to commit. 916 // for the search to commit.
1013 SetNavigationPending(1, true); 917 SetNavigationPending(&infobar_manager, true);
1014 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 918 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
1015 delegate = GetInfoBarDelegate(1); 919 delegate = GetInfoBarDelegate(&infobar_manager);
1016 ASSERT_FALSE(delegate == NULL); 920 ASSERT_FALSE(delegate == NULL);
1017 SetNavigationPending(1, true); 921 SetNavigationPending(&infobar_manager, true);
1018 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 922 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
1019 EXPECT_EQ(1, delegate->pending_id()); 923 EXPECT_EQ(1, delegate->pending_id());
1020 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 924 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true));
1021 925
1022 // But a non-search after this should cancel that state. 926 // But a non-search after this should cancel that state.
1023 SetNavigationPending(1, false); 927 SetNavigationPending(&infobar_manager, false);
1024 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 928 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
1025 EXPECT_EQ(0, delegate->pending_id()); 929 EXPECT_EQ(0, delegate->pending_id());
1026 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 930 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
1027 931
1028 // Another pending search after the non-search should put us back into 932 // Another pending search after the non-search should put us back into
1029 // "waiting for commit" mode. 933 // "waiting for commit" mode.
1030 SetNavigationPending(1, true); 934 SetNavigationPending(&infobar_manager, true);
1031 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 935 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
1032 EXPECT_EQ(1, delegate->pending_id()); 936 EXPECT_EQ(1, delegate->pending_id());
1033 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 937 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true));
1034 938
1035 // A second pending search after the first should not really change anything. 939 // A second pending search after the first should not really change anything.
1036 SetNavigationPending(1, true); 940 SetNavigationPending(&infobar_manager, true);
1037 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 941 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
1038 EXPECT_EQ(1, delegate->pending_id()); 942 EXPECT_EQ(1, delegate->pending_id());
1039 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 943 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true));
1040 944
1041 // Committing this search should change the visible infobar's search_url. 945 // Committing this search should change the visible infobar's search_url.
1042 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); 946 CommitSearch(&infobar_manager,
1043 ASSERT_EQ(delegate, GetInfoBarDelegate(1)); 947 GURL("http://www.google.co.uk/search?q=test2"));
948 ASSERT_EQ(delegate, GetInfoBarDelegate(&infobar_manager));
1044 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), 949 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
1045 delegate->search_url()); 950 delegate->search_url());
1046 EXPECT_EQ(0, delegate->pending_id()); 951 EXPECT_EQ(0, delegate->pending_id());
1047 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 952 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
1048 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); 953 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url());
1049 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); 954 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL());
1050 EXPECT_FALSE(listener_notified()); 955 EXPECT_FALSE(listener_notified());
1051 } 956 }
1052 957
1053 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { 958 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) {
959 TestInfoBarManager infobar_manager(1);
960 TestInfoBarManager infobar_manager2(2);
961 TestInfoBarManager infobar_manager3(3);
962 TestInfoBarManager infobar_manager4(4);
1054 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 963 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
1055 RequestServerCheck(); 964 RequestServerCheck();
1056 FinishSleep(); 965 FinishSleep();
1057 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 966 MockSearchDomainCheckResponse("http://www.google.co.jp/");
1058 967
1059 SetNavigationPending(1, true); 968 SetNavigationPending(&infobar_manager, true);
1060 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); 969 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(&infobar_manager);
1061 ASSERT_FALSE(map_entry == NULL); 970 ASSERT_FALSE(map_entry == NULL);
1062 EXPECT_FALSE(map_entry->has_infobar_delegate()); 971 EXPECT_FALSE(map_entry->has_infobar_delegate());
1063 972
1064 SetNavigationPending(2, true); 973 SetNavigationPending(&infobar_manager2, true);
1065 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); 974 CommitSearch(&infobar_manager2,
1066 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); 975 GURL("http://www.google.co.uk/search?q=test2"));
976 GoogleURLTrackerInfoBarDelegate* delegate2 =
977 GetInfoBarDelegate(&infobar_manager2);
1067 ASSERT_FALSE(delegate2 == NULL); 978 ASSERT_FALSE(delegate2 == NULL);
1068 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), 979 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"),
1069 delegate2->search_url()); 980 delegate2->search_url());
1070 981
1071 SetNavigationPending(3, true); 982 SetNavigationPending(&infobar_manager3, true);
1072 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3); 983 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(&infobar_manager3);
1073 ASSERT_FALSE(map_entry3 == NULL); 984 ASSERT_FALSE(map_entry3 == NULL);
1074 EXPECT_FALSE(map_entry3->has_infobar_delegate()); 985 EXPECT_FALSE(map_entry3->has_infobar_delegate());
1075 986
1076 SetNavigationPending(4, true); 987 SetNavigationPending(&infobar_manager4, true);
1077 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); 988 CommitSearch(&infobar_manager4,
1078 GoogleURLTrackerInfoBarDelegate* delegate4 = GetInfoBarDelegate(4); 989 GURL("http://www.google.co.uk/search?q=test4"));
990 GoogleURLTrackerInfoBarDelegate* delegate4 =
991 GetInfoBarDelegate(&infobar_manager4);
1079 ASSERT_FALSE(delegate4 == NULL); 992 ASSERT_FALSE(delegate4 == NULL);
1080 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), 993 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"),
1081 delegate4->search_url()); 994 delegate4->search_url());
1082 995
1083 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 996 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
1084 EXPECT_TRUE(map_entry->has_infobar_delegate()); 997 EXPECT_TRUE(map_entry->has_infobar_delegate());
1085 998
1086 delegate2->Close(false); 999 delegate2->Close(false);
1087 EXPECT_TRUE(GetMapEntry(2) == NULL); 1000 EXPECT_TRUE(GetMapEntry(&infobar_manager2) == NULL);
1088 EXPECT_FALSE(listener_notified()); 1001 EXPECT_FALSE(listener_notified());
1089 1002
1090 delegate4->Accept(); 1003 delegate4->Accept();
1091 EXPECT_TRUE(GetMapEntry(1) == NULL); 1004 EXPECT_TRUE(GetMapEntry(&infobar_manager) == NULL);
1092 EXPECT_TRUE(GetMapEntry(3) == NULL); 1005 EXPECT_TRUE(GetMapEntry(&infobar_manager3) == NULL);
1093 EXPECT_TRUE(GetMapEntry(4) == NULL); 1006 EXPECT_TRUE(GetMapEntry(&infobar_manager4) == NULL);
1094 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); 1007 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url());
1095 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); 1008 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL());
1096 EXPECT_TRUE(listener_notified()); 1009 EXPECT_TRUE(listener_notified());
1097 } 1010 }
1098 1011
1099 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { 1012 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) {
1013 TestInfoBarManager infobar_manager(1);
1014 TestInfoBarManager infobar_manager2(2);
1100 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); 1015 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/"));
1101 RequestServerCheck(); 1016 RequestServerCheck();
1102 FinishSleep(); 1017 FinishSleep();
1103 MockSearchDomainCheckResponse("http://www.google.co.jp/"); 1018 MockSearchDomainCheckResponse("http://www.google.co.jp/");
1104 1019
1105 // This tests a particularly gnarly sequence of events that used to cause us 1020 // This tests a particularly gnarly sequence of events that used to cause us
1106 // to erroneously listen for a non-search navigation to commit. 1021 // to erroneously listen for a non-search navigation to commit.
1107 SetNavigationPending(1, true); 1022 SetNavigationPending(&infobar_manager, true);
1108 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); 1023 CommitSearch(&infobar_manager, GURL("http://www.google.co.uk/search?q=test"));
1109 SetNavigationPending(2, true); 1024 SetNavigationPending(&infobar_manager2, true);
1110 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); 1025 CommitSearch(&infobar_manager2,
1111 EXPECT_FALSE(GetInfoBarDelegate(1) == NULL); 1026 GURL("http://www.google.co.uk/search?q=test2"));
1112 GoogleURLTrackerInfoBarDelegate* delegate2 = GetInfoBarDelegate(2); 1027 EXPECT_FALSE(GetInfoBarDelegate(&infobar_manager) == NULL);
1028 GoogleURLTrackerInfoBarDelegate* delegate2 =
1029 GetInfoBarDelegate(&infobar_manager2);
1113 ASSERT_FALSE(delegate2 == NULL); 1030 ASSERT_FALSE(delegate2 == NULL);
1114 SetNavigationPending(1, true); 1031 SetNavigationPending(&infobar_manager, true);
1115 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); 1032 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, true));
1116 delegate2->Close(false); 1033 delegate2->Close(false);
1117 SetNavigationPending(1, false); 1034 SetNavigationPending(&infobar_manager, false);
1118 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); 1035 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(&infobar_manager, false));
1119 } 1036 }
OLDNEW
« no previous file with comments | « chrome/browser/google/google_url_tracker_map_entry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698