Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1113)

Side by Side Diff: chrome/browser/plugins/plugin_power_saver_browsertest.cc

Issue 2373893002: [HBD] Enable Plugin Power Saver on ALLOW for HBD feature flag on. (Closed)
Patch Set: refactor Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/plugins/plugin_info_message_filter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/stl_util.h" 10 #include "base/stl_util.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/test/scoped_feature_list.h" 13 #include "base/test/scoped_feature_list.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
20 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/test_switches.h" 22 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/content_settings/core/browser/host_content_settings_map.h"
23 #include "components/zoom/zoom_controller.h" 25 #include "components/zoom/zoom_controller.h"
24 #include "content/public/browser/readback_types.h" 26 #include "content/public/browser/readback_types.h"
25 #include "content/public/browser/render_frame_host.h" 27 #include "content/public/browser/render_frame_host.h"
26 #include "content/public/browser/render_view_host.h" 28 #include "content/public/browser/render_view_host.h"
27 #include "content/public/browser/render_widget_host.h" 29 #include "content/public/browser/render_widget_host.h"
28 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
29 #include "content/public/test/browser_test_utils.h" 31 #include "content/public/test/browser_test_utils.h"
30 #include "content/public/test/ppapi_test_utils.h" 32 #include "content/public/test/ppapi_test_utils.h"
31 #include "net/test/embedded_test_server/embedded_test_server.h" 33 #include "net/test/embedded_test_server/embedded_test_server.h"
32 #include "net/test/embedded_test_server/http_request.h" 34 #include "net/test/embedded_test_server/http_request.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 307 }
306 308
307 ASSERT_TRUE(embedded_test_server()->Started()); 309 ASSERT_TRUE(embedded_test_server()->Started());
308 embedded_test_server()->RegisterRequestHandler( 310 embedded_test_server()->RegisterRequestHandler(
309 base::Bind(&RespondWithHTML, html)); 311 base::Bind(&RespondWithHTML, html));
310 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); 312 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url());
311 EXPECT_TRUE(content::WaitForRenderFrameReady( 313 EXPECT_TRUE(content::WaitForRenderFrameReady(
312 GetActiveWebContents()->GetMainFrame())); 314 GetActiveWebContents()->GetMainFrame()));
313 } 315 }
314 316
317 // Loads a peripheral plugin (small cross origin) named 'plugin'.
318 void LoadPeripheralPlugin() {
319 LoadHTML(
320 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
321 " type='application/x-shockwave-flash' width='400' height='100'>"
322 "</object>");
323 }
324
315 // Returns the background WebContents. 325 // Returns the background WebContents.
316 content::WebContents* LoadHTMLInBackgroundTab(const std::string& html) { 326 content::WebContents* LoadHTMLInBackgroundTab(const std::string& html) {
317 embedded_test_server()->RegisterRequestHandler( 327 embedded_test_server()->RegisterRequestHandler(
318 base::Bind(&RespondWithHTML, html)); 328 base::Bind(&RespondWithHTML, html));
319 ui_test_utils::NavigateToURLWithDisposition( 329 ui_test_utils::NavigateToURLWithDisposition(
320 browser(), embedded_test_server()->base_url(), 330 browser(), embedded_test_server()->base_url(),
321 WindowOpenDisposition::NEW_BACKGROUND_TAB, 331 WindowOpenDisposition::NEW_BACKGROUND_TAB,
322 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 332 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
323 333
324 int index = browser()->tab_strip_model()->GetIndexOfLastWebContentsOpenedBy( 334 int index = browser()->tab_strip_model()->GetIndexOfLastWebContentsOpenedBy(
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); 466 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin");
457 VerifyPluginIsPlaceholderOnly("plugin_poster"); 467 VerifyPluginIsPlaceholderOnly("plugin_poster");
458 468
459 EXPECT_TRUE( 469 EXPECT_TRUE(
460 VerifySnapshot(FILE_PATH_LITERAL("small_cross_origin_expected.png"))); 470 VerifySnapshot(FILE_PATH_LITERAL("small_cross_origin_expected.png")));
461 471
462 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); 472 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50));
463 SimulateClickAndAwaitMarkedEssential("plugin_poster", gfx::Point(50, 150)); 473 SimulateClickAndAwaitMarkedEssential("plugin_poster", gfx::Point(50, 150));
464 } 474 }
465 475
476 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ContentSettings) {
477 HostContentSettingsMap* content_settings_map =
478 HostContentSettingsMapFactory::GetForProfile(browser()->profile());
479
480 // Throttle on DETECT.
481 content_settings_map->SetDefaultContentSetting(
482 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DETECT_IMPORTANT_CONTENT);
483 LoadPeripheralPlugin();
484 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin");
485
486 // Don't throttle on ALLOW.
487 content_settings_map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
488 CONTENT_SETTING_ALLOW);
489 LoadPeripheralPlugin();
490 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin");
491 }
492
466 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallerThanPlayIcon) { 493 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallerThanPlayIcon) {
467 LoadHTML( 494 LoadHTML(
468 "<object id='plugin_16' type='application/x-shockwave-flash' " 495 "<object id='plugin_16' type='application/x-shockwave-flash' "
469 " width='16' height='16'></object>" 496 " width='16' height='16'></object>"
470 "<object id='plugin_32' type='application/x-shockwave-flash' " 497 "<object id='plugin_32' type='application/x-shockwave-flash' "
471 " width='32' height='32'></object>" 498 " width='32' height='32'></object>"
472 "<object id='plugin_16_64' type='application/x-shockwave-flash' " 499 "<object id='plugin_16_64' type='application/x-shockwave-flash' "
473 " width='16' height='64'></object>" 500 " width='16' height='64'></object>"
474 "<object id='plugin_64_16' type='application/x-shockwave-flash' " 501 "<object id='plugin_64_16' type='application/x-shockwave-flash' "
475 " width='64' height='16'></object>"); 502 " width='64' height='16'></object>");
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 654
628 // Test that's unthrottled if it is unobscured. 655 // Test that's unthrottled if it is unobscured.
629 std::string script = 656 std::string script =
630 "var container = window.document.getElementById('container');" 657 "var container = window.document.getElementById('container');"
631 "container.setAttribute('style', 'width: 400px; height: 400px;');"; 658 "container.setAttribute('style', 'width: 400px; height: 400px;');";
632 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); 659 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script));
633 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); 660 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin");
634 } 661 }
635 662
636 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingSmallPlugin) { 663 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingSmallPlugin) {
637 LoadHTML( 664 LoadPeripheralPlugin();
638 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
639 " type='application/x-shockwave-flash' width='400' height='80'>"
640 "</object>");
641 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); 665 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin");
642 666
643 std::string script = "window.document.getElementById('plugin').height = 400;"; 667 std::string script = "window.document.getElementById('plugin').height = 400;";
644 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); 668 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script));
645 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); 669 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin");
646 } 670 }
647 671
648 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { 672 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) {
649 content::WebContents* background_contents = LoadHTMLInBackgroundTab( 673 content::WebContents* background_contents = LoadHTMLInBackgroundTab(
650 "<object id='same_origin' data='fake.swf' " 674 "<object id='same_origin' data='fake.swf' "
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 "<object id='tiny_cross_origin_1' data='http://a.com/fake.swf' " 767 "<object id='tiny_cross_origin_1' data='http://a.com/fake.swf' "
744 " type='application/x-shockwave-flash' width='3' height='3'>" 768 " type='application/x-shockwave-flash' width='3' height='3'>"
745 "</object>" 769 "</object>"
746 "<object id='tiny_cross_origin_2' data='http://a.com/fake.swf' " 770 "<object id='tiny_cross_origin_2' data='http://a.com/fake.swf' "
747 " type='application/x-shockwave-flash' width='1' height='1'>" 771 " type='application/x-shockwave-flash' width='1' height='1'>"
748 "</object>"); 772 "</object>");
749 773
750 VerifyPluginMarkedEssential(GetActiveWebContents(), "tiny_cross_origin_1"); 774 VerifyPluginMarkedEssential(GetActiveWebContents(), "tiny_cross_origin_1");
751 VerifyPluginMarkedEssential(GetActiveWebContents(), "tiny_cross_origin_2"); 775 VerifyPluginMarkedEssential(GetActiveWebContents(), "tiny_cross_origin_2");
752 } 776 }
777
778 // Separate test case with HTML By Default feature flag on.
779 class PluginPowerSaverPreferHtmlBrowserTest
780 : public PluginPowerSaverBrowserTest {
781 public:
782 void SetUpInProcessBrowserTestFixture() override {
783 PluginPowerSaverBrowserTest::SetUpInProcessBrowserTestFixture();
784 feature_list.InitAndEnableFeature(features::kPreferHtmlOverPlugins);
785 }
786
787 private:
788 base::test::ScopedFeatureList feature_list;
789 };
790
791 IN_PROC_BROWSER_TEST_F(PluginPowerSaverPreferHtmlBrowserTest,
792 ThrottlePluginsOnAllowContentSetting) {
793 HostContentSettingsMap* content_settings_map =
794 HostContentSettingsMapFactory::GetForProfile(browser()->profile());
795
796 content_settings_map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_PLUGINS,
797 CONTENT_SETTING_ALLOW);
798 LoadPeripheralPlugin();
799 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin");
800 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_info_message_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698