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

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/browser_tests.isolate » ('j') | ppapi/tests/power_saver_test_plugin.cc » ('J')
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 "ppapi/shared_impl/ppapi_switches.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 command_line->AppendSwitch(switches::kEnablePepperTesting);
23
24 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line));
25 }
26
27 protected:
28 void LoadHTML(const char* html) {
29 std::string url_str = "data:text/html;charset=utf-8,";
30 url_str.append(html);
31 ui_test_utils::NavigateToURL(browser(), GURL(url_str));
32 EXPECT_TRUE(content::WaitForRenderFrameReady(
33 GetActiveWebContents()->GetMainFrame()));
34 }
35
36 content::WebContents* GetActiveWebContents() {
37 return browser()->tab_strip_model()->GetActiveWebContents();
38 }
39
40 bool IsPluginPeripheral(const char* element_id) {
41 std::string script = base::StringPrintf(
42 "var plugin = window.document.getElementById('%s');"
43 "if (plugin == undefined ||"
44 " (plugin.nodeName != 'OBJECT' && plugin.nodeName != 'EMBED')) {"
45 " window.domAutomationController.send(-1);"
Lei Zhang 2015/04/22 23:35:20 and return here, since we already called send() ?
Lei Zhang 2015/04/22 23:35:20 Aren't you trying to extract a bool? i.e. the retu
tommycli 2015/04/23 20:11:22 Well I was using -1 as a sentinel value. It would
tommycli 2015/04/23 20:11:23 Done.
46 "}"
47 "function handleEvent() {"
48 " if (event.data.isPeripheral != undefined &&"
49 " event.data.source == 'getPeripheralStatusResponse') {"
50 " window.domAutomationController.send(event.data.isPeripheral);"
51 " plugin.removeEventListener('message', handleEvent);"
52 " }"
53 "}"
54 "if (plugin.postMessage == undefined) {"
55 " window.domAutomationController.send(true);"
56 "} else {"
57 " plugin.addEventListener('message', handleEvent);"
58 " plugin.postMessage('getPeripheralStatus');"
59 "}",
60 element_id);
61
62 bool result = false;
63 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(GetActiveWebContents(),
64 script, &result));
65 return result;
66 }
67
68 // This sends a simulated click at |point| and waits (by polling) for the
Lei Zhang 2015/04/22 23:35:20 (by polling) .... not any more!
tommycli 2015/04/23 20:11:23 Done.
69 // plugin to be marked essential and run. Simply cycling the message loops
70 // does not work, as the renderer process must mark the plugin essential.
71 void SimulateClickAndAwaitMarkedEssential(const char* element_id,
72 const gfx::Point& point) {
73 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */,
74 blink::WebMouseEvent::ButtonLeft, point);
75
76 std::string script = base::StringPrintf(
77 "var plugin = window.document.getElementById('%s');"
78 "if (plugin == undefined ||"
79 " (plugin.nodeName != 'OBJECT' && plugin.nodeName != 'EMBED')) {"
80 " window.domAutomationController.send(-1);"
Lei Zhang 2015/04/22 23:35:20 Same issue as the JS in IsPluginPeripheral().
tommycli 2015/04/23 20:11:23 Done.
81 "}"
82 "function handleEvent() {"
83 " if (event.data.isPeripheral == false) {"
84 " window.domAutomationController.send(false);"
85 " plugin.removeEventListener('message', handleEvent);"
86 " }"
87 "}"
88 "plugin.addEventListener('message', handleEvent);"
89 "if (plugin.postMessage != undefined) {"
90 " plugin.postMessage('getPeripheralStatus');"
91 "}",
92 element_id);
93
94 bool result = false;
95 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(GetActiveWebContents(),
96 script, &result));
97 EXPECT_FALSE(result);
98 }
99 };
100
101 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) {
102 LoadHTML(
103 "<object id='plugin' data='fake.swf' "
104 "type='application/x-ppapi-tests' width='400' height='100'></object>");
105 EXPECT_FALSE(IsPluginPeripheral("plugin"));
106 }
107
108 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) {
109 LoadHTML(
110 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
111 "type='application/x-ppapi-tests' width='400' height='100'></object>");
112 EXPECT_TRUE(IsPluginPeripheral("plugin"));
113
114 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50));
115 }
116
117 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) {
118 LoadHTML(
119 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
120 "type='application/x-ppapi-tests' width='400' height='500'></object>");
121 EXPECT_FALSE(IsPluginPeripheral("plugin"));
122 }
123
124 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargePluginsUsePosters) {
125 LoadHTML(
126 "<object id='plugin' type='application/x-ppapi-tests' "
127 " width='400' height='500'>"
128 " <param name='poster' value='snapshot1x.png 1x, snapshot2x.png 2x' />"
129 "</object>");
130 EXPECT_TRUE(IsPluginPeripheral("plugin"));
131 }
132
133 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) {
134 LoadHTML(
135 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' "
136 "type='application/x-ppapi-tests' width='400' height='100'></object>"
137 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' "
138 "type='application/x-ppapi-tests' width='400' height='500'></object>");
139 EXPECT_FALSE(IsPluginPeripheral("plugin1"));
140 EXPECT_FALSE(IsPluginPeripheral("plugin2"));
141 }
142
143 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) {
144 LoadHTML(
145 "<div style='width: 100px; height: 100px; overflow: hidden;'>"
146 " <object id='plugin' data='http://otherorigin.com/fake.swf' "
147 " type='application/x-ppapi-tests' width='400' height='500'></object>"
148 "</div>");
149 EXPECT_TRUE(IsPluginPeripheral("plugin"));
150 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser_tests.isolate » ('j') | ppapi/tests/power_saver_test_plugin.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698