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

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

Issue 9491009: Show queued geolocation InfoBars when InfoBar is hidden. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix memory leak in TabDestroyed unit test, suppress gtk memory leak. Created 8 years, 9 months 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) 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 22 matching lines...) Expand all
33 using content::MockRenderProcessHost; 33 using content::MockRenderProcessHost;
34 using content::RenderViewHostTester; 34 using content::RenderViewHostTester;
35 using content::WebContents; 35 using content::WebContents;
36 36
37 // ClosedDelegateTracker ------------------------------------------------------ 37 // ClosedDelegateTracker ------------------------------------------------------
38 38
39 namespace { 39 namespace {
40 40
41 // We need to track which infobars were closed. 41 // We need to track which infobars were closed.
42 class ClosedDelegateTracker : public content::NotificationObserver { 42 class ClosedDelegateTracker : public content::NotificationObserver {
43 FRIEND_TEST_ALL_PREFIXES(GeolocationPermissionContextTests, TabDestroyed);
Peter Kasting 2012/03/26 19:12:22 This doesn't go above the public section, it goes
John Knottenbelt 2012/03/27 10:21:29 Done.
43 public: 44 public:
44 ClosedDelegateTracker(); 45 ClosedDelegateTracker();
45 virtual ~ClosedDelegateTracker(); 46 virtual ~ClosedDelegateTracker();
46 47
47 // content::NotificationObserver: 48 // content::NotificationObserver:
48 virtual void Observe(int type, 49 virtual void Observe(int type,
49 const content::NotificationSource& source, 50 const content::NotificationSource& source,
50 const content::NotificationDetails& details); 51 const content::NotificationDetails& details);
51 52
52 size_t size() const { 53 size_t size() const {
(...skipping 26 matching lines...) Expand all
79 } 80 }
80 81
81 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const { 82 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const {
82 return removed_infobar_delegates_.count(delegate) != 0; 83 return removed_infobar_delegates_.count(delegate) != 0;
83 } 84 }
84 85
85 void ClosedDelegateTracker::Clear() { 86 void ClosedDelegateTracker::Clear() {
86 removed_infobar_delegates_.clear(); 87 removed_infobar_delegates_.clear();
87 } 88 }
88 89
89 } // namespace
90
91
92 // GeolocationPermissionContextTests ------------------------------------------ 90 // GeolocationPermissionContextTests ------------------------------------------
93 91
94 // This class sets up GeolocationArbitrator. 92 // This class sets up GeolocationArbitrator.
95 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { 93 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness {
96 public: 94 public:
97 GeolocationPermissionContextTests(); 95 GeolocationPermissionContextTests();
98 96
99 protected: 97 protected:
100 virtual ~GeolocationPermissionContextTests(); 98 virtual ~GeolocationPermissionContextTests();
101 99
(...skipping 30 matching lines...) Expand all
132 void CheckTabContentsState(const GURL& requesting_frame, 130 void CheckTabContentsState(const GURL& requesting_frame,
133 ContentSetting expected_content_setting); 131 ContentSetting expected_content_setting);
134 132
135 scoped_refptr<ChromeGeolocationPermissionContext> 133 scoped_refptr<ChromeGeolocationPermissionContext>
136 geolocation_permission_context_; 134 geolocation_permission_context_;
137 ClosedDelegateTracker closed_delegate_tracker_; 135 ClosedDelegateTracker closed_delegate_tracker_;
138 ScopedVector<TabContentsWrapper> extra_tabs_; 136 ScopedVector<TabContentsWrapper> extra_tabs_;
139 137
140 private: 138 private:
141 // TabContentsWrapperTestHarness: 139 // TabContentsWrapperTestHarness:
142 virtual void SetUp(); 140 virtual void SetUp() OVERRIDE;
143 virtual void TearDown(); 141 virtual void TearDown() OVERRIDE;
144 142
145 content::TestBrowserThread ui_thread_; 143 content::TestBrowserThread ui_thread_;
146 content::MockGeolocation mock_geolocation_; 144 content::MockGeolocation mock_geolocation_;
147 145
148 // A map between renderer child id and a pair represending the bridge id and 146 // A map between renderer child id and a pair represending the bridge id and
149 // whether the requested permission was allowed. 147 // whether the requested permission was allowed.
150 base::hash_map<int, std::pair<int, bool> > responses_; 148 base::hash_map<int, std::pair<int, bool> > responses_;
151 }; 149 };
152 150
153 GeolocationPermissionContextTests::GeolocationPermissionContextTests() 151 GeolocationPermissionContextTests::GeolocationPermissionContextTests()
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 230 }
233 231
234 void GeolocationPermissionContextTests::SetUp() { 232 void GeolocationPermissionContextTests::SetUp() {
235 TabContentsWrapperTestHarness::SetUp(); 233 TabContentsWrapperTestHarness::SetUp();
236 mock_geolocation_.Setup(); 234 mock_geolocation_.Setup();
237 geolocation_permission_context_ = 235 geolocation_permission_context_ =
238 new ChromeGeolocationPermissionContext(profile()); 236 new ChromeGeolocationPermissionContext(profile());
239 } 237 }
240 238
241 void GeolocationPermissionContextTests::TearDown() { 239 void GeolocationPermissionContextTests::TearDown() {
240 extra_tabs_.reset();
242 mock_geolocation_.TearDown(); 241 mock_geolocation_.TearDown();
243 TabContentsWrapperTestHarness::TearDown(); 242 TabContentsWrapperTestHarness::TearDown();
244 } 243 }
245 244
246 245
247 // Tests ---------------------------------------------------------------------- 246 // Tests ----------------------------------------------------------------------
248 247
249 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 248 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
250 GURL requesting_frame("http://www.example.com/geolocation"); 249 GURL requesting_frame("http://www.example.com/geolocation");
251 NavigateAndCommit(requesting_frame); 250 NavigateAndCommit(requesting_frame);
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 463
465 // But the other tab should still have the info bar... 464 // But the other tab should still have the info bar...
466 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count()); 465 ASSERT_EQ(1U, extra_tabs_[0]->infobar_tab_helper()->infobar_count());
467 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> 466 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
468 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 467 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
469 infobar_1->Cancel(); 468 infobar_1->Cancel();
470 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); 469 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
471 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 470 EXPECT_EQ(1U, closed_delegate_tracker_.size());
472 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 471 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
473 infobar_1->InfoBarClosed(); 472 infobar_1->InfoBarClosed();
474
475 extra_tabs_.reset();
476 } 473 }
477 474
478 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { 475 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) {
479 GURL url_a("http://www.example.com/geolocation"); 476 GURL url_a("http://www.example.com/geolocation");
480 GURL url_b("http://www.example-2.com/geolocation"); 477 GURL url_b("http://www.example-2.com/geolocation");
481 NavigateAndCommit(url_a); 478 NavigateAndCommit(url_a);
482 AddNewTab(url_a); 479 AddNewTab(url_a);
483 480
484 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 481 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count());
485 RequestGeolocationPermission( 482 RequestGeolocationPermission(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 // Accept the second infobar. 518 // Accept the second infobar.
522 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()-> 519 ConfirmInfoBarDelegate* infobar_1 = extra_tabs_[0]->infobar_tab_helper()->
523 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 520 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
524 ASSERT_TRUE(infobar_1); 521 ASSERT_TRUE(infobar_1);
525 infobar_1->Accept(); 522 infobar_1->Accept();
526 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); 523 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true);
527 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1); 524 extra_tabs_[0]->infobar_tab_helper()->RemoveInfoBar(infobar_1);
528 EXPECT_EQ(1U, closed_delegate_tracker_.size()); 525 EXPECT_EQ(1U, closed_delegate_tracker_.size());
529 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); 526 EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1));
530 infobar_1->InfoBarClosed(); 527 infobar_1->InfoBarClosed();
531
532 extra_tabs_.reset();
533 } 528 }
534 529
535 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { 530 TEST_F(GeolocationPermissionContextTests, TabDestroyed) {
536 GURL requesting_frame_0("http://www.example.com/geolocation"); 531 GURL requesting_frame_0("http://www.example.com/geolocation");
537 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 532 GURL requesting_frame_1("http://www.example-2.com/geolocation");
538 EXPECT_EQ( 533 EXPECT_EQ(
539 CONTENT_SETTING_ASK, 534 CONTENT_SETTING_ASK,
540 profile()->GetHostContentSettingsMap()->GetContentSetting( 535 profile()->GetHostContentSettingsMap()->GetContentSetting(
541 requesting_frame_0, 536 requesting_frame_0,
542 requesting_frame_0, 537 requesting_frame_0,
(...skipping 17 matching lines...) Expand all
560 process_id(), render_id(), bridge_id() + 1, requesting_frame_1); 555 process_id(), render_id(), bridge_id() + 1, requesting_frame_1);
561 // Ensure only one infobar is created. 556 // Ensure only one infobar is created.
562 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count()); 557 ASSERT_EQ(1U, infobar_tab_helper()->infobar_count());
563 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> 558 ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()->
564 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 559 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
565 ASSERT_TRUE(infobar_0); 560 ASSERT_TRUE(infobar_0);
566 561
567 // Delete the tab contents. 562 // Delete the tab contents.
568 DeleteContents(); 563 DeleteContents();
569 infobar_0->InfoBarClosed(); 564 infobar_0->InfoBarClosed();
565
566 // During contents destruction, the infobar will have been closed, and a
567 // second (with it's own new delegate) will have been created. In Chromium,
568 // this would be properly deleted by the InfoBarContainer, but in this unit
569 // test, the closest thing we have to that is the ClosedDelegateTracker.
570 ASSERT_EQ(2U, closed_delegate_tracker_.size());
571 ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
572 closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0);
573 (*closed_delegate_tracker_.removed_infobar_delegates_.begin())->
574 InfoBarClosed();
570 } 575 }
571 576
572 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { 577 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
573 GURL requesting_frame_0("http://www.example.com/geolocation"); 578 GURL requesting_frame_0("http://www.example.com/geolocation");
574 GURL requesting_frame_1("http://www.example-2.com/geolocation"); 579 GURL requesting_frame_1("http://www.example-2.com/geolocation");
575 NavigateAndCommit(requesting_frame_0); 580 NavigateAndCommit(requesting_frame_0);
576 NavigateAndCommit(requesting_frame_1); 581 NavigateAndCommit(requesting_frame_1);
577 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count()); 582 EXPECT_EQ(0U, infobar_tab_helper()->infobar_count());
578 // Go back: navigate to a pending entry before requesting geolocation 583 // Go back: navigate to a pending entry before requesting geolocation
579 // permission. 584 // permission.
(...skipping 11 matching lines...) Expand all
591 ASSERT_FALSE(infobar_0->ShouldExpire(details)); 596 ASSERT_FALSE(infobar_0->ShouldExpire(details));
592 // Commit the "GoBack()" above, and ensure the infobar is now expired. 597 // Commit the "GoBack()" above, and ensure the infobar is now expired.
593 contents()->CommitPendingNavigation(); 598 contents()->CommitPendingNavigation();
594 details.entry = contents()->GetController().GetLastCommittedEntry(); 599 details.entry = contents()->GetController().GetLastCommittedEntry();
595 ASSERT_TRUE(infobar_0->ShouldExpire(details)); 600 ASSERT_TRUE(infobar_0->ShouldExpire(details));
596 601
597 // Delete the tab contents. 602 // Delete the tab contents.
598 DeleteContents(); 603 DeleteContents();
599 infobar_0->InfoBarClosed(); 604 infobar_0->InfoBarClosed();
600 } 605 }
606
607 } // namespace
Peter Kasting 2012/03/26 19:12:22 Don't extend the namespace to cover the unit tests
John Knottenbelt 2012/03/27 10:21:29 I removed the namespace. The issue is that the FRI
OLDNEW
« no previous file with comments | « chrome/browser/geolocation/chrome_geolocation_permission_context.cc ('k') | tools/valgrind/memcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698