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 <stdint.h> | 5 #include <stdint.h> |
6 #include <string> | 6 #include <string> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 301 } |
302 | 302 |
303 ASSERT_TRUE(embedded_test_server()->Started()); | 303 ASSERT_TRUE(embedded_test_server()->Started()); |
304 embedded_test_server()->RegisterRequestHandler( | 304 embedded_test_server()->RegisterRequestHandler( |
305 base::Bind(&RespondWithHTML, html)); | 305 base::Bind(&RespondWithHTML, html)); |
306 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); | 306 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); |
307 EXPECT_TRUE(content::WaitForRenderFrameReady( | 307 EXPECT_TRUE(content::WaitForRenderFrameReady( |
308 GetActiveWebContents()->GetMainFrame())); | 308 GetActiveWebContents()->GetMainFrame())); |
309 } | 309 } |
310 | 310 |
| 311 // Returns the background WebContents. |
| 312 content::WebContents* LoadHTMLInBackgroundTab(const std::string& html) { |
| 313 embedded_test_server()->RegisterRequestHandler( |
| 314 base::Bind(&RespondWithHTML, html)); |
| 315 ui_test_utils::NavigateToURLWithDisposition( |
| 316 browser(), embedded_test_server()->base_url(), NEW_BACKGROUND_TAB, |
| 317 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 318 |
| 319 int index = browser()->tab_strip_model()->GetIndexOfLastWebContentsOpenedBy( |
| 320 GetActiveWebContents(), 0 /* start_index */); |
| 321 content::WebContents* contents = |
| 322 browser()->tab_strip_model()->GetWebContentsAt(index); |
| 323 EXPECT_TRUE(content::WaitForRenderFrameReady(contents->GetMainFrame())); |
| 324 return contents; |
| 325 } |
| 326 |
| 327 void ActivateTab(content::WebContents* contents) { |
| 328 browser()->tab_strip_model()->ActivateTabAt( |
| 329 browser()->tab_strip_model()->GetIndexOfWebContents(contents), |
| 330 true /* user_gesture */); |
| 331 } |
| 332 |
311 content::WebContents* GetActiveWebContents() { | 333 content::WebContents* GetActiveWebContents() { |
312 return browser()->tab_strip_model()->GetActiveWebContents(); | 334 return browser()->tab_strip_model()->GetActiveWebContents(); |
313 } | 335 } |
314 | 336 |
315 // This sends a simulated click at |point| and waits for test plugin to send | 337 // This sends a simulated click at |point| and waits for test plugin to send |
316 // a status message indicating that it is essential. The test plugin sends a | 338 // a status message indicating that it is essential. The test plugin sends a |
317 // status message during: | 339 // status message during: |
318 // - Plugin creation, to handle a plugin freshly created from a poster. | 340 // - Plugin creation, to handle a plugin freshly created from a poster. |
319 // - Peripheral status change. | 341 // - Peripheral status change. |
320 // - In response to the explicit 'getPowerSaverStatus' request, in case the | 342 // - In response to the explicit 'getPowerSaverStatus' request, in case the |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 634 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
613 " type='application/x-ppapi-tests' width='400' height='80'></object>"); | 635 " type='application/x-ppapi-tests' width='400' height='80'></object>"); |
614 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 636 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
615 | 637 |
616 std::string script = "window.document.getElementById('plugin').height = 400;"; | 638 std::string script = "window.document.getElementById('plugin').height = 400;"; |
617 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); | 639 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); |
618 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 640 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
619 } | 641 } |
620 | 642 |
621 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { | 643 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { |
622 std::string html = | 644 content::WebContents* background_contents = LoadHTMLInBackgroundTab( |
623 "<object id='same_origin' data='fake.swf' " | 645 "<object id='same_origin' data='fake.swf' " |
624 " type='application/x-ppapi-tests'></object>" | 646 " type='application/x-ppapi-tests'></object>" |
625 "<object id='small_cross_origin' data='http://otherorigin.com/fake1.swf' " | 647 "<object id='small_cross_origin' data='http://otherorigin.com/fake1.swf' " |
626 " type='application/x-ppapi-tests' width='400' height='100'></object>"; | 648 " type='application/x-ppapi-tests' width='400' height='80'></object>"); |
627 embedded_test_server()->RegisterRequestHandler( | |
628 base::Bind(&RespondWithHTML, html)); | |
629 ui_test_utils::NavigateToURLWithDisposition( | |
630 browser(), embedded_test_server()->base_url(), NEW_BACKGROUND_TAB, | |
631 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
632 | |
633 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | |
634 content::WebContents* background_contents = | |
635 browser()->tab_strip_model()->GetWebContentsAt(1); | |
636 EXPECT_TRUE( | |
637 content::WaitForRenderFrameReady(background_contents->GetMainFrame())); | |
638 | 649 |
639 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); | 650 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); |
640 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); | 651 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); |
641 | 652 |
642 browser()->tab_strip_model()->SelectNextTab(); | 653 ActivateTab(background_contents); |
643 EXPECT_EQ(background_contents, GetActiveWebContents()); | |
644 | 654 |
645 VerifyPluginMarkedEssential(background_contents, "same_origin"); | 655 VerifyPluginMarkedEssential(background_contents, "same_origin"); |
646 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); | 656 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); |
647 | |
648 // TODO(groby): We need to cover the edge case of tiny plugin on a a | |
649 // background tab here. If blocking of tiny content is enabled | |
650 // this should be IsThrotthled, not IsPlaceholderOnly. | |
651 } | 657 } |
652 | 658 |
653 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { | 659 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { |
654 zoom::ZoomController::FromWebContents(GetActiveWebContents()) | 660 zoom::ZoomController::FromWebContents(GetActiveWebContents()) |
655 ->SetZoomLevel(4.0); | 661 ->SetZoomLevel(4.0); |
656 LoadHTML( | 662 LoadHTML( |
657 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 663 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
658 " type='application/x-ppapi-tests' width='400' height='200'>" | 664 " type='application/x-ppapi-tests' width='400' height='200'>" |
659 "</object>"); | 665 "</object>"); |
660 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 666 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
661 } | 667 } |
662 | 668 |
663 // Separate test case that blocks tiny plugins. This requires a separate test | 669 // Separate test case that blocks tiny plugins. This requires a separate test |
664 // case, because we need to initialize the renderer with a different feature | 670 // case, because we need to initialize the renderer with a different feature |
665 // setting. | 671 // setting. |
666 class PluginPowerSaverBlockTinyBrowserTest | 672 class PluginPowerSaverBlockTinyBrowserTest |
667 : public PluginPowerSaverBrowserTest { | 673 : public PluginPowerSaverBrowserTest { |
668 public: | 674 public: |
669 void SetUp() override { | 675 void SetUp() override { |
670 base::FeatureList::ClearInstanceForTesting(); | 676 base::FeatureList::ClearInstanceForTesting(); |
671 PluginPowerSaverBrowserTest::SetUp(); | 677 PluginPowerSaverBrowserTest::SetUp(); |
672 } | 678 } |
673 void SetUpInProcessBrowserTestFixture() override { BlockTinyPlugins(); } | 679 void SetUpInProcessBrowserTestFixture() override { |
674 void BlockTinyPlugins() { | |
675 base::FeatureList::ClearInstanceForTesting(); | 680 base::FeatureList::ClearInstanceForTesting(); |
676 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 681 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
677 feature_list->InitializeFromCommandLine(features::kBlockSmallContent.name, | 682 feature_list->InitializeFromCommandLine(features::kBlockSmallContent.name, |
678 std::string()); | 683 std::string()); |
679 base::FeatureList::SetInstance(std::move(feature_list)); | 684 base::FeatureList::SetInstance(std::move(feature_list)); |
680 } | 685 } |
681 }; | 686 }; |
682 | 687 |
683 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBlockTinyBrowserTest, BlockTinyPlugins) { | 688 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBlockTinyBrowserTest, BlockTinyPlugins) { |
684 LoadHTML( | 689 LoadHTML( |
685 "<object id='large_same_origin' data='fake.swf' " | |
686 " type='application/x-ppapi-tests' width='500' height='500'>" | |
687 "</object>" | |
688 "<object id='small_same_origin' data='fake.swf' " | |
689 " type='application/x-ppapi-tests' width='500' height='500'>" | |
690 "</object>" | |
691 "<object id='tiny_same_origin' data='fake.swf' " | 690 "<object id='tiny_same_origin' data='fake.swf' " |
692 " type='application/x-ppapi-tests' width='3' height='3'>" | 691 " type='application/x-ppapi-tests' width='3' height='3'>" |
693 "</object>" | 692 "</object>" |
694 "<object id='tiny_cross_origin_1' data='http://a.com/fake.swf' " | 693 "<object id='tiny_cross_origin_1' data='http://a.com/fake.swf' " |
695 " type='application/x-ppapi-tests' width='3' height='3'>" | 694 " type='application/x-ppapi-tests' width='3' height='3'>" |
696 "</object>" | 695 "</object>" |
697 "<object id='tiny_cross_origin_2' data='http://a.com/fake.swf' " | 696 "<object id='tiny_cross_origin_2' data='http://a.com/fake.swf' " |
698 " type='application/x-ppapi-tests' width='1' height='1'>" | 697 " type='application/x-ppapi-tests' width='1' height='1'>" |
699 "</object>"); | 698 "</object>"); |
700 | 699 |
701 VerifyPluginMarkedEssential(GetActiveWebContents(), "large_same_origin"); | |
702 VerifyPluginMarkedEssential(GetActiveWebContents(), "small_same_origin"); | |
703 VerifyPluginMarkedEssential(GetActiveWebContents(), "tiny_same_origin"); | 700 VerifyPluginMarkedEssential(GetActiveWebContents(), "tiny_same_origin"); |
704 VerifyPluginIsPlaceholderOnly("tiny_cross_origin_1"); | 701 VerifyPluginIsPlaceholderOnly("tiny_cross_origin_1"); |
705 VerifyPluginIsPlaceholderOnly("tiny_cross_origin_2"); | 702 VerifyPluginIsPlaceholderOnly("tiny_cross_origin_2"); |
706 } | 703 } |
| 704 |
| 705 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBlockTinyBrowserTest, |
| 706 BackgroundTabTinyPlugins) { |
| 707 content::WebContents* background_contents = LoadHTMLInBackgroundTab( |
| 708 "<object id='tiny' data='http://a.com/fake.swf' " |
| 709 " type='application/x-ppapi-tests' width='3' height='3'>" |
| 710 "</object>"); |
| 711 EXPECT_FALSE(PluginLoaded(background_contents, "tiny")); |
| 712 |
| 713 ActivateTab(background_contents); |
| 714 VerifyPluginIsPlaceholderOnly("tiny"); |
| 715 } |
| 716 |
| 717 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBlockTinyBrowserTest, |
| 718 ExpandingTinyPlugins) { |
| 719 LoadHTML( |
| 720 "<object id='expand_to_peripheral' data='http://a.com/fake.swf' " |
| 721 " type='application/x-ppapi-tests' width='4' height='4'></object>" |
| 722 "<object id='expand_to_essential' data='http://b.com/fake.swf' " |
| 723 " type='application/x-ppapi-tests' width='4' height='4'></object>"); |
| 724 |
| 725 VerifyPluginIsPlaceholderOnly("expand_to_peripheral"); |
| 726 VerifyPluginIsPlaceholderOnly("expand_to_essential"); |
| 727 |
| 728 std::string script = |
| 729 "window.document.getElementById('expand_to_peripheral').height = 200;" |
| 730 "window.document.getElementById('expand_to_peripheral').width = 200;" |
| 731 "window.document.getElementById('expand_to_essential').height = 400;" |
| 732 "window.document.getElementById('expand_to_essential').width = 400;"; |
| 733 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); |
| 734 |
| 735 VerifyPluginIsThrottled(GetActiveWebContents(), "expand_to_peripheral"); |
| 736 VerifyPluginMarkedEssential(GetActiveWebContents(), "expand_to_essential"); |
| 737 } |
OLD | NEW |