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

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc

Issue 8698016: Remove InfoBarDelegate::InfoBarClosed(), delete InfoBars directly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cancelling changes. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 7
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "chrome/browser/content_settings/host_content_settings_map.h" 9 #include "chrome/browser/content_settings/host_content_settings_map.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 224 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count());
225 geolocation_permission_context_->RequestGeolocationPermission( 225 geolocation_permission_context_->RequestGeolocationPermission(
226 process_id(), render_id(), bridge_id(), requesting_frame); 226 process_id(), render_id(), bridge_id(), requesting_frame);
227 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 227 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count());
228 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 228 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
229 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 229 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
230 infobar_0->Cancel(); 230 infobar_0->Cancel();
231 infobar_tab_helper()->RemoveInfoBar(infobar_0); 231 infobar_tab_helper()->RemoveInfoBar(infobar_0);
232 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 232 EXPECT_EQ(1U, closed_delegate_tracker_.size());
233 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 233 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
234 infobar_0->InfoBarClosed(); 234 delete infobar_0;
235 } 235 }
236 236
237 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { 237 TEST_F(GeolocationPermissionContextTests, QueuedPermission) {
238 GURL requesting_frame_0("http://www.example.com/geolocation"); 238 GURL requesting_frame_0("http://www.example.com/geolocation");
239 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 239 GURL requesting_frame_1("http://www.example-2.com/geolocation");
240 EXPECT_EQ(CONTENT_SETTING_ASK, 240 EXPECT_EQ(CONTENT_SETTING_ASK,
241 profile()->GetHostContentSettingsMap()->GetContentSetting( 241 profile()->GetHostContentSettingsMap()->GetContentSetting(
242 requesting_frame_0, 242 requesting_frame_0,
243 requesting_frame_0, 243 requesting_frame_0,
244 CONTENT_SETTINGS_TYPE_GEOLOCATION, 244 CONTENT_SETTINGS_TYPE_GEOLOCATION,
(...skipping 22 matching lines...) Expand all
267 267
268 // Accept the first frame. 268 // Accept the first frame.
269 infobar_0->Accept(); 269 infobar_0->Accept();
270 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); 270 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW);
271 CheckPermissionMessageSent(bridge_id(), true); 271 CheckPermissionMessageSent(bridge_id(), true);
272 272
273 infobar_tab_helper()->RemoveInfoBar(infobar_0); 273 infobar_tab_helper()->RemoveInfoBar(infobar_0);
274 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 274 EXPECT_EQ(1U, closed_delegate_tracker_.size());
275 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 275 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
276 closed_delegate_tracker_.Clear(); 276 closed_delegate_tracker_.Clear();
277 infobar_0->InfoBarClosed(); 277 delete infobar_0;
278 // Now we should have a new infobar for the second frame. 278 // Now we should have a new infobar for the second frame.
279 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 279 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count());
280 280
281 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> 281 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()->
282 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 282 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
283 ASSERT_TRUE(infobar_1); 283 ASSERT_TRUE(infobar_1);
284 string16 text_1 = infobar_1->GetMessageText(); 284 string16 text_1 = infobar_1->GetMessageText();
285 EXPECT_NE(text_0, text_1); 285 EXPECT_NE(text_0, text_1);
286 286
287 // Cancel (block) this frame. 287 // Cancel (block) this frame.
288 infobar_1->Cancel(); 288 infobar_1->Cancel();
289 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); 289 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK);
290 CheckPermissionMessageSent(bridge_id() + 1, false); 290 CheckPermissionMessageSent(bridge_id() + 1, false);
291 infobar_tab_helper()->RemoveInfoBar(infobar_1); 291 infobar_tab_helper()->RemoveInfoBar(infobar_1);
292 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 292 EXPECT_EQ(1U, closed_delegate_tracker_.size());
293 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 293 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
294 infobar_1->InfoBarClosed(); 294 delete infobar_1;
295 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 295 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count());
296 // Ensure the persisted permissions are ok. 296 // Ensure the persisted permissions are ok.
297 EXPECT_EQ(CONTENT_SETTING_ALLOW, 297 EXPECT_EQ(CONTENT_SETTING_ALLOW,
298 profile()->GetHostContentSettingsMap()->GetContentSetting( 298 profile()->GetHostContentSettingsMap()->GetContentSetting(
299 requesting_frame_0, 299 requesting_frame_0,
300 requesting_frame_0, 300 requesting_frame_0,
301 CONTENT_SETTINGS_TYPE_GEOLOCATION, 301 CONTENT_SETTINGS_TYPE_GEOLOCATION,
302 std::string())); 302 std::string()));
303 303
304 EXPECT_EQ(CONTENT_SETTING_BLOCK, 304 EXPECT_EQ(CONTENT_SETTING_BLOCK,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ASSERT_TRUE(infobar_0); 341 ASSERT_TRUE(infobar_0);
342 string16 text_0 = infobar_0->GetMessageText(); 342 string16 text_0 = infobar_0->GetMessageText();
343 343
344 // Simulate the frame going away, ensure the infobar for this frame 344 // Simulate the frame going away, ensure the infobar for this frame
345 // is removed and the next pending infobar is created. 345 // is removed and the next pending infobar is created.
346 geolocation_permission_context_->CancelGeolocationPermissionRequest( 346 geolocation_permission_context_->CancelGeolocationPermissionRequest(
347 process_id(), render_id(), bridge_id(), requesting_frame_0); 347 process_id(), render_id(), bridge_id(), requesting_frame_0);
348 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 348 EXPECT_EQ(1U, closed_delegate_tracker_.size());
349 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 349 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
350 closed_delegate_tracker_.Clear(); 350 closed_delegate_tracker_.Clear();
351 infobar_0->InfoBarClosed(); 351 delete infobar_0;
352 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 352 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count());
353 353
354 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> 354 ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()->
355 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 355 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
356 ASSERT_TRUE(infobar_1); 356 ASSERT_TRUE(infobar_1);
357 string16 text_1 = infobar_1->GetMessageText(); 357 string16 text_1 = infobar_1->GetMessageText();
358 EXPECT_NE(text_0, text_1); 358 EXPECT_NE(text_0, text_1);
359 359
360 // Allow this frame. 360 // Allow this frame.
361 infobar_1->Accept(); 361 infobar_1->Accept();
362 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); 362 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW);
363 CheckPermissionMessageSent(bridge_id() + 1, true); 363 CheckPermissionMessageSent(bridge_id() + 1, true);
364 infobar_tab_helper()->RemoveInfoBar(infobar_1); 364 infobar_tab_helper()->RemoveInfoBar(infobar_1);
365 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 365 EXPECT_EQ(1U, closed_delegate_tracker_.size());
366 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 366 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
367 infobar_1->InfoBarClosed(); 367 delete infobar_1;
368 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 368 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count());
369 // Ensure the persisted permissions are ok. 369 // Ensure the persisted permissions are ok.
370 EXPECT_EQ(CONTENT_SETTING_ASK, 370 EXPECT_EQ(CONTENT_SETTING_ASK,
371 profile()->GetHostContentSettingsMap()->GetContentSetting( 371 profile()->GetHostContentSettingsMap()->GetContentSetting(
372 requesting_frame_0, 372 requesting_frame_0,
373 requesting_frame_0, 373 requesting_frame_0,
374 CONTENT_SETTINGS_TYPE_GEOLOCATION, 374 CONTENT_SETTINGS_TYPE_GEOLOCATION,
375 std::string())); 375 std::string()));
376 376
377 EXPECT_EQ(CONTENT_SETTING_ALLOW, 377 EXPECT_EQ(CONTENT_SETTING_ALLOW,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 418
419 // Accept the first tab. 419 // Accept the first tab.
420 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 420 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
421 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 421 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
422 ASSERT_TRUE(infobar_0); 422 ASSERT_TRUE(infobar_0);
423 infobar_0->Accept(); 423 infobar_0->Accept();
424 CheckPermissionMessageSent(bridge_id(), true); 424 CheckPermissionMessageSent(bridge_id(), true);
425 infobar_tab_helper()->RemoveInfoBar(infobar_0); 425 infobar_tab_helper()->RemoveInfoBar(infobar_0);
426 EXPECT_EQ(2U, closed_delegate_tracker_.size()); 426 EXPECT_EQ(2U, closed_delegate_tracker_.size());
427 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 427 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
428 infobar_0->InfoBarClosed(); 428 delete infobar_0;
429 // Now the infobar for the tab with the same origin should have gone. 429 // Now the infobar for the tab with the same origin should have gone.
430 EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count()); 430 EXPECT_EQ(0U, extra_tabs_[1]->infobar_tab_helper()->infobar_count());
431 CheckPermissionMessageSentForTab(1, bridge_id(), true); 431 CheckPermissionMessageSentForTab(1, bridge_id(), true);
432 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); 432 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
433 closed_delegate_tracker_.Clear(); 433 closed_delegate_tracker_.Clear();
434 // Destroy the infobar that has just been removed. 434 // Destroy the infobar that has just been removed.
435 removed_infobar->InfoBarClosed(); 435 delete removed_infobar;
436 436
437 // But the other tab should still have the info bar... 437 // But the other tab should still have the info bar...
438 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 438 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
439 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> 439 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
440 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 440 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
441 infobar_1->Cancel(); 441 infobar_1->Cancel();
442 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); 442 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
443 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 443 EXPECT_EQ(1U, closed_delegate_tracker_.size());
444 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 444 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
445 infobar_1->InfoBarClosed(); 445 delete infobar_1;
446 446
447 extra_tabs_.reset(); 447 extra_tabs_.reset();
448 } 448 }
449 449
450 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 450 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
451 GURL url_a("http://www.example.com/geolocation"); 451 GURL url_a("http://www.example.com/geolocation");
452 GURL url_b("http://www.example-2.com/geolocation"); 452 GURL url_b("http://www.example-2.com/geolocation");
453 NavigateAndCommit(url_a); 453 NavigateAndCommit(url_a);
454 AddNewTab(url_a); 454 AddNewTab(url_a);
455 455
(...skipping 15 matching lines...) Expand all
471 471
472 // Accept the second tab. 472 // Accept the second tab.
473 ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()-> 473 ConfirmInfoBarDelegate* infobar_0 = extra_tabs_[0]->infobar_tab_helper()->
474 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 474 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
475 ASSERT_TRUE(infobar_0); 475 ASSERT_TRUE(infobar_0);
476 infobar_0->Accept(); 476 infobar_0->Accept();
477 CheckPermissionMessageSentForTab(0, bridge_id(), true); 477 CheckPermissionMessageSentForTab(0, bridge_id(), true);
478 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0); 478 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_0);
479 EXPECT_EQ(2U, closed_delegate_tracker_.size()); 479 EXPECT_EQ(2U, closed_delegate_tracker_.size());
480 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); 480 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
481 infobar_0->InfoBarClosed(); 481 delete infobar_0;
482 // Now the infobar for the tab with the same origin should have gone. 482 // Now the infobar for the tab with the same origin should have gone.
483 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 483 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count());
484 CheckPermissionMessageSent(bridge_id(), true); 484 CheckPermissionMessageSent(bridge_id(), true);
485 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); 485 EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar));
486 closed_delegate_tracker_.Clear(); 486 closed_delegate_tracker_.Clear();
487 // Destroy the infobar that has just been removed. 487 // Destroy the infobar that has just been removed.
488 removed_infobar->InfoBarClosed(); 488 delete removed_infobar;
489 489
490 // And we should have the queued infobar displayed now. 490 // And we should have the queued infobar displayed now.
491 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 491 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
492 492
493 // Accept the second infobar. 493 // Accept the second infobar.
494 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> 494 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
495 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 495 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
496 ASSERT_TRUE(infobar_1); 496 ASSERT_TRUE(infobar_1);
497 infobar_1->Accept(); 497 infobar_1->Accept();
498 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); 498 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
499 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); 499 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
500 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 500 EXPECT_EQ(1U, closed_delegate_tracker_.size());
501 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 501 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
502 infobar_1->InfoBarClosed(); 502 delete infobar_1;
503 503
504 extra_tabs_.reset(); 504 extra_tabs_.reset();
505 } 505 }
506 506
507 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 507 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
508 GURL requesting_frame_0("http://www.example.com/geolocation"); 508 GURL requesting_frame_0("http://www.example.com/geolocation");
509 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 509 GURL requesting_frame_1("http://www.example-2.com/geolocation");
510 EXPECT_EQ( 510 EXPECT_EQ(
511 CONTENT_SETTING_ASK, 511 CONTENT_SETTING_ASK,
512 profile()->GetHostContentSettingsMap()->GetContentSetting( 512 profile()->GetHostContentSettingsMap()->GetContentSetting(
(...skipping 18 matching lines...) Expand all
531 geolocation_permission_context_->RequestGeolocationPermission( 531 geolocation_permission_context_->RequestGeolocationPermission(
532 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 532 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
533 // Ensure only one infobar is created. 533 // Ensure only one infobar is created.
534 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 534 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count());
535 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 535 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
536 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 536 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
537 ASSERT_TRUE(infobar_0); 537 ASSERT_TRUE(infobar_0);
538 538
539 // Delete the tab contents. 539 // Delete the tab contents.
540 DeleteContents(); 540 DeleteContents();
541 infobar_0->InfoBarClosed(); 541 delete infobar_0;
542 } 542 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_request_infobar_delegate_unittest.cc ('k') | chrome/browser/infobars/infobar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698