OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/browser/api/infobars/infobar_delegate.h" | 11 #include "chrome/browser/api/infobars/infobar_delegate.h" |
12 #include "chrome/browser/google/google_url_tracker_factory.h" | 12 #include "chrome/browser/google/google_url_tracker_factory.h" |
13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" | 13 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h" |
14 #include "chrome/browser/infobars/infobar.h" | |
14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
20 #include "net/url_request/test_url_fetcher_factory.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
21 #include "net/url_request/url_fetcher.h" | 22 #include "net/url_request/url_fetcher.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
23 | 24 |
25 namespace { | |
26 | |
27 // TestInfoBarDelegate -------------------------------------------------------- | |
28 | |
29 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { | |
30 public: | |
31 TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, | |
Ilya Sherman
2012/10/17 00:32:41
nit: Seems like this should still need to be forwa
Peter Kasting
2012/10/17 00:34:28
Yeah, boo to MSVC for letting me get away without
| |
32 InfoBarTabHelper* infobar_helper, | |
33 GoogleURLTracker* google_url_tracker, | |
34 const GURL& search_url); | |
35 virtual ~TestInfoBarDelegate(); | |
36 | |
37 private: | |
38 // GoogleURLTrackerInfoBarDelegate: | |
39 virtual void Update(const GURL& search_url) OVERRIDE; | |
40 virtual void Close(bool redo_search) OVERRIDE; | |
41 | |
42 GoogleURLTrackerTest* test_harness_; | |
43 InfoBarTabHelper* infobar_helper_; | |
44 | |
45 DISALLOW_COPY_AND_ASSIGN(TestInfoBarDelegate); | |
46 }; | |
47 | |
48 // The member function definitions come after the declaration of | |
49 // GoogleURLTrackerTest, so they can call members on it. | |
50 | |
51 | |
24 // TestNotificationObserver --------------------------------------------------- | 52 // TestNotificationObserver --------------------------------------------------- |
25 | 53 |
26 namespace { | |
27 | |
28 class TestNotificationObserver : public content::NotificationObserver { | 54 class TestNotificationObserver : public content::NotificationObserver { |
29 public: | 55 public: |
30 TestNotificationObserver(); | 56 TestNotificationObserver(); |
31 virtual ~TestNotificationObserver(); | 57 virtual ~TestNotificationObserver(); |
32 | 58 |
33 virtual void Observe(int type, | 59 virtual void Observe(int type, |
34 const content::NotificationSource& source, | 60 const content::NotificationSource& source, |
35 const content::NotificationDetails& details); | 61 const content::NotificationDetails& details); |
36 bool notified() const { return notified_; } | 62 bool notified() const { return notified_; } |
37 void clear_notified() { notified_ = false; } | 63 void clear_notified() { notified_ = false; } |
38 | 64 |
39 private: | 65 private: |
40 bool notified_; | 66 bool notified_; |
41 }; | 67 }; |
42 | 68 |
43 TestNotificationObserver::TestNotificationObserver() : notified_(false) { | 69 TestNotificationObserver::TestNotificationObserver() : notified_(false) { |
44 } | 70 } |
45 | 71 |
46 TestNotificationObserver::~TestNotificationObserver() { | 72 TestNotificationObserver::~TestNotificationObserver() { |
47 } | 73 } |
48 | 74 |
49 void TestNotificationObserver::Observe( | 75 void TestNotificationObserver::Observe( |
50 int type, | 76 int type, |
51 const content::NotificationSource& source, | 77 const content::NotificationSource& source, |
52 const content::NotificationDetails& details) { | 78 const content::NotificationDetails& details) { |
53 notified_ = true; | 79 notified_ = true; |
54 } | 80 } |
55 | 81 |
56 | |
57 // TestInfoBarDelegate -------------------------------------------------------- | |
58 | |
59 class TestInfoBarDelegate : public GoogleURLTrackerInfoBarDelegate { | |
60 public: | |
61 TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, | |
62 GoogleURLTracker* google_url_tracker, | |
63 const GURL& new_google_url); | |
64 virtual ~TestInfoBarDelegate(); | |
65 | |
66 GURL search_url() const { return search_url_; } | |
67 GURL new_google_url() const { return new_google_url_; } | |
68 int pending_id() const { return pending_id_; } | |
69 | |
70 private: | |
71 // GoogleURLTrackerInfoBarDelegate: | |
72 virtual void Show(const GURL& search_url) OVERRIDE; | |
73 virtual void Close(bool redo_search) OVERRIDE; | |
74 }; | |
75 | |
76 TestInfoBarDelegate::TestInfoBarDelegate(InfoBarTabHelper* infobar_helper, | |
77 GoogleURLTracker* google_url_tracker, | |
78 const GURL& new_google_url) | |
79 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, new_google_url) { | |
80 // We set |map_key_| here instead of in the superclass constructor so that the | |
81 // InfoBarDelegate base class will not try to dereference it, which would fail | |
82 // since this is really a magic number and not an actual pointer. | |
83 map_key_ = infobar_helper; | |
84 } | |
85 | |
86 void TestInfoBarDelegate::Show(const GURL& search_url) { | |
87 search_url_ = search_url; | |
88 pending_id_ = 0; | |
89 showing_ = true; | |
90 } | |
91 | |
92 void TestInfoBarDelegate::Close(bool redo_search) { | |
93 InfoBarClosed(); | |
94 } | |
95 | |
96 TestInfoBarDelegate::~TestInfoBarDelegate() { | |
97 } | |
98 | |
99 GoogleURLTrackerInfoBarDelegate* CreateTestInfobar( | |
100 InfoBarTabHelper* infobar_helper, | |
101 GoogleURLTracker* google_url_tracker, | |
102 const GURL& new_google_url) { | |
103 return new TestInfoBarDelegate(infobar_helper, google_url_tracker, | |
104 new_google_url); | |
105 } | |
106 | |
107 } // namespace | 82 } // namespace |
108 | 83 |
109 | 84 |
110 // GoogleURLTrackerTest ------------------------------------------------------- | 85 // GoogleURLTrackerTest ------------------------------------------------------- |
111 | 86 |
87 // Ths class exercises GoogleURLTracker. In order to avoid instantiating more | |
88 // of the Chrome infrastructure than necessary, the GoogleURLTracker functions | |
89 // are carefully written so that many of the functions which take WebContents*, | |
90 // NavigationController*, InfoBarTabHelper*, or objects containing such pointers | |
91 // (e.g. NotificationSource) do not actually dereference the objects, merely use | |
92 // them for comparisons and lookups, e.g. in an InfoBarMap. This then allows | |
93 // the test code here to not create any of these objects, and instead supply | |
94 // "pointers" that are actually reinterpret_cast<>()ed magic numbers. Then we | |
95 // write the necessary stubs/hooks, here and in TestInfoBarDelegate above, to | |
96 // make everything continue to work. | |
97 // | |
98 // Technically, the C++98 spec defines the result of casting | |
99 // T* -> intptr_t -> T* to be an identity, but intptr_t -> T* -> intptr_t (what | |
100 // we use here) is "implementation-defined". Since I've never seen a compiler | |
101 // break this, though, and the result would simply be a failing test rather than | |
102 // a bug in Chrome, we'll use it anyway. | |
112 class GoogleURLTrackerTest : public testing::Test { | 103 class GoogleURLTrackerTest : public testing::Test { |
104 public: | |
105 // Called by TestInfoBarDelegate::Close(). | |
106 void OnInfoBarClosed(GoogleURLTrackerInfoBarDelegate* infobar, | |
107 InfoBarTabHelper* infobar_helper); | |
108 | |
113 protected: | 109 protected: |
114 GoogleURLTrackerTest(); | 110 GoogleURLTrackerTest(); |
115 virtual ~GoogleURLTrackerTest(); | 111 virtual ~GoogleURLTrackerTest(); |
116 | 112 |
117 // testing::Test | 113 // testing::Test |
118 virtual void SetUp(); | 114 virtual void SetUp() OVERRIDE; |
119 virtual void TearDown(); | 115 virtual void TearDown() OVERRIDE; |
120 | 116 |
121 net::TestURLFetcher* GetFetcher(); | 117 net::TestURLFetcher* GetFetcher(); |
122 void MockSearchDomainCheckResponse(const std::string& domain); | 118 void MockSearchDomainCheckResponse(const std::string& domain); |
123 void RequestServerCheck(); | 119 void RequestServerCheck(); |
124 void FinishSleep(); | 120 void FinishSleep(); |
125 void NotifyIPAddressChanged(); | 121 void NotifyIPAddressChanged(); |
126 GURL fetched_google_url() const { | 122 GURL fetched_google_url() const { |
127 return google_url_tracker_->fetched_google_url_; | 123 return google_url_tracker_->fetched_google_url(); |
128 } | 124 } |
129 void set_google_url(const GURL& url) { | 125 void set_google_url(const GURL& url) { |
130 google_url_tracker_->google_url_ = url; | 126 google_url_tracker_->google_url_ = url; |
131 } | 127 } |
132 GURL google_url() const { return google_url_tracker_->google_url_; } | 128 GURL google_url() const { return google_url_tracker_->google_url(); } |
133 void SetLastPromptedGoogleURL(const GURL& url); | 129 void SetLastPromptedGoogleURL(const GURL& url); |
134 GURL GetLastPromptedGoogleURL(); | 130 GURL GetLastPromptedGoogleURL(); |
135 void SetNavigationPending(int unique_id, bool is_search); | 131 void SetNavigationPending(intptr_t unique_id, bool is_search); |
136 void CommitNonSearch(int unique_id); | 132 void CommitNonSearch(intptr_t unique_id); |
137 void CommitSearch(int unique_id, const GURL& search_url); | 133 void CommitSearch(intptr_t unique_id, const GURL& search_url); |
138 void DoInstantNavigation(int unique_id, const GURL& search_url); | 134 void DoInstantNavigation(intptr_t unique_id, const GURL& search_url); |
139 void CloseTab(int unique_id); | 135 void CloseTab(intptr_t unique_id); |
140 TestInfoBarDelegate* GetInfoBar(int unique_id); | 136 GoogleURLTrackerMapEntry* GetMapEntry(intptr_t unique_id); |
137 GoogleURLTrackerInfoBarDelegate* GetInfoBar(intptr_t unique_id); | |
141 void ExpectDefaultURLs() const; | 138 void ExpectDefaultURLs() const; |
142 void ExpectListeningForCommit(int unique_id, bool listening) const; | 139 void ExpectListeningForCommit(intptr_t unique_id, bool listening); |
143 | 140 bool observer_notified() const { return observer_.notified(); } |
144 scoped_ptr<TestNotificationObserver> observer_; | 141 void clear_observer_notified() { observer_.clear_notified(); } |
145 | 142 |
146 private: | 143 private: |
144 // Since |infobar_helper| is really a magic number rather than an actual | |
145 // object, we don't add the created infobar to it. Instead we will simulate | |
146 // any helper<->infobar interaction necessary. The returned object will be | |
147 // cleaned up in CloseTab(). | |
148 GoogleURLTrackerInfoBarDelegate* CreateTestInfoBar( | |
149 InfoBarTabHelper* infobar_helper, | |
150 GoogleURLTracker* google_url_tracker, | |
151 const GURL& search_url); | |
152 | |
147 // These are required by the TestURLFetchers GoogleURLTracker will create (see | 153 // These are required by the TestURLFetchers GoogleURLTracker will create (see |
148 // test_url_fetcher_factory.h). | 154 // test_url_fetcher_factory.h). |
149 MessageLoop message_loop_; | 155 MessageLoop message_loop_; |
150 content::TestBrowserThread io_thread_; | 156 content::TestBrowserThread io_thread_; |
151 // Creating this allows us to call | 157 // Creating this allows us to call |
152 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). | 158 // net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(). |
153 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 159 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
154 net::TestURLFetcherFactory fetcher_factory_; | 160 net::TestURLFetcherFactory fetcher_factory_; |
155 content::NotificationRegistrar registrar_; | 161 content::NotificationRegistrar registrar_; |
162 TestNotificationObserver observer_; | |
156 TestingProfile profile_; | 163 TestingProfile profile_; |
157 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 164 scoped_ptr<GoogleURLTracker> google_url_tracker_; |
158 // This tracks the different "tabs" a test has "opened", so we can close them | 165 // This tracks the different "tabs" a test has "opened", so we can close them |
159 // properly before shutting down |google_url_tracker_|, which expects that. | 166 // properly before shutting down |google_url_tracker_|, which expects that. |
160 std::set<int> unique_ids_seen_; | 167 std::set<int> unique_ids_seen_; |
161 }; | 168 }; |
162 | 169 |
170 void GoogleURLTrackerTest::OnInfoBarClosed( | |
171 GoogleURLTrackerInfoBarDelegate* infobar, | |
172 InfoBarTabHelper* infobar_helper) { | |
173 // First, simulate the InfoBarTabHelper firing INFOBAR_REMOVED. | |
174 InfoBarRemovedDetails removed_details(infobar, false); | |
175 GoogleURLTracker::InfoBarMap::const_iterator i = | |
176 google_url_tracker_->infobar_map_.find(infobar_helper); | |
177 ASSERT_FALSE(i == google_url_tracker_->infobar_map_.end()); | |
178 GoogleURLTrackerMapEntry* map_entry = i->second; | |
179 ASSERT_EQ(infobar, map_entry->infobar()); | |
180 map_entry->Observe(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | |
181 content::Source<InfoBarTabHelper>(infobar_helper), | |
182 content::Details<InfoBarRemovedDetails>(&removed_details)); | |
183 | |
184 // Second, simulate the infobar container closing the infobar in response. | |
185 infobar->InfoBarClosed(); | |
186 } | |
187 | |
163 GoogleURLTrackerTest::GoogleURLTrackerTest() | 188 GoogleURLTrackerTest::GoogleURLTrackerTest() |
164 : observer_(new TestNotificationObserver), | 189 : message_loop_(MessageLoop::TYPE_IO), |
165 message_loop_(MessageLoop::TYPE_IO), | |
166 io_thread_(content::BrowserThread::IO, &message_loop_) { | 190 io_thread_(content::BrowserThread::IO, &message_loop_) { |
167 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); | 191 GoogleURLTrackerFactory::GetInstance()->RegisterUserPrefsOnProfile(&profile_); |
168 } | 192 } |
169 | 193 |
170 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 194 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
171 } | 195 } |
172 | 196 |
173 void GoogleURLTrackerTest::SetUp() { | 197 void GoogleURLTrackerTest::SetUp() { |
174 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 198 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
175 google_url_tracker_.reset( | 199 google_url_tracker_.reset( |
176 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); | 200 new GoogleURLTracker(&profile_, GoogleURLTracker::UNIT_TEST_MODE)); |
177 google_url_tracker_->infobar_creator_ = &CreateTestInfobar; | 201 google_url_tracker_->infobar_creator_ = base::Bind( |
202 &GoogleURLTrackerTest::CreateTestInfoBar, base::Unretained(this)); | |
178 } | 203 } |
179 | 204 |
180 void GoogleURLTrackerTest::TearDown() { | 205 void GoogleURLTrackerTest::TearDown() { |
181 while (!unique_ids_seen_.empty()) | 206 while (!unique_ids_seen_.empty()) |
182 CloseTab(*unique_ids_seen_.begin()); | 207 CloseTab(*unique_ids_seen_.begin()); |
183 | 208 |
184 google_url_tracker_.reset(); | 209 google_url_tracker_.reset(); |
185 network_change_notifier_.reset(); | 210 network_change_notifier_.reset(); |
186 } | 211 } |
187 | 212 |
(...skipping 10 matching lines...) Expand all Loading... | |
198 return; | 223 return; |
199 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); | 224 fetcher_factory_.RemoveFetcherFromMap(fetcher->id()); |
200 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); | 225 fetcher->set_url(GURL(GoogleURLTracker::kSearchDomainCheckURL)); |
201 fetcher->set_response_code(200); | 226 fetcher->set_response_code(200); |
202 fetcher->SetResponseString(domain); | 227 fetcher->SetResponseString(domain); |
203 fetcher->delegate()->OnURLFetchComplete(fetcher); | 228 fetcher->delegate()->OnURLFetchComplete(fetcher); |
204 // At this point, |fetcher| is deleted. | 229 // At this point, |fetcher| is deleted. |
205 } | 230 } |
206 | 231 |
207 void GoogleURLTrackerTest::RequestServerCheck() { | 232 void GoogleURLTrackerTest::RequestServerCheck() { |
208 if (!registrar_.IsRegistered(observer_.get(), | 233 if (!registrar_.IsRegistered(&observer_, |
209 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 234 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
210 content::Source<Profile>(&profile_))) { | 235 content::Source<Profile>(&profile_))) { |
211 registrar_.Add(observer_.get(), chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 236 registrar_.Add(&observer_, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
212 content::Source<Profile>(&profile_)); | 237 content::Source<Profile>(&profile_)); |
213 } | 238 } |
214 google_url_tracker_->SetNeedToFetch(); | 239 google_url_tracker_->SetNeedToFetch(); |
215 } | 240 } |
216 | 241 |
217 void GoogleURLTrackerTest::FinishSleep() { | 242 void GoogleURLTrackerTest::FinishSleep() { |
218 google_url_tracker_->FinishSleep(); | 243 google_url_tracker_->FinishSleep(); |
219 } | 244 } |
220 | 245 |
221 void GoogleURLTrackerTest::NotifyIPAddressChanged() { | 246 void GoogleURLTrackerTest::NotifyIPAddressChanged() { |
222 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 247 net::NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
223 // For thread safety, the NCN queues tasks to do the actual notifications, so | 248 // For thread safety, the NCN queues tasks to do the actual notifications, so |
224 // we need to spin the message loop so the tracker will actually be notified. | 249 // we need to spin the message loop so the tracker will actually be notified. |
225 MessageLoop::current()->RunAllPending(); | 250 MessageLoop::current()->RunAllPending(); |
226 } | 251 } |
227 | 252 |
228 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { | 253 void GoogleURLTrackerTest::SetLastPromptedGoogleURL(const GURL& url) { |
229 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); | 254 profile_.GetPrefs()->SetString(prefs::kLastPromptedGoogleURL, url.spec()); |
230 } | 255 } |
231 | 256 |
232 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { | 257 GURL GoogleURLTrackerTest::GetLastPromptedGoogleURL() { |
233 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); | 258 return GURL(profile_.GetPrefs()->GetString(prefs::kLastPromptedGoogleURL)); |
234 } | 259 } |
235 | 260 |
236 void GoogleURLTrackerTest::SetNavigationPending(int unique_id, bool is_search) { | 261 void GoogleURLTrackerTest::SetNavigationPending(intptr_t unique_id, |
262 bool is_search) { | |
237 if (is_search) { | 263 if (is_search) { |
238 google_url_tracker_->SearchCommitted(); | 264 google_url_tracker_->SearchCommitted(); |
239 // Note that the call above might not have actually registered a listener | 265 // Note that the call above might not have actually registered a listener |
240 // for NOTIFICATION_NAV_ENTRY_PENDING if the searchdomaincheck response was | 266 // for NOTIFICATION_NAV_ENTRY_PENDING if the searchdomaincheck response was |
241 // bogus. | 267 // bogus. |
242 } | 268 } |
243 unique_ids_seen_.insert(unique_id); | 269 unique_ids_seen_.insert(unique_id); |
244 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 270 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
245 content::NOTIFICATION_NAV_ENTRY_PENDING, | 271 content::NOTIFICATION_NAV_ENTRY_PENDING, |
246 content::NotificationService::AllBrowserContextsAndSources())) { | 272 content::NotificationService::AllBrowserContextsAndSources())) { |
247 google_url_tracker_->OnNavigationPending( | 273 google_url_tracker_->OnNavigationPending( |
248 content::Source<content::NavigationController>( | 274 content::Source<content::NavigationController>( |
249 reinterpret_cast<content::NavigationController*>(unique_id)), | 275 reinterpret_cast<content::NavigationController*>(unique_id)), |
250 content::Source<content::WebContents>( | 276 content::Source<content::WebContents>( |
251 reinterpret_cast<content::WebContents*>(unique_id)), | 277 reinterpret_cast<content::WebContents*>(unique_id)), |
252 reinterpret_cast<InfoBarTabHelper*>(unique_id), unique_id); | 278 reinterpret_cast<InfoBarTabHelper*>(unique_id), unique_id); |
253 } | 279 } |
254 } | 280 } |
255 | 281 |
256 void GoogleURLTrackerTest::CommitNonSearch(int unique_id) { | 282 void GoogleURLTrackerTest::CommitNonSearch(intptr_t unique_id) { |
257 GoogleURLTracker::InfoBarMap::iterator i = | 283 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
258 google_url_tracker_->infobar_map_.find( | 284 if (!map_entry) |
259 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 285 return; |
260 if (i != google_url_tracker_->infobar_map_.end()) { | 286 |
261 ExpectListeningForCommit(unique_id, false); | 287 ExpectListeningForCommit(unique_id, false); |
262 TestInfoBarDelegate* infobar = | 288 |
263 static_cast<TestInfoBarDelegate*>(i->second.infobar); | 289 // The infobar should be showing; otherwise the pending non-search should |
264 // The infobar should be showing; otherwise the pending non-search should | 290 // have closed it. |
265 // have closed it. | 291 ASSERT_TRUE(map_entry->has_infobar()); |
266 EXPECT_TRUE(infobar->showing()); | 292 |
267 // The pending_id should have been reset to 0 when the non-search became | 293 // The pending_id should have been reset to 0 when the non-search became |
268 // pending. | 294 // pending. |
269 EXPECT_EQ(0, infobar->pending_id()); | 295 EXPECT_EQ(0, map_entry->infobar()->pending_id()); |
270 infobar->InfoBarClosed(); | 296 |
271 } | 297 // Committing the navigation would close the infobar. |
298 map_entry->infobar()->Close(false); | |
272 } | 299 } |
273 | 300 |
274 void GoogleURLTrackerTest::CommitSearch(int unique_id, const GURL& search_url) { | 301 void GoogleURLTrackerTest::CommitSearch(intptr_t unique_id, |
302 const GURL& search_url) { | |
275 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 303 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
276 content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 304 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
277 content::Source<content::NavigationController>( | 305 content::Source<content::NavigationController>( |
278 reinterpret_cast<content::NavigationController*>(unique_id)))) { | 306 reinterpret_cast<content::NavigationController*>(unique_id)))) { |
279 google_url_tracker_->OnNavigationCommittedOrTabClosed( | 307 google_url_tracker_->OnNavigationCommittedOrTabClosed( |
280 reinterpret_cast<InfoBarTabHelper*>(unique_id), | 308 reinterpret_cast<InfoBarTabHelper*>(unique_id), |
281 search_url); | 309 search_url); |
282 } | 310 } |
283 } | 311 } |
284 | 312 |
285 void GoogleURLTrackerTest::DoInstantNavigation(int unique_id, | 313 void GoogleURLTrackerTest::DoInstantNavigation(intptr_t unique_id, |
286 const GURL& search_url) { | 314 const GURL& search_url) { |
287 if (!search_url.is_empty()) { | 315 if (!search_url.is_empty()) { |
288 google_url_tracker_->SearchCommitted(); | 316 google_url_tracker_->SearchCommitted(); |
289 // Note that the call above might not have actually registered a listener | 317 // Note that the call above might not have actually registered a listener |
290 // for NOTIFICATION_INSTANT_COMMITTED if the searchdomaincheck response was | 318 // for NOTIFICATION_INSTANT_COMMITTED if the searchdomaincheck response was |
291 // bogus. | 319 // bogus. |
292 } | 320 } |
293 unique_ids_seen_.insert(unique_id); | 321 unique_ids_seen_.insert(unique_id); |
294 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), | 322 if (google_url_tracker_->registrar_.IsRegistered(google_url_tracker_.get(), |
295 chrome::NOTIFICATION_INSTANT_COMMITTED, | 323 chrome::NOTIFICATION_INSTANT_COMMITTED, |
296 content::NotificationService::AllBrowserContextsAndSources())) { | 324 content::NotificationService::AllBrowserContextsAndSources())) { |
297 google_url_tracker_->OnInstantCommitted( | 325 google_url_tracker_->OnInstantCommitted( |
298 content::Source<content::NavigationController>( | 326 content::Source<content::NavigationController>( |
299 reinterpret_cast<content::NavigationController*>(unique_id)), | 327 reinterpret_cast<content::NavigationController*>(unique_id)), |
300 content::Source<content::WebContents>( | 328 content::Source<content::WebContents>( |
301 reinterpret_cast<content::WebContents*>(unique_id)), | 329 reinterpret_cast<content::WebContents*>(unique_id)), |
302 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); | 330 reinterpret_cast<InfoBarTabHelper*>(unique_id), search_url); |
303 } | 331 } |
304 } | 332 } |
305 | 333 |
306 void GoogleURLTrackerTest::CloseTab(int unique_id) { | 334 void GoogleURLTrackerTest::CloseTab(intptr_t unique_id) { |
307 unique_ids_seen_.erase(unique_id); | 335 unique_ids_seen_.erase(unique_id); |
308 InfoBarTabHelper* infobar_helper = | 336 InfoBarTabHelper* infobar_helper = |
309 reinterpret_cast<InfoBarTabHelper*>(unique_id); | 337 reinterpret_cast<InfoBarTabHelper*>(unique_id); |
310 if (google_url_tracker_->registrar_.IsRegistered( | 338 if (google_url_tracker_->registrar_.IsRegistered( |
311 google_url_tracker_.get(), | 339 google_url_tracker_.get(), content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
312 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 340 content::Source<content::WebContents>( |
313 content::Source<content::WebContents>( | 341 reinterpret_cast<content::WebContents*>(unique_id)))) { |
314 reinterpret_cast<content::WebContents*>(unique_id)))) { | |
315 google_url_tracker_->OnNavigationCommittedOrTabClosed(infobar_helper, | 342 google_url_tracker_->OnNavigationCommittedOrTabClosed(infobar_helper, |
316 GURL()); | 343 GURL()); |
317 } else { | 344 } else { |
318 // Normally, closing a tab with an infobar showing will close the infobar. | 345 // Closing a tab with an infobar showing would close the infobar. |
319 // Since we don't have real tabs and are just faking things with magic | 346 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(unique_id); |
320 // numbers, we have to manually close the infobar, if any. | 347 if (infobar) |
321 GoogleURLTracker::InfoBarMap::iterator i = | 348 infobar->Close(false); |
322 google_url_tracker_->infobar_map_.find(infobar_helper); | |
323 if (i != google_url_tracker_->infobar_map_.end()) { | |
324 TestInfoBarDelegate* infobar = | |
325 static_cast<TestInfoBarDelegate*>(i->second.infobar); | |
326 EXPECT_TRUE(infobar->showing()); | |
327 infobar->InfoBarClosed(); | |
328 } | |
329 } | 349 } |
330 } | 350 } |
331 | 351 |
332 TestInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar(int unique_id) { | 352 GoogleURLTrackerMapEntry* GoogleURLTrackerTest::GetMapEntry( |
353 intptr_t unique_id) { | |
333 GoogleURLTracker::InfoBarMap::const_iterator i = | 354 GoogleURLTracker::InfoBarMap::const_iterator i = |
334 google_url_tracker_->infobar_map_.find( | 355 google_url_tracker_->infobar_map_.find( |
335 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 356 reinterpret_cast<InfoBarTabHelper*>(unique_id)); |
336 return (i == google_url_tracker_->infobar_map_.end()) ? | 357 return (i == google_url_tracker_->infobar_map_.end()) ? NULL : i->second; |
337 NULL : static_cast<TestInfoBarDelegate*>(i->second.infobar); | 358 } |
359 | |
360 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::GetInfoBar( | |
361 intptr_t unique_id) { | |
362 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); | |
363 return map_entry ? map_entry->infobar() : NULL; | |
338 } | 364 } |
339 | 365 |
340 void GoogleURLTrackerTest::ExpectDefaultURLs() const { | 366 void GoogleURLTrackerTest::ExpectDefaultURLs() const { |
341 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 367 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
342 EXPECT_EQ(GURL(), fetched_google_url()); | 368 EXPECT_EQ(GURL(), fetched_google_url()); |
343 } | 369 } |
344 | 370 |
345 void GoogleURLTrackerTest::ExpectListeningForCommit(int unique_id, | 371 void GoogleURLTrackerTest::ExpectListeningForCommit(intptr_t unique_id, |
346 bool listening) const { | 372 bool listening) { |
347 GoogleURLTracker::InfoBarMap::iterator i = | 373 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(unique_id); |
348 google_url_tracker_->infobar_map_.find( | 374 if (map_entry) { |
349 reinterpret_cast<InfoBarTabHelper*>(unique_id)); | 375 EXPECT_EQ(listening, google_url_tracker_->registrar_.IsRegistered( |
350 if (i == google_url_tracker_->infobar_map_.end()) { | 376 google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
377 map_entry->navigation_controller_source())); | |
378 } else { | |
351 EXPECT_FALSE(listening); | 379 EXPECT_FALSE(listening); |
352 return; | |
353 } | 380 } |
354 EXPECT_EQ(listening, google_url_tracker_->registrar_.IsRegistered( | |
355 google_url_tracker_.get(), content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
356 i->second.navigation_controller_source)); | |
357 } | 381 } |
358 | 382 |
383 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerTest::CreateTestInfoBar( | |
384 InfoBarTabHelper* infobar_helper, | |
385 GoogleURLTracker* google_url_tracker, | |
386 const GURL& search_url) { | |
387 return new TestInfoBarDelegate(this, infobar_helper, google_url_tracker, | |
388 search_url); | |
389 } | |
390 | |
391 | |
392 // TestInfoBarDelegate -------------------------------------------------------- | |
393 | |
394 namespace { | |
395 | |
396 TestInfoBarDelegate::TestInfoBarDelegate(GoogleURLTrackerTest* test_harness, | |
397 InfoBarTabHelper* infobar_helper, | |
398 GoogleURLTracker* google_url_tracker, | |
399 const GURL& search_url) | |
400 : GoogleURLTrackerInfoBarDelegate(NULL, google_url_tracker, search_url), | |
401 test_harness_(test_harness), | |
402 infobar_helper_(infobar_helper) { | |
403 } | |
404 | |
405 TestInfoBarDelegate::~TestInfoBarDelegate() { | |
406 } | |
407 | |
408 void TestInfoBarDelegate::Update(const GURL& search_url) { | |
409 set_search_url(search_url); | |
410 set_pending_id(0); | |
411 } | |
412 | |
413 void TestInfoBarDelegate::Close(bool redo_search) { | |
414 test_harness_->OnInfoBarClosed(this, infobar_helper_); | |
415 } | |
416 | |
417 } // namespace | |
418 | |
359 | 419 |
360 // Tests ---------------------------------------------------------------------- | 420 // Tests ---------------------------------------------------------------------- |
361 | 421 |
362 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 422 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
363 ExpectDefaultURLs(); | 423 ExpectDefaultURLs(); |
364 FinishSleep(); | 424 FinishSleep(); |
365 // No one called RequestServerCheck() so nothing should have happened. | 425 // No one called RequestServerCheck() so nothing should have happened. |
366 EXPECT_FALSE(GetFetcher()); | 426 EXPECT_FALSE(GetFetcher()); |
367 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 427 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
368 ExpectDefaultURLs(); | 428 ExpectDefaultURLs(); |
369 EXPECT_FALSE(observer_->notified()); | 429 EXPECT_FALSE(observer_notified()); |
370 } | 430 } |
371 | 431 |
372 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { | 432 TEST_F(GoogleURLTrackerTest, UpdateOnFirstRun) { |
373 RequestServerCheck(); | 433 RequestServerCheck(); |
374 EXPECT_FALSE(GetFetcher()); | 434 EXPECT_FALSE(GetFetcher()); |
375 ExpectDefaultURLs(); | 435 ExpectDefaultURLs(); |
376 EXPECT_FALSE(observer_->notified()); | 436 EXPECT_FALSE(observer_notified()); |
377 | 437 |
378 FinishSleep(); | 438 FinishSleep(); |
379 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 439 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
380 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 440 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
381 // GoogleURL should be updated, becase there was no last prompted URL. | 441 // GoogleURL should be updated, becase there was no last prompted URL. |
382 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 442 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
383 EXPECT_TRUE(observer_->notified()); | 443 EXPECT_TRUE(observer_notified()); |
384 } | 444 } |
385 | 445 |
386 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { | 446 TEST_F(GoogleURLTrackerTest, DontUpdateWhenUnchanged) { |
387 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 447 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
388 | 448 |
389 RequestServerCheck(); | 449 RequestServerCheck(); |
390 EXPECT_FALSE(GetFetcher()); | 450 EXPECT_FALSE(GetFetcher()); |
391 ExpectDefaultURLs(); | 451 ExpectDefaultURLs(); |
392 EXPECT_FALSE(observer_->notified()); | 452 EXPECT_FALSE(observer_notified()); |
393 | 453 |
394 FinishSleep(); | 454 FinishSleep(); |
395 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 455 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
396 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 456 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
397 // GoogleURL should not be updated, because the fetched and prompted URLs | 457 // GoogleURL should not be updated, because the fetched and prompted URLs |
398 // match. | 458 // match. |
399 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 459 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
400 EXPECT_FALSE(observer_->notified()); | 460 EXPECT_FALSE(observer_notified()); |
401 } | 461 } |
402 | 462 |
403 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { | 463 TEST_F(GoogleURLTrackerTest, DontPromptOnBadReplies) { |
404 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 464 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
405 | 465 |
406 RequestServerCheck(); | 466 RequestServerCheck(); |
407 EXPECT_FALSE(GetFetcher()); | 467 EXPECT_FALSE(GetFetcher()); |
408 ExpectDefaultURLs(); | 468 ExpectDefaultURLs(); |
409 EXPECT_FALSE(observer_->notified()); | 469 EXPECT_FALSE(observer_notified()); |
410 | 470 |
411 // Old-style domain string. | 471 // Old-style domain string. |
412 FinishSleep(); | 472 FinishSleep(); |
413 MockSearchDomainCheckResponse(".google.co.in"); | 473 MockSearchDomainCheckResponse(".google.co.in"); |
414 EXPECT_EQ(GURL(), fetched_google_url()); | 474 EXPECT_EQ(GURL(), fetched_google_url()); |
415 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 475 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
416 EXPECT_FALSE(observer_->notified()); | 476 EXPECT_FALSE(observer_notified()); |
417 SetNavigationPending(1, true); | 477 SetNavigationPending(1, true); |
418 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 478 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
419 EXPECT_TRUE(GetInfoBar(1) == NULL); | 479 EXPECT_TRUE(GetMapEntry(1) == NULL); |
420 | 480 |
421 // Bad subdomain. | 481 // Bad subdomain. |
422 NotifyIPAddressChanged(); | 482 NotifyIPAddressChanged(); |
423 MockSearchDomainCheckResponse("http://mail.google.com/"); | 483 MockSearchDomainCheckResponse("http://mail.google.com/"); |
424 EXPECT_EQ(GURL(), fetched_google_url()); | 484 EXPECT_EQ(GURL(), fetched_google_url()); |
425 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 485 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
426 EXPECT_FALSE(observer_->notified()); | 486 EXPECT_FALSE(observer_notified()); |
427 SetNavigationPending(1, true); | 487 SetNavigationPending(1, true); |
428 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 488 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
429 EXPECT_TRUE(GetInfoBar(1) == NULL); | 489 EXPECT_TRUE(GetMapEntry(1) == NULL); |
430 | 490 |
431 // Non-empty path. | 491 // Non-empty path. |
432 NotifyIPAddressChanged(); | 492 NotifyIPAddressChanged(); |
433 MockSearchDomainCheckResponse("http://www.google.com/search"); | 493 MockSearchDomainCheckResponse("http://www.google.com/search"); |
434 EXPECT_EQ(GURL(), fetched_google_url()); | 494 EXPECT_EQ(GURL(), fetched_google_url()); |
435 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 495 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
436 EXPECT_FALSE(observer_->notified()); | 496 EXPECT_FALSE(observer_notified()); |
437 SetNavigationPending(1, true); | 497 SetNavigationPending(1, true); |
438 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 498 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
439 EXPECT_TRUE(GetInfoBar(1) == NULL); | 499 EXPECT_TRUE(GetMapEntry(1) == NULL); |
440 | 500 |
441 // Non-empty query. | 501 // Non-empty query. |
442 NotifyIPAddressChanged(); | 502 NotifyIPAddressChanged(); |
443 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); | 503 MockSearchDomainCheckResponse("http://www.google.com/?q=foo"); |
444 EXPECT_EQ(GURL(), fetched_google_url()); | 504 EXPECT_EQ(GURL(), fetched_google_url()); |
445 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 505 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
446 EXPECT_FALSE(observer_->notified()); | 506 EXPECT_FALSE(observer_notified()); |
447 SetNavigationPending(1, true); | 507 SetNavigationPending(1, true); |
448 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 508 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
449 EXPECT_TRUE(GetInfoBar(1) == NULL); | 509 EXPECT_TRUE(GetMapEntry(1) == NULL); |
450 | 510 |
451 // Non-empty ref. | 511 // Non-empty ref. |
452 NotifyIPAddressChanged(); | 512 NotifyIPAddressChanged(); |
453 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); | 513 MockSearchDomainCheckResponse("http://www.google.com/#anchor"); |
454 EXPECT_EQ(GURL(), fetched_google_url()); | 514 EXPECT_EQ(GURL(), fetched_google_url()); |
455 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 515 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
456 EXPECT_FALSE(observer_->notified()); | 516 EXPECT_FALSE(observer_notified()); |
457 SetNavigationPending(1, true); | 517 SetNavigationPending(1, true); |
458 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 518 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
459 EXPECT_TRUE(GetInfoBar(1) == NULL); | 519 EXPECT_TRUE(GetMapEntry(1) == NULL); |
460 | 520 |
461 // Complete garbage. | 521 // Complete garbage. |
462 NotifyIPAddressChanged(); | 522 NotifyIPAddressChanged(); |
463 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); | 523 MockSearchDomainCheckResponse("HJ)*qF)_*&@f1"); |
464 EXPECT_EQ(GURL(), fetched_google_url()); | 524 EXPECT_EQ(GURL(), fetched_google_url()); |
465 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 525 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
466 EXPECT_FALSE(observer_->notified()); | 526 EXPECT_FALSE(observer_notified()); |
467 SetNavigationPending(1, true); | 527 SetNavigationPending(1, true); |
468 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 528 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
469 EXPECT_TRUE(GetInfoBar(1) == NULL); | 529 EXPECT_TRUE(GetMapEntry(1) == NULL); |
470 } | 530 } |
471 | 531 |
472 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { | 532 TEST_F(GoogleURLTrackerTest, UpdatePromptedURLOnReturnToPreviousLocation) { |
473 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 533 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
474 set_google_url(GURL("http://www.google.co.uk/")); | 534 set_google_url(GURL("http://www.google.co.uk/")); |
475 RequestServerCheck(); | 535 RequestServerCheck(); |
476 FinishSleep(); | 536 FinishSleep(); |
477 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 537 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
478 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 538 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
479 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 539 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
480 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 540 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
481 EXPECT_FALSE(observer_->notified()); | 541 EXPECT_FALSE(observer_notified()); |
482 } | 542 } |
483 | 543 |
484 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { | 544 TEST_F(GoogleURLTrackerTest, SilentlyAcceptSchemeChange) { |
485 // We should auto-accept changes to the current Google URL that merely change | 545 // We should auto-accept changes to the current Google URL that merely change |
486 // the scheme, regardless of what the last prompted URL was. | 546 // the scheme, regardless of what the last prompted URL was. |
487 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); | 547 SetLastPromptedGoogleURL(GURL("http://www.google.co.jp/")); |
488 set_google_url(GURL("http://www.google.co.uk/")); | 548 set_google_url(GURL("http://www.google.co.uk/")); |
489 RequestServerCheck(); | 549 RequestServerCheck(); |
490 FinishSleep(); | 550 FinishSleep(); |
491 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 551 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
492 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); | 552 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
493 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 553 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
494 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 554 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
495 EXPECT_TRUE(observer_->notified()); | 555 EXPECT_TRUE(observer_notified()); |
496 | 556 |
497 NotifyIPAddressChanged(); | 557 NotifyIPAddressChanged(); |
498 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 558 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
499 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 559 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
500 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 560 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
501 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 561 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
502 EXPECT_TRUE(observer_->notified()); | 562 EXPECT_TRUE(observer_notified()); |
503 } | 563 } |
504 | 564 |
505 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { | 565 TEST_F(GoogleURLTrackerTest, RefetchOnIPAddressChange) { |
506 RequestServerCheck(); | 566 RequestServerCheck(); |
507 FinishSleep(); | 567 FinishSleep(); |
508 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 568 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
509 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 569 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
510 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 570 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
511 EXPECT_TRUE(observer_->notified()); | 571 EXPECT_TRUE(observer_notified()); |
512 observer_->clear_notified(); | 572 clear_observer_notified(); |
513 | 573 |
514 NotifyIPAddressChanged(); | 574 NotifyIPAddressChanged(); |
515 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 575 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
516 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); | 576 EXPECT_EQ(GURL("http://www.google.co.in/"), fetched_google_url()); |
517 // Just fetching a new URL shouldn't reset things without a prompt. | 577 // Just fetching a new URL shouldn't reset things without a prompt. |
518 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 578 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
519 EXPECT_FALSE(observer_->notified()); | 579 EXPECT_FALSE(observer_notified()); |
520 } | 580 } |
521 | 581 |
522 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { | 582 TEST_F(GoogleURLTrackerTest, DontRefetchWhenNoOneRequestsCheck) { |
523 FinishSleep(); | 583 FinishSleep(); |
524 NotifyIPAddressChanged(); | 584 NotifyIPAddressChanged(); |
525 // No one called RequestServerCheck() so nothing should have happened. | 585 // No one called RequestServerCheck() so nothing should have happened. |
526 EXPECT_FALSE(GetFetcher()); | 586 EXPECT_FALSE(GetFetcher()); |
527 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 587 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
528 ExpectDefaultURLs(); | 588 ExpectDefaultURLs(); |
529 EXPECT_FALSE(observer_->notified()); | 589 EXPECT_FALSE(observer_notified()); |
530 } | 590 } |
531 | 591 |
532 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { | 592 TEST_F(GoogleURLTrackerTest, FetchOnLateRequest) { |
533 FinishSleep(); | 593 FinishSleep(); |
534 NotifyIPAddressChanged(); | 594 NotifyIPAddressChanged(); |
535 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 595 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
536 | 596 |
537 RequestServerCheck(); | 597 RequestServerCheck(); |
538 // The first request for a check should trigger a fetch if it hasn't happened | 598 // The first request for a check should trigger a fetch if it hasn't happened |
539 // already. | 599 // already. |
540 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 600 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
541 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 601 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
542 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 602 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
543 EXPECT_TRUE(observer_->notified()); | 603 EXPECT_TRUE(observer_notified()); |
544 } | 604 } |
545 | 605 |
546 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { | 606 TEST_F(GoogleURLTrackerTest, DontFetchTwiceOnLateRequests) { |
547 FinishSleep(); | 607 FinishSleep(); |
548 NotifyIPAddressChanged(); | 608 NotifyIPAddressChanged(); |
549 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 609 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
550 | 610 |
551 RequestServerCheck(); | 611 RequestServerCheck(); |
552 // The first request for a check should trigger a fetch if it hasn't happened | 612 // The first request for a check should trigger a fetch if it hasn't happened |
553 // already. | 613 // already. |
554 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 614 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
555 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 615 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
556 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 616 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
557 EXPECT_TRUE(observer_->notified()); | 617 EXPECT_TRUE(observer_notified()); |
558 observer_->clear_notified(); | 618 clear_observer_notified(); |
559 | 619 |
560 RequestServerCheck(); | 620 RequestServerCheck(); |
561 // The second request should be ignored. | 621 // The second request should be ignored. |
562 EXPECT_FALSE(GetFetcher()); | 622 EXPECT_FALSE(GetFetcher()); |
563 MockSearchDomainCheckResponse("http://www.google.co.in/"); | 623 MockSearchDomainCheckResponse("http://www.google.co.in/"); |
564 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 624 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
565 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 625 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
566 EXPECT_FALSE(observer_->notified()); | 626 EXPECT_FALSE(observer_notified()); |
567 } | 627 } |
568 | 628 |
569 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { | 629 TEST_F(GoogleURLTrackerTest, SearchingDoesNothingIfNoNeedToPrompt) { |
570 RequestServerCheck(); | 630 RequestServerCheck(); |
571 FinishSleep(); | 631 FinishSleep(); |
572 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 632 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
573 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 633 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
574 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 634 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
575 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 635 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
576 EXPECT_TRUE(observer_->notified()); | 636 EXPECT_TRUE(observer_notified()); |
577 observer_->clear_notified(); | 637 clear_observer_notified(); |
578 | 638 |
579 SetNavigationPending(1, true); | 639 SetNavigationPending(1, true); |
580 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 640 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
581 TestInfoBarDelegate* infobar = GetInfoBar(1); | 641 EXPECT_TRUE(GetMapEntry(1) == NULL); |
582 EXPECT_TRUE(infobar == NULL); | |
583 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); | 642 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
584 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); | 643 EXPECT_EQ(GURL("http://www.google.co.uk/"), google_url()); |
585 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 644 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
586 EXPECT_FALSE(observer_->notified()); | 645 EXPECT_FALSE(observer_notified()); |
587 } | 646 } |
588 | 647 |
589 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { | 648 TEST_F(GoogleURLTrackerTest, TabClosedOnPendingSearch) { |
590 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 649 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
591 RequestServerCheck(); | 650 RequestServerCheck(); |
592 FinishSleep(); | 651 FinishSleep(); |
593 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 652 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
594 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 653 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
595 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); | 654 EXPECT_EQ(GURL("http://www.google.co.jp/"), fetched_google_url()); |
596 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 655 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
597 EXPECT_FALSE(observer_->notified()); | 656 EXPECT_FALSE(observer_notified()); |
598 | 657 |
599 SetNavigationPending(1, true); | 658 SetNavigationPending(1, true); |
600 TestInfoBarDelegate* infobar = GetInfoBar(1); | 659 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
601 ASSERT_FALSE(infobar == NULL); | 660 ASSERT_FALSE(map_entry == NULL); |
602 EXPECT_FALSE(infobar->showing()); | 661 EXPECT_FALSE(map_entry->has_infobar()); |
603 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 662 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
604 EXPECT_EQ(GURL("http://www.google.co.jp/"), infobar->new_google_url()); | |
605 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 663 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
606 EXPECT_FALSE(observer_->notified()); | 664 EXPECT_FALSE(observer_notified()); |
607 | 665 |
608 CloseTab(1); | 666 CloseTab(1); |
609 EXPECT_TRUE(GetInfoBar(1) == NULL); | 667 EXPECT_TRUE(GetMapEntry(1) == NULL); |
610 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 668 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
611 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 669 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
612 EXPECT_FALSE(observer_->notified()); | 670 EXPECT_FALSE(observer_notified()); |
613 } | 671 } |
614 | 672 |
615 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { | 673 TEST_F(GoogleURLTrackerTest, TabClosedOnCommittedSearch) { |
616 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 674 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
617 RequestServerCheck(); | 675 RequestServerCheck(); |
618 FinishSleep(); | 676 FinishSleep(); |
619 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 677 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
620 | 678 |
621 SetNavigationPending(1, true); | 679 SetNavigationPending(1, true); |
622 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 680 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
623 TestInfoBarDelegate* infobar = GetInfoBar(1); | 681 EXPECT_FALSE(GetInfoBar(1) == NULL); |
624 ASSERT_FALSE(infobar == NULL); | |
625 EXPECT_TRUE(infobar->showing()); | |
626 | 682 |
627 CloseTab(1); | 683 CloseTab(1); |
628 EXPECT_TRUE(GetInfoBar(1) == NULL); | 684 EXPECT_TRUE(GetMapEntry(1) == NULL); |
629 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 685 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
630 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 686 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
631 EXPECT_FALSE(observer_->notified()); | 687 EXPECT_FALSE(observer_notified()); |
632 } | 688 } |
633 | 689 |
634 TEST_F(GoogleURLTrackerTest, InfobarClosed) { | 690 TEST_F(GoogleURLTrackerTest, InfoBarClosed) { |
635 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 691 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
636 RequestServerCheck(); | 692 RequestServerCheck(); |
637 FinishSleep(); | 693 FinishSleep(); |
638 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 694 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
639 | 695 |
640 SetNavigationPending(1, true); | 696 SetNavigationPending(1, true); |
641 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 697 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
642 TestInfoBarDelegate* infobar = GetInfoBar(1); | 698 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
643 ASSERT_FALSE(infobar == NULL); | 699 ASSERT_FALSE(infobar == NULL); |
644 | 700 |
645 infobar->InfoBarClosed(); | 701 infobar->Close(false); |
646 EXPECT_TRUE(GetInfoBar(1) == NULL); | 702 EXPECT_TRUE(GetMapEntry(1) == NULL); |
647 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 703 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
648 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 704 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
649 EXPECT_FALSE(observer_->notified()); | 705 EXPECT_FALSE(observer_notified()); |
650 } | 706 } |
651 | 707 |
652 TEST_F(GoogleURLTrackerTest, InfobarRefused) { | 708 TEST_F(GoogleURLTrackerTest, InfoBarRefused) { |
653 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 709 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
654 RequestServerCheck(); | 710 RequestServerCheck(); |
655 FinishSleep(); | 711 FinishSleep(); |
656 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 712 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
657 | 713 |
658 SetNavigationPending(1, true); | 714 SetNavigationPending(1, true); |
659 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 715 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
660 TestInfoBarDelegate* infobar = GetInfoBar(1); | 716 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
661 ASSERT_FALSE(infobar == NULL); | 717 ASSERT_FALSE(infobar == NULL); |
662 | 718 |
663 infobar->Cancel(); | 719 infobar->Cancel(); |
664 EXPECT_TRUE(GetInfoBar(1) == NULL); | 720 EXPECT_TRUE(GetMapEntry(1) == NULL); |
665 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 721 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
666 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 722 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
667 EXPECT_FALSE(observer_->notified()); | 723 EXPECT_FALSE(observer_notified()); |
668 } | 724 } |
669 | 725 |
670 TEST_F(GoogleURLTrackerTest, InfobarAccepted) { | 726 TEST_F(GoogleURLTrackerTest, InfoBarAccepted) { |
671 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 727 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
672 RequestServerCheck(); | 728 RequestServerCheck(); |
673 FinishSleep(); | 729 FinishSleep(); |
674 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 730 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
675 | 731 |
676 SetNavigationPending(1, true); | 732 SetNavigationPending(1, true); |
677 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 733 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
678 TestInfoBarDelegate* infobar = GetInfoBar(1); | 734 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
679 ASSERT_FALSE(infobar == NULL); | 735 ASSERT_FALSE(infobar == NULL); |
680 | 736 |
681 infobar->Accept(); | 737 infobar->Accept(); |
682 EXPECT_TRUE(GetInfoBar(1) == NULL); | 738 EXPECT_TRUE(GetMapEntry(1) == NULL); |
683 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 739 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
684 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 740 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
685 EXPECT_TRUE(observer_->notified()); | 741 EXPECT_TRUE(observer_notified()); |
686 } | 742 } |
687 | 743 |
688 TEST_F(GoogleURLTrackerTest, InfobarForInstant) { | 744 TEST_F(GoogleURLTrackerTest, InfoBarForInstant) { |
689 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 745 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
690 RequestServerCheck(); | 746 RequestServerCheck(); |
691 FinishSleep(); | 747 FinishSleep(); |
692 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 748 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
693 | 749 |
694 DoInstantNavigation(1, GURL("http://www.google.co.uk/search?q=test")); | 750 DoInstantNavigation(1, GURL("http://www.google.co.uk/search?q=test")); |
695 TestInfoBarDelegate* infobar = GetInfoBar(1); | 751 EXPECT_FALSE(GetInfoBar(1) == NULL); |
696 ASSERT_FALSE(infobar == NULL); | |
697 EXPECT_TRUE(infobar->showing()); | |
698 } | 752 } |
699 | 753 |
700 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfobars) { | 754 TEST_F(GoogleURLTrackerTest, FetchesCanAutomaticallyCloseInfoBars) { |
701 RequestServerCheck(); | 755 RequestServerCheck(); |
702 FinishSleep(); | 756 FinishSleep(); |
703 MockSearchDomainCheckResponse(google_url().spec()); | 757 MockSearchDomainCheckResponse(google_url().spec()); |
704 | 758 |
705 // Re-fetching the accepted URL after showing an infobar for another URL | 759 // Re-fetching the accepted URL after showing an infobar for another URL |
706 // should close the infobar. | 760 // should close the infobar. |
707 NotifyIPAddressChanged(); | 761 NotifyIPAddressChanged(); |
708 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 762 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
709 SetNavigationPending(1, true); | 763 SetNavigationPending(1, true); |
710 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 764 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
711 EXPECT_FALSE(GetInfoBar(1) == NULL); | 765 EXPECT_FALSE(GetInfoBar(1) == NULL); |
712 NotifyIPAddressChanged(); | 766 NotifyIPAddressChanged(); |
713 MockSearchDomainCheckResponse(google_url().spec()); | 767 MockSearchDomainCheckResponse(google_url().spec()); |
714 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); | 768 EXPECT_EQ(google_url(), GetLastPromptedGoogleURL()); |
715 EXPECT_TRUE(GetInfoBar(1) == NULL); | 769 EXPECT_TRUE(GetMapEntry(1) == NULL); |
716 | 770 |
717 // As should fetching a URL that differs from the accepted only by the scheme. | 771 // As should fetching a URL that differs from the accepted only by the scheme. |
718 NotifyIPAddressChanged(); | 772 NotifyIPAddressChanged(); |
719 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 773 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
720 SetNavigationPending(1, true); | 774 SetNavigationPending(1, true); |
721 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 775 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
722 EXPECT_FALSE(GetInfoBar(1) == NULL); | 776 EXPECT_FALSE(GetInfoBar(1) == NULL); |
723 NotifyIPAddressChanged(); | 777 NotifyIPAddressChanged(); |
724 url_canon::Replacements<char> replacements; | 778 url_canon::Replacements<char> replacements; |
725 const std::string& scheme("https"); | 779 const std::string& scheme("https"); |
726 replacements.SetScheme(scheme.data(), | 780 replacements.SetScheme(scheme.data(), |
727 url_parse::Component(0, scheme.length())); | 781 url_parse::Component(0, scheme.length())); |
728 GURL new_google_url(google_url().ReplaceComponents(replacements)); | 782 GURL new_google_url(google_url().ReplaceComponents(replacements)); |
729 MockSearchDomainCheckResponse(new_google_url.spec()); | 783 MockSearchDomainCheckResponse(new_google_url.spec()); |
730 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); | 784 EXPECT_EQ(new_google_url, GetLastPromptedGoogleURL()); |
731 EXPECT_TRUE(GetInfoBar(1) == NULL); | 785 EXPECT_TRUE(GetMapEntry(1) == NULL); |
732 | 786 |
733 // As should re-fetching the last prompted URL. | 787 // As should re-fetching the last prompted URL. |
734 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 788 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
735 NotifyIPAddressChanged(); | 789 NotifyIPAddressChanged(); |
736 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 790 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
737 SetNavigationPending(1, true); | 791 SetNavigationPending(1, true); |
738 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 792 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
739 EXPECT_FALSE(GetInfoBar(1) == NULL); | 793 EXPECT_FALSE(GetInfoBar(1) == NULL); |
740 NotifyIPAddressChanged(); | 794 NotifyIPAddressChanged(); |
741 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 795 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
742 EXPECT_EQ(new_google_url, google_url()); | 796 EXPECT_EQ(new_google_url, google_url()); |
743 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 797 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
744 EXPECT_TRUE(GetInfoBar(1) == NULL); | 798 EXPECT_TRUE(GetMapEntry(1) == NULL); |
745 | 799 |
746 // And one that differs from the last prompted URL only by the scheme. | 800 // And one that differs from the last prompted URL only by the scheme. |
747 NotifyIPAddressChanged(); | 801 NotifyIPAddressChanged(); |
748 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 802 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
749 SetNavigationPending(1, true); | 803 SetNavigationPending(1, true); |
750 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 804 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
751 EXPECT_FALSE(GetInfoBar(1) == NULL); | 805 EXPECT_FALSE(GetInfoBar(1) == NULL); |
752 NotifyIPAddressChanged(); | 806 NotifyIPAddressChanged(); |
753 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 807 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
754 EXPECT_EQ(new_google_url, google_url()); | 808 EXPECT_EQ(new_google_url, google_url()); |
755 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 809 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
756 EXPECT_TRUE(GetInfoBar(1) == NULL); | 810 EXPECT_TRUE(GetMapEntry(1) == NULL); |
757 | 811 |
758 // And fetching a different URL entirely. | 812 // And fetching a different URL entirely. |
759 NotifyIPAddressChanged(); | 813 NotifyIPAddressChanged(); |
760 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 814 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
761 SetNavigationPending(1, true); | 815 SetNavigationPending(1, true); |
762 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | 816 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
763 EXPECT_FALSE(GetInfoBar(1) == NULL); | 817 EXPECT_FALSE(GetInfoBar(1) == NULL); |
764 NotifyIPAddressChanged(); | 818 NotifyIPAddressChanged(); |
765 MockSearchDomainCheckResponse("https://www.google.co.in/"); | 819 MockSearchDomainCheckResponse("https://www.google.co.in/"); |
766 EXPECT_EQ(new_google_url, google_url()); | 820 EXPECT_EQ(new_google_url, google_url()); |
767 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 821 EXPECT_EQ(GURL("https://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
768 EXPECT_TRUE(GetInfoBar(1) == NULL); | 822 EXPECT_TRUE(GetMapEntry(1) == NULL); |
769 } | 823 } |
770 | 824 |
771 TEST_F(GoogleURLTrackerTest, ResetInfobarGoogleURLs) { | 825 TEST_F(GoogleURLTrackerTest, ResetInfoBarGoogleURLs) { |
772 RequestServerCheck(); | 826 RequestServerCheck(); |
773 FinishSleep(); | 827 FinishSleep(); |
774 MockSearchDomainCheckResponse(google_url().spec()); | 828 MockSearchDomainCheckResponse(google_url().spec()); |
775 | 829 |
776 NotifyIPAddressChanged(); | 830 NotifyIPAddressChanged(); |
777 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | 831 MockSearchDomainCheckResponse("http://www.google.co.uk/"); |
778 SetNavigationPending(1, true); | 832 SetNavigationPending(1, true); |
779 TestInfoBarDelegate* infobar = GetInfoBar(1); | 833 CommitSearch(1, GURL("http://www.google.com/search?q=test")); |
834 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); | |
780 ASSERT_FALSE(infobar == NULL); | 835 ASSERT_FALSE(infobar == NULL); |
781 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); | 836 EXPECT_EQ(GURL("http://www.google.co.uk/"), fetched_google_url()); |
782 | 837 |
783 // If while an infobar is pending we fetch a new URL that differs from the | 838 // If while an infobar is showing we fetch a new URL that differs from the |
784 // infobar's only by scheme, the infobar should stay pending but have its | 839 // infobar's only by scheme, the infobar should stay showing. |
785 // Google URL reset. | |
786 NotifyIPAddressChanged(); | 840 NotifyIPAddressChanged(); |
787 MockSearchDomainCheckResponse("https://www.google.co.uk/"); | 841 MockSearchDomainCheckResponse("https://www.google.co.uk/"); |
788 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 842 EXPECT_EQ(infobar, GetInfoBar(1)); |
789 ASSERT_FALSE(new_infobar == NULL); | 843 EXPECT_EQ(GURL("https://www.google.co.uk/"), fetched_google_url()); |
790 EXPECT_EQ(infobar, new_infobar); | |
791 EXPECT_EQ(GURL("https://www.google.co.uk/"), new_infobar->new_google_url()); | |
792 | |
793 // Same with an infobar that is showing. | |
794 CommitSearch(1, GURL("http://www.google.com/search?q=test")); | |
795 EXPECT_TRUE(infobar->showing()); | |
796 NotifyIPAddressChanged(); | |
797 MockSearchDomainCheckResponse("http://www.google.co.uk/"); | |
798 new_infobar = GetInfoBar(1); | |
799 ASSERT_FALSE(new_infobar == NULL); | |
800 EXPECT_EQ(infobar, new_infobar); | |
801 EXPECT_EQ(GURL("http://www.google.co.uk/"), infobar->new_google_url()); | |
802 EXPECT_TRUE(infobar->showing()); | |
803 } | 844 } |
804 | 845 |
805 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { | 846 TEST_F(GoogleURLTrackerTest, NavigationsAfterPendingSearch) { |
806 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 847 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
807 RequestServerCheck(); | 848 RequestServerCheck(); |
808 FinishSleep(); | 849 FinishSleep(); |
809 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 850 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
810 | 851 |
811 // A pending non-search after a pending search should close the infobar. | 852 // A pending non-search after a pending search should delete the map entry. |
812 SetNavigationPending(1, true); | 853 SetNavigationPending(1, true); |
813 TestInfoBarDelegate* infobar = GetInfoBar(1); | 854 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
814 ASSERT_FALSE(infobar == NULL); | 855 ASSERT_FALSE(map_entry == NULL); |
815 EXPECT_FALSE(infobar->showing()); | 856 EXPECT_FALSE(map_entry->has_infobar()); |
816 SetNavigationPending(1, false); | 857 SetNavigationPending(1, false); |
817 infobar = GetInfoBar(1); | 858 EXPECT_TRUE(GetMapEntry(1) == NULL); |
818 EXPECT_TRUE(infobar == NULL); | |
819 | 859 |
820 // A pending search after a pending search should leave the infobar alive. | 860 // A pending search after a pending search should leave the map entry alive. |
821 SetNavigationPending(1, true); | 861 SetNavigationPending(1, true); |
822 infobar = GetInfoBar(1); | 862 map_entry = GetMapEntry(1); |
823 ASSERT_FALSE(infobar == NULL); | 863 ASSERT_FALSE(map_entry == NULL); |
824 EXPECT_FALSE(infobar->showing()); | 864 EXPECT_FALSE(map_entry->has_infobar()); |
825 SetNavigationPending(1, true); | 865 SetNavigationPending(1, true); |
826 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 866 ASSERT_EQ(map_entry, GetMapEntry(1)); |
827 ASSERT_FALSE(new_infobar == NULL); | 867 EXPECT_FALSE(map_entry->has_infobar()); |
828 EXPECT_EQ(infobar, new_infobar); | |
829 EXPECT_FALSE(infobar->showing()); | |
830 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 868 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
831 | 869 |
832 // Committing this search should show the infobar. | 870 // Committing this search should show an infobar. |
833 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 871 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
834 EXPECT_TRUE(infobar->showing()); | 872 EXPECT_TRUE(map_entry->has_infobar()); |
835 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 873 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
836 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 874 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
837 EXPECT_FALSE(observer_->notified()); | 875 EXPECT_FALSE(observer_notified()); |
838 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 876 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
839 } | 877 } |
840 | 878 |
841 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { | 879 TEST_F(GoogleURLTrackerTest, NavigationsAfterCommittedSearch) { |
842 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 880 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
843 RequestServerCheck(); | 881 RequestServerCheck(); |
844 FinishSleep(); | 882 FinishSleep(); |
845 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 883 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
846 SetNavigationPending(1, true); | 884 SetNavigationPending(1, true); |
847 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 885 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
848 TestInfoBarDelegate* infobar = GetInfoBar(1); | 886 GoogleURLTrackerInfoBarDelegate* infobar = GetInfoBar(1); |
849 ASSERT_FALSE(infobar == NULL); | 887 ASSERT_FALSE(infobar == NULL); |
850 EXPECT_TRUE(infobar->showing()); | |
851 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 888 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
852 | 889 |
853 // A pending non-search on a visible infobar should basically do nothing. | 890 // A pending non-search on a visible infobar should basically do nothing. |
854 SetNavigationPending(1, false); | 891 SetNavigationPending(1, false); |
855 TestInfoBarDelegate* new_infobar = GetInfoBar(1); | 892 ASSERT_EQ(infobar, GetInfoBar(1)); |
856 ASSERT_FALSE(new_infobar == NULL); | |
857 EXPECT_EQ(infobar, new_infobar); | |
858 EXPECT_TRUE(infobar->showing()); | |
859 EXPECT_EQ(0, infobar->pending_id()); | 893 EXPECT_EQ(0, infobar->pending_id()); |
860 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 894 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
861 | 895 |
862 // As should another pending non-search after the first. | 896 // As should another pending non-search after the first. |
863 SetNavigationPending(1, false); | 897 SetNavigationPending(1, false); |
864 new_infobar = GetInfoBar(1); | 898 ASSERT_EQ(infobar, GetInfoBar(1)); |
865 ASSERT_FALSE(new_infobar == NULL); | |
866 EXPECT_EQ(infobar, new_infobar); | |
867 EXPECT_TRUE(infobar->showing()); | |
868 EXPECT_EQ(0, infobar->pending_id()); | 899 EXPECT_EQ(0, infobar->pending_id()); |
869 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 900 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
870 | 901 |
871 // Committing this non-search should close the infobar. The control flow in | 902 // Committing this non-search should close the infobar. The control flow in |
872 // these tests is not really comparable to in the real browser, but at least a | 903 // these tests is not really comparable to in the real browser, but at least a |
873 // few sanity-checks will be performed. | 904 // few sanity-checks will be performed. |
874 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); | 905 ASSERT_NO_FATAL_FAILURE(CommitNonSearch(1)); |
875 new_infobar = GetInfoBar(1); | 906 EXPECT_TRUE(GetMapEntry(1) == NULL); |
876 EXPECT_TRUE(new_infobar == NULL); | |
877 | 907 |
878 // A pending search on a visible infobar should cause the infobar to listen | 908 // A pending search on a visible infobar should cause the infobar to listen |
879 // for the search to commit. | 909 // for the search to commit. |
880 SetNavigationPending(1, true); | 910 SetNavigationPending(1, true); |
881 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 911 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
882 infobar = GetInfoBar(1); | 912 infobar = GetInfoBar(1); |
883 ASSERT_FALSE(infobar == NULL); | 913 ASSERT_FALSE(infobar == NULL); |
884 EXPECT_TRUE(infobar->showing()); | |
885 SetNavigationPending(1, true); | 914 SetNavigationPending(1, true); |
886 new_infobar = GetInfoBar(1); | 915 ASSERT_EQ(infobar, GetInfoBar(1)); |
887 ASSERT_FALSE(new_infobar == NULL); | |
888 EXPECT_EQ(infobar, new_infobar); | |
889 EXPECT_TRUE(infobar->showing()); | |
890 EXPECT_EQ(1, infobar->pending_id()); | 916 EXPECT_EQ(1, infobar->pending_id()); |
891 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 917 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
892 | 918 |
893 // But a non-search after this should cancel that state. | 919 // But a non-search after this should cancel that state. |
894 SetNavigationPending(1, false); | 920 SetNavigationPending(1, false); |
895 new_infobar = GetInfoBar(1); | 921 ASSERT_EQ(infobar, GetInfoBar(1)); |
896 ASSERT_FALSE(new_infobar == NULL); | |
897 EXPECT_EQ(infobar, new_infobar); | |
898 EXPECT_TRUE(infobar->showing()); | |
899 EXPECT_EQ(0, infobar->pending_id()); | 922 EXPECT_EQ(0, infobar->pending_id()); |
900 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 923 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
901 | 924 |
902 // Another pending search after the non-search should put us back into | 925 // Another pending search after the non-search should put us back into |
903 // "waiting for commit" mode. | 926 // "waiting for commit" mode. |
904 SetNavigationPending(1, true); | 927 SetNavigationPending(1, true); |
905 new_infobar = GetInfoBar(1); | 928 ASSERT_EQ(infobar, GetInfoBar(1)); |
906 ASSERT_FALSE(new_infobar == NULL); | |
907 EXPECT_EQ(infobar, new_infobar); | |
908 EXPECT_TRUE(infobar->showing()); | |
909 EXPECT_EQ(1, infobar->pending_id()); | 929 EXPECT_EQ(1, infobar->pending_id()); |
910 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 930 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
911 | 931 |
912 // A second pending search after the first should not really change anything. | 932 // A second pending search after the first should not really change anything. |
913 SetNavigationPending(1, true); | 933 SetNavigationPending(1, true); |
914 new_infobar = GetInfoBar(1); | 934 ASSERT_EQ(infobar, GetInfoBar(1)); |
915 ASSERT_FALSE(new_infobar == NULL); | |
916 EXPECT_EQ(infobar, new_infobar); | |
917 EXPECT_TRUE(infobar->showing()); | |
918 EXPECT_EQ(1, infobar->pending_id()); | 935 EXPECT_EQ(1, infobar->pending_id()); |
919 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 936 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
920 | 937 |
921 // Committing this search should change the visible infobar's search_url. | 938 // Committing this search should change the visible infobar's search_url. |
922 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); | 939 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test2")); |
923 new_infobar = GetInfoBar(1); | 940 ASSERT_EQ(infobar, GetInfoBar(1)); |
924 ASSERT_FALSE(new_infobar == NULL); | 941 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
925 EXPECT_EQ(infobar, new_infobar); | 942 infobar->search_url()); |
926 EXPECT_TRUE(infobar->showing()); | |
927 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), infobar->search_url( )); | |
928 EXPECT_EQ(0, infobar->pending_id()); | 943 EXPECT_EQ(0, infobar->pending_id()); |
929 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 944 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
930 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 945 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
931 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); | 946 EXPECT_EQ(GURL("http://www.google.co.uk/"), GetLastPromptedGoogleURL()); |
932 EXPECT_FALSE(observer_->notified()); | 947 EXPECT_FALSE(observer_notified()); |
933 } | 948 } |
934 | 949 |
935 TEST_F(GoogleURLTrackerTest, MultipleInfobars) { | 950 TEST_F(GoogleURLTrackerTest, MultipleMapEntries) { |
936 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 951 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
937 RequestServerCheck(); | 952 RequestServerCheck(); |
938 FinishSleep(); | 953 FinishSleep(); |
939 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 954 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
940 | 955 |
941 SetNavigationPending(1, true); | 956 SetNavigationPending(1, true); |
942 TestInfoBarDelegate* infobar = GetInfoBar(1); | 957 GoogleURLTrackerMapEntry* map_entry = GetMapEntry(1); |
943 ASSERT_FALSE(infobar == NULL); | 958 ASSERT_FALSE(map_entry == NULL); |
944 EXPECT_FALSE(infobar->showing()); | 959 EXPECT_FALSE(map_entry->has_infobar()); |
945 | 960 |
946 SetNavigationPending(2, true); | 961 SetNavigationPending(2, true); |
947 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 962 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
948 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | 963 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); |
949 ASSERT_FALSE(infobar2 == NULL); | 964 ASSERT_FALSE(infobar2 == NULL); |
950 EXPECT_TRUE(infobar2->showing()); | |
951 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), | 965 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test2"), |
952 infobar2->search_url()); | 966 infobar2->search_url()); |
953 | 967 |
954 SetNavigationPending(3, true); | 968 SetNavigationPending(3, true); |
955 TestInfoBarDelegate* infobar3 = GetInfoBar(3); | 969 GoogleURLTrackerMapEntry* map_entry3 = GetMapEntry(3); |
956 ASSERT_FALSE(infobar3 == NULL); | 970 ASSERT_FALSE(map_entry3 == NULL); |
957 EXPECT_FALSE(infobar3->showing()); | 971 EXPECT_FALSE(map_entry3->has_infobar()); |
958 | 972 |
959 SetNavigationPending(4, true); | 973 SetNavigationPending(4, true); |
960 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); | 974 CommitSearch(4, GURL("http://www.google.co.uk/search?q=test4")); |
961 TestInfoBarDelegate* infobar4 = GetInfoBar(4); | 975 GoogleURLTrackerInfoBarDelegate* infobar4 = GetInfoBar(4); |
962 ASSERT_FALSE(infobar4 == NULL); | 976 ASSERT_FALSE(infobar4 == NULL); |
963 EXPECT_TRUE(infobar4->showing()); | |
964 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), | 977 EXPECT_EQ(GURL("http://www.google.co.uk/search?q=test4"), |
965 infobar4->search_url()); | 978 infobar4->search_url()); |
966 | 979 |
967 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 980 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
968 EXPECT_TRUE(infobar->showing()); | 981 EXPECT_TRUE(map_entry->has_infobar()); |
969 | 982 |
970 infobar2->InfoBarClosed(); | 983 infobar2->Close(false); |
971 EXPECT_TRUE(GetInfoBar(2) == NULL); | 984 EXPECT_TRUE(GetMapEntry(2) == NULL); |
972 EXPECT_FALSE(observer_->notified()); | 985 EXPECT_FALSE(observer_notified()); |
973 | 986 |
974 infobar4->Accept(); | 987 infobar4->Accept(); |
975 EXPECT_TRUE(GetInfoBar(1) == NULL); | 988 EXPECT_TRUE(GetMapEntry(1) == NULL); |
976 EXPECT_TRUE(GetInfoBar(3) == NULL); | 989 EXPECT_TRUE(GetMapEntry(3) == NULL); |
977 EXPECT_TRUE(GetInfoBar(4) == NULL); | 990 EXPECT_TRUE(GetMapEntry(4) == NULL); |
978 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); | 991 EXPECT_EQ(GURL("http://www.google.co.jp/"), google_url()); |
979 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); | 992 EXPECT_EQ(GURL("http://www.google.co.jp/"), GetLastPromptedGoogleURL()); |
980 EXPECT_TRUE(observer_->notified()); | 993 EXPECT_TRUE(observer_notified()); |
981 } | 994 } |
982 | 995 |
983 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantInstantNavigation) { | 996 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantInstantNavigation) { |
984 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 997 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
985 RequestServerCheck(); | 998 RequestServerCheck(); |
986 FinishSleep(); | 999 FinishSleep(); |
987 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 1000 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
988 | 1001 |
989 // Starting a search pending on any tab should cause us to listen for pending | 1002 // Starting a search pending on any tab should cause us to listen for pending |
990 // and instant navigations on all tabs, but we should ignore these when they | 1003 // and instant navigations on all tabs, but we should ignore these when they |
991 // are for tabs that we don't care about. | 1004 // are for tabs that we don't care about. |
992 SetNavigationPending(1, true); | 1005 SetNavigationPending(1, true); |
993 TestInfoBarDelegate* infobar = GetInfoBar(1); | 1006 EXPECT_FALSE(GetMapEntry(1) == NULL); |
994 ASSERT_FALSE(infobar == NULL); | |
995 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1007 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
996 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); | 1008 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); |
997 | 1009 |
998 DoInstantNavigation(2, GURL()); | 1010 DoInstantNavigation(2, GURL()); |
999 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | 1011 EXPECT_TRUE(GetMapEntry(2) == NULL); |
1000 ASSERT_TRUE(infobar2 == NULL); | |
1001 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1012 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
1002 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); | 1013 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(2, false)); |
1003 } | 1014 } |
1004 | 1015 |
1005 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { | 1016 TEST_F(GoogleURLTrackerTest, IgnoreIrrelevantNavigation) { |
1006 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); | 1017 SetLastPromptedGoogleURL(GURL("http://www.google.co.uk/")); |
1007 RequestServerCheck(); | 1018 RequestServerCheck(); |
1008 FinishSleep(); | 1019 FinishSleep(); |
1009 MockSearchDomainCheckResponse("http://www.google.co.jp/"); | 1020 MockSearchDomainCheckResponse("http://www.google.co.jp/"); |
1010 | 1021 |
1011 // This tests a particularly gnarly sequence of events that used to cause us | 1022 // This tests a particularly gnarly sequence of events that used to cause us |
1012 // to erroneously listen for a non-search navigation to commit. | 1023 // to erroneously listen for a non-search navigation to commit. |
1013 SetNavigationPending(1, true); | 1024 SetNavigationPending(1, true); |
1014 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); | 1025 CommitSearch(1, GURL("http://www.google.co.uk/search?q=test")); |
1015 SetNavigationPending(2, true); | 1026 SetNavigationPending(2, true); |
1016 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); | 1027 CommitSearch(2, GURL("http://www.google.co.uk/search?q=test2")); |
1017 TestInfoBarDelegate* infobar = GetInfoBar(1); | 1028 EXPECT_FALSE(GetInfoBar(1) == NULL); |
1018 ASSERT_FALSE(infobar == NULL); | 1029 GoogleURLTrackerInfoBarDelegate* infobar2 = GetInfoBar(2); |
1019 EXPECT_TRUE(infobar->showing()); | |
1020 TestInfoBarDelegate* infobar2 = GetInfoBar(2); | |
1021 ASSERT_FALSE(infobar2 == NULL); | 1030 ASSERT_FALSE(infobar2 == NULL); |
1022 EXPECT_TRUE(infobar2->showing()); | |
1023 SetNavigationPending(1, true); | 1031 SetNavigationPending(1, true); |
1024 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); | 1032 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, true)); |
1025 infobar2->InfoBarClosed(); | 1033 infobar2->Close(false); |
1026 SetNavigationPending(1, false); | 1034 SetNavigationPending(1, false); |
1027 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); | 1035 ASSERT_NO_FATAL_FAILURE(ExpectListeningForCommit(1, false)); |
1028 } | 1036 } |
OLD | NEW |