| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "content/public/test/test_renderer_host.h" | 48 #include "content/public/test/test_renderer_host.h" |
| 49 #include "content/public/test/test_utils.h" | 49 #include "content/public/test/test_utils.h" |
| 50 #include "content/public/test/web_contents_tester.h" | 50 #include "content/public/test/web_contents_tester.h" |
| 51 #include "testing/gtest/include/gtest/gtest.h" | 51 #include "testing/gtest/include/gtest/gtest.h" |
| 52 | 52 |
| 53 #if BUILDFLAG(ANDROID_JAVA_UI) | 53 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 54 #include "chrome/browser/android/mock_location_settings.h" | 54 #include "chrome/browser/android/mock_location_settings.h" |
| 55 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" | 55 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" |
| 56 #include "components/prefs/pref_service.h" | 56 #include "components/prefs/pref_service.h" |
| 57 #else | 57 #else |
| 58 #include "chrome/browser/permissions/permission_request_manager.h" |
| 58 #include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h" | 59 #include "chrome/browser/ui/website_settings/mock_permission_bubble_factory.h" |
| 59 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 #if defined(ENABLE_EXTENSIONS) | 62 #if defined(ENABLE_EXTENSIONS) |
| 63 #include "extensions/browser/view_type_utils.h" | 63 #include "extensions/browser/view_type_utils.h" |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 using content::MockRenderProcessHost; | 66 using content::MockRenderProcessHost; |
| 67 | 67 |
| 68 | 68 |
| 69 // ClosedInfoBarTracker ------------------------------------------------------- | 69 // ClosedInfoBarTracker ------------------------------------------------------- |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 ContentSetting content_setting); | 143 ContentSetting content_setting); |
| 144 void CheckPermissionMessageSent(int request_id, bool allowed); | 144 void CheckPermissionMessageSent(int request_id, bool allowed); |
| 145 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed); | 145 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed); |
| 146 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 146 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
| 147 int request_id, | 147 int request_id, |
| 148 bool allowed); | 148 bool allowed); |
| 149 void AddNewTab(const GURL& url); | 149 void AddNewTab(const GURL& url); |
| 150 void CheckTabContentsState(const GURL& requesting_frame, | 150 void CheckTabContentsState(const GURL& requesting_frame, |
| 151 ContentSetting expected_content_setting); | 151 ContentSetting expected_content_setting); |
| 152 #if !BUILDFLAG(ANDROID_JAVA_UI) | 152 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 153 void SetupBubbleManager(content::WebContents* web_contents); | 153 void SetupRequestManager(content::WebContents* web_contents); |
| 154 size_t GetBubblesQueueSize(PermissionBubbleManager* manager); | 154 size_t GetBubblesQueueSize(PermissionRequestManager* manager); |
| 155 void AcceptBubble(PermissionBubbleManager* manager); | 155 void AcceptBubble(PermissionRequestManager* manager); |
| 156 void DenyBubble(PermissionBubbleManager* manager); | 156 void DenyBubble(PermissionRequestManager* manager); |
| 157 void CloseBubble(PermissionBubbleManager* manager); | 157 void CloseBubble(PermissionRequestManager* manager); |
| 158 #endif | 158 #endif |
| 159 void BubbleManagerDocumentLoadCompleted(); | 159 void RequestManagerDocumentLoadCompleted(); |
| 160 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); | 160 void RequestManagerDocumentLoadCompleted(content::WebContents* web_contents); |
| 161 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); | 161 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); |
| 162 size_t GetNumberOfPrompts(); | 162 size_t GetNumberOfPrompts(); |
| 163 void AcceptPrompt(); | 163 void AcceptPrompt(); |
| 164 base::string16 GetPromptText(); | 164 base::string16 GetPromptText(); |
| 165 | 165 |
| 166 // owned by the browser context | 166 // owned by the browser context |
| 167 GeolocationPermissionContext* geolocation_permission_context_; | 167 GeolocationPermissionContext* geolocation_permission_context_; |
| 168 ClosedInfoBarTracker closed_infobar_tracker_; | 168 ClosedInfoBarTracker closed_infobar_tracker_; |
| 169 std::vector<std::unique_ptr<content::WebContents>> extra_tabs_; | 169 std::vector<std::unique_ptr<content::WebContents>> extra_tabs_; |
| 170 #if !BUILDFLAG(ANDROID_JAVA_UI) | 170 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url); | 247 ->SendNavigate(extra_tabs_.size() + 1, entry->GetUniqueID(), true, url); |
| 248 | 248 |
| 249 // Set up required helpers, and make this be as "tabby" as the code requires. | 249 // Set up required helpers, and make this be as "tabby" as the code requires. |
| 250 #if defined(ENABLE_EXTENSIONS) | 250 #if defined(ENABLE_EXTENSIONS) |
| 251 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); | 251 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
| 252 #endif | 252 #endif |
| 253 | 253 |
| 254 #if BUILDFLAG(ANDROID_JAVA_UI) | 254 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 255 InfoBarService::CreateForWebContents(new_tab); | 255 InfoBarService::CreateForWebContents(new_tab); |
| 256 #else | 256 #else |
| 257 SetupBubbleManager(new_tab); | 257 SetupRequestManager(new_tab); |
| 258 #endif | 258 #endif |
| 259 | 259 |
| 260 extra_tabs_.push_back(base::WrapUnique(new_tab)); | 260 extra_tabs_.push_back(base::WrapUnique(new_tab)); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void GeolocationPermissionContextTests::CheckTabContentsState( | 263 void GeolocationPermissionContextTests::CheckTabContentsState( |
| 264 const GURL& requesting_frame, | 264 const GURL& requesting_frame, |
| 265 ContentSetting expected_content_setting) { | 265 ContentSetting expected_content_setting) { |
| 266 TabSpecificContentSettings* content_settings = | 266 TabSpecificContentSettings* content_settings = |
| 267 TabSpecificContentSettings::FromWebContents(web_contents()); | 267 TabSpecificContentSettings::FromWebContents(web_contents()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 288 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( | 288 geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( |
| 289 PermissionManager::Get(profile())->GetPermissionContext( | 289 PermissionManager::Get(profile())->GetPermissionContext( |
| 290 content::PermissionType::GEOLOCATION)); | 290 content::PermissionType::GEOLOCATION)); |
| 291 #if BUILDFLAG(ANDROID_JAVA_UI) | 291 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 292 static_cast<GeolocationPermissionContextAndroid*>( | 292 static_cast<GeolocationPermissionContextAndroid*>( |
| 293 geolocation_permission_context_) | 293 geolocation_permission_context_) |
| 294 ->SetLocationSettingsForTesting( | 294 ->SetLocationSettingsForTesting( |
| 295 std::unique_ptr<LocationSettings>(new MockLocationSettings())); | 295 std::unique_ptr<LocationSettings>(new MockLocationSettings())); |
| 296 MockLocationSettings::SetLocationStatus(true, true); | 296 MockLocationSettings::SetLocationStatus(true, true); |
| 297 #else | 297 #else |
| 298 SetupBubbleManager(web_contents()); | 298 SetupRequestManager(web_contents()); |
| 299 #endif | 299 #endif |
| 300 } | 300 } |
| 301 | 301 |
| 302 void GeolocationPermissionContextTests::TearDown() { | 302 void GeolocationPermissionContextTests::TearDown() { |
| 303 #if !BUILDFLAG(ANDROID_JAVA_UI) | 303 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 304 mock_permission_bubble_factories_.clear(); | 304 mock_permission_bubble_factories_.clear(); |
| 305 #endif | 305 #endif |
| 306 extra_tabs_.clear(); | 306 extra_tabs_.clear(); |
| 307 ChromeRenderViewHostTestHarness::TearDown(); | 307 ChromeRenderViewHostTestHarness::TearDown(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 #if !BUILDFLAG(ANDROID_JAVA_UI) | 310 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 311 void GeolocationPermissionContextTests::SetupBubbleManager( | 311 void GeolocationPermissionContextTests::SetupRequestManager( |
| 312 content::WebContents* web_contents) { | 312 content::WebContents* web_contents) { |
| 313 // Create PermissionBubbleManager. | 313 // Create PermissionRequestManager. |
| 314 PermissionBubbleManager::CreateForWebContents(web_contents); | 314 PermissionRequestManager::CreateForWebContents(web_contents); |
| 315 PermissionBubbleManager* permission_bubble_manager = | 315 PermissionRequestManager* permission_request_manager = |
| 316 PermissionBubbleManager::FromWebContents(web_contents); | 316 PermissionRequestManager::FromWebContents(web_contents); |
| 317 | 317 |
| 318 // Create a MockPermissionBubbleFactory for the PermissionBubbleManager. | 318 // Create a MockPermissionBubbleFactory for the PermissionRequestManager. |
| 319 mock_permission_bubble_factories_.push_back(base::WrapUnique( | 319 mock_permission_bubble_factories_.push_back(base::WrapUnique( |
| 320 new MockPermissionBubbleFactory(permission_bubble_manager))); | 320 new MockPermissionBubbleFactory(permission_request_manager))); |
| 321 | 321 |
| 322 // Prepare the PermissionBubbleManager to display a mock bubble. | 322 // Prepare the PermissionRequestManager to display a mock bubble. |
| 323 permission_bubble_manager->DisplayPendingRequests(); | 323 permission_request_manager->DisplayPendingRequests(); |
| 324 } | 324 } |
| 325 | 325 |
| 326 size_t GeolocationPermissionContextTests::GetBubblesQueueSize( | 326 size_t GeolocationPermissionContextTests::GetBubblesQueueSize( |
| 327 PermissionBubbleManager* manager) { | 327 PermissionRequestManager* manager) { |
| 328 return manager->requests_.size(); | 328 return manager->requests_.size(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 void GeolocationPermissionContextTests::AcceptBubble( | 331 void GeolocationPermissionContextTests::AcceptBubble( |
| 332 PermissionBubbleManager* manager) { | 332 PermissionRequestManager* manager) { |
| 333 manager->Accept(); | 333 manager->Accept(); |
| 334 } | 334 } |
| 335 | 335 |
| 336 void GeolocationPermissionContextTests::DenyBubble( | 336 void GeolocationPermissionContextTests::DenyBubble( |
| 337 PermissionBubbleManager* manager) { | 337 PermissionRequestManager* manager) { |
| 338 manager->Deny(); | 338 manager->Deny(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void GeolocationPermissionContextTests::CloseBubble( | 341 void GeolocationPermissionContextTests::CloseBubble( |
| 342 PermissionBubbleManager* manager) { | 342 PermissionRequestManager* manager) { |
| 343 manager->Closing(); | 343 manager->Closing(); |
| 344 } | 344 } |
| 345 #endif | 345 #endif |
| 346 | 346 |
| 347 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { | 347 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() { |
| 348 GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( | 348 GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( |
| 349 web_contents()); | 349 web_contents()); |
| 350 } | 350 } |
| 351 | 351 |
| 352 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( | 352 void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( |
| 353 content::WebContents* web_contents) { | 353 content::WebContents* web_contents) { |
| 354 #if !BUILDFLAG(ANDROID_JAVA_UI) | 354 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 355 PermissionBubbleManager::FromWebContents(web_contents)-> | 355 PermissionRequestManager::FromWebContents(web_contents)-> |
| 356 DocumentOnLoadCompletedInMainFrame(); | 356 DocumentOnLoadCompletedInMainFrame(); |
| 357 #endif | 357 #endif |
| 358 } | 358 } |
| 359 | 359 |
| 360 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( | 360 ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( |
| 361 GURL frame_0, GURL frame_1) { | 361 GURL frame_0, GURL frame_1) { |
| 362 return HostContentSettingsMapFactory::GetForProfile(profile()) | 362 return HostContentSettingsMapFactory::GetForProfile(profile()) |
| 363 ->GetContentSetting(frame_0, | 363 ->GetContentSetting(frame_0, |
| 364 frame_1, | 364 frame_1, |
| 365 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 365 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 366 std::string()); | 366 std::string()); |
| 367 } | 367 } |
| 368 | 368 |
| 369 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { | 369 size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { |
| 370 #if !BUILDFLAG(ANDROID_JAVA_UI) | 370 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 371 PermissionBubbleManager* manager = | 371 PermissionRequestManager* manager = |
| 372 PermissionBubbleManager::FromWebContents(web_contents()); | 372 PermissionRequestManager::FromWebContents(web_contents()); |
| 373 return GetBubblesQueueSize(manager); | 373 return GetBubblesQueueSize(manager); |
| 374 #else | 374 #else |
| 375 return infobar_service()->infobar_count(); | 375 return infobar_service()->infobar_count(); |
| 376 #endif | 376 #endif |
| 377 } | 377 } |
| 378 | 378 |
| 379 void GeolocationPermissionContextTests::AcceptPrompt() { | 379 void GeolocationPermissionContextTests::AcceptPrompt() { |
| 380 #if !BUILDFLAG(ANDROID_JAVA_UI) | 380 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 381 PermissionBubbleManager* manager = | 381 PermissionRequestManager* manager = |
| 382 PermissionBubbleManager::FromWebContents(web_contents()); | 382 PermissionRequestManager::FromWebContents(web_contents()); |
| 383 AcceptBubble(manager); | 383 AcceptBubble(manager); |
| 384 #else | 384 #else |
| 385 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 385 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 386 ConfirmInfoBarDelegate* infobar_delegate = | 386 ConfirmInfoBarDelegate* infobar_delegate = |
| 387 infobar->delegate()->AsConfirmInfoBarDelegate(); | 387 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 388 infobar_delegate->Accept(); | 388 infobar_delegate->Accept(); |
| 389 #endif | 389 #endif |
| 390 } | 390 } |
| 391 | 391 |
| 392 base::string16 GeolocationPermissionContextTests::GetPromptText() { | 392 base::string16 GeolocationPermissionContextTests::GetPromptText() { |
| 393 #if !BUILDFLAG(ANDROID_JAVA_UI) | 393 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 394 PermissionBubbleManager* manager = | 394 PermissionRequestManager* manager = |
| 395 PermissionBubbleManager::FromWebContents(web_contents()); | 395 PermissionRequestManager::FromWebContents(web_contents()); |
| 396 PermissionBubbleRequest* request = manager->requests_.front(); | 396 PermissionBubbleRequest* request = manager->requests_.front(); |
| 397 return base::ASCIIToUTF16(request->GetOrigin().spec()) + | 397 return base::ASCIIToUTF16(request->GetOrigin().spec()) + |
| 398 request->GetMessageTextFragment(); | 398 request->GetMessageTextFragment(); |
| 399 #else | 399 #else |
| 400 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 400 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 401 ConfirmInfoBarDelegate* infobar_delegate = | 401 ConfirmInfoBarDelegate* infobar_delegate = |
| 402 infobar->delegate()->AsConfirmInfoBarDelegate(); | 402 infobar->delegate()->AsConfirmInfoBarDelegate(); |
| 403 return infobar_delegate->GetMessageText(); | 403 return infobar_delegate->GetMessageText(); |
| 404 #endif | 404 #endif |
| 405 } | 405 } |
| 406 | 406 |
| 407 // Tests ---------------------------------------------------------------------- | 407 // Tests ---------------------------------------------------------------------- |
| 408 | 408 |
| 409 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { | 409 TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { |
| 410 GURL requesting_frame("https://www.example.com/geolocation"); | 410 GURL requesting_frame("https://www.example.com/geolocation"); |
| 411 NavigateAndCommit(requesting_frame); | 411 NavigateAndCommit(requesting_frame); |
| 412 BubbleManagerDocumentLoadCompleted(); | 412 RequestManagerDocumentLoadCompleted(); |
| 413 | 413 |
| 414 EXPECT_EQ(0U, GetNumberOfPrompts()); | 414 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 415 RequestGeolocationPermission( | 415 RequestGeolocationPermission( |
| 416 web_contents(), RequestID(0), requesting_frame, true); | 416 web_contents(), RequestID(0), requesting_frame, true); |
| 417 ASSERT_EQ(1U, GetNumberOfPrompts()); | 417 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 418 } | 418 } |
| 419 | 419 |
| 420 TEST_F(GeolocationPermissionContextTests, | 420 TEST_F(GeolocationPermissionContextTests, |
| 421 SinglePermissionBubbleFailsOnInsecureOrigin) { | 421 SinglePermissionBubbleFailsOnInsecureOrigin) { |
| 422 GURL requesting_frame("http://www.example.com/geolocation"); | 422 GURL requesting_frame("http://www.example.com/geolocation"); |
| 423 NavigateAndCommit(requesting_frame); | 423 NavigateAndCommit(requesting_frame); |
| 424 BubbleManagerDocumentLoadCompleted(); | 424 RequestManagerDocumentLoadCompleted(); |
| 425 | 425 |
| 426 EXPECT_EQ(0U, GetNumberOfPrompts()); | 426 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 427 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, | 427 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| 428 true); | 428 true); |
| 429 ASSERT_EQ(0U, GetNumberOfPrompts()); | 429 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 430 } | 430 } |
| 431 | 431 |
| 432 #if BUILDFLAG(ANDROID_JAVA_UI) | 432 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 433 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { | 433 TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { |
| 434 GURL requesting_frame("https://www.example.com/geolocation"); | 434 GURL requesting_frame("https://www.example.com/geolocation"); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 GURL requesting_frame_0("https://www.example.com/geolocation"); | 501 GURL requesting_frame_0("https://www.example.com/geolocation"); |
| 502 GURL requesting_frame_1("https://www.example-2.com/geolocation"); | 502 GURL requesting_frame_1("https://www.example-2.com/geolocation"); |
| 503 EXPECT_EQ( | 503 EXPECT_EQ( |
| 504 CONTENT_SETTING_ASK, | 504 CONTENT_SETTING_ASK, |
| 505 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); | 505 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_1)); |
| 506 EXPECT_EQ( | 506 EXPECT_EQ( |
| 507 CONTENT_SETTING_ASK, | 507 CONTENT_SETTING_ASK, |
| 508 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1)); | 508 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_1)); |
| 509 | 509 |
| 510 NavigateAndCommit(requesting_frame_0); | 510 NavigateAndCommit(requesting_frame_0); |
| 511 BubbleManagerDocumentLoadCompleted(); | 511 RequestManagerDocumentLoadCompleted(); |
| 512 | 512 |
| 513 // Check that no permission requests have happened yet. | 513 // Check that no permission requests have happened yet. |
| 514 EXPECT_EQ(0U, GetNumberOfPrompts()); | 514 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 515 | 515 |
| 516 // Request permission for two frames. | 516 // Request permission for two frames. |
| 517 RequestGeolocationPermission( | 517 RequestGeolocationPermission( |
| 518 web_contents(), RequestID(0), requesting_frame_0, true); | 518 web_contents(), RequestID(0), requesting_frame_0, true); |
| 519 RequestGeolocationPermission( | 519 RequestGeolocationPermission( |
| 520 web_contents(), RequestID(1), requesting_frame_1, true); | 520 web_contents(), RequestID(1), requesting_frame_1, true); |
| 521 // Ensure only one infobar is created. | 521 // Ensure only one infobar is created. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 537 | 537 |
| 538 // Now we should have a new infobar for the second frame. | 538 // Now we should have a new infobar for the second frame. |
| 539 ASSERT_EQ(1U, GetNumberOfPrompts()); | 539 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 540 base::string16 text_1 = GetPromptText(); | 540 base::string16 text_1 = GetPromptText(); |
| 541 | 541 |
| 542 // Check that the messages differ. | 542 // Check that the messages differ. |
| 543 EXPECT_NE(text_0, text_1); | 543 EXPECT_NE(text_0, text_1); |
| 544 | 544 |
| 545 // Cancel (block) this frame. | 545 // Cancel (block) this frame. |
| 546 #if !BUILDFLAG(ANDROID_JAVA_UI) | 546 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 547 PermissionBubbleManager* manager = | 547 PermissionRequestManager* manager = |
| 548 PermissionBubbleManager::FromWebContents(web_contents()); | 548 PermissionRequestManager::FromWebContents(web_contents()); |
| 549 DenyBubble(manager); | 549 DenyBubble(manager); |
| 550 #else | 550 #else |
| 551 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 551 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); |
| 552 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | 552 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| 553 #endif | 553 #endif |
| 554 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 554 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| 555 CheckPermissionMessageSent(1, false); | 555 CheckPermissionMessageSent(1, false); |
| 556 | 556 |
| 557 // Ensure the persisted permissions are ok. | 557 // Ensure the persisted permissions are ok. |
| 558 EXPECT_EQ( | 558 EXPECT_EQ( |
| 559 CONTENT_SETTING_ALLOW, | 559 CONTENT_SETTING_ALLOW, |
| 560 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); | 560 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
| 561 EXPECT_EQ( | 561 EXPECT_EQ( |
| 562 CONTENT_SETTING_BLOCK, | 562 CONTENT_SETTING_BLOCK, |
| 563 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); | 563 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| 564 } | 564 } |
| 565 | 565 |
| 566 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 566 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
| 567 GURL url_a("https://www.example.com/geolocation#a"); | 567 GURL url_a("https://www.example.com/geolocation#a"); |
| 568 GURL url_b("https://www.example.com/geolocation#b"); | 568 GURL url_b("https://www.example.com/geolocation#b"); |
| 569 | 569 |
| 570 // Navigate to the first url. | 570 // Navigate to the first url. |
| 571 NavigateAndCommit(url_a); | 571 NavigateAndCommit(url_a); |
| 572 BubbleManagerDocumentLoadCompleted(); | 572 RequestManagerDocumentLoadCompleted(); |
| 573 | 573 |
| 574 // Check permission is requested. | 574 // Check permission is requested. |
| 575 ASSERT_EQ(0U, GetNumberOfPrompts()); | 575 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 576 #if BUILDFLAG(ANDROID_JAVA_UI) | 576 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 577 const bool user_gesture = false; | 577 const bool user_gesture = false; |
| 578 #else | 578 #else |
| 579 const bool user_gesture = true; | 579 const bool user_gesture = true; |
| 580 #endif | 580 #endif |
| 581 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, | 581 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, |
| 582 user_gesture); | 582 user_gesture); |
| 583 ASSERT_EQ(1U, GetNumberOfPrompts()); | 583 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 584 | 584 |
| 585 // Change the hash, we'll still be on the same page. | 585 // Change the hash, we'll still be on the same page. |
| 586 NavigateAndCommit(url_b); | 586 NavigateAndCommit(url_b); |
| 587 BubbleManagerDocumentLoadCompleted(); | 587 RequestManagerDocumentLoadCompleted(); |
| 588 | 588 |
| 589 // Accept. | 589 // Accept. |
| 590 AcceptPrompt(); | 590 AcceptPrompt(); |
| 591 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 591 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| 592 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 592 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| 593 CheckPermissionMessageSent(0, true); | 593 CheckPermissionMessageSent(0, true); |
| 594 | 594 |
| 595 // Cleanup. | 595 // Cleanup. |
| 596 #if BUILDFLAG(ANDROID_JAVA_UI) | 596 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 597 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 597 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| 598 infobar_service()->RemoveInfoBar(infobar); | 598 infobar_service()->RemoveInfoBar(infobar); |
| 599 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 599 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| 600 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 600 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| 601 #endif | 601 #endif |
| 602 } | 602 } |
| 603 | 603 |
| 604 // TODO(felt): The bubble is rejecting file:// permission requests. | 604 // TODO(felt): The bubble is rejecting file:// permission requests. |
| 605 // Fix and enable this test. crbug.com/444047 | 605 // Fix and enable this test. crbug.com/444047 |
| 606 #if BUILDFLAG(ANDROID_JAVA_UI) | 606 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 607 #define MAYBE_PermissionForFileScheme PermissionForFileScheme | 607 #define MAYBE_PermissionForFileScheme PermissionForFileScheme |
| 608 #else | 608 #else |
| 609 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme | 609 #define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme |
| 610 #endif | 610 #endif |
| 611 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { | 611 TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { |
| 612 GURL requesting_frame("file://example/geolocation.html"); | 612 GURL requesting_frame("file://example/geolocation.html"); |
| 613 NavigateAndCommit(requesting_frame); | 613 NavigateAndCommit(requesting_frame); |
| 614 BubbleManagerDocumentLoadCompleted(); | 614 RequestManagerDocumentLoadCompleted(); |
| 615 | 615 |
| 616 // Check permission is requested. | 616 // Check permission is requested. |
| 617 ASSERT_EQ(0U, GetNumberOfPrompts()); | 617 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 618 RequestGeolocationPermission( | 618 RequestGeolocationPermission( |
| 619 web_contents(), RequestID(0), requesting_frame, true); | 619 web_contents(), RequestID(0), requesting_frame, true); |
| 620 EXPECT_EQ(1U, GetNumberOfPrompts()); | 620 EXPECT_EQ(1U, GetNumberOfPrompts()); |
| 621 | 621 |
| 622 // Accept the frame. | 622 // Accept the frame. |
| 623 AcceptPrompt(); | 623 AcceptPrompt(); |
| 624 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 624 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| 625 CheckPermissionMessageSent(0, true); | 625 CheckPermissionMessageSent(0, true); |
| 626 | 626 |
| 627 // Make sure the setting is not stored. | 627 // Make sure the setting is not stored. |
| 628 EXPECT_EQ( | 628 EXPECT_EQ( |
| 629 CONTENT_SETTING_ASK, | 629 CONTENT_SETTING_ASK, |
| 630 GetGeolocationContentSetting(requesting_frame, requesting_frame)); | 630 GetGeolocationContentSetting(requesting_frame, requesting_frame)); |
| 631 } | 631 } |
| 632 | 632 |
| 633 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 633 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| 634 GURL frame_0("https://www.example.com/geolocation"); | 634 GURL frame_0("https://www.example.com/geolocation"); |
| 635 GURL frame_1("https://www.example-2.com/geolocation"); | 635 GURL frame_1("https://www.example-2.com/geolocation"); |
| 636 EXPECT_EQ( | 636 EXPECT_EQ( |
| 637 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); | 637 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); |
| 638 EXPECT_EQ( | 638 EXPECT_EQ( |
| 639 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0)); | 639 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_1, frame_0)); |
| 640 | 640 |
| 641 NavigateAndCommit(frame_0); | 641 NavigateAndCommit(frame_0); |
| 642 BubbleManagerDocumentLoadCompleted(); | 642 RequestManagerDocumentLoadCompleted(); |
| 643 | 643 |
| 644 ASSERT_EQ(0U, GetNumberOfPrompts()); | 644 ASSERT_EQ(0U, GetNumberOfPrompts()); |
| 645 | 645 |
| 646 // Request permission for two frames. | 646 // Request permission for two frames. |
| 647 RequestGeolocationPermission( | 647 RequestGeolocationPermission( |
| 648 web_contents(), RequestID(0), frame_0, true); | 648 web_contents(), RequestID(0), frame_0, true); |
| 649 RequestGeolocationPermission( | 649 RequestGeolocationPermission( |
| 650 web_contents(), RequestID(1), frame_1, true); | 650 web_contents(), RequestID(1), frame_1, true); |
| 651 | 651 |
| 652 // Get the first permission request text. | 652 // Get the first permission request text. |
| 653 ASSERT_EQ(1U, GetNumberOfPrompts()); | 653 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 654 base::string16 text_0 = GetPromptText(); | 654 base::string16 text_0 = GetPromptText(); |
| 655 ASSERT_FALSE(text_0.empty()); | 655 ASSERT_FALSE(text_0.empty()); |
| 656 | 656 |
| 657 // Simulate the frame going away; the request should be removed. | 657 // Simulate the frame going away; the request should be removed. |
| 658 #if !BUILDFLAG(ANDROID_JAVA_UI) | 658 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 659 PermissionBubbleManager* manager = | 659 PermissionRequestManager* manager = |
| 660 PermissionBubbleManager::FromWebContents(web_contents()); | 660 PermissionRequestManager::FromWebContents(web_contents()); |
| 661 CloseBubble(manager); | 661 CloseBubble(manager); |
| 662 #else | 662 #else |
| 663 geolocation_permission_context_->CancelPermissionRequest(web_contents(), | 663 geolocation_permission_context_->CancelPermissionRequest(web_contents(), |
| 664 RequestID(0)); | 664 RequestID(0)); |
| 665 #endif | 665 #endif |
| 666 | 666 |
| 667 // Check that the next pending request is created correctly. | 667 // Check that the next pending request is created correctly. |
| 668 base::string16 text_1 = GetPromptText(); | 668 base::string16 text_1 = GetPromptText(); |
| 669 EXPECT_NE(text_0, text_1); | 669 EXPECT_NE(text_0, text_1); |
| 670 | 670 |
| 671 // Allow this frame and check that it worked. | 671 // Allow this frame and check that it worked. |
| 672 AcceptPrompt(); | 672 AcceptPrompt(); |
| 673 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); | 673 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); |
| 674 CheckPermissionMessageSent(1, true); | 674 CheckPermissionMessageSent(1, true); |
| 675 | 675 |
| 676 // Ensure the persisted permissions are ok. | 676 // Ensure the persisted permissions are ok. |
| 677 EXPECT_EQ( | 677 EXPECT_EQ( |
| 678 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); | 678 CONTENT_SETTING_ASK, GetGeolocationContentSetting(frame_0, frame_0)); |
| 679 EXPECT_EQ( | 679 EXPECT_EQ( |
| 680 CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0)); | 680 CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0)); |
| 681 } | 681 } |
| 682 | 682 |
| 683 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 683 TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| 684 // Navigate to the first url. | 684 // Navigate to the first url. |
| 685 GURL invalid_embedder("about:blank"); | 685 GURL invalid_embedder("about:blank"); |
| 686 GURL requesting_frame; | 686 GURL requesting_frame; |
| 687 NavigateAndCommit(invalid_embedder); | 687 NavigateAndCommit(invalid_embedder); |
| 688 BubbleManagerDocumentLoadCompleted(); | 688 RequestManagerDocumentLoadCompleted(); |
| 689 | 689 |
| 690 // Nothing should be displayed. | 690 // Nothing should be displayed. |
| 691 EXPECT_EQ(0U, GetNumberOfPrompts()); | 691 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 692 RequestGeolocationPermission( | 692 RequestGeolocationPermission( |
| 693 web_contents(), RequestID(0), requesting_frame, true); | 693 web_contents(), RequestID(0), requesting_frame, true); |
| 694 EXPECT_EQ(0U, GetNumberOfPrompts()); | 694 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 695 CheckPermissionMessageSent(0, false); | 695 CheckPermissionMessageSent(0, false); |
| 696 } | 696 } |
| 697 | 697 |
| 698 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 698 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| 699 GURL url_a("https://www.example.com/geolocation"); | 699 GURL url_a("https://www.example.com/geolocation"); |
| 700 GURL url_b("https://www.example-2.com/geolocation"); | 700 GURL url_b("https://www.example-2.com/geolocation"); |
| 701 NavigateAndCommit(url_a); // Tab A0 | 701 NavigateAndCommit(url_a); // Tab A0 |
| 702 AddNewTab(url_b); // Tab B (extra_tabs_[0]) | 702 AddNewTab(url_b); // Tab B (extra_tabs_[0]) |
| 703 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) | 703 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) |
| 704 BubbleManagerDocumentLoadCompleted(); | 704 RequestManagerDocumentLoadCompleted(); |
| 705 BubbleManagerDocumentLoadCompleted(extra_tabs_[0].get()); | 705 RequestManagerDocumentLoadCompleted(extra_tabs_[0].get()); |
| 706 BubbleManagerDocumentLoadCompleted(extra_tabs_[1].get()); | 706 RequestManagerDocumentLoadCompleted(extra_tabs_[1].get()); |
| 707 #if !BUILDFLAG(ANDROID_JAVA_UI) | 707 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 708 PermissionBubbleManager* manager_a0 = | 708 PermissionRequestManager* manager_a0 = |
| 709 PermissionBubbleManager::FromWebContents(web_contents()); | 709 PermissionRequestManager::FromWebContents(web_contents()); |
| 710 PermissionBubbleManager* manager_b = | 710 PermissionRequestManager* manager_b = |
| 711 PermissionBubbleManager::FromWebContents(extra_tabs_[0].get()); | 711 PermissionRequestManager::FromWebContents(extra_tabs_[0].get()); |
| 712 PermissionBubbleManager* manager_a1 = | 712 PermissionRequestManager* manager_a1 = |
| 713 PermissionBubbleManager::FromWebContents(extra_tabs_[1].get()); | 713 PermissionRequestManager::FromWebContents(extra_tabs_[1].get()); |
| 714 #endif | 714 #endif |
| 715 | 715 |
| 716 // Request permission in all three tabs. | 716 // Request permission in all three tabs. |
| 717 RequestGeolocationPermission( | 717 RequestGeolocationPermission( |
| 718 web_contents(), RequestID(0), url_a, true); | 718 web_contents(), RequestID(0), url_a, true); |
| 719 RequestGeolocationPermission( | 719 RequestGeolocationPermission( |
| 720 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b, true); | 720 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_b, true); |
| 721 RequestGeolocationPermission( | 721 RequestGeolocationPermission( |
| 722 extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true); | 722 extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true); |
| 723 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. | 723 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 755 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| 756 #endif | 756 #endif |
| 757 } | 757 } |
| 758 | 758 |
| 759 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | 759 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| 760 GURL url_a("https://www.example.com/geolocation"); | 760 GURL url_a("https://www.example.com/geolocation"); |
| 761 GURL url_b("https://www.example-2.com/geolocation"); | 761 GURL url_b("https://www.example-2.com/geolocation"); |
| 762 NavigateAndCommit(url_a); // Tab A0. | 762 NavigateAndCommit(url_a); // Tab A0. |
| 763 AddNewTab(url_a); // Tab A1. | 763 AddNewTab(url_a); // Tab A1. |
| 764 #if !BUILDFLAG(ANDROID_JAVA_UI) | 764 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 765 BubbleManagerDocumentLoadCompleted(); | 765 RequestManagerDocumentLoadCompleted(); |
| 766 BubbleManagerDocumentLoadCompleted(extra_tabs_[0].get()); | 766 RequestManagerDocumentLoadCompleted(extra_tabs_[0].get()); |
| 767 PermissionBubbleManager* manager_a0 = | 767 PermissionRequestManager* manager_a0 = |
| 768 PermissionBubbleManager::FromWebContents(web_contents()); | 768 PermissionRequestManager::FromWebContents(web_contents()); |
| 769 PermissionBubbleManager* manager_a1 = | 769 PermissionRequestManager* manager_a1 = |
| 770 PermissionBubbleManager::FromWebContents(extra_tabs_[0].get()); | 770 PermissionRequestManager::FromWebContents(extra_tabs_[0].get()); |
| 771 #endif | 771 #endif |
| 772 | 772 |
| 773 // Request permission in both tabs; the extra tab will have two permission | 773 // Request permission in both tabs; the extra tab will have two permission |
| 774 // requests from two origins. | 774 // requests from two origins. |
| 775 RequestGeolocationPermission( | 775 RequestGeolocationPermission( |
| 776 web_contents(), RequestID(0), url_a, true); | 776 web_contents(), RequestID(0), url_a, true); |
| 777 RequestGeolocationPermission( | 777 RequestGeolocationPermission( |
| 778 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true); | 778 extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true); |
| 779 RequestGeolocationPermission( | 779 RequestGeolocationPermission( |
| 780 extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true); | 780 extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 GURL requesting_frame_0("https://www.example.com/geolocation"); | 835 GURL requesting_frame_0("https://www.example.com/geolocation"); |
| 836 GURL requesting_frame_1("https://www.example-2.com/geolocation"); | 836 GURL requesting_frame_1("https://www.example-2.com/geolocation"); |
| 837 EXPECT_EQ( | 837 EXPECT_EQ( |
| 838 CONTENT_SETTING_ASK, | 838 CONTENT_SETTING_ASK, |
| 839 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); | 839 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
| 840 EXPECT_EQ( | 840 EXPECT_EQ( |
| 841 CONTENT_SETTING_ASK, | 841 CONTENT_SETTING_ASK, |
| 842 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); | 842 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| 843 | 843 |
| 844 NavigateAndCommit(requesting_frame_0); | 844 NavigateAndCommit(requesting_frame_0); |
| 845 BubbleManagerDocumentLoadCompleted(); | 845 RequestManagerDocumentLoadCompleted(); |
| 846 | 846 |
| 847 // Request permission for two frames. | 847 // Request permission for two frames. |
| 848 RequestGeolocationPermission( | 848 RequestGeolocationPermission( |
| 849 web_contents(), RequestID(0), requesting_frame_0, false); | 849 web_contents(), RequestID(0), requesting_frame_0, false); |
| 850 RequestGeolocationPermission( | 850 RequestGeolocationPermission( |
| 851 web_contents(), RequestID(1), requesting_frame_1, false); | 851 web_contents(), RequestID(1), requesting_frame_1, false); |
| 852 | 852 |
| 853 // Ensure only one prompt is created. | 853 // Ensure only one prompt is created. |
| 854 ASSERT_EQ(1U, GetNumberOfPrompts()); | 854 ASSERT_EQ(1U, GetNumberOfPrompts()); |
| 855 | 855 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 866 CONTENT_SETTING_ASK, | 866 CONTENT_SETTING_ASK, |
| 867 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); | 867 GetGeolocationContentSetting(requesting_frame_0, requesting_frame_0)); |
| 868 EXPECT_EQ( | 868 EXPECT_EQ( |
| 869 CONTENT_SETTING_ASK, | 869 CONTENT_SETTING_ASK, |
| 870 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); | 870 GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| 871 } | 871 } |
| 872 | 872 |
| 873 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { | 873 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { |
| 874 GURL requesting_frame("https://www.example.com/geolocation"); | 874 GURL requesting_frame("https://www.example.com/geolocation"); |
| 875 NavigateAndCommit(requesting_frame); | 875 NavigateAndCommit(requesting_frame); |
| 876 BubbleManagerDocumentLoadCompleted(); | 876 RequestManagerDocumentLoadCompleted(); |
| 877 | 877 |
| 878 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 878 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
| 879 test_clock->SetNow(base::Time::UnixEpoch() + | 879 test_clock->SetNow(base::Time::UnixEpoch() + |
| 880 base::TimeDelta::FromSeconds(10)); | 880 base::TimeDelta::FromSeconds(10)); |
| 881 | 881 |
| 882 HostContentSettingsMap* map = | 882 HostContentSettingsMap* map = |
| 883 HostContentSettingsMapFactory::GetForProfile(profile()); | 883 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 884 map->SetPrefClockForTesting(std::unique_ptr<base::Clock>(test_clock)); | 884 map->SetPrefClockForTesting(std::unique_ptr<base::Clock>(test_clock)); |
| 885 | 885 |
| 886 // The permission shouldn't have been used yet. | 886 // The permission shouldn't have been used yet. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 930 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 931 requesting_frame_0.GetOrigin(), | 931 requesting_frame_0.GetOrigin(), |
| 932 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 932 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 933 0); | 933 0); |
| 934 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 934 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 935 requesting_frame_0.GetOrigin(), | 935 requesting_frame_0.GetOrigin(), |
| 936 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 936 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 937 0); | 937 0); |
| 938 | 938 |
| 939 NavigateAndCommit(requesting_frame_0); | 939 NavigateAndCommit(requesting_frame_0); |
| 940 BubbleManagerDocumentLoadCompleted(); | 940 RequestManagerDocumentLoadCompleted(); |
| 941 | 941 |
| 942 EXPECT_EQ(0U, GetNumberOfPrompts()); | 942 EXPECT_EQ(0U, GetNumberOfPrompts()); |
| 943 | 943 |
| 944 // Request permission for two frames. | 944 // Request permission for two frames. |
| 945 RequestGeolocationPermission( | 945 RequestGeolocationPermission( |
| 946 web_contents(), RequestID(0), requesting_frame_0, false); | 946 web_contents(), RequestID(0), requesting_frame_0, false); |
| 947 RequestGeolocationPermission( | 947 RequestGeolocationPermission( |
| 948 web_contents(), RequestID(1), requesting_frame_1, false); | 948 web_contents(), RequestID(1), requesting_frame_1, false); |
| 949 | 949 |
| 950 // Ensure only one infobar is created. | 950 // Ensure only one infobar is created. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 999 // it is the embedder. | 999 // it is the embedder. |
| 1000 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1000 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
| 1001 requesting_frame_0.GetOrigin(), | 1001 requesting_frame_0.GetOrigin(), |
| 1002 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1002 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1003 13); | 1003 13); |
| 1004 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1004 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
| 1005 requesting_frame_0.GetOrigin(), | 1005 requesting_frame_0.GetOrigin(), |
| 1006 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1006 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
| 1007 11); | 1007 11); |
| 1008 } | 1008 } |
| OLD | NEW |