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