Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | |
| 6 | |
| 5 #include "base/memory/scoped_vector.h" | 7 #include "base/memory/scoped_vector.h" |
| 6 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 8 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 7 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 9 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 8 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 10 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 9 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 10 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 12 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 11 #include "chrome/test/testing_profile.h" | 13 #include "chrome/test/testing_profile.h" |
| 12 #include "content/browser/browser_thread.h" | 14 #include "content/browser/browser_thread.h" |
| 13 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " | 15 #include "content/browser/geolocation/arbitrator_dependency_factories_for_test.h " |
| 14 #include "content/browser/geolocation/geolocation_permission_context.h" | 16 #include "content/browser/geolocation/geolocation_permission_context.h" |
| 15 #include "content/browser/geolocation/location_arbitrator.h" | 17 #include "content/browser/geolocation/location_arbitrator.h" |
| 16 #include "content/browser/geolocation/location_provider.h" | 18 #include "content/browser/geolocation/location_provider.h" |
| 17 #include "content/browser/geolocation/mock_location_provider.h" | 19 #include "content/browser/geolocation/mock_location_provider.h" |
| 18 #include "content/browser/renderer_host/mock_render_process_host.h" | 20 #include "content/browser/renderer_host/mock_render_process_host.h" |
| 19 #include "content/browser/tab_contents/test_tab_contents.h" | 21 #include "content/browser/tab_contents/test_tab_contents.h" |
| 20 #include "content/common/geolocation_messages.h" | 22 #include "content/common/geolocation_messages.h" |
| 21 #include "content/common/notification_details.h" | |
| 22 #include "content/common/notification_registrar.h" | 23 #include "content/common/notification_registrar.h" |
| 23 #include "content/common/notification_source.h" | 24 #include "content/common/notification_service.h" |
| 24 #include "content/common/notification_type.h" | |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 // TestTabContentsWithPendingInfoBar ------------------------------------------ | 27 // ClosedDelegateTracker ------------------------------------------------------ |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // TestTabContents short-circuits TAB_CONTENTS_INFOBAR_REMOVED to call | 31 // We need to track which infobars were closed. |
| 32 // InfoBarClosed() directly. We need to observe it and call InfoBarClosed() | 32 class ClosedDelegateTracker : public NotificationObserver { |
| 33 // later. | |
| 34 class TestTabContentsWithPendingInfoBar : public TabContentsWrapper { | |
| 35 public: | 33 public: |
| 36 TestTabContentsWithPendingInfoBar(Profile* profile, SiteInstance* instance); | 34 ClosedDelegateTracker(); |
| 37 virtual ~TestTabContentsWithPendingInfoBar(); | 35 virtual ~ClosedDelegateTracker(); |
| 38 | 36 |
| 39 // TabContentsWrapper: | 37 // NotificationObserver: |
| 40 virtual void Observe(NotificationType type, | 38 virtual void Observe(NotificationType type, |
| 41 const NotificationSource& source, | 39 const NotificationSource& source, |
| 42 const NotificationDetails& details); | 40 const NotificationDetails& details); |
| 43 | 41 |
| 44 InfoBarDelegate* removed_infobar_delegate_; | 42 size_t size() const { |
| 43 return removed_infobar_delegates_.size(); | |
| 44 } | |
| 45 | |
| 46 bool Contains(InfoBarDelegate* delegate) const; | |
| 47 void Clear(); | |
| 48 | |
| 49 private: | |
| 45 NotificationRegistrar registrar_; | 50 NotificationRegistrar registrar_; |
| 51 std::set<InfoBarDelegate*> removed_infobar_delegates_; | |
| 46 }; | 52 }; |
| 47 | 53 |
| 48 TestTabContentsWithPendingInfoBar::TestTabContentsWithPendingInfoBar( | 54 ClosedDelegateTracker::ClosedDelegateTracker() { |
| 49 Profile* profile, | |
| 50 SiteInstance* instance) | |
| 51 : TabContentsWrapper( | |
| 52 new TabContents(profile, instance, MSG_ROUTING_NONE, NULL, NULL)), | |
| 53 removed_infobar_delegate_(NULL) { | |
| 54 Source<TabContentsWrapper> source(this); | |
| 55 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, | 55 registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
| 56 source); | 56 NotificationService::AllSources()); |
| 57 } | 57 } |
| 58 | 58 |
| 59 TestTabContentsWithPendingInfoBar::~TestTabContentsWithPendingInfoBar() { | 59 ClosedDelegateTracker::~ClosedDelegateTracker() { |
| 60 } | 60 } |
| 61 | 61 |
| 62 void TestTabContentsWithPendingInfoBar::Observe( | 62 void ClosedDelegateTracker::Observe(NotificationType type, |
| 63 NotificationType type, | 63 const NotificationSource& source, |
| 64 const NotificationSource& source, | 64 const NotificationDetails& details) { |
| 65 const NotificationDetails& details) { | 65 DCHECK(type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED); |
| 66 if (type.value == NotificationType::TAB_CONTENTS_INFOBAR_REMOVED) { | 66 removed_infobar_delegates_.insert( |
| 67 removed_infobar_delegate_ = | 67 Details<std::pair<InfoBarDelegate*, bool> >(details)->first); |
| 68 Details<std::pair<InfoBarDelegate*, bool> >(details)->first; | 68 } |
| 69 } else { | 69 |
| 70 TabContentsWrapper::Observe(type, source, details); | 70 bool ClosedDelegateTracker::Contains(InfoBarDelegate* delegate) const { |
| 71 } | 71 return removed_infobar_delegates_.count(delegate) != 0; |
| 72 } | |
| 73 | |
| 74 void ClosedDelegateTracker::Clear() { | |
| 75 removed_infobar_delegates_.clear(); | |
| 72 } | 76 } |
| 73 | 77 |
| 74 } // namespace | 78 } // namespace |
| 75 | 79 |
| 76 | 80 |
| 77 // GeolocationPermissionContextTests ------------------------------------------ | 81 // GeolocationPermissionContextTests ------------------------------------------ |
| 78 | 82 |
| 79 // This class sets up GeolocationArbitrator. | 83 // This class sets up GeolocationArbitrator. |
| 80 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { | 84 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { |
| 81 public: | 85 public: |
| 82 GeolocationPermissionContextTests(); | 86 GeolocationPermissionContextTests(); |
| 83 | 87 |
| 84 protected: | 88 protected: |
| 85 virtual ~GeolocationPermissionContextTests(); | 89 virtual ~GeolocationPermissionContextTests(); |
| 86 | 90 |
| 87 int process_id() { return contents()->render_view_host()->process()->id(); } | 91 int process_id() { return contents()->render_view_host()->process()->id(); } |
| 88 int process_id_for_tab(int tab) { | 92 int process_id_for_tab(int tab) { |
| 89 return extra_tabs_[tab]->render_view_host()->process()->id(); | 93 return extra_tabs_[tab]->tab_contents()->render_view_host()->process()-> |
| 94 id(); | |
| 90 } | 95 } |
| 91 int render_id() { return contents()->render_view_host()->routing_id(); } | 96 int render_id() { return contents()->render_view_host()->routing_id(); } |
| 92 int render_id_for_tab(int tab) { | 97 int render_id_for_tab(int tab) { |
| 93 return extra_tabs_[tab]->render_view_host()->routing_id(); | 98 return extra_tabs_[tab]->tab_contents()->render_view_host()->routing_id(); |
| 94 } | 99 } |
| 95 int bridge_id() const { return 42; } // Not relevant at this level. | 100 int bridge_id() const { return 42; } // Not relevant at this level. |
| 96 | 101 |
| 97 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 102 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
| 98 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 103 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
| 99 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 104 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
| 100 int bridge_id, | 105 int bridge_id, |
| 101 bool allowed); | 106 bool allowed); |
| 102 void AddNewTab(const GURL& url); | 107 void AddNewTab(const GURL& url); |
| 103 void CheckTabContentsState(const GURL& requesting_frame, | 108 void CheckTabContentsState(const GURL& requesting_frame, |
| 104 ContentSetting expected_content_setting); | 109 ContentSetting expected_content_setting); |
| 105 | 110 |
| 106 TestTabContentsWithPendingInfoBar* tab_contents_with_pending_infobar_; | |
| 107 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; | 111 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; |
| 108 ScopedVector<TestTabContentsWithPendingInfoBar> extra_tabs_; | 112 scoped_ptr<ClosedDelegateTracker> closed_delegate_tracker_; |
|
bulach
2011/06/03 19:15:05
nit: it no longer depends on anything for lazy ini
| |
| 113 ScopedVector<TabContentsWrapper> extra_tabs_; | |
| 109 | 114 |
| 110 private: | 115 private: |
| 111 // TabContentsWrapperTestHarness: | 116 // TabContentsWrapperTestHarness: |
| 112 virtual void SetUp(); | 117 virtual void SetUp(); |
| 113 virtual void TearDown(); | 118 virtual void TearDown(); |
| 114 | 119 |
| 115 BrowserThread ui_thread_; | 120 BrowserThread ui_thread_; |
| 116 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; | 121 scoped_refptr<GeolocationArbitratorDependencyFactory> dependency_factory_; |
| 117 }; | 122 }; |
| 118 | 123 |
| 119 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 124 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
| 120 : tab_contents_with_pending_infobar_(NULL), | 125 : TabContentsWrapperTestHarness(), |
|
bulach
2011/06/03 19:15:05
nit: unnecessary?
Peter Kasting
2011/06/03 20:37:36
The compiler will do it implicitly, but I prefer t
| |
| 121 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 126 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
| 122 dependency_factory_( | 127 dependency_factory_( |
| 123 new GeolocationArbitratorDependencyFactoryWithLocationProvider( | 128 new GeolocationArbitratorDependencyFactoryWithLocationProvider( |
| 124 &NewAutoSuccessMockNetworkLocationProvider)) { | 129 &NewAutoSuccessMockNetworkLocationProvider)) { |
| 125 } | 130 } |
| 126 | 131 |
| 127 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { | 132 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
| 128 } | 133 } |
| 129 | 134 |
| 130 void GeolocationPermissionContextTests::CheckPermissionMessageSent( | 135 void GeolocationPermissionContextTests::CheckPermissionMessageSent( |
| 131 int bridge_id, | 136 int bridge_id, |
| 132 bool allowed) { | 137 bool allowed) { |
| 133 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); | 138 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); |
| 134 } | 139 } |
| 135 | 140 |
| 136 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( | 141 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( |
| 137 int tab, | 142 int tab, |
| 138 int bridge_id, | 143 int bridge_id, |
| 139 bool allowed) { | 144 bool allowed) { |
| 140 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>( | 145 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>( |
| 141 extra_tabs_[tab]->render_view_host()->process()), bridge_id, allowed); | 146 extra_tabs_[tab]->tab_contents()->render_view_host()->process()), |
| 147 bridge_id, allowed); | |
| 142 } | 148 } |
| 143 | 149 |
| 144 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal( | 150 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal( |
| 145 MockRenderProcessHost* process, | 151 MockRenderProcessHost* process, |
| 146 int bridge_id, | 152 int bridge_id, |
| 147 bool allowed) { | 153 bool allowed) { |
| 148 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 154 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 149 MessageLoop::current()->Run(); | 155 MessageLoop::current()->Run(); |
| 150 const IPC::Message* message = process->sink().GetFirstMessageMatching( | 156 const IPC::Message* message = process->sink().GetFirstMessageMatching( |
| 151 GeolocationMsg_PermissionSet::ID); | 157 GeolocationMsg_PermissionSet::ID); |
| 152 ASSERT_TRUE(message); | 158 ASSERT_TRUE(message); |
| 153 GeolocationMsg_PermissionSet::Param param; | 159 GeolocationMsg_PermissionSet::Param param; |
| 154 GeolocationMsg_PermissionSet::Read(message, ¶m); | 160 GeolocationMsg_PermissionSet::Read(message, ¶m); |
| 155 EXPECT_EQ(bridge_id, param.a); | 161 EXPECT_EQ(bridge_id, param.a); |
| 156 EXPECT_EQ(allowed, param.b); | 162 EXPECT_EQ(allowed, param.b); |
| 157 process->sink().ClearMessages(); | 163 process->sink().ClearMessages(); |
| 158 } | 164 } |
| 159 | 165 |
| 160 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { | 166 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { |
| 161 TestTabContentsWithPendingInfoBar* new_tab = | 167 TabContents* new_tab = |
| 162 new TestTabContentsWithPendingInfoBar(profile(), NULL); | 168 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL, NULL); |
| 163 new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED); | 169 new_tab->controller().LoadURL(url, GURL(), PageTransition::TYPED); |
| 164 static_cast<TestRenderViewHost*>(new_tab->tab_contents()->render_manager()-> | 170 static_cast<TestRenderViewHost*>(new_tab->render_manager()->current_host())-> |
| 165 current_host())->SendNavigate(extra_tabs_.size() + 1, url); | 171 SendNavigate(extra_tabs_.size() + 1, url); |
| 166 extra_tabs_.push_back(new_tab); | 172 extra_tabs_.push_back(new TabContentsWrapper(new_tab)); |
| 167 } | 173 } |
| 168 | 174 |
| 169 void GeolocationPermissionContextTests::CheckTabContentsState( | 175 void GeolocationPermissionContextTests::CheckTabContentsState( |
| 170 const GURL& requesting_frame, | 176 const GURL& requesting_frame, |
| 171 ContentSetting expected_content_setting) { | 177 ContentSetting expected_content_setting) { |
| 172 TabSpecificContentSettings* content_settings = | 178 TabSpecificContentSettings* content_settings = |
| 173 contents_wrapper()->content_settings(); | 179 contents_wrapper()->content_settings(); |
| 174 const GeolocationSettingsState::StateMap& state_map = | 180 const GeolocationSettingsState::StateMap& state_map = |
| 175 content_settings->geolocation_settings_state().state_map(); | 181 content_settings->geolocation_settings_state().state_map(); |
| 176 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); | 182 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); |
| 177 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 183 EXPECT_EQ(0U, state_map.count(requesting_frame)); |
| 178 GeolocationSettingsState::StateMap::const_iterator settings = | 184 GeolocationSettingsState::StateMap::const_iterator settings = |
| 179 state_map.find(requesting_frame.GetOrigin()); | 185 state_map.find(requesting_frame.GetOrigin()); |
| 180 ASSERT_FALSE(settings == state_map.end()) | 186 ASSERT_FALSE(settings == state_map.end()) |
| 181 << "geolocation state not found " << requesting_frame; | 187 << "geolocation state not found " << requesting_frame; |
| 182 EXPECT_EQ(expected_content_setting, settings->second); | 188 EXPECT_EQ(expected_content_setting, settings->second); |
| 183 } | 189 } |
| 184 | 190 |
| 185 void GeolocationPermissionContextTests::SetUp() { | 191 void GeolocationPermissionContextTests::SetUp() { |
| 186 TabContentsWrapperTestHarness::SetUp(); | 192 TabContentsWrapperTestHarness::SetUp(); |
| 187 GeolocationArbitrator::SetDependencyFactoryForTest( | 193 GeolocationArbitrator::SetDependencyFactoryForTest( |
| 188 dependency_factory_.get()); | 194 dependency_factory_.get()); |
| 189 SiteInstance* site_instance = contents()->GetSiteInstance(); | 195 SiteInstance* site_instance = contents()->GetSiteInstance(); |
| 190 tab_contents_with_pending_infobar_ = | |
| 191 new TestTabContentsWithPendingInfoBar(profile_.get(), site_instance); | |
| 192 SetContentsWrapper(tab_contents_with_pending_infobar_); | |
| 193 geolocation_permission_context_ = | 196 geolocation_permission_context_ = |
| 194 new GeolocationPermissionContext(profile()); | 197 new GeolocationPermissionContext(profile()); |
| 198 closed_delegate_tracker_.reset(new ClosedDelegateTracker()); | |
| 195 } | 199 } |
| 196 | 200 |
| 197 void GeolocationPermissionContextTests::TearDown() { | 201 void GeolocationPermissionContextTests::TearDown() { |
| 202 closed_delegate_tracker_.reset(); | |
| 198 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); | 203 GeolocationArbitrator::SetDependencyFactoryForTest(NULL); |
| 199 TabContentsWrapperTestHarness::TearDown(); | 204 TabContentsWrapperTestHarness::TearDown(); |
| 200 } | 205 } |
| 201 | 206 |
| 202 | 207 |
| 203 // Tests ---------------------------------------------------------------------- | 208 // Tests ---------------------------------------------------------------------- |
| 204 | 209 |
| 205 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 210 TEST_F(GeolocationPermissionContextTests, SinglePermission) { |
| 206 GURL requesting_frame("http://www.example.com/geolocation"); | 211 GURL requesting_frame("http://www.example.com/geolocation"); |
| 207 NavigateAndCommit(requesting_frame); | 212 NavigateAndCommit(requesting_frame); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 234 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 239 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 235 ASSERT_TRUE(infobar_0); | 240 ASSERT_TRUE(infobar_0); |
| 236 string16 text_0 = infobar_0->GetMessageText(); | 241 string16 text_0 = infobar_0->GetMessageText(); |
| 237 | 242 |
| 238 // Accept the first frame. | 243 // Accept the first frame. |
| 239 infobar_0->Accept(); | 244 infobar_0->Accept(); |
| 240 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 245 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 241 CheckPermissionMessageSent(bridge_id(), true); | 246 CheckPermissionMessageSent(bridge_id(), true); |
| 242 | 247 |
| 243 contents_wrapper()->RemoveInfoBar(infobar_0); | 248 contents_wrapper()->RemoveInfoBar(infobar_0); |
| 244 EXPECT_EQ(infobar_0, | 249 EXPECT_EQ(1U, closed_delegate_tracker_->size()); |
| 245 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 250 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0)); |
| 251 closed_delegate_tracker_->Clear(); | |
| 246 infobar_0->InfoBarClosed(); | 252 infobar_0->InfoBarClosed(); |
| 247 // Now we should have a new infobar for the second frame. | 253 // Now we should have a new infobar for the second frame. |
| 248 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); | 254 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); |
| 249 | 255 |
| 250 ConfirmInfoBarDelegate* infobar_1 = | 256 ConfirmInfoBarDelegate* infobar_1 = |
| 251 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 257 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 252 ASSERT_TRUE(infobar_1); | 258 ASSERT_TRUE(infobar_1); |
| 253 string16 text_1 = infobar_1->GetMessageText(); | 259 string16 text_1 = infobar_1->GetMessageText(); |
| 254 EXPECT_NE(text_0, text_1); | 260 EXPECT_NE(text_0, text_1); |
| 255 | 261 |
| 256 // Cancel (block) this frame. | 262 // Cancel (block) this frame. |
| 257 infobar_1->Cancel(); | 263 infobar_1->Cancel(); |
| 258 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 264 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 259 CheckPermissionMessageSent(bridge_id() + 1, false); | 265 CheckPermissionMessageSent(bridge_id() + 1, false); |
| 260 contents_wrapper()->RemoveInfoBar(infobar_1); | 266 contents_wrapper()->RemoveInfoBar(infobar_1); |
| 261 EXPECT_EQ(infobar_1, | 267 EXPECT_EQ(1U, closed_delegate_tracker_->size()); |
| 262 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 268 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_1)); |
| 263 infobar_1->InfoBarClosed(); | 269 infobar_1->InfoBarClosed(); |
| 264 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 270 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); |
| 265 // Ensure the persisted permissions are ok. | 271 // Ensure the persisted permissions are ok. |
| 266 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 272 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 267 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 273 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 268 requesting_frame_0, requesting_frame_0)); | 274 requesting_frame_0, requesting_frame_0)); |
| 269 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 275 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 270 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 276 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 271 requesting_frame_1, requesting_frame_0)); | 277 requesting_frame_1, requesting_frame_0)); |
| 272 } | 278 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 292 | 298 |
| 293 ConfirmInfoBarDelegate* infobar_0 = | 299 ConfirmInfoBarDelegate* infobar_0 = |
| 294 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 300 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 295 ASSERT_TRUE(infobar_0); | 301 ASSERT_TRUE(infobar_0); |
| 296 string16 text_0 = infobar_0->GetMessageText(); | 302 string16 text_0 = infobar_0->GetMessageText(); |
| 297 | 303 |
| 298 // Simulate the frame going away, ensure the infobar for this frame | 304 // Simulate the frame going away, ensure the infobar for this frame |
| 299 // is removed and the next pending infobar is created. | 305 // is removed and the next pending infobar is created. |
| 300 geolocation_permission_context_->CancelGeolocationPermissionRequest( | 306 geolocation_permission_context_->CancelGeolocationPermissionRequest( |
| 301 process_id(), render_id(), bridge_id(), requesting_frame_0); | 307 process_id(), render_id(), bridge_id(), requesting_frame_0); |
| 302 EXPECT_EQ(infobar_0, | 308 EXPECT_EQ(1U, closed_delegate_tracker_->size()); |
| 303 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 309 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0)); |
| 310 closed_delegate_tracker_->Clear(); | |
| 304 infobar_0->InfoBarClosed(); | 311 infobar_0->InfoBarClosed(); |
| 305 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); | 312 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); |
| 306 | 313 |
| 307 ConfirmInfoBarDelegate* infobar_1 = | 314 ConfirmInfoBarDelegate* infobar_1 = |
| 308 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 315 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 309 ASSERT_TRUE(infobar_1); | 316 ASSERT_TRUE(infobar_1); |
| 310 string16 text_1 = infobar_1->GetMessageText(); | 317 string16 text_1 = infobar_1->GetMessageText(); |
| 311 EXPECT_NE(text_0, text_1); | 318 EXPECT_NE(text_0, text_1); |
| 312 | 319 |
| 313 // Allow this frame. | 320 // Allow this frame. |
| 314 infobar_1->Accept(); | 321 infobar_1->Accept(); |
| 315 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 322 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 316 CheckPermissionMessageSent(bridge_id() + 1, true); | 323 CheckPermissionMessageSent(bridge_id() + 1, true); |
| 317 contents_wrapper()->RemoveInfoBar(infobar_1); | 324 contents_wrapper()->RemoveInfoBar(infobar_1); |
| 318 EXPECT_EQ(infobar_1, | 325 EXPECT_EQ(1U, closed_delegate_tracker_->size()); |
| 319 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 326 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_1)); |
| 320 infobar_1->InfoBarClosed(); | 327 infobar_1->InfoBarClosed(); |
| 321 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 328 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); |
| 322 // Ensure the persisted permissions are ok. | 329 // Ensure the persisted permissions are ok. |
| 323 EXPECT_EQ(CONTENT_SETTING_ASK, | 330 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 324 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 331 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 325 requesting_frame_0, requesting_frame_0)); | 332 requesting_frame_0, requesting_frame_0)); |
| 326 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 333 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 327 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( | 334 profile()->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 328 requesting_frame_1, requesting_frame_0)); | 335 requesting_frame_1, requesting_frame_0)); |
| 329 } | 336 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 ConfirmInfoBarDelegate* removed_infobar = | 369 ConfirmInfoBarDelegate* removed_infobar = |
| 363 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 370 extra_tabs_[1]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 364 | 371 |
| 365 // Accept the first tab. | 372 // Accept the first tab. |
| 366 ConfirmInfoBarDelegate* infobar_0 = | 373 ConfirmInfoBarDelegate* infobar_0 = |
| 367 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 374 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 368 ASSERT_TRUE(infobar_0); | 375 ASSERT_TRUE(infobar_0); |
| 369 infobar_0->Accept(); | 376 infobar_0->Accept(); |
| 370 CheckPermissionMessageSent(bridge_id(), true); | 377 CheckPermissionMessageSent(bridge_id(), true); |
| 371 contents_wrapper()->RemoveInfoBar(infobar_0); | 378 contents_wrapper()->RemoveInfoBar(infobar_0); |
| 372 EXPECT_EQ(infobar_0, | 379 EXPECT_EQ(2U, closed_delegate_tracker_->size()); |
|
bulach
2011/06/03 19:15:05
this may fail: infobar_0 may just get the same add
Peter Kasting
2011/06/03 20:37:36
I don't see how that's possible; the two infobars
bulach
2011/06/08 14:23:03
sorry again for the lack of response, I was happy
| |
| 373 tab_contents_with_pending_infobar_->removed_infobar_delegate_); | 380 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0)); |
| 374 infobar_0->InfoBarClosed(); | 381 infobar_0->InfoBarClosed(); |
| 375 // Now the infobar for the tab with the same origin should have gone. | 382 // Now the infobar for the tab with the same origin should have gone. |
| 376 EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); | 383 EXPECT_EQ(0U, extra_tabs_[1]->infobar_count()); |
| 377 CheckPermissionMessageSentForTab(1, bridge_id(), true); | 384 CheckPermissionMessageSentForTab(1, bridge_id(), true); |
| 385 EXPECT_TRUE(closed_delegate_tracker_->Contains(removed_infobar)); | |
| 378 // Destroy the infobar that has just been removed. | 386 // Destroy the infobar that has just been removed. |
| 379 removed_infobar->InfoBarClosed(); | 387 removed_infobar->InfoBarClosed(); |
| 380 | 388 |
| 381 // But the other tab should still have the info bar... | 389 // But the other tab should still have the info bar... |
| 382 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); | 390 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); |
| 383 extra_tabs_.reset(); | 391 extra_tabs_.reset(); |
| 384 } | 392 } |
| 385 | 393 |
| 386 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 394 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| 387 GURL url_a("http://www.example.com/geolocation"); | 395 GURL url_a("http://www.example.com/geolocation"); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 405 ConfirmInfoBarDelegate* removed_infobar = | 413 ConfirmInfoBarDelegate* removed_infobar = |
| 406 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 414 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 407 | 415 |
| 408 // Accept the second tab. | 416 // Accept the second tab. |
| 409 ConfirmInfoBarDelegate* infobar_0 = | 417 ConfirmInfoBarDelegate* infobar_0 = |
| 410 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 418 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 411 ASSERT_TRUE(infobar_0); | 419 ASSERT_TRUE(infobar_0); |
| 412 infobar_0->Accept(); | 420 infobar_0->Accept(); |
| 413 CheckPermissionMessageSentForTab(0, bridge_id(), true); | 421 CheckPermissionMessageSentForTab(0, bridge_id(), true); |
| 414 extra_tabs_[0]->RemoveInfoBar(infobar_0); | 422 extra_tabs_[0]->RemoveInfoBar(infobar_0); |
| 415 EXPECT_EQ(infobar_0, | 423 EXPECT_EQ(2U, closed_delegate_tracker_->size()); |
|
bulach
2011/06/03 19:15:05
ditto
| |
| 416 extra_tabs_[0]->removed_infobar_delegate_); | 424 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_0)); |
| 417 infobar_0->InfoBarClosed(); | 425 infobar_0->InfoBarClosed(); |
| 418 // Now the infobar for the tab with the same origin should have gone. | 426 // Now the infobar for the tab with the same origin should have gone. |
| 419 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); | 427 EXPECT_EQ(0U, contents_wrapper()->infobar_count()); |
| 420 CheckPermissionMessageSent(bridge_id(), true); | 428 CheckPermissionMessageSent(bridge_id(), true); |
| 429 EXPECT_TRUE(closed_delegate_tracker_->Contains(removed_infobar)); | |
| 430 closed_delegate_tracker_->Clear(); | |
| 421 // Destroy the infobar that has just been removed. | 431 // Destroy the infobar that has just been removed. |
| 422 removed_infobar->InfoBarClosed(); | 432 removed_infobar->InfoBarClosed(); |
| 423 | 433 |
| 424 // And we should have the queued infobar displayed now. | 434 // And we should have the queued infobar displayed now. |
| 425 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); | 435 EXPECT_EQ(1U, extra_tabs_[0]->infobar_count()); |
| 426 | 436 |
| 427 // Accept the second infobar. | 437 // Accept the second infobar. |
| 428 ConfirmInfoBarDelegate* infobar_1 = | 438 ConfirmInfoBarDelegate* infobar_1 = |
| 429 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 439 extra_tabs_[0]->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 430 ASSERT_TRUE(infobar_1); | 440 ASSERT_TRUE(infobar_1); |
| 431 infobar_1->Accept(); | 441 infobar_1->Accept(); |
| 432 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); | 442 CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); |
| 433 extra_tabs_[0]->RemoveInfoBar(infobar_1); | 443 extra_tabs_[0]->RemoveInfoBar(infobar_1); |
| 434 EXPECT_EQ(infobar_1, | 444 EXPECT_EQ(1U, closed_delegate_tracker_->size()); |
| 435 extra_tabs_[0]->removed_infobar_delegate_); | 445 EXPECT_TRUE(closed_delegate_tracker_->Contains(infobar_1)); |
| 436 infobar_1->InfoBarClosed(); | 446 infobar_1->InfoBarClosed(); |
| 437 | 447 |
| 438 extra_tabs_.reset(); | 448 extra_tabs_.reset(); |
| 439 } | 449 } |
| 440 | 450 |
| 441 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 451 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
| 442 GURL requesting_frame_0("http://www.example.com/geolocation"); | 452 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 443 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 453 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 444 EXPECT_EQ( | 454 EXPECT_EQ( |
| 445 CONTENT_SETTING_ASK, | 455 CONTENT_SETTING_ASK, |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 460 // Ensure only one infobar is created. | 470 // Ensure only one infobar is created. |
| 461 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); | 471 EXPECT_EQ(1U, contents_wrapper()->infobar_count()); |
| 462 ConfirmInfoBarDelegate* infobar_0 = | 472 ConfirmInfoBarDelegate* infobar_0 = |
| 463 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 473 contents_wrapper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 464 ASSERT_TRUE(infobar_0); | 474 ASSERT_TRUE(infobar_0); |
| 465 string16 text_0 = infobar_0->GetMessageText(); | 475 string16 text_0 = infobar_0->GetMessageText(); |
| 466 | 476 |
| 467 // Delete the tab contents. | 477 // Delete the tab contents. |
| 468 DeleteContents(); | 478 DeleteContents(); |
| 469 } | 479 } |
| OLD | NEW |