| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/permissions/permission_request_manager.h" | 5 #include "chrome/browser/permissions/permission_request_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 10 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 DISABLED_RequestsBeforeLoad) { | 279 DISABLED_RequestsBeforeLoad) { |
| 280 ASSERT_TRUE(embedded_test_server()->Start()); | 280 ASSERT_TRUE(embedded_test_server()->Start()); |
| 281 | 281 |
| 282 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 282 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 283 browser(), | 283 browser(), |
| 284 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), | 284 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), |
| 285 1); | 285 1); |
| 286 bubble_factory()->WaitForPermissionBubble(); | 286 bubble_factory()->WaitForPermissionBubble(); |
| 287 | 287 |
| 288 EXPECT_EQ(1, bubble_factory()->show_count()); | 288 EXPECT_EQ(1, bubble_factory()->show_count()); |
| 289 EXPECT_EQ(2, bubble_factory()->total_request_count()); | 289 EXPECT_EQ(2, bubble_factory()->TotalRequestCount()); |
| 290 } | 290 } |
| 291 | 291 |
| 292 // Requests before the load should not be bundled with a request after the load. | 292 // Requests before the load should not be bundled with a request after the load. |
| 293 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, | 293 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, |
| 294 RequestsBeforeAfterLoad) { | 294 RequestsBeforeAfterLoad) { |
| 295 ASSERT_TRUE(embedded_test_server()->Start()); | 295 ASSERT_TRUE(embedded_test_server()->Start()); |
| 296 | 296 |
| 297 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 297 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 298 browser(), | 298 browser(), |
| 299 embedded_test_server()->GetURL( | 299 embedded_test_server()->GetURL( |
| 300 "/permissions/requests-before-after-load.html"), | 300 "/permissions/requests-before-after-load.html"), |
| 301 1); | 301 1); |
| 302 bubble_factory()->WaitForPermissionBubble(); | 302 bubble_factory()->WaitForPermissionBubble(); |
| 303 | 303 |
| 304 EXPECT_EQ(1, bubble_factory()->show_count()); | 304 EXPECT_EQ(1, bubble_factory()->show_count()); |
| 305 EXPECT_EQ(1, bubble_factory()->total_request_count()); | 305 EXPECT_EQ(1, bubble_factory()->TotalRequestCount()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 // Navigating twice to the same URL should be equivalent to refresh. This means | 308 // Navigating twice to the same URL should be equivalent to refresh. This means |
| 309 // showing the bubbles twice. | 309 // showing the bubbles twice. |
| 310 // http://crbug.com/512849 flaky | 310 // http://crbug.com/512849 flaky |
| 311 #if defined(OS_WIN) | 311 #if defined(OS_WIN) |
| 312 #define MAYBE_NavTwice DISABLED_NavTwice | 312 #define MAYBE_NavTwice DISABLED_NavTwice |
| 313 #else | 313 #else |
| 314 #define MAYBE_NavTwice NavTwice | 314 #define MAYBE_NavTwice NavTwice |
| 315 #endif | 315 #endif |
| 316 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, MAYBE_NavTwice) { | 316 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, MAYBE_NavTwice) { |
| 317 ASSERT_TRUE(embedded_test_server()->Start()); | 317 ASSERT_TRUE(embedded_test_server()->Start()); |
| 318 | 318 |
| 319 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 319 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 320 browser(), | 320 browser(), |
| 321 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), | 321 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), |
| 322 1); | 322 1); |
| 323 bubble_factory()->WaitForPermissionBubble(); | 323 bubble_factory()->WaitForPermissionBubble(); |
| 324 | 324 |
| 325 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 325 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 326 browser(), | 326 browser(), |
| 327 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), | 327 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), |
| 328 1); | 328 1); |
| 329 bubble_factory()->WaitForPermissionBubble(); | 329 bubble_factory()->WaitForPermissionBubble(); |
| 330 | 330 |
| 331 EXPECT_EQ(2, bubble_factory()->show_count()); | 331 EXPECT_EQ(2, bubble_factory()->show_count()); |
| 332 EXPECT_EQ(4, bubble_factory()->total_request_count()); | 332 EXPECT_EQ(4, bubble_factory()->TotalRequestCount()); |
| 333 } | 333 } |
| 334 | 334 |
| 335 // Navigating twice to the same URL with a hash should be navigation within the | 335 // Navigating twice to the same URL with a hash should be navigation within the |
| 336 // page. This means the bubble is only shown once. | 336 // page. This means the bubble is only shown once. |
| 337 // http://crbug.com/512849 flaky | 337 // http://crbug.com/512849 flaky |
| 338 #if defined(OS_WIN) | 338 #if defined(OS_WIN) |
| 339 #define MAYBE_NavTwiceWithHash DISABLED_NavTwiceWithHash | 339 #define MAYBE_NavTwiceWithHash DISABLED_NavTwiceWithHash |
| 340 #else | 340 #else |
| 341 #define MAYBE_NavTwiceWithHash NavTwiceWithHash | 341 #define MAYBE_NavTwiceWithHash NavTwiceWithHash |
| 342 #endif | 342 #endif |
| 343 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, | 343 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, |
| 344 MAYBE_NavTwiceWithHash) { | 344 MAYBE_NavTwiceWithHash) { |
| 345 ASSERT_TRUE(embedded_test_server()->Start()); | 345 ASSERT_TRUE(embedded_test_server()->Start()); |
| 346 | 346 |
| 347 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 347 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 348 browser(), | 348 browser(), |
| 349 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), | 349 embedded_test_server()->GetURL("/permissions/requests-before-load.html"), |
| 350 1); | 350 1); |
| 351 bubble_factory()->WaitForPermissionBubble(); | 351 bubble_factory()->WaitForPermissionBubble(); |
| 352 | 352 |
| 353 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 353 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 354 browser(), | 354 browser(), |
| 355 embedded_test_server()->GetURL( | 355 embedded_test_server()->GetURL( |
| 356 "/permissions/requests-before-load.html#0"), | 356 "/permissions/requests-before-load.html#0"), |
| 357 1); | 357 1); |
| 358 bubble_factory()->WaitForPermissionBubble(); | 358 bubble_factory()->WaitForPermissionBubble(); |
| 359 | 359 |
| 360 EXPECT_EQ(1, bubble_factory()->show_count()); | 360 EXPECT_EQ(1, bubble_factory()->show_count()); |
| 361 EXPECT_EQ(2, bubble_factory()->total_request_count()); | 361 EXPECT_EQ(2, bubble_factory()->TotalRequestCount()); |
| 362 } | 362 } |
| 363 | 363 |
| 364 // Bubble requests should be shown after in-page navigation. | 364 // Bubble requests should be shown after in-page navigation. |
| 365 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, InPageNavigation) { | 365 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, InPageNavigation) { |
| 366 ASSERT_TRUE(embedded_test_server()->Start()); | 366 ASSERT_TRUE(embedded_test_server()->Start()); |
| 367 | 367 |
| 368 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 368 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 369 browser(), | 369 browser(), |
| 370 embedded_test_server()->GetURL("/empty.html"), | 370 embedded_test_server()->GetURL("/empty.html"), |
| 371 1); | 371 1); |
| 372 | 372 |
| 373 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 373 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 374 browser(), | 374 browser(), |
| 375 embedded_test_server()->GetURL("/empty.html#0"), | 375 embedded_test_server()->GetURL("/empty.html#0"), |
| 376 1); | 376 1); |
| 377 | 377 |
| 378 // Request 'geolocation' permission. | 378 // Request 'geolocation' permission. |
| 379 ExecuteScriptAndGetValue( | 379 ExecuteScriptAndGetValue( |
| 380 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 380 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| 381 "navigator.geolocation.getCurrentPosition(function(){});"); | 381 "navigator.geolocation.getCurrentPosition(function(){});"); |
| 382 bubble_factory()->WaitForPermissionBubble(); | 382 bubble_factory()->WaitForPermissionBubble(); |
| 383 | 383 |
| 384 EXPECT_EQ(1, bubble_factory()->show_count()); | 384 EXPECT_EQ(1, bubble_factory()->show_count()); |
| 385 EXPECT_EQ(1, bubble_factory()->total_request_count()); | 385 EXPECT_EQ(1, bubble_factory()->TotalRequestCount()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // Bubble requests should not be shown when the killswitch is on. | 388 // Bubble requests should not be shown when the killswitch is on. |
| 389 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, | 389 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, |
| 390 KillSwitchGeolocation) { | 390 KillSwitchGeolocation) { |
| 391 ASSERT_TRUE(embedded_test_server()->Start()); | 391 ASSERT_TRUE(embedded_test_server()->Start()); |
| 392 | 392 |
| 393 ui_test_utils::NavigateToURL( | 393 ui_test_utils::NavigateToURL( |
| 394 browser(), | 394 browser(), |
| 395 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); | 395 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); |
| 396 | 396 |
| 397 // Now enable the geolocation killswitch. | 397 // Now enable the geolocation killswitch. |
| 398 EnableKillSwitch(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 398 EnableKillSwitch(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 399 content::WebContents* web_contents = | 399 content::WebContents* web_contents = |
| 400 browser()->tab_strip_model()->GetActiveWebContents(); | 400 browser()->tab_strip_model()->GetActiveWebContents(); |
| 401 | 401 |
| 402 std::string result; | 402 std::string result; |
| 403 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 403 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 404 web_contents, "requestGeolocation();", &result)); | 404 web_contents, "requestGeolocation();", &result)); |
| 405 EXPECT_EQ("denied", result); | 405 EXPECT_EQ("denied", result); |
| 406 EXPECT_EQ(0, bubble_factory()->show_count()); | 406 EXPECT_EQ(0, bubble_factory()->show_count()); |
| 407 EXPECT_EQ(0, bubble_factory()->total_request_count()); | 407 EXPECT_EQ(0, bubble_factory()->TotalRequestCount()); |
| 408 | 408 |
| 409 // Disable the trial. | 409 // Disable the trial. |
| 410 variations::testing::ClearAllVariationParams(); | 410 variations::testing::ClearAllVariationParams(); |
| 411 | 411 |
| 412 // Reload the page to get around blink layer caching for geolocation | 412 // Reload the page to get around blink layer caching for geolocation |
| 413 // requests. | 413 // requests. |
| 414 ui_test_utils::NavigateToURL( | 414 ui_test_utils::NavigateToURL( |
| 415 browser(), | 415 browser(), |
| 416 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); | 416 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); |
| 417 | 417 |
| 418 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestGeolocation();")); | 418 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestGeolocation();")); |
| 419 bubble_factory()->WaitForPermissionBubble(); | 419 bubble_factory()->WaitForPermissionBubble(); |
| 420 EXPECT_EQ(1, bubble_factory()->show_count()); | 420 EXPECT_EQ(1, bubble_factory()->show_count()); |
| 421 EXPECT_EQ(1, bubble_factory()->total_request_count()); | 421 EXPECT_EQ(1, bubble_factory()->TotalRequestCount()); |
| 422 } | 422 } |
| 423 | 423 |
| 424 // Bubble requests should not be shown when the killswitch is on. | 424 // Bubble requests should not be shown when the killswitch is on. |
| 425 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, | 425 IN_PROC_BROWSER_TEST_F(PermissionRequestManagerBrowserTest, |
| 426 KillSwitchNotifications) { | 426 KillSwitchNotifications) { |
| 427 ASSERT_TRUE(embedded_test_server()->Start()); | 427 ASSERT_TRUE(embedded_test_server()->Start()); |
| 428 | 428 |
| 429 ui_test_utils::NavigateToURL( | 429 ui_test_utils::NavigateToURL( |
| 430 browser(), | 430 browser(), |
| 431 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); | 431 embedded_test_server()->GetURL("/permissions/killswitch_tester.html")); |
| 432 | 432 |
| 433 // Now enable the notifications killswitch. | 433 // Now enable the notifications killswitch. |
| 434 EnableKillSwitch(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 434 EnableKillSwitch(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 435 content::WebContents* web_contents = | 435 content::WebContents* web_contents = |
| 436 browser()->tab_strip_model()->GetActiveWebContents(); | 436 browser()->tab_strip_model()->GetActiveWebContents(); |
| 437 | 437 |
| 438 std::string result; | 438 std::string result; |
| 439 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 439 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 440 web_contents, "requestNotification();", &result)); | 440 web_contents, "requestNotification();", &result)); |
| 441 EXPECT_EQ("denied", result); | 441 EXPECT_EQ("denied", result); |
| 442 EXPECT_EQ(0, bubble_factory()->show_count()); | 442 EXPECT_EQ(0, bubble_factory()->show_count()); |
| 443 EXPECT_EQ(0, bubble_factory()->total_request_count()); | 443 EXPECT_EQ(0, bubble_factory()->TotalRequestCount()); |
| 444 | 444 |
| 445 // Disable the trial. | 445 // Disable the trial. |
| 446 variations::testing::ClearAllVariationParams(); | 446 variations::testing::ClearAllVariationParams(); |
| 447 | 447 |
| 448 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestNotification();")); | 448 EXPECT_TRUE(content::ExecuteScript(web_contents, "requestNotification();")); |
| 449 bubble_factory()->WaitForPermissionBubble(); | 449 bubble_factory()->WaitForPermissionBubble(); |
| 450 EXPECT_EQ(1, bubble_factory()->show_count()); | 450 EXPECT_EQ(1, bubble_factory()->show_count()); |
| 451 EXPECT_EQ(1, bubble_factory()->total_request_count()); | 451 EXPECT_EQ(1, bubble_factory()->TotalRequestCount()); |
| 452 } | 452 } |
| 453 | 453 |
| 454 // Host wants to run flash. | 454 // Host wants to run flash. |
| 455 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_flash) { | 455 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_flash) { |
| 456 RunDialog(); | 456 RunDialog(); |
| 457 } | 457 } |
| 458 | 458 |
| 459 // Host wants to know your location. | 459 // Host wants to know your location. |
| 460 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_geolocation) { | 460 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, InvokeDialog_geolocation) { |
| 461 RunDialog(); | 461 RunDialog(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 #define MAYBE_InvokeDialog_protected_media InvokeDialog_protected_media | 496 #define MAYBE_InvokeDialog_protected_media InvokeDialog_protected_media |
| 497 #else | 497 #else |
| 498 #define MAYBE_InvokeDialog_protected_media DISABLED_InvokeDialog_protected_media | 498 #define MAYBE_InvokeDialog_protected_media DISABLED_InvokeDialog_protected_media |
| 499 #endif | 499 #endif |
| 500 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, | 500 IN_PROC_BROWSER_TEST_F(PermissionDialogTest, |
| 501 MAYBE_InvokeDialog_protected_media) { | 501 MAYBE_InvokeDialog_protected_media) { |
| 502 RunDialog(); | 502 RunDialog(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 } // anonymous namespace | 505 } // anonymous namespace |
| OLD | NEW |