| 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/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/test/simple_test_clock.h" | 16 #include "base/test/simple_test_clock.h" |
| 17 #include "base/time/clock.h" | 17 #include "base/time/clock.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/content_settings/host_content_settings_map.h" | 19 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 20 #include "chrome/browser/content_settings/permission_request_id.h" | 20 #include "chrome/browser/content_settings/permission_request_id.h" |
| 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 21 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 22 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
| 23 #include "chrome/browser/infobars/infobar_service.h" | 23 #include "chrome/browser/infobars/infobar_service.h" |
| 24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 25 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" |
| 26 #include "chrome/browser/ui/website_settings/permission_bubble_view.h" |
| 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 25 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
| 26 #include "components/infobars/core/confirm_infobar_delegate.h" | 29 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 27 #include "components/infobars/core/infobar.h" | 30 #include "components/infobars/core/infobar.h" |
| 28 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/navigation_details.h" | 32 #include "content/public/browser/navigation_details.h" |
| 30 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
| 31 #include "content/public/browser/notification_service.h" | 34 #include "content/public/browser/notification_service.h" |
| 32 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 33 #include "content/public/test/mock_render_process_host.h" | 36 #include "content/public/test/mock_render_process_host.h" |
| 34 #include "content/public/test/test_renderer_host.h" | 37 #include "content/public/test/test_renderer_host.h" |
| 35 #include "content/public/test/web_contents_tester.h" | 38 #include "content/public/test/web_contents_tester.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 40 |
| 38 #if defined(OS_ANDROID) | 41 #if defined(OS_ANDROID) |
| 39 #include "base/prefs/pref_service.h" | 42 #include "base/prefs/pref_service.h" |
| 40 #include "chrome/browser/android/mock_google_location_settings_helper.h" | 43 #include "chrome/browser/android/mock_google_location_settings_helper.h" |
| 41 #include "chrome/common/pref_names.h" | 44 #include "chrome/common/pref_names.h" |
| 42 #endif | 45 #endif |
| 43 | 46 |
| 44 #if defined(ENABLE_EXTENSIONS) | 47 #if defined(ENABLE_EXTENSIONS) |
| 45 #include "extensions/browser/view_type_utils.h" | 48 #include "extensions/browser/view_type_utils.h" |
| 46 #endif | 49 #endif |
| 47 | 50 |
| 48 using content::MockRenderProcessHost; | 51 using content::MockRenderProcessHost; |
| 49 | 52 |
| 53 class MockPermissionBubbleView : public PermissionBubbleView { |
| 54 public: |
| 55 MockPermissionBubbleView() {} |
| 56 virtual ~MockPermissionBubbleView() {} |
| 57 |
| 58 virtual void SetDelegate(Delegate* delegate) OVERRIDE { |
| 59 } |
| 60 |
| 61 virtual void Show( |
| 62 const std::vector<PermissionBubbleRequest*>& requests, |
| 63 const std::vector<bool>& accept_state, |
| 64 bool customization_mode) OVERRIDE { |
| 65 } |
| 66 |
| 67 virtual bool CanAcceptRequestUpdate() OVERRIDE { |
| 68 return true; |
| 69 } |
| 70 |
| 71 virtual void Hide() OVERRIDE { |
| 72 } |
| 73 |
| 74 virtual bool IsVisible() OVERRIDE { |
| 75 return false; |
| 76 } |
| 77 }; |
| 50 | 78 |
| 51 // ClosedInfoBarTracker ------------------------------------------------------- | 79 // ClosedInfoBarTracker ------------------------------------------------------- |
| 52 | 80 |
| 53 // We need to track which infobars were closed. | 81 // We need to track which infobars were closed. |
| 54 class ClosedInfoBarTracker : public content::NotificationObserver { | 82 class ClosedInfoBarTracker : public content::NotificationObserver { |
| 55 public: | 83 public: |
| 56 ClosedInfoBarTracker(); | 84 ClosedInfoBarTracker(); |
| 57 virtual ~ClosedInfoBarTracker(); | 85 virtual ~ClosedInfoBarTracker(); |
| 58 | 86 |
| 59 // content::NotificationObserver: | 87 // content::NotificationObserver: |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 PermissionRequestID RequestIDForTab(int tab, int bridge_id); | 139 PermissionRequestID RequestIDForTab(int tab, int bridge_id); |
| 112 InfoBarService* infobar_service() { | 140 InfoBarService* infobar_service() { |
| 113 return InfoBarService::FromWebContents(web_contents()); | 141 return InfoBarService::FromWebContents(web_contents()); |
| 114 } | 142 } |
| 115 InfoBarService* infobar_service_for_tab(int tab) { | 143 InfoBarService* infobar_service_for_tab(int tab) { |
| 116 return InfoBarService::FromWebContents(extra_tabs_[tab]); | 144 return InfoBarService::FromWebContents(extra_tabs_[tab]); |
| 117 } | 145 } |
| 118 | 146 |
| 119 void RequestGeolocationPermission(content::WebContents* web_contents, | 147 void RequestGeolocationPermission(content::WebContents* web_contents, |
| 120 const PermissionRequestID& id, | 148 const PermissionRequestID& id, |
| 121 const GURL& requesting_frame); | 149 const GURL& requesting_frame, |
| 150 bool user_gesture); |
| 122 void RequestGeolocationPermission(content::WebContents* web_contents, | 151 void RequestGeolocationPermission(content::WebContents* web_contents, |
| 123 const PermissionRequestID& id, | 152 const PermissionRequestID& id, |
| 124 const GURL& requesting_frame, | 153 const GURL& requesting_frame, |
| 154 bool user_gesture, |
| 125 base::Closure* cancel_callback); | 155 base::Closure* cancel_callback); |
| 126 void PermissionResponse(const PermissionRequestID& id, | 156 void PermissionResponse(const PermissionRequestID& id, |
| 127 bool allowed); | 157 bool allowed); |
| 128 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 158 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
| 129 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 159 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
| 130 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 160 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
| 131 int bridge_id, | 161 int bridge_id, |
| 132 bool allowed); | 162 bool allowed); |
| 133 void AddNewTab(const GURL& url); | 163 void AddNewTab(const GURL& url); |
| 134 void CheckTabContentsState(const GURL& requesting_frame, | 164 void CheckTabContentsState(const GURL& requesting_frame, |
| 135 ContentSetting expected_content_setting); | 165 ContentSetting expected_content_setting); |
| 166 base::string16 GetFirstRequestText(PermissionBubbleManager* mgr); |
| 167 int GetBubblesQueueSize(PermissionBubbleManager* mgr); |
| 168 void AcceptBubble(PermissionBubbleManager* mgr); |
| 169 void DenyBubble(PermissionBubbleManager* mgr); |
| 170 void BubbleManagerDocumentLoadCompleted(); |
| 136 | 171 |
| 137 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; | 172 scoped_refptr<GeolocationPermissionContext> geolocation_permission_context_; |
| 138 ClosedInfoBarTracker closed_infobar_tracker_; | 173 ClosedInfoBarTracker closed_infobar_tracker_; |
| 174 MockPermissionBubbleView bubble_view_; |
| 139 ScopedVector<content::WebContents> extra_tabs_; | 175 ScopedVector<content::WebContents> extra_tabs_; |
| 140 | 176 |
| 141 // A map between renderer child id and a pair represending the bridge id and | 177 // A map between renderer child id and a pair represending the bridge id and |
| 142 // whether the requested permission was allowed. | 178 // whether the requested permission was allowed. |
| 143 base::hash_map<int, std::pair<int, bool> > responses_; | 179 base::hash_map<int, std::pair<int, bool> > responses_; |
| 144 }; | 180 }; |
| 145 | 181 |
| 146 PermissionRequestID GeolocationPermissionContextTests::RequestID( | 182 PermissionRequestID GeolocationPermissionContextTests::RequestID( |
| 147 int bridge_id) { | 183 int bridge_id) { |
| 148 return PermissionRequestID( | 184 return PermissionRequestID( |
| 149 web_contents()->GetRenderProcessHost()->GetID(), | 185 web_contents()->GetRenderProcessHost()->GetID(), |
| 150 web_contents()->GetRenderViewHost()->GetRoutingID(), | 186 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 151 bridge_id, | 187 bridge_id, |
| 152 GURL()); | 188 GURL()); |
| 153 } | 189 } |
| 154 | 190 |
| 155 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( | 191 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( |
| 156 int tab, | 192 int tab, |
| 157 int bridge_id) { | 193 int bridge_id) { |
| 158 return PermissionRequestID( | 194 return PermissionRequestID( |
| 159 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), | 195 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
| 160 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), | 196 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
| 161 bridge_id, | 197 bridge_id, |
| 162 GURL()); | 198 GURL()); |
| 163 } | 199 } |
| 164 | 200 |
| 165 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 201 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
| 166 content::WebContents* web_contents, | 202 content::WebContents* web_contents, |
| 167 const PermissionRequestID& id, | 203 const PermissionRequestID& id, |
| 168 const GURL& requesting_frame) { | 204 const GURL& requesting_frame, |
| 169 RequestGeolocationPermission(web_contents, id, requesting_frame, NULL); | 205 bool user_gesture) { |
| 206 RequestGeolocationPermission(web_contents, id, requesting_frame, |
| 207 user_gesture, NULL); |
| 170 } | 208 } |
| 171 | 209 |
| 172 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 210 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
| 173 content::WebContents* web_contents, | 211 content::WebContents* web_contents, |
| 174 const PermissionRequestID& id, | 212 const PermissionRequestID& id, |
| 175 const GURL& requesting_frame, | 213 const GURL& requesting_frame, |
| 214 bool user_gesture, |
| 176 base::Closure* cancel_callback) { | 215 base::Closure* cancel_callback) { |
| 177 geolocation_permission_context_->RequestGeolocationPermission( | 216 geolocation_permission_context_->RequestGeolocationPermission( |
| 178 web_contents, id.bridge_id(), requesting_frame, false, | 217 web_contents, id.bridge_id(), requesting_frame, user_gesture, |
| 179 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 218 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
| 180 base::Unretained(this), id), | 219 base::Unretained(this), id), |
| 181 cancel_callback); | 220 cancel_callback); |
| 182 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 221 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 183 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
| 184 } | 223 } |
| 185 | 224 |
| 186 void GeolocationPermissionContextTests::PermissionResponse( | 225 void GeolocationPermissionContextTests::PermissionResponse( |
| 187 const PermissionRequestID& id, | 226 const PermissionRequestID& id, |
| 188 bool allowed) { | 227 bool allowed) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 extra_tabs_.push_back(new_tab); | 270 extra_tabs_.push_back(new_tab); |
| 232 } | 271 } |
| 233 | 272 |
| 234 void GeolocationPermissionContextTests::CheckTabContentsState( | 273 void GeolocationPermissionContextTests::CheckTabContentsState( |
| 235 const GURL& requesting_frame, | 274 const GURL& requesting_frame, |
| 236 ContentSetting expected_content_setting) { | 275 ContentSetting expected_content_setting) { |
| 237 TabSpecificContentSettings* content_settings = | 276 TabSpecificContentSettings* content_settings = |
| 238 TabSpecificContentSettings::FromWebContents(web_contents()); | 277 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 239 const ContentSettingsUsagesState::StateMap& state_map = | 278 const ContentSettingsUsagesState::StateMap& state_map = |
| 240 content_settings->geolocation_usages_state().state_map(); | 279 content_settings->geolocation_usages_state().state_map(); |
| 241 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); | 280 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())) |
| 242 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 281 << " for " << requesting_frame.spec(); |
| 282 EXPECT_EQ(0U, state_map.count(requesting_frame)) |
| 283 << " for " << requesting_frame.spec(); |
| 243 ContentSettingsUsagesState::StateMap::const_iterator settings = | 284 ContentSettingsUsagesState::StateMap::const_iterator settings = |
| 244 state_map.find(requesting_frame.GetOrigin()); | 285 state_map.find(requesting_frame.GetOrigin()); |
| 245 ASSERT_FALSE(settings == state_map.end()) | 286 ASSERT_FALSE(settings == state_map.end()) |
| 246 << "geolocation state not found " << requesting_frame; | 287 << "geolocation state not found " << requesting_frame; |
| 247 EXPECT_EQ(expected_content_setting, settings->second); | 288 EXPECT_EQ(expected_content_setting, settings->second) |
| 289 << " for " << requesting_frame.spec(); |
| 248 } | 290 } |
| 249 | 291 |
| 250 void GeolocationPermissionContextTests::SetUp() { | 292 void GeolocationPermissionContextTests::SetUp() { |
| 251 ChromeRenderViewHostTestHarness::SetUp(); | 293 ChromeRenderViewHostTestHarness::SetUp(); |
| 252 | 294 |
| 253 // Set up required helpers, and make this be as "tabby" as the code requires. | 295 // Set up required helpers, and make this be as "tabby" as the code requires. |
| 254 #if defined(ENABLE_EXTENSIONS) | 296 #if defined(ENABLE_EXTENSIONS) |
| 255 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); | 297 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); |
| 256 #endif | 298 #endif |
| 257 InfoBarService::CreateForWebContents(web_contents()); | 299 InfoBarService::CreateForWebContents(web_contents()); |
| 258 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 300 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 259 #if defined(OS_ANDROID) | 301 #if defined(OS_ANDROID) |
| 260 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 302 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
| 261 #endif | 303 #endif |
| 262 geolocation_permission_context_ = | 304 geolocation_permission_context_ = |
| 263 GeolocationPermissionContextFactory::GetForProfile(profile()); | 305 GeolocationPermissionContextFactory::GetForProfile(profile()); |
| 306 |
| 307 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 308 PermissionBubbleManager::FromWebContents(web_contents())->SetView( |
| 309 &bubble_view_); |
| 264 } | 310 } |
| 265 | 311 |
| 266 void GeolocationPermissionContextTests::TearDown() { | 312 void GeolocationPermissionContextTests::TearDown() { |
| 267 extra_tabs_.clear(); | 313 extra_tabs_.clear(); |
| 268 ChromeRenderViewHostTestHarness::TearDown(); | 314 ChromeRenderViewHostTestHarness::TearDown(); |
| 269 } | 315 } |
| 270 | 316 |
| 317 base::string16 GeolocationPermissionContextTests::GetFirstRequestText( |
| 318 PermissionBubbleManager* mgr) { |
| 319 return mgr->requests_.front()->GetMessageText(); |
| 320 } |
| 321 |
| 322 int GeolocationPermissionContextTests::GetBubblesQueueSize( |
| 323 PermissionBubbleManager* mgr) { |
| 324 return static_cast<int>(mgr->requests_.size()); |
| 325 } |
| 326 |
| 327 void GeolocationPermissionContextTests::AcceptBubble( |
| 328 PermissionBubbleManager* mgr) { |
| 329 mgr->Accept(); |
| 330 } |
| 331 |
| 332 void GeolocationPermissionContextTests::DenyBubble( |
| 333 PermissionBubbleManager* mgr) { |
| 334 mgr->Deny(); |
| 335 } |
| 336 |
| 337 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { |
| 338 PermissionBubbleManager::FromWebContents(web_contents())-> |
| 339 DocumentOnLoadCompletedInMainFrame(); |
| 340 } |
| 341 |
| 271 // Tests ---------------------------------------------------------------------- | 342 // Tests ---------------------------------------------------------------------- |
| 272 | 343 |
| 273 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 344 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { |
| 345 if (PermissionBubbleManager::Enabled()) |
| 346 return; |
| 347 |
| 274 GURL requesting_frame("http://www.example.com/geolocation"); | 348 GURL requesting_frame("http://www.example.com/geolocation"); |
| 275 NavigateAndCommit(requesting_frame); | 349 NavigateAndCommit(requesting_frame); |
| 276 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 350 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 277 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 351 RequestGeolocationPermission( |
| 352 web_contents(), RequestID(0), requesting_frame, true); |
| 278 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 353 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 279 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 354 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 280 ConfirmInfoBarDelegate* infobar_delegate = | 355 ConfirmInfoBarDelegate* infobar_delegate = |
| 281 infobar->delegate()->AsConfirmInfoBarDelegate(); | 356 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 282 ASSERT_TRUE(infobar_delegate); | 357 ASSERT_TRUE(infobar_delegate); |
| 283 infobar_delegate->Cancel(); | 358 infobar_delegate->Cancel(); |
| 284 infobar_service()->RemoveInfoBar(infobar); | 359 infobar_service()->RemoveInfoBar(infobar); |
| 285 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 360 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 286 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 361 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 287 } | 362 } |
| 288 | 363 |
| 364 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { |
| 365 if (!PermissionBubbleManager::Enabled()) |
| 366 return; |
| 367 |
| 368 GURL requesting_frame("http://www.example.com/geolocation"); |
| 369 NavigateAndCommit(requesting_frame); |
| 370 BubbleManagerDocumentLoadCompleted(); |
| 371 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 372 RequestGeolocationPermission( |
| 373 web_contents(), RequestID(0), requesting_frame, true); |
| 374 PermissionBubbleManager* mgr = |
| 375 PermissionBubbleManager::FromWebContents(web_contents()); |
| 376 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 377 } |
| 378 |
| 289 #if defined(OS_ANDROID) | 379 #if defined(OS_ANDROID) |
| 290 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 380 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
| 291 GURL requesting_frame("http://www.example.com/geolocation"); | 381 GURL requesting_frame("http://www.example.com/geolocation"); |
| 292 NavigateAndCommit(requesting_frame); | 382 NavigateAndCommit(requesting_frame); |
| 293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 383 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
| 294 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 384 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 295 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 385 RequestGeolocationPermission( |
| 386 web_contents(), RequestID(0), requesting_frame, true); |
| 296 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 387 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 297 ConfirmInfoBarDelegate* infobar_delegate_0 = | 388 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 298 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 389 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 299 ASSERT_TRUE(infobar_delegate_0); | 390 ASSERT_TRUE(infobar_delegate_0); |
| 300 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | 391 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( |
| 301 ConfirmInfoBarDelegate::BUTTON_OK); | 392 ConfirmInfoBarDelegate::BUTTON_OK); |
| 302 | 393 |
| 303 Reload(); | 394 Reload(); |
| 304 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 395 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
| 305 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 396 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 306 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 397 RequestGeolocationPermission( |
| 307 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 398 web_contents(), RequestID(0), requesting_frame, true); |
| 399 RequestGeolocationPermission( |
| 400 web_contents(), RequestID(0), requesting_frame, true); |
| 401 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 308 } | 402 } |
| 309 | 403 |
| 310 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 404 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
| 311 GURL requesting_frame("http://www.example.com/geolocation"); | 405 GURL requesting_frame("http://www.example.com/geolocation"); |
| 312 NavigateAndCommit(requesting_frame); | 406 NavigateAndCommit(requesting_frame); |
| 313 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 407 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
| 314 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 408 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 315 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 409 RequestGeolocationPermission( |
| 410 web_contents(), RequestID(0), requesting_frame, true); |
| 316 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 411 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 317 ConfirmInfoBarDelegate* infobar_delegate = | 412 ConfirmInfoBarDelegate* infobar_delegate = |
| 318 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 413 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 319 ASSERT_TRUE(infobar_delegate); | 414 ASSERT_TRUE(infobar_delegate); |
| 320 infobar_delegate->Accept(); | 415 infobar_delegate->Accept(); |
| 321 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 416 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 322 CheckPermissionMessageSent(0, true); | 417 CheckPermissionMessageSent(0, true); |
| 323 } | 418 } |
| 324 | 419 |
| 325 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 420 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { |
| 326 GURL requesting_frame("http://www.example.com/geolocation"); | 421 GURL requesting_frame("http://www.example.com/geolocation"); |
| 327 NavigateAndCommit(requesting_frame); | 422 NavigateAndCommit(requesting_frame); |
| 328 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 423 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); |
| 329 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 424 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 330 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 425 RequestGeolocationPermission( |
| 426 web_contents(), RequestID(0), requesting_frame, true); |
| 331 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 427 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 332 } | 428 } |
| 333 #endif | 429 #endif |
| 334 | 430 |
| 335 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 431 TEST_F(GeolocationPermissionContextTests, QueuedPermissionInfobar) { |
| 432 if (PermissionBubbleManager::Enabled()) |
| 433 return; |
| 434 |
| 336 GURL requesting_frame_0("http://www.example.com/geolocation"); | 435 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 337 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 436 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 338 EXPECT_EQ(CONTENT_SETTING_ASK, | 437 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 339 profile()->GetHostContentSettingsMap()->GetContentSetting( | 438 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 340 requesting_frame_0, requesting_frame_0, | 439 requesting_frame_0, requesting_frame_0, |
| 341 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 440 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 342 EXPECT_EQ(CONTENT_SETTING_ASK, | 441 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 343 profile()->GetHostContentSettingsMap()->GetContentSetting( | 442 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 344 requesting_frame_1, requesting_frame_0, | 443 requesting_frame_1, requesting_frame_0, |
| 345 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 444 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 346 | 445 |
| 347 NavigateAndCommit(requesting_frame_0); | 446 NavigateAndCommit(requesting_frame_0); |
| 348 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 447 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 349 // Request permission for two frames. | 448 // Request permission for two frames. |
| 350 RequestGeolocationPermission( | 449 RequestGeolocationPermission( |
| 351 web_contents(), RequestID(0), requesting_frame_0); | 450 web_contents(), RequestID(0), requesting_frame_0, true); |
| 352 RequestGeolocationPermission( | 451 RequestGeolocationPermission( |
| 353 web_contents(), RequestID(1), requesting_frame_1); | 452 web_contents(), RequestID(1), requesting_frame_1, true); |
| 354 // Ensure only one infobar is created. | 453 // Ensure only one infobar is created. |
| 355 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 454 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 356 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 455 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
| 357 ConfirmInfoBarDelegate* infobar_delegate_0 = | 456 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 358 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 457 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 359 ASSERT_TRUE(infobar_delegate_0); | 458 ASSERT_TRUE(infobar_delegate_0); |
| 360 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 459 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
| 361 | 460 |
| 362 // Accept the first frame. | 461 // Accept the first frame. |
| 363 infobar_delegate_0->Accept(); | 462 infobar_delegate_0->Accept(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 391 profile()->GetHostContentSettingsMap()->GetContentSetting( | 490 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 392 requesting_frame_0, requesting_frame_0, | 491 requesting_frame_0, requesting_frame_0, |
| 393 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 492 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 394 | 493 |
| 395 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 494 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 396 profile()->GetHostContentSettingsMap()->GetContentSetting( | 495 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 397 requesting_frame_1, requesting_frame_0, | 496 requesting_frame_1, requesting_frame_0, |
| 398 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 497 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 399 } | 498 } |
| 400 | 499 |
| 401 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 500 TEST_F(GeolocationPermissionContextTests, QueuedPermissionBubble) { |
| 501 if (!PermissionBubbleManager::Enabled()) |
| 502 return; |
| 503 |
| 504 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 505 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 506 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 507 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 508 requesting_frame_0, requesting_frame_0, |
| 509 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 510 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 511 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 512 requesting_frame_1, requesting_frame_0, |
| 513 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 514 |
| 515 NavigateAndCommit(requesting_frame_0); |
| 516 BubbleManagerDocumentLoadCompleted(); |
| 517 |
| 518 PermissionBubbleManager* mgr = |
| 519 PermissionBubbleManager::FromWebContents(web_contents()); |
| 520 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 521 |
| 522 // Request permission for two frames. |
| 523 RequestGeolocationPermission( |
| 524 web_contents(), RequestID(0), requesting_frame_0, true); |
| 525 RequestGeolocationPermission( |
| 526 web_contents(), RequestID(1), requesting_frame_1, true); |
| 527 // Only main frame permission shown. |
| 528 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 529 base::string16 text_0 = GetFirstRequestText(mgr); |
| 530 |
| 531 // Accept the first frame. |
| 532 AcceptBubble(mgr); |
| 533 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 534 CheckPermissionMessageSent(0, true); |
| 535 |
| 536 // Now we should have a new bubble for the second frame. |
| 537 EXPECT_EQ(1, GetBubblesQueueSize(mgr)); |
| 538 |
| 539 base::string16 text_1 = GetFirstRequestText(mgr); |
| 540 EXPECT_NE(text_0, text_1); |
| 541 |
| 542 // Cancel (block) this frame. |
| 543 DenyBubble(mgr); |
| 544 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 545 CheckPermissionMessageSent(1, false); |
| 546 |
| 547 // Ensure the persisted permissions are ok. |
| 548 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 549 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 550 requesting_frame_0, requesting_frame_0, |
| 551 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 552 |
| 553 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 554 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 555 requesting_frame_1, requesting_frame_0, |
| 556 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 557 } |
| 558 |
| 559 TEST_F(GeolocationPermissionContextTests, UrlFragmentIsIgnoredInfobar) { |
| 560 if (PermissionBubbleManager::Enabled()) |
| 561 return; |
| 562 |
| 402 GURL url_a("http://www.example.com/geolocation#a"); | 563 GURL url_a("http://www.example.com/geolocation#a"); |
| 403 GURL url_b("http://www.example.com/geolocation#b"); | 564 GURL url_b("http://www.example.com/geolocation#b"); |
| 404 | 565 |
| 405 // Navigate to the first url and check permission is requested. | 566 // Navigate to the first url and check permission is requested. |
| 406 NavigateAndCommit(url_a); | 567 NavigateAndCommit(url_a); |
| 407 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 568 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 408 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 569 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
| 409 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 570 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 410 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 571 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 411 ConfirmInfoBarDelegate* infobar_delegate = | 572 ConfirmInfoBarDelegate* infobar_delegate = |
| 412 infobar->delegate()->AsConfirmInfoBarDelegate(); | 573 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 413 ASSERT_TRUE(infobar_delegate); | 574 ASSERT_TRUE(infobar_delegate); |
| 414 | 575 |
| 415 // Change the hash, we'll still be on the same page. | 576 // Change the hash, we'll still be on the same page. |
| 416 NavigateAndCommit(url_b); | 577 NavigateAndCommit(url_b); |
| 417 | 578 |
| 418 // Accept. | 579 // Accept. |
| 419 infobar_delegate->Accept(); | 580 infobar_delegate->Accept(); |
| 420 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 581 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| 421 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 582 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| 422 CheckPermissionMessageSent(0, true); | 583 CheckPermissionMessageSent(0, true); |
| 423 | 584 |
| 424 // Cleanup. | 585 // Cleanup. |
| 425 infobar_service()->RemoveInfoBar(infobar); | 586 infobar_service()->RemoveInfoBar(infobar); |
| 426 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 587 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 427 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 588 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 428 } | 589 } |
| 429 | 590 |
| 430 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 591 TEST_F(GeolocationPermissionContextTests, UrlFragmentIsIgnoredBubble) { |
| 592 if (!PermissionBubbleManager::Enabled()) |
| 593 return; |
| 594 |
| 595 GURL url_a("http://www.example.com/geolocation#a"); |
| 596 GURL url_b("http://www.example.com/geolocation#b"); |
| 597 |
| 598 // Navigate to the first url and check permission is requested. |
| 599 NavigateAndCommit(url_a); |
| 600 BubbleManagerDocumentLoadCompleted(); |
| 601 |
| 602 PermissionBubbleManager* mgr = |
| 603 PermissionBubbleManager::FromWebContents(web_contents()); |
| 604 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 605 |
| 606 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
| 607 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 608 |
| 609 // Change the hash, we'll still be on the same page. |
| 610 NavigateAndCommit(url_b); |
| 611 BubbleManagerDocumentLoadCompleted(); |
| 612 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 613 |
| 614 // Accept. |
| 615 AcceptBubble(mgr); |
| 616 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| 617 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| 618 CheckPermissionMessageSent(0, true); |
| 619 } |
| 620 |
| 621 TEST_F(GeolocationPermissionContextTests, PermissionForFileSchemeInfobars) { |
| 622 if (PermissionBubbleManager::Enabled()) |
| 623 return; |
| 624 |
| 431 GURL requesting_frame("file://example/geolocation.html"); | 625 GURL requesting_frame("file://example/geolocation.html"); |
| 432 NavigateAndCommit(requesting_frame); | 626 NavigateAndCommit(requesting_frame); |
| 433 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 627 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 434 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 628 RequestGeolocationPermission( |
| 629 web_contents(), RequestID(0), requesting_frame, true); |
| 435 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 630 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 436 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 631 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 437 ConfirmInfoBarDelegate* infobar_delegate = | 632 ConfirmInfoBarDelegate* infobar_delegate = |
| 438 infobar->delegate()->AsConfirmInfoBarDelegate(); | 633 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 439 ASSERT_TRUE(infobar_delegate); | 634 ASSERT_TRUE(infobar_delegate); |
| 440 // Accept the frame. | 635 // Accept the frame. |
| 441 infobar_delegate->Accept(); | 636 infobar_delegate->Accept(); |
| 442 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 637 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 443 CheckPermissionMessageSent(0, true); | 638 CheckPermissionMessageSent(0, true); |
| 444 infobar_service()->RemoveInfoBar(infobar); | 639 infobar_service()->RemoveInfoBar(infobar); |
| 445 | 640 |
| 446 // Make sure the setting is not stored. | 641 // Make sure the setting is not stored. |
| 447 EXPECT_EQ(CONTENT_SETTING_ASK, | 642 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 448 profile()->GetHostContentSettingsMap()->GetContentSetting( | 643 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 449 requesting_frame, | 644 requesting_frame, |
| 450 requesting_frame, | 645 requesting_frame, |
| 451 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 646 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 452 std::string())); | 647 std::string())); |
| 453 } | 648 } |
| 454 | 649 |
| 455 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 650 TEST_F(GeolocationPermissionContextTests, PermissionForFileSchemeBubbles) { |
| 651 if (!PermissionBubbleManager::Enabled()) |
| 652 return; |
| 653 |
| 654 GURL requesting_frame("file://example/geolocation.html"); |
| 655 NavigateAndCommit(requesting_frame); |
| 656 BubbleManagerDocumentLoadCompleted(); |
| 657 |
| 658 PermissionBubbleManager* mgr = |
| 659 PermissionBubbleManager::FromWebContents(web_contents()); |
| 660 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 661 RequestGeolocationPermission( |
| 662 web_contents(), RequestID(0), requesting_frame, true); |
| 663 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 664 |
| 665 // Accept the frame. |
| 666 AcceptBubble(mgr); |
| 667 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 668 CheckPermissionMessageSent(0, true); |
| 669 |
| 670 // Make sure the setting is not stored. |
| 671 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 672 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 673 requesting_frame, |
| 674 requesting_frame, |
| 675 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 676 std::string())); |
| 677 } |
| 678 |
| 679 TEST_F(GeolocationPermissionContextTests, |
| 680 CancelGeolocationPermissionRequestInfobar) { |
| 681 if (PermissionBubbleManager::Enabled()) |
| 682 return; |
| 683 |
| 456 GURL requesting_frame_0("http://www.example.com/geolocation"); | 684 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 457 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 685 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 458 EXPECT_EQ(CONTENT_SETTING_ASK, | 686 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 459 profile()->GetHostContentSettingsMap()->GetContentSetting( | 687 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 460 requesting_frame_0, requesting_frame_0, | 688 requesting_frame_0, requesting_frame_0, |
| 461 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 689 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 462 | 690 |
| 463 EXPECT_EQ(CONTENT_SETTING_ASK, | 691 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 464 profile()->GetHostContentSettingsMap()->GetContentSetting( | 692 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 465 requesting_frame_1, requesting_frame_0, | 693 requesting_frame_1, requesting_frame_0, |
| 466 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 694 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 467 | 695 |
| 468 NavigateAndCommit(requesting_frame_0); | 696 NavigateAndCommit(requesting_frame_0); |
| 469 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 697 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 470 // Request permission for two frames. | 698 // Request permission for two frames. |
| 471 base::Closure cancel_callback; | 699 base::Closure cancel_callback; |
| 472 RequestGeolocationPermission( | 700 RequestGeolocationPermission( |
| 473 web_contents(), RequestID(0), requesting_frame_0, &cancel_callback); | 701 web_contents(), RequestID(0), requesting_frame_0, true, &cancel_callback); |
| 474 RequestGeolocationPermission( | 702 RequestGeolocationPermission( |
| 475 web_contents(), RequestID(1), requesting_frame_1); | 703 web_contents(), RequestID(1), requesting_frame_1, true); |
| 476 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 704 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 477 | 705 |
| 478 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 706 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
| 479 ConfirmInfoBarDelegate* infobar_delegate_0 = | 707 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 480 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 708 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 481 ASSERT_TRUE(infobar_delegate_0); | 709 ASSERT_TRUE(infobar_delegate_0); |
| 482 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 710 base::string16 text_0 = infobar_delegate_0->GetMessageText(); |
| 483 | 711 |
| 484 // Simulate the frame going away, ensure the infobar for this frame | 712 // Simulate the frame going away, ensure the infobar for this frame |
| 485 // is removed and the next pending infobar is created. | 713 // is removed and the next pending infobar is created. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 509 profile()->GetHostContentSettingsMap()->GetContentSetting( | 737 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 510 requesting_frame_0, requesting_frame_0, | 738 requesting_frame_0, requesting_frame_0, |
| 511 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 739 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 512 | 740 |
| 513 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 741 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 514 profile()->GetHostContentSettingsMap()->GetContentSetting( | 742 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 515 requesting_frame_1, requesting_frame_0, | 743 requesting_frame_1, requesting_frame_0, |
| 516 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 744 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 517 } | 745 } |
| 518 | 746 |
| 747 TEST_F(GeolocationPermissionContextTests, |
| 748 CancelGeolocationPermissionRequestBubbles) { |
| 749 if (!PermissionBubbleManager::Enabled()) |
| 750 return; |
| 751 |
| 752 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 753 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 754 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 755 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 756 requesting_frame_0, requesting_frame_0, |
| 757 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 758 |
| 759 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 760 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 761 requesting_frame_1, requesting_frame_0, |
| 762 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 763 |
| 764 NavigateAndCommit(requesting_frame_0); |
| 765 BubbleManagerDocumentLoadCompleted(); |
| 766 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 767 // Request permission for two frames. |
| 768 base::Closure cancel_callback; |
| 769 RequestGeolocationPermission( |
| 770 web_contents(), RequestID(0), requesting_frame_0, true, &cancel_callback); |
| 771 RequestGeolocationPermission( |
| 772 web_contents(), RequestID(1), requesting_frame_1, true); |
| 773 |
| 774 PermissionBubbleManager* mgr = |
| 775 PermissionBubbleManager::FromWebContents(web_contents()); |
| 776 ASSERT_TRUE(mgr != NULL); |
| 777 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 778 base::string16 text_0 = GetFirstRequestText(mgr); |
| 779 ASSERT_NE(base::string16(), text_0); |
| 780 |
| 781 // Cancel the request. This will still leave the bubble showing, since |
| 782 // the request is showing in the view. It will just be dummied. |
| 783 cancel_callback.Run(); |
| 784 AcceptBubble(mgr); // Dummy accept |
| 785 base::string16 text_1 = GetFirstRequestText(mgr); |
| 786 EXPECT_NE(text_0, text_1); |
| 787 |
| 788 // Allow this frame. |
| 789 AcceptBubble(mgr); |
| 790 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 791 CheckPermissionMessageSent(1, true); |
| 792 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); |
| 793 |
| 794 // Ensure the persisted permissions are ok. |
| 795 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 796 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 797 requesting_frame_0, requesting_frame_0, |
| 798 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 799 |
| 800 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 801 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 802 requesting_frame_1, requesting_frame_0, |
| 803 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 804 } |
| 805 |
| 519 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 806 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| 520 GURL invalid_embedder("about:blank"); | 807 GURL invalid_embedder("about:blank"); |
| 521 GURL requesting_frame; | 808 GURL requesting_frame; |
| 522 NavigateAndCommit(invalid_embedder); | 809 NavigateAndCommit(invalid_embedder); |
| 523 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 810 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 524 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 811 RequestGeolocationPermission( |
| 812 web_contents(), RequestID(0), requesting_frame, true); |
| 525 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 813 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 526 CheckPermissionMessageSent(0, false); | 814 CheckPermissionMessageSent(0, false); |
| 527 } | 815 } |
| 528 | 816 |
| 529 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 817 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabsInfobar) { |
| 818 if (PermissionBubbleManager::Enabled()) |
| 819 return; |
| 820 |
| 530 GURL url_a("http://www.example.com/geolocation"); | 821 GURL url_a("http://www.example.com/geolocation"); |
| 531 GURL url_b("http://www.example-2.com/geolocation"); | 822 GURL url_b("http://www.example-2.com/geolocation"); |
| 532 NavigateAndCommit(url_a); | 823 NavigateAndCommit(url_a); |
| 533 AddNewTab(url_b); | 824 AddNewTab(url_b); |
| 534 AddNewTab(url_a); | 825 AddNewTab(url_a); |
| 535 | 826 |
| 536 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 827 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 537 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 828 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
| 538 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 829 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 539 | 830 |
| 540 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b); | 831 RequestGeolocationPermission( |
| 832 extra_tabs_[0], RequestIDForTab(0, 0), url_b, true); |
| 541 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 833 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 542 | 834 |
| 543 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a); | 835 RequestGeolocationPermission( |
| 836 extra_tabs_[1], RequestIDForTab(1, 0), url_a, true); |
| 544 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 837 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
| 545 | 838 |
| 546 infobars::InfoBar* removed_infobar = | 839 infobars::InfoBar* removed_infobar = |
| 547 infobar_service_for_tab(1)->infobar_at(0); | 840 infobar_service_for_tab(1)->infobar_at(0); |
| 548 | 841 |
| 549 // Accept the first tab. | 842 // Accept the first tab. |
| 550 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 843 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
| 551 ConfirmInfoBarDelegate* infobar_delegate_0 = | 844 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 552 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 845 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 553 ASSERT_TRUE(infobar_delegate_0); | 846 ASSERT_TRUE(infobar_delegate_0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 567 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 860 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); |
| 568 ConfirmInfoBarDelegate* infobar_delegate_1 = | 861 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 569 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 862 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 570 ASSERT_TRUE(infobar_delegate_1); | 863 ASSERT_TRUE(infobar_delegate_1); |
| 571 infobar_delegate_1->Cancel(); | 864 infobar_delegate_1->Cancel(); |
| 572 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 865 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
| 573 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 866 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 574 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 867 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
| 575 } | 868 } |
| 576 | 869 |
| 577 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 870 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabsInfobar) { |
| 871 if (PermissionBubbleManager::Enabled()) |
| 872 return; |
| 873 |
| 578 GURL url_a("http://www.example.com/geolocation"); | 874 GURL url_a("http://www.example.com/geolocation"); |
| 579 GURL url_b("http://www.example-2.com/geolocation"); | 875 GURL url_b("http://www.example-2.com/geolocation"); |
| 580 NavigateAndCommit(url_a); | 876 NavigateAndCommit(url_a); |
| 581 AddNewTab(url_a); | 877 AddNewTab(url_a); |
| 582 | 878 |
| 583 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 879 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 584 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 880 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
| 585 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 881 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 586 | 882 |
| 587 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a); | 883 RequestGeolocationPermission( |
| 884 extra_tabs_[0], RequestIDForTab(0, 0), url_a, true); |
| 588 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 885 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 589 | 886 |
| 590 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b); | 887 RequestGeolocationPermission( |
| 888 extra_tabs_[0], RequestIDForTab(0, 1), url_b, true); |
| 591 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 889 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 592 | 890 |
| 593 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 891 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); |
| 594 | 892 |
| 595 // Accept the second tab. | 893 // Accept the second tab. |
| 596 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 894 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); |
| 597 ConfirmInfoBarDelegate* infobar_delegate_0 = | 895 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 598 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 896 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 599 ASSERT_TRUE(infobar_delegate_0); | 897 ASSERT_TRUE(infobar_delegate_0); |
| 600 infobar_delegate_0->Accept(); | 898 infobar_delegate_0->Accept(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 616 ConfirmInfoBarDelegate* infobar_delegate_1 = | 914 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 617 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 915 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 618 ASSERT_TRUE(infobar_delegate_1); | 916 ASSERT_TRUE(infobar_delegate_1); |
| 619 infobar_delegate_1->Accept(); | 917 infobar_delegate_1->Accept(); |
| 620 CheckPermissionMessageSentForTab(0, 1, true); | 918 CheckPermissionMessageSentForTab(0, 1, true); |
| 621 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 919 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); |
| 622 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 920 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 623 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 921 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
| 624 } | 922 } |
| 625 | 923 |
| 626 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 924 TEST_F(GeolocationPermissionContextTests, TabDestroyedInfobar) { |
| 925 if (PermissionBubbleManager::Enabled()) |
| 926 return; |
| 927 |
| 627 GURL requesting_frame_0("http://www.example.com/geolocation"); | 928 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 628 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 929 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 629 EXPECT_EQ(CONTENT_SETTING_ASK, | 930 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 630 profile()->GetHostContentSettingsMap()->GetContentSetting( | 931 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 631 requesting_frame_0, requesting_frame_0, | 932 requesting_frame_0, requesting_frame_0, |
| 632 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 933 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 633 | 934 |
| 634 EXPECT_EQ(CONTENT_SETTING_ASK, | 935 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 635 profile()->GetHostContentSettingsMap()->GetContentSetting( | 936 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 636 requesting_frame_1, requesting_frame_0, | 937 requesting_frame_1, requesting_frame_0, |
| 637 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 938 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 638 | 939 |
| 639 NavigateAndCommit(requesting_frame_0); | 940 NavigateAndCommit(requesting_frame_0); |
| 640 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 941 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 641 // Request permission for two frames. | 942 // Request permission for two frames. |
| 642 RequestGeolocationPermission( | 943 RequestGeolocationPermission( |
| 643 web_contents(), RequestID(0), requesting_frame_0); | 944 web_contents(), RequestID(0), requesting_frame_0, true); |
| 644 RequestGeolocationPermission( | 945 RequestGeolocationPermission( |
| 645 web_contents(), RequestID(1), requesting_frame_1); | 946 web_contents(), RequestID(1), requesting_frame_1, true); |
| 646 // Ensure only one infobar is created. | 947 // Ensure only one infobar is created. |
| 647 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 948 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 648 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 949 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 649 | 950 |
| 650 // Delete the tab contents. | 951 // Delete the tab contents. |
| 651 DeleteContents(); | 952 DeleteContents(); |
| 652 | 953 |
| 653 // During contents destruction, the infobar will have been closed, and the | 954 // During contents destruction, the infobar will have been closed, and the |
| 654 // pending request should have been cleared without an infobar being created. | 955 // pending request should have been cleared without an infobar being created. |
| 655 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 956 ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
| 656 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 957 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 657 } | 958 } |
| 658 | 959 |
| 960 TEST_F(GeolocationPermissionContextTests, TabDestroyedBubbles) { |
| 961 if (!PermissionBubbleManager::Enabled()) |
| 962 return; |
| 963 |
| 964 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 965 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 966 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 967 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 968 requesting_frame_0, requesting_frame_0, |
| 969 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 970 |
| 971 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 972 profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 973 requesting_frame_1, requesting_frame_0, |
| 974 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 975 |
| 976 NavigateAndCommit(requesting_frame_0); |
| 977 BubbleManagerDocumentLoadCompleted(); |
| 978 PermissionBubbleManager* mgr = |
| 979 PermissionBubbleManager::FromWebContents(web_contents()); |
| 980 ASSERT_TRUE(mgr != NULL); |
| 981 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
| 982 |
| 983 // Request permission for two frames. |
| 984 RequestGeolocationPermission( |
| 985 web_contents(), RequestID(0), requesting_frame_0, true); |
| 986 RequestGeolocationPermission( |
| 987 web_contents(), RequestID(1), requesting_frame_1, true); |
| 988 // Ensure only one bubble request is shown. |
| 989 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
| 990 |
| 991 // Delete the tab contents. |
| 992 DeleteContents(); |
| 993 |
| 994 // During contents destruction, the bubble will have been closed, and the |
| 995 // pending request should have been cleared without a bubble being shown. |
| 996 } |
| 997 |
| 659 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { | 998 TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) { |
| 999 if (PermissionBubbleManager::Enabled()) |
| 1000 return; |
| 1001 |
| 660 GURL requesting_frame_0("http://www.example.com/geolocation"); | 1002 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 661 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 1003 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 662 NavigateAndCommit(requesting_frame_0); | 1004 NavigateAndCommit(requesting_frame_0); |
| 663 NavigateAndCommit(requesting_frame_1); | 1005 NavigateAndCommit(requesting_frame_1); |
| 664 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1006 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 665 // Go back: navigate to a pending entry before requesting geolocation | 1007 // Go back: navigate to a pending entry before requesting geolocation |
| 666 // permission. | 1008 // permission. |
| 667 web_contents()->GetController().GoBack(); | 1009 web_contents()->GetController().GoBack(); |
| 668 // Request permission for the committed frame (not the pending one). | 1010 // Request permission for the committed frame (not the pending one). |
| 669 RequestGeolocationPermission( | 1011 RequestGeolocationPermission( |
| 670 web_contents(), RequestID(0), requesting_frame_1); | 1012 web_contents(), RequestID(0), requesting_frame_1, true); |
| 671 // Ensure the infobar is created. | 1013 // Ensure the infobar is created. |
| 672 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1014 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 673 infobars::InfoBarDelegate* infobar_delegate = | 1015 infobars::InfoBarDelegate* infobar_delegate = |
| 674 infobar_service()->infobar_at(0)->delegate(); | 1016 infobar_service()->infobar_at(0)->delegate(); |
| 675 ASSERT_TRUE(infobar_delegate); | 1017 ASSERT_TRUE(infobar_delegate); |
| 676 // Ensure the infobar wouldn't expire for a navigation to the committed entry. | 1018 // Ensure the infobar wouldn't expire for a navigation to the committed entry. |
| 677 content::LoadCommittedDetails details; | 1019 content::LoadCommittedDetails details; |
| 678 details.entry = web_contents()->GetController().GetLastCommittedEntry(); | 1020 details.entry = web_contents()->GetController().GetLastCommittedEntry(); |
| 679 EXPECT_FALSE(infobar_delegate->ShouldExpire( | 1021 EXPECT_FALSE(infobar_delegate->ShouldExpire( |
| 680 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); | 1022 InfoBarService::NavigationDetailsFromLoadCommittedDetails(details))); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 698 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 1040 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
| 699 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 1041 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
| 700 | 1042 |
| 701 // The permission shouldn't have been used yet. | 1043 // The permission shouldn't have been used yet. |
| 702 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 1044 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
| 703 requesting_frame.GetOrigin(), | 1045 requesting_frame.GetOrigin(), |
| 704 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1046 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 705 0); | 1047 0); |
| 706 | 1048 |
| 707 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1049 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 708 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 1050 RequestGeolocationPermission( |
| 1051 web_contents(), RequestID(0), requesting_frame, true); |
| 709 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1052 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 710 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 1053 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 711 ConfirmInfoBarDelegate* infobar_delegate = | 1054 ConfirmInfoBarDelegate* infobar_delegate = |
| 712 infobar->delegate()->AsConfirmInfoBarDelegate(); | 1055 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 713 ASSERT_TRUE(infobar_delegate); | 1056 ASSERT_TRUE(infobar_delegate); |
| 714 infobar_delegate->Accept(); | 1057 infobar_delegate->Accept(); |
| 715 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 1058 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 716 CheckPermissionMessageSent(0, true); | 1059 CheckPermissionMessageSent(0, true); |
| 717 | 1060 |
| 718 // Permission has been used at the starting time. | 1061 // Permission has been used at the starting time. |
| 719 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 1062 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
| 720 requesting_frame.GetOrigin(), | 1063 requesting_frame.GetOrigin(), |
| 721 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1064 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 722 10); | 1065 10); |
| 723 | 1066 |
| 724 test_clock->Advance(base::TimeDelta::FromSeconds(3)); | 1067 test_clock->Advance(base::TimeDelta::FromSeconds(3)); |
| 725 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 1068 RequestGeolocationPermission( |
| 1069 web_contents(), RequestID(0), requesting_frame, true); |
| 726 | 1070 |
| 727 // Permission has been used three seconds later. | 1071 // Permission has been used three seconds later. |
| 728 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 1072 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
| 729 requesting_frame.GetOrigin(), | 1073 requesting_frame.GetOrigin(), |
| 730 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1074 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 731 13); | 1075 13); |
| 732 } | 1076 } |
| 733 | 1077 |
| 734 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { | 1078 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { |
| 735 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 1079 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 750 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1094 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 751 requesting_frame_0.GetOrigin(), | 1095 requesting_frame_0.GetOrigin(), |
| 752 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1096 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 753 0); | 1097 0); |
| 754 | 1098 |
| 755 NavigateAndCommit(requesting_frame_0); | 1099 NavigateAndCommit(requesting_frame_0); |
| 756 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1100 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 757 | 1101 |
| 758 // Request permission for two frames. | 1102 // Request permission for two frames. |
| 759 RequestGeolocationPermission( | 1103 RequestGeolocationPermission( |
| 760 web_contents(), RequestID(0), requesting_frame_0); | 1104 web_contents(), RequestID(0), requesting_frame_0, true); |
| 761 RequestGeolocationPermission( | 1105 RequestGeolocationPermission( |
| 762 web_contents(), RequestID(1), requesting_frame_1); | 1106 web_contents(), RequestID(1), requesting_frame_1, true); |
| 763 | 1107 |
| 764 // Ensure only one infobar is created. | 1108 // Ensure only one infobar is created. |
| 765 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1109 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 766 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 1110 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
| 767 ConfirmInfoBarDelegate* infobar_delegate_0 = | 1111 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 768 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 1112 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
| 769 | 1113 |
| 770 // Accept the first frame. | 1114 // Accept the first frame. |
| 771 infobar_delegate_0->Accept(); | 1115 infobar_delegate_0->Accept(); |
| 772 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 1116 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 802 requesting_frame_0.GetOrigin(), | 1146 requesting_frame_0.GetOrigin(), |
| 803 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1147 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 804 10); | 1148 10); |
| 805 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1149 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 806 requesting_frame_0.GetOrigin(), | 1150 requesting_frame_0.GetOrigin(), |
| 807 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1151 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 808 11); | 1152 11); |
| 809 | 1153 |
| 810 test_clock->Advance(base::TimeDelta::FromSeconds(2)); | 1154 test_clock->Advance(base::TimeDelta::FromSeconds(2)); |
| 811 RequestGeolocationPermission( | 1155 RequestGeolocationPermission( |
| 812 web_contents(), RequestID(0), requesting_frame_0); | 1156 web_contents(), RequestID(0), requesting_frame_0, true); |
| 813 | 1157 |
| 814 // Verify that requesting permission in one frame doesn't update other where | 1158 // Verify that requesting permission in one frame doesn't update other where |
| 815 // it is the embedder. | 1159 // it is the embedder. |
| 816 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1160 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 817 requesting_frame_0.GetOrigin(), | 1161 requesting_frame_0.GetOrigin(), |
| 818 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1162 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 819 13); | 1163 13); |
| 820 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1164 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 821 requesting_frame_0.GetOrigin(), | 1165 requesting_frame_0.GetOrigin(), |
| 822 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1166 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 823 11); | 1167 11); |
| 824 } | 1168 } |
| OLD | NEW |