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 <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 #include "chrome/browser/prefs/pref_service.h" | 35 #include "chrome/browser/prefs/pref_service.h" |
36 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
37 #endif | 37 #endif |
38 | 38 |
39 using content::BrowserThread; | 39 using content::BrowserThread; |
40 using content::MockRenderProcessHost; | 40 using content::MockRenderProcessHost; |
41 using content::RenderViewHostTester; | 41 using content::RenderViewHostTester; |
42 using content::WebContents; | 42 using content::WebContents; |
43 using content::WebContentsTester; | 43 using content::WebContentsTester; |
44 | 44 |
| 45 |
45 // ClosedDelegateTracker ------------------------------------------------------ | 46 // ClosedDelegateTracker ------------------------------------------------------ |
46 | 47 |
47 // We need to track which infobars were closed. | 48 // We need to track which infobars were closed. |
48 class ClosedDelegateTracker : public content::NotificationObserver { | 49 class ClosedDelegateTracker : public content::NotificationObserver { |
49 public: | 50 public: |
50 ClosedDelegateTracker(); | 51 ClosedDelegateTracker(); |
51 virtual ~ClosedDelegateTracker(); | 52 virtual ~ClosedDelegateTracker(); |
52 | 53 |
53 // content::NotificationObserver: | 54 // content::NotificationObserver: |
54 virtual void Observe(int type, | 55 virtual void Observe(int type, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 87 } |
87 | 88 |
88 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const { | 89 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const { |
89 return removed_infobar_delegates_.count(delegate) != 0; | 90 return removed_infobar_delegates_.count(delegate) != 0; |
90 } | 91 } |
91 | 92 |
92 void ClosedDelegateTracker::Clear() { | 93 void ClosedDelegateTracker::Clear() { |
93 removed_infobar_delegates_.clear(); | 94 removed_infobar_delegates_.clear(); |
94 } | 95 } |
95 | 96 |
| 97 |
96 // GeolocationPermissionContextTests ------------------------------------------ | 98 // GeolocationPermissionContextTests ------------------------------------------ |
97 | 99 |
98 // This class sets up GeolocationArbitrator. | 100 // This class sets up GeolocationArbitrator. |
99 class GeolocationPermissionContextTests | 101 class GeolocationPermissionContextTests |
100 : public ChromeRenderViewHostTestHarness { | 102 : public ChromeRenderViewHostTestHarness { |
101 public: | 103 public: |
102 GeolocationPermissionContextTests(); | 104 GeolocationPermissionContextTests(); |
103 | 105 |
104 protected: | 106 protected: |
105 virtual ~GeolocationPermissionContextTests(); | 107 virtual ~GeolocationPermissionContextTests(); |
106 | 108 |
107 int process_id() { | 109 content::GeolocationPermissionRequestID RequestID(int bridge_id); |
108 return web_contents()->GetRenderProcessHost()->GetID(); | 110 content::GeolocationPermissionRequestID RequestIDForTab(int tab, |
109 } | 111 int bridge_id); |
110 int process_id_for_tab(int tab) { | |
111 return extra_tabs_[tab]->GetRenderProcessHost()->GetID(); | |
112 } | |
113 int render_id() { | |
114 return web_contents()->GetRenderViewHost()->GetRoutingID(); | |
115 } | |
116 int render_id_for_tab(int tab) { | |
117 return extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(); | |
118 } | |
119 int bridge_id() const { return 42; } // Not relevant at this level. | |
120 InfoBarTabHelper* infobar_tab_helper() { | 112 InfoBarTabHelper* infobar_tab_helper() { |
121 return InfoBarTabHelper::FromWebContents(web_contents()); | 113 return InfoBarTabHelper::FromWebContents(web_contents()); |
122 } | 114 } |
123 InfoBarTabHelper* infobar_tab_helper_for_tab(int tab) { | 115 InfoBarTabHelper* infobar_tab_helper_for_tab(int tab) { |
124 return InfoBarTabHelper::FromWebContents(extra_tabs_[tab]); | 116 return InfoBarTabHelper::FromWebContents(extra_tabs_[tab]); |
125 } | 117 } |
126 | 118 |
127 void RequestGeolocationPermission(int render_process_id, | 119 void RequestGeolocationPermission( |
128 int render_view_id, | 120 const content::GeolocationPermissionRequestID& id, |
129 int bridge_id, | 121 const GURL& requesting_frame); |
130 const GURL& requesting_frame); | 122 void PermissionResponse(const content::GeolocationPermissionRequestID& id, |
131 void PermissionResponse(int render_process_id, | |
132 int render_view_id, | |
133 int bridge_id, | |
134 bool allowed); | 123 bool allowed); |
135 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 124 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
136 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 125 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
137 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 126 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
138 int bridge_id, | 127 int bridge_id, |
139 bool allowed); | 128 bool allowed); |
140 void AddNewTab(const GURL& url); | 129 void AddNewTab(const GURL& url); |
141 void CheckTabContentsState(const GURL& requesting_frame, | 130 void CheckTabContentsState(const GURL& requesting_frame, |
142 ContentSetting expected_content_setting); | 131 ContentSetting expected_content_setting); |
143 | 132 |
(...skipping 17 matching lines...) Expand all Loading... |
161 | 150 |
162 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 151 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
163 : ChromeRenderViewHostTestHarness(), | 152 : ChromeRenderViewHostTestHarness(), |
164 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 153 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
165 db_thread_(BrowserThread::DB) { | 154 db_thread_(BrowserThread::DB) { |
166 } | 155 } |
167 | 156 |
168 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { | 157 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
169 } | 158 } |
170 | 159 |
| 160 content::GeolocationPermissionRequestID |
| 161 GeolocationPermissionContextTests::RequestID(int bridge_id) { |
| 162 return content::GeolocationPermissionRequestID( |
| 163 web_contents()->GetRenderProcessHost()->GetID(), |
| 164 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 165 bridge_id); |
| 166 } |
| 167 |
| 168 content::GeolocationPermissionRequestID |
| 169 GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) { |
| 170 return content::GeolocationPermissionRequestID( |
| 171 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
| 172 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
| 173 bridge_id); |
| 174 } |
| 175 |
171 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 176 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
172 int render_process_id, | 177 const content::GeolocationPermissionRequestID& id, |
173 int render_view_id, | |
174 int bridge_id, | |
175 const GURL& requesting_frame) { | 178 const GURL& requesting_frame) { |
176 geolocation_permission_context_->RequestGeolocationPermission( | 179 geolocation_permission_context_->RequestGeolocationPermission( |
177 render_process_id, render_view_id, bridge_id, requesting_frame, | 180 id, requesting_frame, base::Bind( |
178 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 181 &GeolocationPermissionContextTests::PermissionResponse, |
179 base::Unretained(this), | 182 base::Unretained(this), id)); |
180 render_process_id, | |
181 render_view_id, | |
182 bridge_id)); | |
183 } | 183 } |
184 | 184 |
185 void GeolocationPermissionContextTests::PermissionResponse( | 185 void GeolocationPermissionContextTests::PermissionResponse( |
186 int render_process_id, | 186 const content::GeolocationPermissionRequestID& id, |
187 int render_view_id, | |
188 int bridge_id, | |
189 bool allowed) { | 187 bool allowed) { |
190 responses_[render_process_id] = std::make_pair(bridge_id, allowed); | 188 responses_[id.render_process_id] = std::make_pair(id.bridge_id, allowed); |
191 } | 189 } |
192 | 190 |
193 void GeolocationPermissionContextTests::CheckPermissionMessageSent( | 191 void GeolocationPermissionContextTests::CheckPermissionMessageSent( |
194 int bridge_id, | 192 int bridge_id, |
195 bool allowed) { | 193 bool allowed) { |
196 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); | 194 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); |
197 } | 195 } |
198 | 196 |
199 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( | 197 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( |
200 int tab, | 198 int tab, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 db_thread_.Stop(); | 269 db_thread_.Stop(); |
272 } | 270 } |
273 | 271 |
274 | 272 |
275 // Tests ---------------------------------------------------------------------- | 273 // Tests ---------------------------------------------------------------------- |
276 | 274 |
277 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 275 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
278 GURL requesting_frame("http://www.example.com/geolocation"); | 276 GURL requesting_frame("http://www.example.com/geolocation"); |
279 NavigateAndCommit(requesting_frame); | 277 NavigateAndCommit(requesting_frame); |
280 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 278 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
281 RequestGeolocationPermission( | 279 RequestGeolocationPermission(RequestID(0), requesting_frame); |
282 process_id(), render_id(), bridge_id(), requesting_frame); | |
283 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 280 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
284 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 281 ConfirmInfoBarDelegate* infobar_0 = |
285 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 282 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
286 infobar_0->Cancel(); | 283 infobar_0->Cancel(); |
287 infobar_tab_helper()->RemoveInfoBar(infobar_0); | 284 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
288 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 285 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
289 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 286 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
290 infobar_0->InfoBarClosed(); | 287 infobar_0->InfoBarClosed(); |
291 } | 288 } |
292 | 289 |
293 #if defined(OS_ANDROID) | 290 #if defined(OS_ANDROID) |
294 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 291 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
295 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( | 292 profile()->GetHostContentSettingsMap()->SetDefaultContentSetting( |
296 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 293 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
297 CONTENT_SETTING_ALLOW); | 294 CONTENT_SETTING_ALLOW); |
298 | 295 |
299 // Check that the request is denied with preference disabled, | 296 // Check that the request is denied with preference disabled, |
300 // even though the default policy allows it. | 297 // even though the default policy allows it. |
301 GURL requesting_frame("http://www.example.com/geolocation"); | 298 GURL requesting_frame("http://www.example.com/geolocation"); |
302 NavigateAndCommit(requesting_frame); | 299 NavigateAndCommit(requesting_frame); |
303 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 300 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
304 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); | 301 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); |
305 RequestGeolocationPermission( | 302 RequestGeolocationPermission(RequestID(0), requesting_frame); |
306 process_id(), render_id(), bridge_id(), requesting_frame); | |
307 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 303 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
308 CheckPermissionMessageSent(bridge_id(), false); | 304 CheckPermissionMessageSent(0, false); |
309 | 305 |
310 // Reenable the preference and check that the request now goes though. | 306 // Reenable the preference and check that the request now goes though. |
311 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); | 307 profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); |
312 RequestGeolocationPermission( | 308 RequestGeolocationPermission(RequestID(1), requesting_frame); |
313 process_id(), render_id(), bridge_id() + 1, requesting_frame); | |
314 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 309 ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
315 CheckPermissionMessageSent(bridge_id() + 1, true); | 310 CheckPermissionMessageSent(1, true); |
316 } | 311 } |
317 #endif | 312 #endif |
318 | 313 |
319 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 314 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
320 GURL requesting_frame_0("http://www.example.com/geolocation"); | 315 GURL requesting_frame_0("http://www.example.com/geolocation"); |
321 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 316 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
322 EXPECT_EQ(CONTENT_SETTING_ASK, | 317 EXPECT_EQ(CONTENT_SETTING_ASK, |
323 profile()->GetHostContentSettingsMap()->GetContentSetting( | 318 profile()->GetHostContentSettingsMap()->GetContentSetting( |
324 requesting_frame_0, | 319 requesting_frame_0, |
325 requesting_frame_0, | 320 requesting_frame_0, |
326 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 321 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
327 std::string())); | 322 std::string())); |
328 EXPECT_EQ(CONTENT_SETTING_ASK, | 323 EXPECT_EQ(CONTENT_SETTING_ASK, |
329 profile()->GetHostContentSettingsMap()->GetContentSetting( | 324 profile()->GetHostContentSettingsMap()->GetContentSetting( |
330 requesting_frame_1, | 325 requesting_frame_1, |
331 requesting_frame_0, | 326 requesting_frame_0, |
332 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 327 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
333 std::string())); | 328 std::string())); |
334 | 329 |
335 | 330 |
336 NavigateAndCommit(requesting_frame_0); | 331 NavigateAndCommit(requesting_frame_0); |
337 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 332 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
338 // Request permission for two frames. | 333 // Request permission for two frames. |
339 RequestGeolocationPermission( | 334 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
340 process_id(), render_id(), bridge_id(), requesting_frame_0); | 335 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
341 RequestGeolocationPermission( | |
342 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | |
343 // Ensure only one infobar is created. | 336 // Ensure only one infobar is created. |
344 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 337 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
345 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 338 ConfirmInfoBarDelegate* infobar_0 = |
346 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 339 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
347 ASSERT_TRUE(infobar_0); | 340 ASSERT_TRUE(infobar_0); |
348 string16 text_0 = infobar_0->GetMessageText(); | 341 string16 text_0 = infobar_0->GetMessageText(); |
349 | 342 |
350 // Accept the first frame. | 343 // Accept the first frame. |
351 infobar_0->Accept(); | 344 infobar_0->Accept(); |
352 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 345 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
353 CheckPermissionMessageSent(bridge_id(), true); | 346 CheckPermissionMessageSent(0, true); |
354 | 347 |
355 infobar_tab_helper()->RemoveInfoBar(infobar_0); | 348 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
356 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 349 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
357 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 350 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
358 closed_delegate_tracker_.Clear(); | 351 closed_delegate_tracker_.Clear(); |
359 infobar_0->InfoBarClosed(); | 352 infobar_0->InfoBarClosed(); |
360 // Now we should have a new infobar for the second frame. | 353 // Now we should have a new infobar for the second frame. |
361 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 354 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
362 | 355 |
363 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> | 356 ConfirmInfoBarDelegate* infobar_1 = |
364 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 357 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
365 ASSERT_TRUE(infobar_1); | 358 ASSERT_TRUE(infobar_1); |
366 string16 text_1 = infobar_1->GetMessageText(); | 359 string16 text_1 = infobar_1->GetMessageText(); |
367 EXPECT_NE(text_0, text_1); | 360 EXPECT_NE(text_0, text_1); |
368 | 361 |
369 // Cancel (block) this frame. | 362 // Cancel (block) this frame. |
370 infobar_1->Cancel(); | 363 infobar_1->Cancel(); |
371 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 364 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
372 CheckPermissionMessageSent(bridge_id() + 1, false); | 365 CheckPermissionMessageSent(1, false); |
373 infobar_tab_helper()->RemoveInfoBar(infobar_1); | 366 infobar_tab_helper()->RemoveInfoBar(infobar_1); |
374 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 367 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
375 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 368 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
376 infobar_1->InfoBarClosed(); | 369 infobar_1->InfoBarClosed(); |
377 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 370 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
378 // Ensure the persisted permissions are ok. | 371 // Ensure the persisted permissions are ok. |
379 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 372 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
380 profile()->GetHostContentSettingsMap()->GetContentSetting( | 373 profile()->GetHostContentSettingsMap()->GetContentSetting( |
381 requesting_frame_0, | 374 requesting_frame_0, |
382 requesting_frame_0, | 375 requesting_frame_0, |
(...skipping 22 matching lines...) Expand all Loading... |
405 profile()->GetHostContentSettingsMap()->GetContentSetting( | 398 profile()->GetHostContentSettingsMap()->GetContentSetting( |
406 requesting_frame_1, | 399 requesting_frame_1, |
407 requesting_frame_0, | 400 requesting_frame_0, |
408 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 401 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
409 std::string())); | 402 std::string())); |
410 | 403 |
411 | 404 |
412 NavigateAndCommit(requesting_frame_0); | 405 NavigateAndCommit(requesting_frame_0); |
413 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 406 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
414 // Request permission for two frames. | 407 // Request permission for two frames. |
415 RequestGeolocationPermission( | 408 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
416 process_id(), render_id(), bridge_id(), requesting_frame_0); | 409 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
417 RequestGeolocationPermission( | |
418 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | |
419 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 410 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
420 | 411 |
421 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 412 ConfirmInfoBarDelegate* infobar_0 = |
422 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 413 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
423 ASSERT_TRUE(infobar_0); | 414 ASSERT_TRUE(infobar_0); |
424 string16 text_0 = infobar_0->GetMessageText(); | 415 string16 text_0 = infobar_0->GetMessageText(); |
425 | 416 |
426 // Simulate the frame going away, ensure the infobar for this frame | 417 // Simulate the frame going away, ensure the infobar for this frame |
427 // is removed and the next pending infobar is created. | 418 // is removed and the next pending infobar is created. |
428 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 419 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
429 process_id(), render_id(), bridge_id(), requesting_frame_0); | 420 RequestID(0), requesting_frame_0); |
430 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 421 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
431 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 422 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
432 closed_delegate_tracker_.Clear(); | 423 closed_delegate_tracker_.Clear(); |
433 infobar_0->InfoBarClosed(); | 424 infobar_0->InfoBarClosed(); |
434 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 425 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
435 | 426 |
436 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> | 427 ConfirmInfoBarDelegate* infobar_1 = |
437 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 428 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
438 ASSERT_TRUE(infobar_1); | 429 ASSERT_TRUE(infobar_1); |
439 string16 text_1 = infobar_1->GetMessageText(); | 430 string16 text_1 = infobar_1->GetMessageText(); |
440 EXPECT_NE(text_0, text_1); | 431 EXPECT_NE(text_0, text_1); |
441 | 432 |
442 // Allow this frame. | 433 // Allow this frame. |
443 infobar_1->Accept(); | 434 infobar_1->Accept(); |
444 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 435 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
445 CheckPermissionMessageSent(bridge_id() + 1, true); | 436 CheckPermissionMessageSent(1, true); |
446 infobar_tab_helper()->RemoveInfoBar(infobar_1); | 437 infobar_tab_helper()->RemoveInfoBar(infobar_1); |
447 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 438 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
448 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 439 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
449 infobar_1->InfoBarClosed(); | 440 infobar_1->InfoBarClosed(); |
450 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 441 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
451 // Ensure the persisted permissions are ok. | 442 // Ensure the persisted permissions are ok. |
452 EXPECT_EQ(CONTENT_SETTING_ASK, | 443 EXPECT_EQ(CONTENT_SETTING_ASK, |
453 profile()->GetHostContentSettingsMap()->GetContentSetting( | 444 profile()->GetHostContentSettingsMap()->GetContentSetting( |
454 requesting_frame_0, | 445 requesting_frame_0, |
455 requesting_frame_0, | 446 requesting_frame_0, |
456 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 447 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
457 std::string())); | 448 std::string())); |
458 | 449 |
459 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 450 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
460 profile()->GetHostContentSettingsMap()->GetContentSetting( | 451 profile()->GetHostContentSettingsMap()->GetContentSetting( |
461 requesting_frame_1, | 452 requesting_frame_1, |
462 requesting_frame_0, | 453 requesting_frame_0, |
463 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 454 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
464 std::string())); | 455 std::string())); |
465 } | 456 } |
466 | 457 |
467 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 458 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
468 GURL invalid_embedder("about:blank"); | 459 GURL invalid_embedder("about:blank"); |
469 GURL requesting_frame; | 460 GURL requesting_frame; |
470 NavigateAndCommit(invalid_embedder); | 461 NavigateAndCommit(invalid_embedder); |
471 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 462 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
472 RequestGeolocationPermission( | 463 RequestGeolocationPermission(RequestID(0), requesting_frame); |
473 process_id(), render_id(), bridge_id(), requesting_frame); | |
474 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 464 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
475 CheckPermissionMessageSent(bridge_id(), false); | 465 CheckPermissionMessageSent(0, false); |
476 } | 466 } |
477 | 467 |
478 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 468 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
479 GURL url_a("http://www.example.com/geolocation"); | 469 GURL url_a("http://www.example.com/geolocation"); |
480 GURL url_b("http://www.example-2.com/geolocation"); | 470 GURL url_b("http://www.example-2.com/geolocation"); |
481 NavigateAndCommit(url_a); | 471 NavigateAndCommit(url_a); |
482 AddNewTab(url_b); | 472 AddNewTab(url_b); |
483 AddNewTab(url_a); | 473 AddNewTab(url_a); |
484 | 474 |
485 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 475 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
486 RequestGeolocationPermission( | 476 RequestGeolocationPermission(RequestID(0), url_a); |
487 process_id(), render_id(), bridge_id(), url_a); | |
488 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 477 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
489 | 478 |
490 RequestGeolocationPermission( | 479 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
491 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); | |
492 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 480 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
493 | 481 |
494 RequestGeolocationPermission( | 482 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
495 process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); | |
496 ASSERT_EQ(1U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); | 483 ASSERT_EQ(1U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); |
497 | 484 |
498 ConfirmInfoBarDelegate* removed_infobar = infobar_tab_helper_for_tab(1)-> | 485 ConfirmInfoBarDelegate* removed_infobar = infobar_tab_helper_for_tab(1)-> |
499 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 486 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
500 | 487 |
501 // Accept the first tab. | 488 // Accept the first tab. |
502 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 489 ConfirmInfoBarDelegate* infobar_0 = |
503 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 490 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
504 ASSERT_TRUE(infobar_0); | 491 ASSERT_TRUE(infobar_0); |
505 infobar_0->Accept(); | 492 infobar_0->Accept(); |
506 CheckPermissionMessageSent(bridge_id(), true); | 493 CheckPermissionMessageSent(0, true); |
507 infobar_tab_helper()->RemoveInfoBar(infobar_0); | 494 infobar_tab_helper()->RemoveInfoBar(infobar_0); |
508 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 495 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
509 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 496 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
510 infobar_0->InfoBarClosed(); | 497 infobar_0->InfoBarClosed(); |
511 // Now the infobar for the tab with the same origin should have gone. | 498 // Now the infobar for the tab with the same origin should have gone. |
512 EXPECT_EQ(0U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); | 499 EXPECT_EQ(0U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); |
513 CheckPermissionMessageSentForTab(1, bridge_id(), true); | 500 CheckPermissionMessageSentForTab(1, 0, true); |
514 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 501 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
515 closed_delegate_tracker_.Clear(); | 502 closed_delegate_tracker_.Clear(); |
516 // Destroy the infobar that has just been removed. | 503 // Destroy the infobar that has just been removed. |
517 removed_infobar->InfoBarClosed(); | 504 removed_infobar->InfoBarClosed(); |
518 | 505 |
519 // But the other tab should still have the info bar... | 506 // But the other tab should still have the info bar... |
520 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 507 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
521 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> | 508 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> |
522 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 509 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
523 infobar_1->Cancel(); | 510 infobar_1->Cancel(); |
524 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); | 511 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); |
525 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 512 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
526 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 513 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
527 infobar_1->InfoBarClosed(); | 514 infobar_1->InfoBarClosed(); |
528 } | 515 } |
529 | 516 |
530 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 517 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
531 GURL url_a("http://www.example.com/geolocation"); | 518 GURL url_a("http://www.example.com/geolocation"); |
532 GURL url_b("http://www.example-2.com/geolocation"); | 519 GURL url_b("http://www.example-2.com/geolocation"); |
533 NavigateAndCommit(url_a); | 520 NavigateAndCommit(url_a); |
534 AddNewTab(url_a); | 521 AddNewTab(url_a); |
535 | 522 |
536 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 523 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
537 RequestGeolocationPermission( | 524 RequestGeolocationPermission(RequestID(0), url_a); |
538 process_id(), render_id(), bridge_id(), url_a); | |
539 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 525 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
540 | 526 |
541 RequestGeolocationPermission( | 527 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
542 process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); | |
543 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 528 EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
544 | 529 |
545 RequestGeolocationPermission( | 530 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
546 process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); | |
547 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 531 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
548 | 532 |
549 ConfirmInfoBarDelegate* removed_infobar = | 533 ConfirmInfoBarDelegate* removed_infobar = |
550 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 534 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
551 | 535 |
552 // Accept the second tab. | 536 // Accept the second tab. |
553 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper_for_tab(0)-> | 537 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper_for_tab(0)-> |
554 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 538 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
555 ASSERT_TRUE(infobar_0); | 539 ASSERT_TRUE(infobar_0); |
556 infobar_0->Accept(); | 540 infobar_0->Accept(); |
557 CheckPermissionMessageSentForTab(0, bridge_id(), true); | 541 CheckPermissionMessageSentForTab(0, 0, true); |
558 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_0); | 542 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_0); |
559 EXPECT_EQ(2U, closed_delegate_tracker_.size()); | 543 EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
560 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 544 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
561 infobar_0->InfoBarClosed(); | 545 infobar_0->InfoBarClosed(); |
562 // Now the infobar for the tab with the same origin should have gone. | 546 // Now the infobar for the tab with the same origin should have gone. |
563 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 547 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
564 CheckPermissionMessageSent(bridge_id(), true); | 548 CheckPermissionMessageSent(0, true); |
565 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); | 549 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
566 closed_delegate_tracker_.Clear(); | 550 closed_delegate_tracker_.Clear(); |
567 // Destroy the infobar that has just been removed. | 551 // Destroy the infobar that has just been removed. |
568 removed_infobar->InfoBarClosed(); | 552 removed_infobar->InfoBarClosed(); |
569 | 553 |
570 // And we should have the queued infobar displayed now. | 554 // And we should have the queued infobar displayed now. |
571 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); | 555 ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
572 | 556 |
573 // Accept the second infobar. | 557 // Accept the second infobar. |
574 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> | 558 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper_for_tab(0)-> |
575 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 559 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
576 ASSERT_TRUE(infobar_1); | 560 ASSERT_TRUE(infobar_1); |
577 infobar_1->Accept(); | 561 infobar_1->Accept(); |
578 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); | 562 CheckPermissionMessageSentForTab(0, 1, true); |
579 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); | 563 infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); |
580 EXPECT_EQ(1U, closed_delegate_tracker_.size()); | 564 EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
581 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); | 565 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
582 infobar_1->InfoBarClosed(); | 566 infobar_1->InfoBarClosed(); |
583 } | 567 } |
584 | 568 |
585 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 569 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
586 GURL requesting_frame_0("http://www.example.com/geolocation"); | 570 GURL requesting_frame_0("http://www.example.com/geolocation"); |
587 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 571 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
588 EXPECT_EQ( | 572 EXPECT_EQ( |
589 CONTENT_SETTING_ASK, | 573 CONTENT_SETTING_ASK, |
590 profile()->GetHostContentSettingsMap()->GetContentSetting( | 574 profile()->GetHostContentSettingsMap()->GetContentSetting( |
591 requesting_frame_0, | 575 requesting_frame_0, |
592 requesting_frame_0, | 576 requesting_frame_0, |
593 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 577 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
594 std::string())); | 578 std::string())); |
595 | 579 |
596 EXPECT_EQ( | 580 EXPECT_EQ( |
597 CONTENT_SETTING_ASK, | 581 CONTENT_SETTING_ASK, |
598 profile()->GetHostContentSettingsMap()->GetContentSetting( | 582 profile()->GetHostContentSettingsMap()->GetContentSetting( |
599 requesting_frame_1, | 583 requesting_frame_1, |
600 requesting_frame_0, | 584 requesting_frame_0, |
601 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 585 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
602 std::string())); | 586 std::string())); |
603 | 587 |
604 NavigateAndCommit(requesting_frame_0); | 588 NavigateAndCommit(requesting_frame_0); |
605 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 589 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
606 // Request permission for two frames. | 590 // Request permission for two frames. |
607 RequestGeolocationPermission( | 591 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
608 process_id(), render_id(), bridge_id(), requesting_frame_0); | 592 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
609 RequestGeolocationPermission( | |
610 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); | |
611 // Ensure only one infobar is created. | 593 // Ensure only one infobar is created. |
612 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 594 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
613 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> | 595 ConfirmInfoBarDelegate* infobar_0 = |
614 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 596 infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
615 ASSERT_TRUE(infobar_0); | 597 ASSERT_TRUE(infobar_0); |
616 | 598 |
617 // Delete the tab contents. | 599 // Delete the tab contents. |
618 DeleteContents(); | 600 DeleteContents(); |
619 infobar_0->InfoBarClosed(); | 601 infobar_0->InfoBarClosed(); |
620 | 602 |
621 // During contents destruction, the infobar will have been closed, and a | 603 // During contents destruction, the infobar will have been closed, and a |
622 // second (with it's own new delegate) will have been created. In Chromium, | 604 // second (with it's own new delegate) will have been created. In Chromium, |
623 // this would be properly deleted by the InfoBarContainer, but in this unit | 605 // this would be properly deleted by the InfoBarContainer, but in this unit |
624 // test, the closest thing we have to that is the ClosedDelegateTracker. | 606 // test, the closest thing we have to that is the ClosedDelegateTracker. |
625 ASSERT_EQ(2U, closed_delegate_tracker_.size()); | 607 ASSERT_EQ(2U, closed_delegate_tracker_.size()); |
626 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); | 608 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
627 closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0); | 609 closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0); |
628 (*closed_delegate_tracker_.removed_infobar_delegates_.begin())-> | 610 (*closed_delegate_tracker_.removed_infobar_delegates_.begin())-> |
629 InfoBarClosed(); | 611 InfoBarClosed(); |
630 } | 612 } |
631 | 613 |
632 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 614 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
633 GURL requesting_frame_0("http://www.example.com/geolocation"); | 615 GURL requesting_frame_0("http://www.example.com/geolocation"); |
634 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 616 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
635 NavigateAndCommit(requesting_frame_0); | 617 NavigateAndCommit(requesting_frame_0); |
636 NavigateAndCommit(requesting_frame_1); | 618 NavigateAndCommit(requesting_frame_1); |
637 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); | 619 EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
638 // Go back: navigate to a pending entry before requesting geolocation | 620 // Go back: navigate to a pending entry before requesting geolocation |
639 // permission. | 621 // permission. |
640 web_contents()->GetController().GoBack(); | 622 web_contents()->GetController().GoBack(); |
641 // Request permission for the committed frame (not the pending one). | 623 // Request permission for the committed frame (not the pending one). |
642 RequestGeolocationPermission( | 624 RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
643 process_id(), render_id(), bridge_id(), requesting_frame_1); | |
644 // Ensure the infobar is created. | 625 // Ensure the infobar is created. |
645 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); | 626 ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
646 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); | 627 InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); |
647 ASSERT_TRUE(infobar_0); | 628 ASSERT_TRUE(infobar_0); |
648 // Ensure the infobar is not yet expired. | 629 // Ensure the infobar is not yet expired. |
649 content::LoadCommittedDetails details; | 630 content::LoadCommittedDetails details; |
650 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 631 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
651 ASSERT_FALSE(infobar_0->ShouldExpire(details)); | 632 ASSERT_FALSE(infobar_0->ShouldExpire(details)); |
652 // Commit the "GoBack()" above, and ensure the infobar is now expired. | 633 // Commit the "GoBack()" above, and ensure the infobar is now expired. |
653 WebContentsTester::For(web_contents())->CommitPendingNavigation(); | 634 WebContentsTester::For(web_contents())->CommitPendingNavigation(); |
654 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 635 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
655 ASSERT_TRUE(infobar_0->ShouldExpire(details)); | 636 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
656 | 637 |
657 // Delete the tab contents. | 638 // Delete the tab contents. |
658 DeleteContents(); | 639 DeleteContents(); |
659 infobar_0->InfoBarClosed(); | 640 infobar_0->InfoBarClosed(); |
660 } | 641 } |
OLD | NEW |