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/geolocation/chrome_geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 ClosedInfoBarTracker(); | 49 ClosedInfoBarTracker(); |
50 virtual ~ClosedInfoBarTracker(); | 50 virtual ~ClosedInfoBarTracker(); |
51 | 51 |
52 // content::NotificationObserver: | 52 // content::NotificationObserver: |
53 virtual void Observe(int type, | 53 virtual void Observe(int type, |
54 const content::NotificationSource& source, | 54 const content::NotificationSource& source, |
55 const content::NotificationDetails& details) OVERRIDE; | 55 const content::NotificationDetails& details) OVERRIDE; |
56 | 56 |
57 size_t size() const { return removed_infobars_.size(); } | 57 size_t size() const { return removed_infobars_.size(); } |
58 | 58 |
59 bool Contains(InfoBar* infobar) const; | 59 bool Contains(InfoBarDelegate* infobar) const; |
60 void Clear(); | 60 void Clear(); |
61 | 61 |
62 private: | 62 private: |
63 FRIEND_TEST_ALL_PREFIXES(GeolocationPermissionContextTests, TabDestroyed); | 63 FRIEND_TEST_ALL_PREFIXES(GeolocationPermissionContextTests, TabDestroyed); |
64 content::NotificationRegistrar registrar_; | 64 content::NotificationRegistrar registrar_; |
65 std::set<InfoBar*> removed_infobars_; | 65 std::set<InfoBarDelegate*> removed_infobars_; |
66 }; | 66 }; |
67 | 67 |
68 ClosedInfoBarTracker::ClosedInfoBarTracker() { | 68 ClosedInfoBarTracker::ClosedInfoBarTracker() { |
69 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 69 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
70 content::NotificationService::AllSources()); | 70 content::NotificationService::AllSources()); |
71 } | 71 } |
72 | 72 |
73 ClosedInfoBarTracker::~ClosedInfoBarTracker() { | 73 ClosedInfoBarTracker::~ClosedInfoBarTracker() { |
74 } | 74 } |
75 | 75 |
76 void ClosedInfoBarTracker::Observe( | 76 void ClosedInfoBarTracker::Observe( |
77 int type, | 77 int type, |
78 const content::NotificationSource& source, | 78 const content::NotificationSource& source, |
79 const content::NotificationDetails& details) { | 79 const content::NotificationDetails& details) { |
80 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); | 80 DCHECK(type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED); |
81 removed_infobars_.insert( | 81 removed_infobars_.insert( |
82 content::Details<InfoBar::RemovedDetails>(details)->first); | 82 content::Details<InfoBar::RemovedDetails>(details)->first); |
83 } | 83 } |
84 | 84 |
85 bool ClosedInfoBarTracker::Contains(InfoBar* infobar) const { | 85 bool ClosedInfoBarTracker::Contains(InfoBarDelegate* infobar) const { |
86 return removed_infobars_.count(infobar) != 0; | 86 return removed_infobars_.count(infobar) != 0; |
87 } | 87 } |
88 | 88 |
89 void ClosedInfoBarTracker::Clear() { | 89 void ClosedInfoBarTracker::Clear() { |
90 removed_infobars_.clear(); | 90 removed_infobars_.clear(); |
91 } | 91 } |
92 | 92 |
93 | 93 |
94 // GeolocationPermissionContextTests ------------------------------------------ | 94 // GeolocationPermissionContextTests ------------------------------------------ |
95 | 95 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 251 } |
252 | 252 |
253 // Tests ---------------------------------------------------------------------- | 253 // Tests ---------------------------------------------------------------------- |
254 | 254 |
255 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 255 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
256 GURL requesting_frame("http://www.example.com/geolocation"); | 256 GURL requesting_frame("http://www.example.com/geolocation"); |
257 NavigateAndCommit(requesting_frame); | 257 NavigateAndCommit(requesting_frame); |
258 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 258 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
259 RequestGeolocationPermission(RequestID(0), requesting_frame); | 259 RequestGeolocationPermission(RequestID(0), requesting_frame); |
260 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 260 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
261 InfoBar* infobar = infobar_service()->infobar_at(0); | |
262 ConfirmInfoBarDelegate* infobar_delegate = | 261 ConfirmInfoBarDelegate* infobar_delegate = |
263 infobar->delegate()->AsConfirmInfoBarDelegate(); | 262 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
264 ASSERT_TRUE(infobar_delegate); | 263 ASSERT_TRUE(infobar_delegate); |
265 infobar_delegate->Cancel(); | 264 infobar_delegate->Cancel(); |
266 infobar_service()->RemoveInfoBar(infobar); | 265 infobar_service()->RemoveInfoBar(infobar_delegate); |
267 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 266 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
268 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 267 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate)); |
| 268 delete infobar_delegate; |
269 } | 269 } |
270 | 270 |
271 #if defined(OS_ANDROID) | 271 #if defined(OS_ANDROID) |
272 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 272 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
273 GURL requesting_frame("http://www.example.com/geolocation"); | 273 GURL requesting_frame("http://www.example.com/geolocation"); |
274 NavigateAndCommit(requesting_frame); | 274 NavigateAndCommit(requesting_frame); |
275 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 275 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
276 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 276 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
277 RequestGeolocationPermission(RequestID(0), requesting_frame); | 277 RequestGeolocationPermission(RequestID(0), requesting_frame); |
278 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 278 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
279 ConfirmInfoBarDelegate* infobar_delegate_0 = infobar_service()-> | 279 ConfirmInfoBarDelegate* infobar_delegate_0 = |
280 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 280 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
281 ASSERT_TRUE(infobar_delegate_0); | 281 ASSERT_TRUE(infobar_delegate_0); |
282 string16 text_0 = infobar_delegate_0->GetButtonLabel( | 282 string16 text_0 = infobar_delegate_0->GetButtonLabel( |
283 ConfirmInfoBarDelegate::BUTTON_OK); | 283 ConfirmInfoBarDelegate::BUTTON_OK); |
284 | 284 |
285 NavigateAndCommit(requesting_frame); | 285 NavigateAndCommit(requesting_frame); |
286 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 286 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
287 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 287 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
288 RequestGeolocationPermission(RequestID(0), requesting_frame); | 288 RequestGeolocationPermission(RequestID(0), requesting_frame); |
289 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 289 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
290 ConfirmInfoBarDelegate* infobar_delegate_1 = infobar_service()-> | 290 ConfirmInfoBarDelegate* infobar_delegate_1 = |
291 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 291 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
292 ASSERT_TRUE(infobar_delegate_1); | 292 ASSERT_TRUE(infobar_delegate_1); |
293 string16 text_1 = infobar_delegate_1->GetButtonLabel( | 293 string16 text_1 = infobar_delegate_1->GetButtonLabel( |
294 ConfirmInfoBarDelegate::BUTTON_OK); | 294 ConfirmInfoBarDelegate::BUTTON_OK); |
295 EXPECT_NE(text_0, text_1); | 295 EXPECT_NE(text_0, text_1); |
296 | 296 |
297 NavigateAndCommit(requesting_frame); | 297 NavigateAndCommit(requesting_frame); |
298 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); | 298 MockGoogleLocationSettingsHelper::SetLocationStatus(false, false); |
299 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 299 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
300 RequestGeolocationPermission(RequestID(0), requesting_frame); | 300 RequestGeolocationPermission(RequestID(0), requesting_frame); |
301 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 301 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
302 } | 302 } |
303 | 303 |
304 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 304 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
305 GURL requesting_frame("http://www.example.com/geolocation"); | 305 GURL requesting_frame("http://www.example.com/geolocation"); |
306 NavigateAndCommit(requesting_frame); | 306 NavigateAndCommit(requesting_frame); |
307 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 307 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
308 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 308 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
309 RequestGeolocationPermission(RequestID(0), requesting_frame); | 309 RequestGeolocationPermission(RequestID(0), requesting_frame); |
310 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 310 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
311 ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> | 311 ConfirmInfoBarDelegate* infobar_delegate = |
312 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 312 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
313 ASSERT_TRUE(infobar_delegate); | 313 ASSERT_TRUE(infobar_delegate); |
314 infobar_delegate->Accept(); | 314 infobar_delegate->Accept(); |
315 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 315 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
316 CheckPermissionMessageSent(0, true); | 316 CheckPermissionMessageSent(0, true); |
317 } | 317 } |
318 | 318 |
319 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 319 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { |
320 GURL requesting_frame("http://www.example.com/geolocation"); | 320 GURL requesting_frame("http://www.example.com/geolocation"); |
321 NavigateAndCommit(requesting_frame); | 321 NavigateAndCommit(requesting_frame); |
322 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 322 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
323 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 323 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
324 RequestGeolocationPermission(RequestID(0), requesting_frame); | 324 RequestGeolocationPermission(RequestID(0), requesting_frame); |
325 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 325 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
326 ConfirmInfoBarDelegate* infobar_delegate = infobar_service()-> | 326 ConfirmInfoBarDelegate* infobar_delegate = |
327 infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 327 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
328 ASSERT_TRUE(infobar_delegate); | 328 ASSERT_TRUE(infobar_delegate); |
329 infobar_delegate->Accept(); | 329 infobar_delegate->Accept(); |
330 EXPECT_TRUE( | 330 EXPECT_TRUE( |
331 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); | 331 MockGoogleLocationSettingsHelper::WasGoogleLocationSettingsCalled()); |
332 } | 332 } |
333 #endif | 333 #endif |
334 | 334 |
335 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 335 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
336 GURL requesting_frame_0("http://www.example.com/geolocation"); | 336 GURL requesting_frame_0("http://www.example.com/geolocation"); |
337 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 337 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
338 EXPECT_EQ(CONTENT_SETTING_ASK, | 338 EXPECT_EQ(CONTENT_SETTING_ASK, |
339 profile()->GetHostContentSettingsMap()->GetContentSetting( | 339 profile()->GetHostContentSettingsMap()->GetContentSetting( |
340 requesting_frame_0, requesting_frame_0, | 340 requesting_frame_0, requesting_frame_0, |
341 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 341 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
342 EXPECT_EQ(CONTENT_SETTING_ASK, | 342 EXPECT_EQ(CONTENT_SETTING_ASK, |
343 profile()->GetHostContentSettingsMap()->GetContentSetting( | 343 profile()->GetHostContentSettingsMap()->GetContentSetting( |
344 requesting_frame_1, requesting_frame_0, | 344 requesting_frame_1, requesting_frame_0, |
345 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 345 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
346 | 346 |
347 NavigateAndCommit(requesting_frame_0); | 347 NavigateAndCommit(requesting_frame_0); |
348 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 348 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
349 // Request permission for two frames. | 349 // Request permission for two frames. |
350 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 350 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
351 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 351 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
352 // Ensure only one infobar is created. | 352 // Ensure only one infobar is created. |
353 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 353 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
354 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | |
355 ConfirmInfoBarDelegate* infobar_delegate_0 = | 354 ConfirmInfoBarDelegate* infobar_delegate_0 = |
356 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 355 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
357 ASSERT_TRUE(infobar_delegate_0); | 356 ASSERT_TRUE(infobar_delegate_0); |
358 string16 text_0 = infobar_delegate_0->GetMessageText(); | 357 string16 text_0 = infobar_delegate_0->GetMessageText(); |
359 | 358 |
360 // Accept the first frame. | 359 // Accept the first frame. |
361 infobar_delegate_0->Accept(); | 360 infobar_delegate_0->Accept(); |
362 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 361 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
363 CheckPermissionMessageSent(0, true); | 362 CheckPermissionMessageSent(0, true); |
364 | 363 |
365 infobar_service()->RemoveInfoBar(infobar_0); | 364 infobar_service()->RemoveInfoBar(infobar_delegate_0); |
366 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 365 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
367 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 366 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); |
368 closed_infobar_tracker_.Clear(); | 367 closed_infobar_tracker_.Clear(); |
| 368 delete infobar_delegate_0; |
369 // Now we should have a new infobar for the second frame. | 369 // Now we should have a new infobar for the second frame. |
370 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 370 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
371 | 371 |
372 InfoBar* infobar_1 = infobar_service()->infobar_at(0); | |
373 ConfirmInfoBarDelegate* infobar_delegate_1 = | 372 ConfirmInfoBarDelegate* infobar_delegate_1 = |
374 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 373 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
375 ASSERT_TRUE(infobar_delegate_1); | 374 ASSERT_TRUE(infobar_delegate_1); |
376 string16 text_1 = infobar_delegate_1->GetMessageText(); | 375 string16 text_1 = infobar_delegate_1->GetMessageText(); |
377 EXPECT_NE(text_0, text_1); | 376 EXPECT_NE(text_0, text_1); |
378 | 377 |
379 // Cancel (block) this frame. | 378 // Cancel (block) this frame. |
380 infobar_delegate_1->Cancel(); | 379 infobar_delegate_1->Cancel(); |
381 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 380 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
382 CheckPermissionMessageSent(1, false); | 381 CheckPermissionMessageSent(1, false); |
383 infobar_service()->RemoveInfoBar(infobar_1); | 382 infobar_service()->RemoveInfoBar(infobar_delegate_1); |
384 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 383 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
385 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 384 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); |
| 385 delete infobar_delegate_1; |
386 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 386 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
387 // Ensure the persisted permissions are ok. | 387 // Ensure the persisted permissions are ok. |
388 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 388 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
389 profile()->GetHostContentSettingsMap()->GetContentSetting( | 389 profile()->GetHostContentSettingsMap()->GetContentSetting( |
390 requesting_frame_0, requesting_frame_0, | 390 requesting_frame_0, requesting_frame_0, |
391 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 391 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
392 | 392 |
393 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 393 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
394 profile()->GetHostContentSettingsMap()->GetContentSetting( | 394 profile()->GetHostContentSettingsMap()->GetContentSetting( |
395 requesting_frame_1, requesting_frame_0, | 395 requesting_frame_1, requesting_frame_0, |
396 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 396 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
397 } | 397 } |
398 | 398 |
399 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 399 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
400 GURL url_a("http://www.example.com/geolocation#a"); | 400 GURL url_a("http://www.example.com/geolocation#a"); |
401 GURL url_b("http://www.example.com/geolocation#b"); | 401 GURL url_b("http://www.example.com/geolocation#b"); |
402 | 402 |
403 // Navigate to the first url and check permission is requested. | 403 // Navigate to the first url and check permission is requested. |
404 NavigateAndCommit(url_a); | 404 NavigateAndCommit(url_a); |
405 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 405 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
406 RequestGeolocationPermission(RequestID(0), url_a); | 406 RequestGeolocationPermission(RequestID(0), url_a); |
407 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 407 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
408 InfoBar* infobar = infobar_service()->infobar_at(0); | |
409 ConfirmInfoBarDelegate* infobar_delegate = | 408 ConfirmInfoBarDelegate* infobar_delegate = |
410 infobar->delegate()->AsConfirmInfoBarDelegate(); | 409 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
411 ASSERT_TRUE(infobar_delegate); | 410 ASSERT_TRUE(infobar_delegate); |
412 | 411 |
413 // Change the hash, we'll still be on the same page. | 412 // Change the hash, we'll still be on the same page. |
414 NavigateAndCommit(url_b); | 413 NavigateAndCommit(url_b); |
415 | 414 |
416 // Accept. | 415 // Accept. |
417 infobar_delegate->Accept(); | 416 infobar_delegate->Accept(); |
418 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 417 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
419 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 418 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
420 CheckPermissionMessageSent(0, true); | 419 CheckPermissionMessageSent(0, true); |
421 | 420 |
422 // Cleanup. | 421 // Cleanup. |
423 infobar_service()->RemoveInfoBar(infobar); | 422 infobar_service()->RemoveInfoBar(infobar_delegate); |
424 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 423 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
425 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 424 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate)); |
| 425 closed_infobar_tracker_.Clear(); |
| 426 delete infobar_delegate; |
426 } | 427 } |
427 | 428 |
428 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 429 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { |
429 GURL requesting_frame("file://example/geolocation.html"); | 430 GURL requesting_frame("file://example/geolocation.html"); |
430 NavigateAndCommit(requesting_frame); | 431 NavigateAndCommit(requesting_frame); |
431 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 432 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
432 RequestGeolocationPermission(RequestID(0), requesting_frame); | 433 RequestGeolocationPermission(RequestID(0), requesting_frame); |
433 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 434 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
434 InfoBar* infobar = infobar_service()->infobar_at(0); | |
435 ConfirmInfoBarDelegate* infobar_delegate = | 435 ConfirmInfoBarDelegate* infobar_delegate = |
436 infobar->delegate()->AsConfirmInfoBarDelegate(); | 436 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
437 ASSERT_TRUE(infobar_delegate); | 437 ASSERT_TRUE(infobar_delegate); |
438 // Accept the frame. | 438 // Accept the frame. |
439 infobar_delegate->Accept(); | 439 infobar_delegate->Accept(); |
440 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 440 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
441 CheckPermissionMessageSent(0, true); | 441 CheckPermissionMessageSent(0, true); |
442 infobar_service()->RemoveInfoBar(infobar); | 442 infobar_service()->RemoveInfoBar(infobar_delegate); |
| 443 delete infobar_delegate; |
443 | 444 |
444 // Make sure the setting is not stored. | 445 // Make sure the setting is not stored. |
445 EXPECT_EQ(CONTENT_SETTING_ASK, | 446 EXPECT_EQ(CONTENT_SETTING_ASK, |
446 profile()->GetHostContentSettingsMap()->GetContentSetting( | 447 profile()->GetHostContentSettingsMap()->GetContentSetting( |
447 requesting_frame, | 448 requesting_frame, |
448 requesting_frame, | 449 requesting_frame, |
449 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 450 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
450 std::string())); | 451 std::string())); |
451 } | 452 } |
452 | 453 |
(...skipping 10 matching lines...) Expand all Loading... |
463 requesting_frame_1, requesting_frame_0, | 464 requesting_frame_1, requesting_frame_0, |
464 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 465 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
465 | 466 |
466 NavigateAndCommit(requesting_frame_0); | 467 NavigateAndCommit(requesting_frame_0); |
467 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 468 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
468 // Request permission for two frames. | 469 // Request permission for two frames. |
469 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 470 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
470 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 471 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
471 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 472 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
472 | 473 |
473 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | |
474 ConfirmInfoBarDelegate* infobar_delegate_0 = | 474 ConfirmInfoBarDelegate* infobar_delegate_0 = |
475 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 475 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
476 ASSERT_TRUE(infobar_delegate_0); | 476 ASSERT_TRUE(infobar_delegate_0); |
477 string16 text_0 = infobar_delegate_0->GetMessageText(); | 477 string16 text_0 = infobar_delegate_0->GetMessageText(); |
478 | 478 |
479 // Simulate the frame going away, ensure the infobar for this frame | 479 // Simulate the frame going away, ensure the infobar for this frame |
480 // is removed and the next pending infobar is created. | 480 // is removed and the next pending infobar is created. |
481 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); | 481 CancelGeolocationPermissionRequest(RequestID(0), requesting_frame_0); |
482 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 482 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
483 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 483 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); |
484 closed_infobar_tracker_.Clear(); | 484 closed_infobar_tracker_.Clear(); |
| 485 delete infobar_delegate_0; |
485 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 486 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
486 | 487 |
487 InfoBar* infobar_1 = infobar_service()->infobar_at(0); | |
488 ConfirmInfoBarDelegate* infobar_delegate_1 = | 488 ConfirmInfoBarDelegate* infobar_delegate_1 = |
489 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 489 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
490 ASSERT_TRUE(infobar_delegate_1); | 490 ASSERT_TRUE(infobar_delegate_1); |
491 string16 text_1 = infobar_delegate_1->GetMessageText(); | 491 string16 text_1 = infobar_delegate_1->GetMessageText(); |
492 EXPECT_NE(text_0, text_1); | 492 EXPECT_NE(text_0, text_1); |
493 | 493 |
494 // Allow this frame. | 494 // Allow this frame. |
495 infobar_delegate_1->Accept(); | 495 infobar_delegate_1->Accept(); |
496 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 496 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
497 CheckPermissionMessageSent(1, true); | 497 CheckPermissionMessageSent(1, true); |
498 infobar_service()->RemoveInfoBar(infobar_1); | 498 infobar_service()->RemoveInfoBar(infobar_delegate_1); |
499 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 499 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
500 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 500 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); |
| 501 delete infobar_delegate_1; |
501 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 502 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
502 // Ensure the persisted permissions are ok. | 503 // Ensure the persisted permissions are ok. |
503 EXPECT_EQ(CONTENT_SETTING_ASK, | 504 EXPECT_EQ(CONTENT_SETTING_ASK, |
504 profile()->GetHostContentSettingsMap()->GetContentSetting( | 505 profile()->GetHostContentSettingsMap()->GetContentSetting( |
505 requesting_frame_0, requesting_frame_0, | 506 requesting_frame_0, requesting_frame_0, |
506 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 507 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
507 | 508 |
508 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 509 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
509 profile()->GetHostContentSettingsMap()->GetContentSetting( | 510 profile()->GetHostContentSettingsMap()->GetContentSetting( |
510 requesting_frame_1, requesting_frame_0, | 511 requesting_frame_1, requesting_frame_0, |
(...skipping 20 matching lines...) Expand all Loading... |
531 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 532 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
532 RequestGeolocationPermission(RequestID(0), url_a); | 533 RequestGeolocationPermission(RequestID(0), url_a); |
533 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 534 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
534 | 535 |
535 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); | 536 RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
536 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 537 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
537 | 538 |
538 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); | 539 RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
539 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 540 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
540 | 541 |
541 InfoBar* removed_infobar = infobar_service_for_tab(1)->infobar_at(0); | 542 ConfirmInfoBarDelegate* removed_infobar = |
| 543 infobar_service_for_tab(1)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
542 | 544 |
543 // Accept the first tab. | 545 // Accept the first tab. |
544 InfoBar* infobar_0 = infobar_service()->infobar_at(0); | |
545 ConfirmInfoBarDelegate* infobar_delegate_0 = | 546 ConfirmInfoBarDelegate* infobar_delegate_0 = |
546 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 547 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
547 ASSERT_TRUE(infobar_delegate_0); | 548 ASSERT_TRUE(infobar_delegate_0); |
548 infobar_delegate_0->Accept(); | 549 infobar_delegate_0->Accept(); |
549 CheckPermissionMessageSent(0, true); | 550 CheckPermissionMessageSent(0, true); |
550 infobar_service()->RemoveInfoBar(infobar_0); | 551 infobar_service()->RemoveInfoBar(infobar_delegate_0); |
551 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 552 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
552 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 553 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); |
| 554 delete infobar_delegate_0; |
553 // Now the infobar for the tab with the same origin should have gone. | 555 // Now the infobar for the tab with the same origin should have gone. |
554 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); | 556 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); |
555 CheckPermissionMessageSentForTab(1, 0, true); | 557 CheckPermissionMessageSentForTab(1, 0, true); |
556 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 558 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); |
557 closed_infobar_tracker_.Clear(); | 559 closed_infobar_tracker_.Clear(); |
| 560 // Destroy the infobar that has just been removed. |
| 561 delete removed_infobar; |
558 | 562 |
559 // But the other tab should still have the info bar... | 563 // But the other tab should still have the info bar... |
560 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 564 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
561 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | |
562 ConfirmInfoBarDelegate* infobar_delegate_1 = | 565 ConfirmInfoBarDelegate* infobar_delegate_1 = |
563 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 566 infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
564 ASSERT_TRUE(infobar_delegate_1); | |
565 infobar_delegate_1->Cancel(); | 567 infobar_delegate_1->Cancel(); |
566 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 568 infobar_service_for_tab(0)->RemoveInfoBar(infobar_delegate_1); |
567 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 569 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
568 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 570 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); |
| 571 delete infobar_delegate_1; |
569 } | 572 } |
570 | 573 |
571 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 574 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
572 GURL url_a("http://www.example.com/geolocation"); | 575 GURL url_a("http://www.example.com/geolocation"); |
573 GURL url_b("http://www.example-2.com/geolocation"); | 576 GURL url_b("http://www.example-2.com/geolocation"); |
574 NavigateAndCommit(url_a); | 577 NavigateAndCommit(url_a); |
575 AddNewTab(url_a); | 578 AddNewTab(url_a); |
576 | 579 |
577 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 580 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
578 RequestGeolocationPermission(RequestID(0), url_a); | 581 RequestGeolocationPermission(RequestID(0), url_a); |
579 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 582 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
580 | 583 |
581 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); | 584 RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
582 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 585 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
583 | 586 |
584 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); | 587 RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
585 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 588 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
586 | 589 |
587 InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 590 ConfirmInfoBarDelegate* removed_infobar = |
| 591 infobar_service()->infobar_at(0)->AsConfirmInfoBarDelegate(); |
588 | 592 |
589 // Accept the second tab. | 593 // Accept the second tab. |
590 InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | |
591 ConfirmInfoBarDelegate* infobar_delegate_0 = | 594 ConfirmInfoBarDelegate* infobar_delegate_0 = |
592 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 595 infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
593 ASSERT_TRUE(infobar_delegate_0); | 596 ASSERT_TRUE(infobar_delegate_0); |
594 infobar_delegate_0->Accept(); | 597 infobar_delegate_0->Accept(); |
595 CheckPermissionMessageSentForTab(0, 0, true); | 598 CheckPermissionMessageSentForTab(0, 0, true); |
596 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 599 infobar_service_for_tab(0)->RemoveInfoBar(infobar_delegate_0); |
597 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 600 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
598 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 601 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_0)); |
| 602 delete infobar_delegate_0; |
599 // Now the infobar for the tab with the same origin should have gone. | 603 // Now the infobar for the tab with the same origin should have gone. |
600 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 604 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
601 CheckPermissionMessageSent(0, true); | 605 CheckPermissionMessageSent(0, true); |
602 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 606 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); |
603 closed_infobar_tracker_.Clear(); | 607 closed_infobar_tracker_.Clear(); |
| 608 delete removed_infobar; |
604 | 609 |
605 // And we should have the queued infobar displayed now. | 610 // And we should have the queued infobar displayed now. |
606 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 611 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
607 | 612 |
608 // Accept the second infobar. | 613 // Accept the second infobar. |
609 InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | |
610 ConfirmInfoBarDelegate* infobar_delegate_1 = | 614 ConfirmInfoBarDelegate* infobar_delegate_1 = |
611 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 615 infobar_service_for_tab(0)->infobar_at(0)->AsConfirmInfoBarDelegate(); |
612 ASSERT_TRUE(infobar_delegate_1); | 616 ASSERT_TRUE(infobar_delegate_1); |
613 infobar_delegate_1->Accept(); | 617 infobar_delegate_1->Accept(); |
614 CheckPermissionMessageSentForTab(0, 1, true); | 618 CheckPermissionMessageSentForTab(0, 1, true); |
615 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 619 infobar_service_for_tab(0)->RemoveInfoBar(infobar_delegate_1); |
616 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 620 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
617 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 621 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_delegate_1)); |
| 622 delete infobar_delegate_1; |
618 } | 623 } |
619 | 624 |
620 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 625 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
621 GURL requesting_frame_0("http://www.example.com/geolocation"); | 626 GURL requesting_frame_0("http://www.example.com/geolocation"); |
622 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 627 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
623 EXPECT_EQ(CONTENT_SETTING_ASK, | 628 EXPECT_EQ(CONTENT_SETTING_ASK, |
624 profile()->GetHostContentSettingsMap()->GetContentSetting( | 629 profile()->GetHostContentSettingsMap()->GetContentSetting( |
625 requesting_frame_0, requesting_frame_0, | 630 requesting_frame_0, requesting_frame_0, |
626 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 631 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
627 | 632 |
628 EXPECT_EQ(CONTENT_SETTING_ASK, | 633 EXPECT_EQ(CONTENT_SETTING_ASK, |
629 profile()->GetHostContentSettingsMap()->GetContentSetting( | 634 profile()->GetHostContentSettingsMap()->GetContentSetting( |
630 requesting_frame_1, requesting_frame_0, | 635 requesting_frame_1, requesting_frame_0, |
631 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 636 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
632 | 637 |
633 NavigateAndCommit(requesting_frame_0); | 638 NavigateAndCommit(requesting_frame_0); |
634 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 639 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
635 // Request permission for two frames. | 640 // Request permission for two frames. |
636 RequestGeolocationPermission(RequestID(0), requesting_frame_0); | 641 RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
637 RequestGeolocationPermission(RequestID(1), requesting_frame_1); | 642 RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
638 // Ensure only one infobar is created. | 643 // Ensure only one infobar is created. |
639 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 644 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
640 InfoBar* infobar = infobar_service()->infobar_at(0); | 645 InfoBarDelegate* infobar = infobar_service()->infobar_at(0); |
641 | 646 |
642 // Delete the tab contents. | 647 // Delete the tab contents. |
643 DeleteContents(); | 648 DeleteContents(); |
| 649 delete infobar; |
644 | 650 |
645 // During contents destruction, the infobar will have been closed, and the | 651 // During contents destruction, the infobar will have been closed, and the |
646 // pending request should have been cleared without an infobar being created. | 652 // pending request should have been cleared without an infobar being created. |
647 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 653 ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
648 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 654 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
649 } | 655 } |
650 | 656 |
651 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 657 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
652 GURL requesting_frame_0("http://www.example.com/geolocation"); | 658 GURL requesting_frame_0("http://www.example.com/geolocation"); |
653 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 659 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
654 NavigateAndCommit(requesting_frame_0); | 660 NavigateAndCommit(requesting_frame_0); |
655 NavigateAndCommit(requesting_frame_1); | 661 NavigateAndCommit(requesting_frame_1); |
656 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 662 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
657 // Go back: navigate to a pending entry before requesting geolocation | 663 // Go back: navigate to a pending entry before requesting geolocation |
658 // permission. | 664 // permission. |
659 web_contents()->GetController().GoBack(); | 665 web_contents()->GetController().GoBack(); |
660 // Request permission for the committed frame (not the pending one). | 666 // Request permission for the committed frame (not the pending one). |
661 RequestGeolocationPermission(RequestID(0), requesting_frame_1); | 667 RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
662 // Ensure the infobar is created. | 668 // Ensure the infobar is created. |
663 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 669 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
664 InfoBarDelegate* infobar_delegate = | 670 InfoBarDelegate* infobar_delegate = infobar_service()->infobar_at(0); |
665 infobar_service()->infobar_at(0)->delegate(); | |
666 ASSERT_TRUE(infobar_delegate); | 671 ASSERT_TRUE(infobar_delegate); |
667 // Ensure the infobar wouldn't expire for a navigation to the committed entry. | 672 // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
668 content::LoadCommittedDetails details; | 673 content::LoadCommittedDetails details; |
669 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 674 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
670 EXPECT_FALSE(infobar_delegate->ShouldExpire(details)); | 675 EXPECT_FALSE(infobar_delegate->ShouldExpire(details)); |
671 // Ensure the infobar will expire when we commit the pending navigation. | 676 // Ensure the infobar will expire when we commit the pending navigation. |
672 details.entry = web_contents()->GetController().GetActiveEntry(); | 677 details.entry = web_contents()->GetController().GetActiveEntry(); |
673 EXPECT_TRUE(infobar_delegate->ShouldExpire(details)); | 678 EXPECT_TRUE(infobar_delegate->ShouldExpire(details)); |
674 | 679 |
675 // Delete the tab contents. | 680 // Delete the tab contents. |
676 DeleteContents(); | 681 DeleteContents(); |
| 682 delete infobar_delegate; |
677 } | 683 } |
OLD | NEW |