| 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/command_line.h" |
| 12 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
| 13 #include "base/id_map.h" | 14 #include "base/id_map.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/test/simple_test_clock.h" | 17 #include "base/test/simple_test_clock.h" |
| 17 #include "base/time/clock.h" | 18 #include "base/time/clock.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| 20 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 21 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
| 21 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
| 23 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.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/common/chrome_switches.h" |
| 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 25 #include "components/content_settings/core/common/permission_request_id.h" | 30 #include "components/content_settings/core/common/permission_request_id.h" |
| 26 #include "components/infobars/core/confirm_infobar_delegate.h" | 31 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 27 #include "components/infobars/core/infobar.h" | 32 #include "components/infobars/core/infobar.h" |
| 28 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/navigation_details.h" | 34 #include "content/public/browser/navigation_details.h" |
| 30 #include "content/public/browser/notification_observer.h" | 35 #include "content/public/browser/notification_observer.h" |
| 31 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 PermissionRequestID RequestIDForTab(int tab, int bridge_id); | 118 PermissionRequestID RequestIDForTab(int tab, int bridge_id); |
| 114 InfoBarService* infobar_service() { | 119 InfoBarService* infobar_service() { |
| 115 return InfoBarService::FromWebContents(web_contents()); | 120 return InfoBarService::FromWebContents(web_contents()); |
| 116 } | 121 } |
| 117 InfoBarService* infobar_service_for_tab(int tab) { | 122 InfoBarService* infobar_service_for_tab(int tab) { |
| 118 return InfoBarService::FromWebContents(extra_tabs_[tab]); | 123 return InfoBarService::FromWebContents(extra_tabs_[tab]); |
| 119 } | 124 } |
| 120 | 125 |
| 121 void RequestGeolocationPermission(content::WebContents* web_contents, | 126 void RequestGeolocationPermission(content::WebContents* web_contents, |
| 122 const PermissionRequestID& id, | 127 const PermissionRequestID& id, |
| 123 const GURL& requesting_frame); | 128 const GURL& requesting_frame, |
| 129 bool user_gesture); |
| 124 | 130 |
| 125 void PermissionResponse(const PermissionRequestID& id, | 131 void PermissionResponse(const PermissionRequestID& id, |
| 126 bool allowed); | 132 bool allowed); |
| 127 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 133 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
| 128 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 134 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
| 129 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 135 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
| 130 int bridge_id, | 136 int bridge_id, |
| 131 bool allowed); | 137 bool allowed); |
| 132 void AddNewTab(const GURL& url); | 138 void AddNewTab(const GURL& url); |
| 133 void CheckTabContentsState(const GURL& requesting_frame, | 139 void CheckTabContentsState(const GURL& requesting_frame, |
| 134 ContentSetting expected_content_setting); | 140 ContentSetting expected_content_setting); |
| 141 size_t GetBubblesQueueSize(PermissionBubbleManager* manager); |
| 142 void AcceptBubble(PermissionBubbleManager* manager); |
| 143 void DenyBubble(PermissionBubbleManager* manager); |
| 144 void CloseBubble(PermissionBubbleManager* manager); |
| 145 void BubbleManagerDocumentLoadCompleted(); |
| 146 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); |
| 147 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); |
| 135 | 148 |
| 136 // owned by the browser context | 149 // owned by the browser context |
| 137 GeolocationPermissionContext* geolocation_permission_context_; | 150 GeolocationPermissionContext* geolocation_permission_context_; |
| 138 ClosedInfoBarTracker closed_infobar_tracker_; | 151 ClosedInfoBarTracker closed_infobar_tracker_; |
| 152 MockPermissionBubbleView bubble_view_; |
| 139 ScopedVector<content::WebContents> extra_tabs_; | 153 ScopedVector<content::WebContents> extra_tabs_; |
| 140 | 154 |
| 141 // A map between renderer child id and a pair represending the bridge id and | 155 // A map between renderer child id and a pair represending the bridge id and |
| 142 // whether the requested permission was allowed. | 156 // whether the requested permission was allowed. |
| 143 base::hash_map<int, std::pair<int, bool> > responses_; | 157 base::hash_map<int, std::pair<int, bool> > responses_; |
| 144 }; | 158 }; |
| 145 | 159 |
| 146 PermissionRequestID GeolocationPermissionContextTests::RequestID( | 160 PermissionRequestID GeolocationPermissionContextTests::RequestID( |
| 147 int bridge_id) { | 161 int bridge_id) { |
| 148 return PermissionRequestID( | 162 return PermissionRequestID( |
| 149 web_contents()->GetRenderProcessHost()->GetID(), | 163 web_contents()->GetRenderProcessHost()->GetID(), |
| 150 web_contents()->GetRenderViewHost()->GetRoutingID(), | 164 web_contents()->GetRenderViewHost()->GetRoutingID(), |
| 151 bridge_id, | 165 bridge_id, |
| 152 GURL()); | 166 GURL()); |
| 153 } | 167 } |
| 154 | 168 |
| 155 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( | 169 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( |
| 156 int tab, | 170 int tab, |
| 157 int bridge_id) { | 171 int bridge_id) { |
| 158 return PermissionRequestID( | 172 return PermissionRequestID( |
| 159 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), | 173 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
| 160 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), | 174 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
| 161 bridge_id, | 175 bridge_id, |
| 162 GURL()); | 176 GURL()); |
| 163 } | 177 } |
| 164 | 178 |
| 165 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 179 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
| 166 content::WebContents* web_contents, | 180 content::WebContents* web_contents, |
| 167 const PermissionRequestID& id, | 181 const PermissionRequestID& id, |
| 168 const GURL& requesting_frame) { | 182 const GURL& requesting_frame, |
| 183 bool user_gesture) { |
| 169 geolocation_permission_context_->RequestPermission( | 184 geolocation_permission_context_->RequestPermission( |
| 170 web_contents, id, requesting_frame, false, | 185 web_contents, id, requesting_frame, user_gesture, |
| 171 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 186 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
| 172 base::Unretained(this), id)); | 187 base::Unretained(this), id)); |
| 173 content::RunAllBlockingPoolTasksUntilIdle(); | 188 content::RunAllBlockingPoolTasksUntilIdle(); |
| 174 } | 189 } |
| 175 | 190 |
| 176 void GeolocationPermissionContextTests::PermissionResponse( | 191 void GeolocationPermissionContextTests::PermissionResponse( |
| 177 const PermissionRequestID& id, | 192 const PermissionRequestID& id, |
| 178 bool allowed) { | 193 bool allowed) { |
| 179 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); | 194 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); |
| 180 } | 195 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 210 new_tab->GetController().LoadURL( | 225 new_tab->GetController().LoadURL( |
| 211 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 226 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
| 212 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) | 227 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) |
| 213 ->SendNavigate(extra_tabs_.size() + 1, url); | 228 ->SendNavigate(extra_tabs_.size() + 1, url); |
| 214 | 229 |
| 215 // Set up required helpers, and make this be as "tabby" as the code requires. | 230 // Set up required helpers, and make this be as "tabby" as the code requires. |
| 216 #if defined(ENABLE_EXTENSIONS) | 231 #if defined(ENABLE_EXTENSIONS) |
| 217 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); | 232 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
| 218 #endif | 233 #endif |
| 219 InfoBarService::CreateForWebContents(new_tab); | 234 InfoBarService::CreateForWebContents(new_tab); |
| 235 PermissionBubbleManager::CreateForWebContents(new_tab); |
| 236 PermissionBubbleManager::FromWebContents(new_tab)->SetView(&bubble_view_); |
| 220 | 237 |
| 221 extra_tabs_.push_back(new_tab); | 238 extra_tabs_.push_back(new_tab); |
| 222 } | 239 } |
| 223 | 240 |
| 224 void GeolocationPermissionContextTests::CheckTabContentsState( | 241 void GeolocationPermissionContextTests::CheckTabContentsState( |
| 225 const GURL& requesting_frame, | 242 const GURL& requesting_frame, |
| 226 ContentSetting expected_content_setting) { | 243 ContentSetting expected_content_setting) { |
| 227 TabSpecificContentSettings* content_settings = | 244 TabSpecificContentSettings* content_settings = |
| 228 TabSpecificContentSettings::FromWebContents(web_contents()); | 245 TabSpecificContentSettings::FromWebContents(web_contents()); |
| 229 const ContentSettingsUsagesState::StateMap& state_map = | 246 const ContentSettingsUsagesState::StateMap& state_map = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 248 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 265 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 249 geolocation_permission_context_ = | 266 geolocation_permission_context_ = |
| 250 GeolocationPermissionContextFactory::GetForProfile(profile()); | 267 GeolocationPermissionContextFactory::GetForProfile(profile()); |
| 251 #if defined(OS_ANDROID) | 268 #if defined(OS_ANDROID) |
| 252 static_cast<GeolocationPermissionContextAndroid*>( | 269 static_cast<GeolocationPermissionContextAndroid*>( |
| 253 geolocation_permission_context_) | 270 geolocation_permission_context_) |
| 254 ->SetLocationSettingsForTesting( | 271 ->SetLocationSettingsForTesting( |
| 255 scoped_ptr<LocationSettings>(new MockLocationSettings())); | 272 scoped_ptr<LocationSettings>(new MockLocationSettings())); |
| 256 MockLocationSettings::SetLocationStatus(true, true); | 273 MockLocationSettings::SetLocationStatus(true, true); |
| 257 #endif | 274 #endif |
| 275 PermissionBubbleManager::CreateForWebContents(web_contents()); |
| 276 PermissionBubbleManager::FromWebContents(web_contents())->SetView( |
| 277 &bubble_view_); |
| 258 } | 278 } |
| 259 | 279 |
| 260 void GeolocationPermissionContextTests::TearDown() { | 280 void GeolocationPermissionContextTests::TearDown() { |
| 261 extra_tabs_.clear(); | 281 extra_tabs_.clear(); |
| 262 ChromeRenderViewHostTestHarness::TearDown(); | 282 ChromeRenderViewHostTestHarness::TearDown(); |
| 263 } | 283 } |
| 264 | 284 |
| 285 size_t GeolocationPermissionContextTests::GetBubblesQueueSize( |
| 286 PermissionBubbleManager* manager) { |
| 287 return manager->requests_.size(); |
| 288 } |
| 289 |
| 290 void GeolocationPermissionContextTests::AcceptBubble( |
| 291 PermissionBubbleManager* manager) { |
| 292 manager->Accept(); |
| 293 } |
| 294 |
| 295 void GeolocationPermissionContextTests::DenyBubble( |
| 296 PermissionBubbleManager* manager) { |
| 297 manager->Deny(); |
| 298 } |
| 299 |
| 300 void GeolocationPermissionContextTests::CloseBubble( |
| 301 PermissionBubbleManager* manager) { |
| 302 manager->Closing(); |
| 303 } |
| 304 |
| 305 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { |
| 306 GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( |
| 307 web_contents()); |
| 308 } |
| 309 |
| 310 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( |
| 311 content::WebContents* web_contents) { |
| 312 PermissionBubbleManager::FromWebContents(web_contents)-> |
| 313 DocumentOnLoadCompletedInMainFrame(); |
| 314 } |
| 315 |
| 316 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( |
| 317 GURL frame_0, GURL frame_1) { |
| 318 return profile()->GetHostContentSettingsMap()->GetContentSetting( |
| 319 frame_0, frame_1, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()); |
| 320 } |
| 321 |
| 322 // Needed to parameterize the tests for both infobars & permission bubbles. |
| 323 class GeolocationPermissionContextParamTests : |
| 324 public GeolocationPermissionContextTests, |
| 325 public ::testing::WithParamInterface<bool> { |
| 326 protected: |
| 327 GeolocationPermissionContextParamTests() {} |
| 328 ~GeolocationPermissionContextParamTests() override {} |
| 329 |
| 330 bool BubbleEnabled() const { |
| 331 #if defined (OS_ANDROID) |
| 332 return false; |
| 333 #else |
| 334 return GetParam(); |
| 335 #endif |
| 336 } |
| 337 |
| 338 void SetUp() override { |
| 339 GeolocationPermissionContextTests::SetUp(); |
| 340 #if !defined(OS_ANDROID) |
| 341 if (BubbleEnabled()) { |
| 342 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 343 switches::kEnablePermissionsBubbles); |
| 344 EXPECT_TRUE(PermissionBubbleManager::Enabled()); |
| 345 } else { |
| 346 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 347 switches::kDisablePermissionsBubbles); |
| 348 EXPECT_FALSE(PermissionBubbleManager::Enabled()); |
| 349 } |
| 350 #endif |
| 351 } |
| 352 |
| 353 size_t GetNumberOfPrompts() { |
| 354 if (BubbleEnabled()) { |
| 355 PermissionBubbleManager* manager = |
| 356 PermissionBubbleManager::FromWebContents(web_contents()); |
| 357 return GetBubblesQueueSize(manager); |
| 358 } else { |
| 359 return infobar_service()->infobar_count(); |
| 360 } |
| 361 } |
| 362 |
| 363 void AcceptPrompt() { |
| 364 if (BubbleEnabled()) { |
| 365 PermissionBubbleManager* manager = |
| 366 PermissionBubbleManager::FromWebContents(web_contents()); |
| 367 AcceptBubble(manager); |
| 368 } else { |
| 369 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 370 ConfirmInfoBarDelegate* infobar_delegate = |
| 371 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 372 infobar_delegate->Accept(); |
| 373 } |
| 374 } |
| 375 |
| 376 base::string16 GetPromptText() { |
| 377 if (BubbleEnabled()) { |
| 378 PermissionBubbleManager* manager = |
| 379 PermissionBubbleManager::FromWebContents(web_contents()); |
| 380 return manager->requests_.front()->GetMessageText(); |
| 381 } |
| 382 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 383 ConfirmInfoBarDelegate* infobar_delegate = |
| 384 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 385 return infobar_delegate->GetMessageText(); |
| 386 } |
| 387 private: |
| 388 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextParamTests); |
| 389 }; |
| 390 |
| 265 // Tests ---------------------------------------------------------------------- | 391 // Tests ---------------------------------------------------------------------- |
| 266 | 392 |
| 267 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 393 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionInfobar) { |
| 394 if (BubbleEnabled()) return; |
| 395 |
| 268 GURL requesting_frame("http://www.example.com/geolocation"); | 396 GURL requesting_frame("http://www.example.com/geolocation"); |
| 269 NavigateAndCommit(requesting_frame); | 397 NavigateAndCommit(requesting_frame); |
| 270 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 398 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 271 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 399 RequestGeolocationPermission( |
| 400 web_contents(), RequestID(0), requesting_frame, true); |
| 272 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 401 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 273 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 402 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 274 ConfirmInfoBarDelegate* infobar_delegate = | 403 ConfirmInfoBarDelegate* infobar_delegate = |
| 275 infobar->delegate()->AsConfirmInfoBarDelegate(); | 404 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 276 ASSERT_TRUE(infobar_delegate); | 405 ASSERT_TRUE(infobar_delegate); |
| 277 infobar_delegate->Cancel(); | 406 infobar_delegate->Cancel(); |
| 278 infobar_service()->RemoveInfoBar(infobar); | 407 infobar_service()->RemoveInfoBar(infobar); |
| 279 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 408 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 280 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 409 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 281 } | 410 } |
| 282 | 411 |
| 412 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionBubble) { |
| 413 if (!BubbleEnabled()) return; |
| 414 |
| 415 GURL requesting_frame("http://www.example.com/geolocation"); |
| 416 NavigateAndCommit(requesting_frame); |
| 417 BubbleManagerDocumentLoadCompleted(); |
| 418 |
| 419 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 420 RequestGeolocationPermission( |
| 421 web_contents(), RequestID(0), requesting_frame, true); |
| 422 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 423 } |
| 424 |
| 283 #if defined(OS_ANDROID) | 425 #if defined(OS_ANDROID) |
| 426 // Infobar-only tests; Android doesn't support permission bubbles. |
| 284 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 427 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
| 285 GURL requesting_frame("http://www.example.com/geolocation"); | 428 GURL requesting_frame("http://www.example.com/geolocation"); |
| 286 NavigateAndCommit(requesting_frame); | 429 NavigateAndCommit(requesting_frame); |
| 287 MockLocationSettings::SetLocationStatus(true, true); | 430 MockLocationSettings::SetLocationStatus(true, true); |
| 288 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 431 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 289 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 432 RequestGeolocationPermission( |
| 433 web_contents(), RequestID(0), requesting_frame, true); |
| 290 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 434 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 291 ConfirmInfoBarDelegate* infobar_delegate_0 = | 435 ConfirmInfoBarDelegate* infobar_delegate_0 = |
| 292 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 436 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 293 ASSERT_TRUE(infobar_delegate_0); | 437 ASSERT_TRUE(infobar_delegate_0); |
| 294 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | 438 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( |
| 295 ConfirmInfoBarDelegate::BUTTON_OK); | 439 ConfirmInfoBarDelegate::BUTTON_OK); |
| 296 | 440 |
| 297 Reload(); | 441 Reload(); |
| 298 MockLocationSettings::SetLocationStatus(true, false); | 442 MockLocationSettings::SetLocationStatus(true, false); |
| 299 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 443 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 300 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 444 RequestGeolocationPermission( |
| 445 web_contents(), RequestID(0), requesting_frame, true); |
| 301 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 446 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 302 } | 447 } |
| 303 | 448 |
| 304 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 449 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { |
| 305 GURL requesting_frame("http://www.example.com/geolocation"); | 450 GURL requesting_frame("http://www.example.com/geolocation"); |
| 306 NavigateAndCommit(requesting_frame); | 451 NavigateAndCommit(requesting_frame); |
| 307 MockLocationSettings::SetLocationStatus(true, true); | 452 MockLocationSettings::SetLocationStatus(true, true); |
| 308 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 453 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 309 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 454 RequestGeolocationPermission( |
| 455 web_contents(), RequestID(0), requesting_frame, true); |
| 310 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 456 EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| 311 ConfirmInfoBarDelegate* infobar_delegate = | 457 ConfirmInfoBarDelegate* infobar_delegate = |
| 312 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 458 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 313 ASSERT_TRUE(infobar_delegate); | 459 ASSERT_TRUE(infobar_delegate); |
| 314 infobar_delegate->Accept(); | 460 infobar_delegate->Accept(); |
| 315 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 461 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 316 CheckPermissionMessageSent(0, true); | 462 CheckPermissionMessageSent(0, true); |
| 317 } | 463 } |
| 318 | 464 |
| 319 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | 465 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { |
| 320 GURL requesting_frame("http://www.example.com/geolocation"); | 466 GURL requesting_frame("http://www.example.com/geolocation"); |
| 321 NavigateAndCommit(requesting_frame); | 467 NavigateAndCommit(requesting_frame); |
| 322 MockLocationSettings::SetLocationStatus(true, false); | 468 MockLocationSettings::SetLocationStatus(true, false); |
| 323 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 469 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 324 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 470 RequestGeolocationPermission( |
| 471 web_contents(), RequestID(0), requesting_frame, true); |
| 325 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 472 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 326 } | 473 } |
| 327 #endif | 474 #endif |
| 328 | 475 |
| 329 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | 476 TEST_P(GeolocationPermissionContextParamTests, QueuedPermission) { |
| 330 GURL requesting_frame_0("http://www.example.com/geolocation"); | 477 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 331 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 478 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 332 EXPECT_EQ(CONTENT_SETTING_ASK, | 479 EXPECT_EQ( |
| 333 profile()->GetHostContentSettingsMap()->GetContentSetting( | 480 CONTENT_SETTING_ASK, |
| 334 requesting_frame_0, requesting_frame_0, | 481 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); |
| 335 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 482 EXPECT_EQ( |
| 336 EXPECT_EQ(CONTENT_SETTING_ASK, | 483 CONTENT_SETTING_ASK, |
| 337 profile()->GetHostContentSettingsMap()->GetContentSetting( | 484 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1)); |
| 338 requesting_frame_1, requesting_frame_0, | |
| 339 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
| 340 | 485 |
| 341 NavigateAndCommit(requesting_frame_0); | 486 NavigateAndCommit(requesting_frame_0); |
| 342 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 487 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 488 |
| 489 // Check that no permission requests have happened yet. |
| 490 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 491 |
| 343 // Request permission for two frames. | 492 // Request permission for two frames. |
| 344 RequestGeolocationPermission( | 493 RequestGeolocationPermission( |
| 345 web_contents(), RequestID(0), requesting_frame_0); | 494 web_contents(), RequestID(0), requesting_frame_0, true); |
| 346 RequestGeolocationPermission( | 495 RequestGeolocationPermission( |
| 347 web_contents(), RequestID(1), requesting_frame_1); | 496 web_contents(), RequestID(1), requesting_frame_1, true); |
| 348 // Ensure only one infobar is created. | 497 // Ensure only one infobar is created. |
| 349 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 498 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 350 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 499 base::string16 text_0 = GetPromptText(); |
| 351 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
| 352 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | |
| 353 ASSERT_TRUE(infobar_delegate_0); | |
| 354 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | |
| 355 | 500 |
| 356 // Accept the first frame. | 501 // Accept the first frame. |
| 357 infobar_delegate_0->Accept(); | 502 AcceptPrompt(); |
| 358 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 503 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 359 CheckPermissionMessageSent(0, true); | 504 CheckPermissionMessageSent(0, true); |
| 360 | 505 |
| 361 infobar_service()->RemoveInfoBar(infobar_0); | 506 if (!BubbleEnabled()) { |
| 362 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 507 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
| 363 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 508 infobar_service()->RemoveInfoBar(infobar_0); |
| 364 closed_infobar_tracker_.Clear(); | 509 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 510 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
| 511 closed_infobar_tracker_.Clear(); |
| 512 } |
| 513 |
| 365 // Now we should have a new infobar for the second frame. | 514 // Now we should have a new infobar for the second frame. |
| 366 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 515 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 367 | 516 base::string16 text_1 = GetPromptText(); |
| 368 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 517 |
| 369 ConfirmInfoBarDelegate* infobar_delegate_1 = | 518 // Check that the messages differ. |
| 370 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
| 371 ASSERT_TRUE(infobar_delegate_1); | |
| 372 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | |
| 373 EXPECT_NE(text_0, text_1); | 519 EXPECT_NE(text_0, text_1); |
| 374 | 520 |
| 375 // Cancel (block) this frame. | 521 // Cancel (block) this frame. |
| 376 infobar_delegate_1->Cancel(); | 522 if (BubbleEnabled()) { |
| 523 PermissionBubbleManager* manager = |
| 524 PermissionBubbleManager::FromWebContents(web_contents()); |
| 525 DenyBubble(manager); |
| 526 } else { |
| 527 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); |
| 528 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| 529 } |
| 377 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 530 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 378 CheckPermissionMessageSent(1, false); | 531 CheckPermissionMessageSent(1, false); |
| 379 infobar_service()->RemoveInfoBar(infobar_1); | 532 |
| 380 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
| 381 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
| 382 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
| 383 // Ensure the persisted permissions are ok. | 533 // Ensure the persisted permissions are ok. |
| 384 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 534 EXPECT_EQ( |
| 385 profile()->GetHostContentSettingsMap()->GetContentSetting( | 535 CONTENT_SETTING_ALLOW, |
| 386 requesting_frame_0, requesting_frame_0, | 536 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
| 387 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 537 EXPECT_EQ( |
| 388 | 538 CONTENT_SETTING_BLOCK, |
| 389 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 539 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| 390 profile()->GetHostContentSettingsMap()->GetContentSetting( | 540 } |
| 391 requesting_frame_1, requesting_frame_0, | 541 |
| 392 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 542 TEST_P(GeolocationPermissionContextParamTests, HashIsIgnored) { |
| 393 } | |
| 394 | |
| 395 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | |
| 396 GURL url_a("http://www.example.com/geolocation#a"); | 543 GURL url_a("http://www.example.com/geolocation#a"); |
| 397 GURL url_b("http://www.example.com/geolocation#b"); | 544 GURL url_b("http://www.example.com/geolocation#b"); |
| 398 | 545 |
| 399 // Navigate to the first url and check permission is requested. | 546 // Navigate to the first url. |
| 400 NavigateAndCommit(url_a); | 547 NavigateAndCommit(url_a); |
| 401 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 548 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 402 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 549 |
| 403 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 550 // Check permission is requested. |
| 404 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 551 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 405 ConfirmInfoBarDelegate* infobar_delegate = | 552 RequestGeolocationPermission( |
| 406 infobar->delegate()->AsConfirmInfoBarDelegate(); | 553 web_contents(), RequestID(0), url_a, BubbleEnabled()); |
| 407 ASSERT_TRUE(infobar_delegate); | 554 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 408 | 555 |
| 409 // Change the hash, we'll still be on the same page. | 556 // Change the hash, we'll still be on the same page. |
| 410 NavigateAndCommit(url_b); | 557 NavigateAndCommit(url_b); |
| 558 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 411 | 559 |
| 412 // Accept. | 560 // Accept. |
| 413 infobar_delegate->Accept(); | 561 AcceptPrompt(); |
| 414 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 562 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| 415 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 563 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| 416 CheckPermissionMessageSent(0, true); | 564 CheckPermissionMessageSent(0, true); |
| 417 | 565 |
| 418 // Cleanup. | 566 // Cleanup. |
| 419 infobar_service()->RemoveInfoBar(infobar); | 567 if (!BubbleEnabled()) { |
| 420 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 568 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 421 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 569 infobar_service()->RemoveInfoBar(infobar); |
| 422 } | 570 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 423 | 571 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 424 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 572 } |
| 573 } |
| 574 |
| 575 TEST_P(GeolocationPermissionContextParamTests, PermissionForFileScheme) { |
| 576 // TODO(felt): The bubble is rejecting file:// permission requests. |
| 577 // Fix and enable this test. crbug.com/444047 |
| 578 if (BubbleEnabled()) return; |
| 579 |
| 425 GURL requesting_frame("file://example/geolocation.html"); | 580 GURL requesting_frame("file://example/geolocation.html"); |
| 426 NavigateAndCommit(requesting_frame); | 581 NavigateAndCommit(requesting_frame); |
| 427 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 582 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 428 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 583 |
| 429 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 584 // Check permission is requested. |
| 430 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 585 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 431 ConfirmInfoBarDelegate* infobar_delegate = | 586 RequestGeolocationPermission( |
| 432 infobar->delegate()->AsConfirmInfoBarDelegate(); | 587 web_contents(), RequestID(0), requesting_frame, true); |
| 433 ASSERT_TRUE(infobar_delegate); | 588 EXPECT_EQ(1U, GetNumberOfPrompts()); |
| 589 |
| 434 // Accept the frame. | 590 // Accept the frame. |
| 435 infobar_delegate->Accept(); | 591 AcceptPrompt(); |
| 436 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 592 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 437 CheckPermissionMessageSent(0, true); | 593 CheckPermissionMessageSent(0, true); |
| 438 infobar_service()->RemoveInfoBar(infobar); | |
| 439 | 594 |
| 440 // Make sure the setting is not stored. | 595 // Make sure the setting is not stored. |
| 441 EXPECT_EQ(CONTENT_SETTING_ASK, | 596 EXPECT_EQ( |
| 442 profile()->GetHostContentSettingsMap()->GetContentSetting( | 597 CONTENT_SETTING_ASK, |
| 443 requesting_frame, | 598 GetGeolocationContentSetting(requesting_frame, requesting_frame)); |
| 444 requesting_frame, | 599 } |
| 445 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 600 |
| 446 std::string())); | 601 TEST_P(GeolocationPermissionContextParamTests, |
| 447 } | 602 CancelGeolocationPermissionRequest) { |
| 448 | 603 GURL frame_0("http://www.example.com/geolocation"); |
| 449 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 604 GURL frame_1("http://www.example-2.com/geolocation"); |
| 450 GURL requesting_frame_0("http://www.example.com/geolocation"); | 605 EXPECT_EQ( |
| 451 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 606 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); |
| 452 EXPECT_EQ(CONTENT_SETTING_ASK, | 607 EXPECT_EQ( |
| 453 profile()->GetHostContentSettingsMap()->GetContentSetting( | 608 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0)); |
| 454 requesting_frame_0, requesting_frame_0, | 609 |
| 455 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 610 NavigateAndCommit(frame_0); |
| 456 | 611 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 457 EXPECT_EQ(CONTENT_SETTING_ASK, | 612 |
| 458 profile()->GetHostContentSettingsMap()->GetContentSetting( | 613 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 459 requesting_frame_1, requesting_frame_0, | |
| 460 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
| 461 | |
| 462 NavigateAndCommit(requesting_frame_0); | |
| 463 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
| 464 | 614 |
| 465 // Request permission for two frames. | 615 // Request permission for two frames. |
| 466 RequestGeolocationPermission( | 616 RequestGeolocationPermission( |
| 467 web_contents(), RequestID(0), requesting_frame_0); | 617 web_contents(), RequestID(0), frame_0, true); |
| 468 RequestGeolocationPermission( | 618 RequestGeolocationPermission( |
| 469 web_contents(), RequestID(1), requesting_frame_1); | 619 web_contents(), RequestID(1), frame_1, true); |
| 470 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 620 |
| 471 | 621 // Get the first permission request text. |
| 472 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 622 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 473 ConfirmInfoBarDelegate* infobar_delegate_0 = | 623 base::string16 text_0 = GetPromptText(); |
| 474 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 624 ASSERT_FALSE(text_0.empty()); |
| 475 ASSERT_TRUE(infobar_delegate_0); | 625 |
| 476 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 626 // Simulate the frame going away; the request should be removed. |
| 477 | 627 if (BubbleEnabled()) { |
| 478 // Simulate the frame going away, ensure the infobar for this frame | 628 PermissionBubbleManager* manager = |
| 479 // is removed and the next pending infobar is created. | 629 PermissionBubbleManager::FromWebContents(web_contents()); |
| 480 geolocation_permission_context_->CancelPermissionRequest(web_contents(), | 630 CloseBubble(manager); |
| 481 RequestID(0)); | 631 } else { |
| 482 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 632 geolocation_permission_context_->CancelPermissionRequest(web_contents(), |
| 483 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 633 RequestID(0)); |
| 484 closed_infobar_tracker_.Clear(); | 634 } |
| 485 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 635 |
| 486 | 636 // Check that the next pending request is created correctly. |
| 487 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 637 base::string16 text_1 = GetPromptText(); |
| 488 ConfirmInfoBarDelegate* infobar_delegate_1 = | |
| 489 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
| 490 ASSERT_TRUE(infobar_delegate_1); | |
| 491 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | |
| 492 EXPECT_NE(text_0, text_1); | 638 EXPECT_NE(text_0, text_1); |
| 493 | 639 |
| 494 // Allow this frame. | 640 // Allow this frame and check that it worked. |
| 495 infobar_delegate_1->Accept(); | 641 AcceptPrompt(); |
| 496 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 642 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); |
| 497 CheckPermissionMessageSent(1, true); | 643 CheckPermissionMessageSent(1, true); |
| 498 infobar_service()->RemoveInfoBar(infobar_1); | 644 |
| 499 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
| 500 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
| 501 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
| 502 // Ensure the persisted permissions are ok. | 645 // Ensure the persisted permissions are ok. |
| 503 EXPECT_EQ(CONTENT_SETTING_ASK, | 646 EXPECT_EQ( |
| 504 profile()->GetHostContentSettingsMap()->GetContentSetting( | 647 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); |
| 505 requesting_frame_0, requesting_frame_0, | 648 EXPECT_EQ( |
| 506 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 649 CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0)); |
| 507 | 650 } |
| 508 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 651 |
| 509 profile()->GetHostContentSettingsMap()->GetContentSetting( | 652 TEST_P(GeolocationPermissionContextParamTests, InvalidURL) { |
| 510 requesting_frame_1, requesting_frame_0, | 653 // Navigate to the first url. |
| 511 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
| 512 } | |
| 513 | |
| 514 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | |
| 515 GURL invalid_embedder("about:blank"); | 654 GURL invalid_embedder("about:blank"); |
| 516 GURL requesting_frame; | 655 GURL requesting_frame; |
| 517 NavigateAndCommit(invalid_embedder); | 656 NavigateAndCommit(invalid_embedder); |
| 518 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 657 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 519 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 658 |
| 520 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 659 // Nothing should be displayed. |
| 660 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 661 RequestGeolocationPermission( |
| 662 web_contents(), RequestID(0), requesting_frame, true); |
| 663 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 521 CheckPermissionMessageSent(0, false); | 664 CheckPermissionMessageSent(0, false); |
| 522 } | 665 } |
| 523 | 666 |
| 524 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 667 TEST_P(GeolocationPermissionContextParamTests, SameOriginMultipleTabs) { |
| 525 GURL url_a("http://www.example.com/geolocation"); | 668 GURL url_a("http://www.example.com/geolocation"); |
| 526 GURL url_b("http://www.example-2.com/geolocation"); | 669 GURL url_b("http://www.example-2.com/geolocation"); |
| 527 NavigateAndCommit(url_a); | 670 NavigateAndCommit(url_a); // Tab A0 |
| 528 AddNewTab(url_b); | 671 AddNewTab(url_b); // Tab B (extra_tabs_[0]) |
| 529 AddNewTab(url_a); | 672 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) |
| 530 | 673 if (BubbleEnabled()) { |
| 531 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 674 BubbleManagerDocumentLoadCompleted(); |
| 532 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 675 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); |
| 533 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 676 BubbleManagerDocumentLoadCompleted(extra_tabs_[1]); |
| 534 | 677 } |
| 535 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b); | 678 PermissionBubbleManager* manager_a0 = |
| 536 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 679 PermissionBubbleManager::FromWebContents(web_contents()); |
| 537 | 680 PermissionBubbleManager* manager_b = |
| 538 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a); | 681 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); |
| 539 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 682 PermissionBubbleManager* manager_a1 = |
| 540 | 683 PermissionBubbleManager::FromWebContents(extra_tabs_[1]); |
| 541 infobars::InfoBar* removed_infobar = | 684 |
| 542 infobar_service_for_tab(1)->infobar_at(0); | 685 // Request permission in all three tabs. |
| 543 | 686 RequestGeolocationPermission( |
| 544 // Accept the first tab. | 687 web_contents(), RequestID(0), url_a, true); |
| 545 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 688 RequestGeolocationPermission( |
| 546 ConfirmInfoBarDelegate* infobar_delegate_0 = | 689 extra_tabs_[0], RequestIDForTab(0, 0), url_b, true); |
| 547 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 690 RequestGeolocationPermission( |
| 548 ASSERT_TRUE(infobar_delegate_0); | 691 extra_tabs_[1], RequestIDForTab(1, 0), url_a, true); |
| 549 infobar_delegate_0->Accept(); | 692 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. |
| 693 if (BubbleEnabled()) { |
| 694 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); |
| 695 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| 696 } else { |
| 697 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 698 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
| 699 } |
| 700 |
| 701 // Accept the permission in tab A0. |
| 702 if (BubbleEnabled()) { |
| 703 AcceptBubble(manager_a0); |
| 704 } else { |
| 705 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); |
| 706 ConfirmInfoBarDelegate* infobar_delegate_a0 = |
| 707 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); |
| 708 ASSERT_TRUE(infobar_delegate_a0); |
| 709 infobar_delegate_a0->Accept(); |
| 710 infobar_service()->RemoveInfoBar(infobar_a0); |
| 711 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| 712 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); |
| 713 } |
| 550 CheckPermissionMessageSent(0, true); | 714 CheckPermissionMessageSent(0, true); |
| 551 infobar_service()->RemoveInfoBar(infobar_0); | 715 // Because they're the same origin, this will cause tab A1's infobar to |
| 552 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 716 // disappear. It does not cause the bubble to disappear: crbug.com/443013. |
| 553 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 717 // TODO(felt): Update this test when the bubble's behavior is changed. |
| 554 // Now the infobar for the tab with the same origin should have gone. | 718 if (BubbleEnabled()) |
| 555 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); | 719 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| 556 CheckPermissionMessageSentForTab(1, 0, true); | 720 else |
| 557 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 721 CheckPermissionMessageSentForTab(1, 0, true); |
| 558 closed_infobar_tracker_.Clear(); | 722 |
| 559 | 723 // Either way, tab B should still have a pending permission request. |
| 560 // But the other tab should still have the info bar... | 724 if (BubbleEnabled()) |
| 561 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 725 ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); |
| 562 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 726 else |
| 563 ConfirmInfoBarDelegate* infobar_delegate_1 = | 727 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 564 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 728 } |
| 565 ASSERT_TRUE(infobar_delegate_1); | 729 |
| 566 infobar_delegate_1->Cancel(); | 730 TEST_P(GeolocationPermissionContextParamTests, QueuedOriginMultipleTabs) { |
| 567 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | |
| 568 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
| 569 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
| 570 } | |
| 571 | |
| 572 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | |
| 573 GURL url_a("http://www.example.com/geolocation"); | 731 GURL url_a("http://www.example.com/geolocation"); |
| 574 GURL url_b("http://www.example-2.com/geolocation"); | 732 GURL url_b("http://www.example-2.com/geolocation"); |
| 575 NavigateAndCommit(url_a); | 733 NavigateAndCommit(url_a); // Tab A0. |
| 576 AddNewTab(url_a); | 734 AddNewTab(url_a); // Tab A1. |
| 577 | 735 if (BubbleEnabled()) { |
| 578 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 736 BubbleManagerDocumentLoadCompleted(); |
| 579 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 737 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); |
| 580 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 738 } |
| 581 | 739 PermissionBubbleManager* manager_a0 = |
| 582 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a); | 740 PermissionBubbleManager::FromWebContents(web_contents()); |
| 583 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 741 PermissionBubbleManager* manager_a1 = |
| 584 | 742 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); |
| 585 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b); | 743 |
| 586 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 744 // Request permission in both tabs; the extra tab will have two permission |
| 587 | 745 // requests from two origins. |
| 588 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 746 RequestGeolocationPermission( |
| 589 | 747 web_contents(), RequestID(0), url_a, true); |
| 590 // Accept the second tab. | 748 RequestGeolocationPermission( |
| 591 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 749 extra_tabs_[0], RequestIDForTab(0, 0), url_a, true); |
| 592 ConfirmInfoBarDelegate* infobar_delegate_0 = | 750 RequestGeolocationPermission( |
| 593 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 751 extra_tabs_[0], RequestIDForTab(0, 1), url_b, true); |
| 594 ASSERT_TRUE(infobar_delegate_0); | 752 if (BubbleEnabled()) { |
| 595 infobar_delegate_0->Accept(); | 753 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0)); |
| 754 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| 755 } else { |
| 756 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| 757 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 758 } |
| 759 |
| 760 // Accept the first request in tab A1. |
| 761 if (BubbleEnabled()) { |
| 762 AcceptBubble(manager_a1); |
| 763 } else { |
| 764 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); |
| 765 ConfirmInfoBarDelegate* infobar_delegate_a1 = |
| 766 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); |
| 767 ASSERT_TRUE(infobar_delegate_a1); |
| 768 infobar_delegate_a1->Accept(); |
| 769 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); |
| 770 EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| 771 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); |
| 772 } |
| 596 CheckPermissionMessageSentForTab(0, 0, true); | 773 CheckPermissionMessageSentForTab(0, 0, true); |
| 597 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 774 |
| 598 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 775 // Because they're the same origin, this will cause tab A0's infobar to |
| 599 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 776 // disappear. It does not cause the bubble to disappear: crbug.com/443013. |
| 600 // Now the infobar for the tab with the same origin should have gone. | 777 // TODO(felt): Update this test when the bubble's behavior is changed. |
| 601 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 778 if (BubbleEnabled()) { |
| 602 CheckPermissionMessageSent(0, true); | 779 EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); |
| 603 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 780 } else { |
| 604 closed_infobar_tracker_.Clear(); | 781 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| 605 | 782 CheckPermissionMessageSent(0, true); |
| 606 // And we should have the queued infobar displayed now. | 783 } |
| 607 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 784 |
| 608 | 785 // The second request should now be visible in tab A1. |
| 609 // Accept the second infobar. | 786 if (BubbleEnabled()) |
| 610 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 787 ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| 611 ConfirmInfoBarDelegate* infobar_delegate_1 = | 788 else |
| 612 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 789 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 613 ASSERT_TRUE(infobar_delegate_1); | 790 |
| 614 infobar_delegate_1->Accept(); | 791 // Accept the second request and check that it's gone. |
| 615 CheckPermissionMessageSentForTab(0, 1, true); | 792 if (BubbleEnabled()) { |
| 616 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 793 AcceptBubble(manager_a1); |
| 617 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 794 EXPECT_EQ(0U, GetBubblesQueueSize(manager_a1)); |
| 618 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 795 } else { |
| 619 } | 796 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); |
| 620 | 797 ConfirmInfoBarDelegate* infobar_delegate_1 = |
| 621 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | 798 infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| 799 ASSERT_TRUE(infobar_delegate_1); |
| 800 infobar_delegate_1->Accept(); |
| 801 } |
| 802 } |
| 803 |
| 804 TEST_P(GeolocationPermissionContextParamTests, TabDestroyed) { |
| 622 GURL requesting_frame_0("http://www.example.com/geolocation"); | 805 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 623 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 806 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 624 EXPECT_EQ(CONTENT_SETTING_ASK, | 807 EXPECT_EQ( |
| 625 profile()->GetHostContentSettingsMap()->GetContentSetting( | 808 CONTENT_SETTING_ASK, |
| 626 requesting_frame_0, requesting_frame_0, | 809 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
| 627 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 810 EXPECT_EQ( |
| 628 | 811 CONTENT_SETTING_ASK, |
| 629 EXPECT_EQ(CONTENT_SETTING_ASK, | 812 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| 630 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
| 631 requesting_frame_1, requesting_frame_0, | |
| 632 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
| 633 | 813 |
| 634 NavigateAndCommit(requesting_frame_0); | 814 NavigateAndCommit(requesting_frame_0); |
| 635 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 815 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 816 |
| 636 // Request permission for two frames. | 817 // Request permission for two frames. |
| 637 RequestGeolocationPermission( | 818 RequestGeolocationPermission( |
| 638 web_contents(), RequestID(0), requesting_frame_0); | 819 web_contents(), RequestID(0), requesting_frame_0, false); |
| 639 RequestGeolocationPermission( | 820 RequestGeolocationPermission( |
| 640 web_contents(), RequestID(1), requesting_frame_1); | 821 web_contents(), RequestID(1), requesting_frame_1, false); |
| 641 // Ensure only one infobar is created. | 822 |
| 642 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 823 // Ensure only one prompt is created. |
| 643 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 824 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 644 | 825 |
| 645 // Delete the tab contents. | 826 // Delete the tab contents. |
| 646 DeleteContents(); | 827 if (!BubbleEnabled()) { |
| 647 | 828 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 648 // During contents destruction, the infobar will have been closed, and the | 829 DeleteContents(); |
| 649 // pending request should have been cleared without an infobar being created. | 830 ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
| 650 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 831 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 651 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 832 } |
| 652 } | 833 |
| 653 | 834 // The content settings should not have changed. |
| 654 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { | 835 EXPECT_EQ( |
| 836 CONTENT_SETTING_ASK, |
| 837 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
| 838 EXPECT_EQ( |
| 839 CONTENT_SETTING_ASK, |
| 840 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| 841 } |
| 842 |
| 843 TEST_P(GeolocationPermissionContextParamTests, LastUsageAudited) { |
| 655 GURL requesting_frame("http://www.example.com/geolocation"); | 844 GURL requesting_frame("http://www.example.com/geolocation"); |
| 656 NavigateAndCommit(requesting_frame); | 845 NavigateAndCommit(requesting_frame); |
| 846 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 657 | 847 |
| 658 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 848 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
| 659 test_clock->SetNow(base::Time::UnixEpoch() + | 849 test_clock->SetNow(base::Time::UnixEpoch() + |
| 660 base::TimeDelta::FromSeconds(10)); | 850 base::TimeDelta::FromSeconds(10)); |
| 661 | 851 |
| 662 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 852 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
| 663 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 853 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
| 664 | 854 |
| 665 // The permission shouldn't have been used yet. | 855 // The permission shouldn't have been used yet. |
| 666 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 856 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
| 667 requesting_frame.GetOrigin(), | 857 requesting_frame.GetOrigin(), |
| 668 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 858 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 669 0); | 859 0); |
| 860 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 861 RequestGeolocationPermission( |
| 862 web_contents(), RequestID(0), requesting_frame, false); |
| 863 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 670 | 864 |
| 671 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 865 AcceptPrompt(); |
| 672 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | |
| 673 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
| 674 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | |
| 675 ConfirmInfoBarDelegate* infobar_delegate = | |
| 676 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
| 677 ASSERT_TRUE(infobar_delegate); | |
| 678 infobar_delegate->Accept(); | |
| 679 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 866 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 680 CheckPermissionMessageSent(0, true); | 867 CheckPermissionMessageSent(0, true); |
| 681 | 868 |
| 682 // Permission has been used at the starting time. | 869 // Permission has been used at the starting time. |
| 683 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 870 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
| 684 requesting_frame.GetOrigin(), | 871 requesting_frame.GetOrigin(), |
| 685 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 872 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 686 10); | 873 10); |
| 687 | 874 |
| 688 test_clock->Advance(base::TimeDelta::FromSeconds(3)); | 875 test_clock->Advance(base::TimeDelta::FromSeconds(3)); |
| 689 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 876 RequestGeolocationPermission( |
| 877 web_contents(), RequestID(0), requesting_frame, false); |
| 690 | 878 |
| 691 // Permission has been used three seconds later. | 879 // Permission has been used three seconds later. |
| 692 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 880 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
| 693 requesting_frame.GetOrigin(), | 881 requesting_frame.GetOrigin(), |
| 694 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 882 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 695 13); | 883 13); |
| 696 } | 884 } |
| 697 | 885 |
| 698 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { | 886 TEST_P(GeolocationPermissionContextParamTests, LastUsageAuditedMultipleFrames) { |
| 699 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 887 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
| 700 test_clock->SetNow(base::Time::UnixEpoch() + | 888 test_clock->SetNow(base::Time::UnixEpoch() + |
| 701 base::TimeDelta::FromSeconds(10)); | 889 base::TimeDelta::FromSeconds(10)); |
| 702 | 890 |
| 703 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 891 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
| 704 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 892 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
| 705 | 893 |
| 706 GURL requesting_frame_0("http://www.example.com/geolocation"); | 894 GURL requesting_frame_0("http://www.example.com/geolocation"); |
| 707 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 895 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
| 708 | 896 |
| 709 // The permission shouldn't have been used yet. | 897 // The permission shouldn't have been used yet. |
| 710 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 898 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 711 requesting_frame_0.GetOrigin(), | 899 requesting_frame_0.GetOrigin(), |
| 712 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 900 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 713 0); | 901 0); |
| 714 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 902 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 715 requesting_frame_0.GetOrigin(), | 903 requesting_frame_0.GetOrigin(), |
| 716 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 904 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 717 0); | 905 0); |
| 718 | 906 |
| 719 NavigateAndCommit(requesting_frame_0); | 907 NavigateAndCommit(requesting_frame_0); |
| 720 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 908 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
| 909 |
| 910 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 721 | 911 |
| 722 // Request permission for two frames. | 912 // Request permission for two frames. |
| 723 RequestGeolocationPermission( | 913 RequestGeolocationPermission( |
| 724 web_contents(), RequestID(0), requesting_frame_0); | 914 web_contents(), RequestID(0), requesting_frame_0, false); |
| 725 RequestGeolocationPermission( | 915 RequestGeolocationPermission( |
| 726 web_contents(), RequestID(1), requesting_frame_1); | 916 web_contents(), RequestID(1), requesting_frame_1, false); |
| 727 | 917 |
| 728 // Ensure only one infobar is created. | 918 // Ensure only one infobar is created. |
| 729 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 919 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 730 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | |
| 731 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
| 732 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | |
| 733 | 920 |
| 734 // Accept the first frame. | 921 // Accept the first frame. |
| 735 infobar_delegate_0->Accept(); | 922 AcceptPrompt(); |
| 923 if (!BubbleEnabled()) |
| 924 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); |
| 736 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 925 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| 737 CheckPermissionMessageSent(0, true); | 926 CheckPermissionMessageSent(0, true); |
| 738 infobar_service()->RemoveInfoBar(infobar_0); | |
| 739 | 927 |
| 740 // Verify that accepting the first didn't accept because it's embedder | 928 // Verify that accepting the first didn't accept because it's embedded |
| 741 // in the other. | 929 // in the other. |
| 742 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 930 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 743 requesting_frame_0.GetOrigin(), | 931 requesting_frame_0.GetOrigin(), |
| 744 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 932 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 745 10); | 933 10); |
| 746 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 934 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 747 requesting_frame_0.GetOrigin(), | 935 requesting_frame_0.GetOrigin(), |
| 748 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 936 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 749 0); | 937 0); |
| 750 | 938 |
| 751 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 939 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 752 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | |
| 753 ConfirmInfoBarDelegate* infobar_delegate_1 = | |
| 754 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
| 755 | 940 |
| 756 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | 941 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 757 | 942 |
| 758 // Allow the second frame. | 943 // Allow the second frame. |
| 759 infobar_delegate_1->Accept(); | 944 AcceptPrompt(); |
| 760 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 945 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
| 761 CheckPermissionMessageSent(1, true); | 946 CheckPermissionMessageSent(1, true); |
| 762 infobar_service()->RemoveInfoBar(infobar_1); | 947 if (!BubbleEnabled()) |
| 948 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); |
| 763 | 949 |
| 764 // Verify that the times are different. | 950 // Verify that the times are different. |
| 765 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 951 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 766 requesting_frame_0.GetOrigin(), | 952 requesting_frame_0.GetOrigin(), |
| 767 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 953 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 768 10); | 954 10); |
| 769 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 955 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 770 requesting_frame_0.GetOrigin(), | 956 requesting_frame_0.GetOrigin(), |
| 771 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 957 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 772 11); | 958 11); |
| 773 | 959 |
| 774 test_clock->Advance(base::TimeDelta::FromSeconds(2)); | 960 test_clock->Advance(base::TimeDelta::FromSeconds(2)); |
| 775 RequestGeolocationPermission( | 961 RequestGeolocationPermission( |
| 776 web_contents(), RequestID(0), requesting_frame_0); | 962 web_contents(), RequestID(0), requesting_frame_0, false); |
| 777 | 963 |
| 778 // Verify that requesting permission in one frame doesn't update other where | 964 // Verify that requesting permission in one frame doesn't update other where |
| 779 // it is the embedder. | 965 // it is the embedder. |
| 780 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 966 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 781 requesting_frame_0.GetOrigin(), | 967 requesting_frame_0.GetOrigin(), |
| 782 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 968 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 783 13); | 969 13); |
| 784 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 970 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 785 requesting_frame_0.GetOrigin(), | 971 requesting_frame_0.GetOrigin(), |
| 786 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 972 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 787 11); | 973 11); |
| 788 } | 974 } |
| 975 |
| 976 INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles, |
| 977 GeolocationPermissionContextParamTests, |
| 978 ::testing::Values(false, true)); |
| OLD | NEW |