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

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

Issue 1088763002: Plugin Power Saver: Add comprehensive browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0260-plugins-overhaul-prerender-tests
Patch Set: Created 5 years, 8 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 | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/strings/stringprintf.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/ppapi_test_utils.h"
14 #include "content/public/test/test_utils.h"
15 #include "third_party/WebKit/public/web/WebInputEvent.h"
16 #include "ui/gfx/geometry/point.h"
17
18 class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest {
19 public:
20 void SetUpCommandLine(base::CommandLine* command_line) override {
21 command_line->AppendSwitch(switches::kEnablePluginPowerSaver);
22
23 ppapi::RegisterTestLibrary(command_line);
24 }
25
26 protected:
27 void LoadHTML(const char* html) {
28 std::string url_str = "data:text/html;charset=utf-8,";
29 url_str.append(html);
30 ui_test_utils::NavigateToURL(browser(), GURL(url_str));
31 }
32
33 content::WebContents* GetActiveWebContents() {
34 return browser()->tab_strip_model()->GetActiveWebContents();
35 }
36
37 bool IsPluginPeripheral(const char* element_id) {
38 std::string script = base::StringPrintf(
39 "var plugin = window.document.getElementById('%s');"
40 "if (plugin != undefined) {"
41 " var b = plugin.postMessage == undefined || plugin.isPeripheral();"
42 " window.domAutomationController.send(b);"
43 "}",
44 element_id);
45
46 bool result = false;
47 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(GetActiveWebContents(),
48 script, &result));
49 return result;
50 }
51 };
52
53 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) {
54 LoadHTML(
55 "<object id='plugin' data='fake.swf' "
56 "type='application/x-ppapi-tests' width='400' height='100'></object>");
57 EXPECT_FALSE(IsPluginPeripheral("plugin"));
58 }
59
60 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) {
61 LoadHTML(
62 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
63 "type='application/x-ppapi-tests' width='400' height='100'></object>");
64 EXPECT_TRUE(IsPluginPeripheral("plugin"));
65
66 // Test unthrottle on click.
67 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */,
68 blink::WebMouseEvent::ButtonLeft,
69 gfx::Point(50, 50));
70 content::RunAllBlockingPoolTasksUntilIdle();
71
72 EXPECT_FALSE(IsPluginPeripheral("plugin"));
73 }
74
75 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) {
76 LoadHTML(
77 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
78 "type='application/x-ppapi-tests' width='400' height='500'></object>");
79 EXPECT_FALSE(IsPluginPeripheral("plugin"));
80 }
81
82 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeWithPoster) {
83 LoadHTML(
84 "<object id='plugin' type='application/x-ppapi-tests' "
85 " width='400' height='500'>"
86 " <param name='poster' value='snapshot1x.png 1x, snapshot2x.png 2x' />"
87 "</object>");
88 EXPECT_TRUE(IsPluginPeripheral("plugin"));
Lei Zhang 2015/04/15 05:52:44 Can you remind me why this is peripheral? Is is th
tommycli 2015/04/15 22:30:28 Yes. Large plugins with posters are not loaded imm
89 }
90
91 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) {
92 LoadHTML(
93 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' "
94 "type='application/x-ppapi-tests' width='400' height='100'></object>"
95 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' "
96 "type='application/x-ppapi-tests' width='400' height='500'></object>");
97 EXPECT_FALSE(IsPluginPeripheral("plugin1"));
98 EXPECT_FALSE(IsPluginPeripheral("plugin2"));
99 }
100
101 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) {
102 LoadHTML(
103 "<div style='width: 100px; height: 100px; overflow: hidden;'>"
104 " <object id='plugin' data='http://otherorigin.com/fake.swf' "
105 " type='application/x-ppapi-tests' width='400' height='500'></object>"
106 "</div>");
107 EXPECT_TRUE(IsPluginPeripheral("plugin"));
108 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698