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

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') | content/renderer/pepper/message_channel.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 "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::RegisterTestPlugin(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 EXPECT_TRUE(content::WaitForRenderFrameReady(
32 GetActiveWebContents()->GetMainFrame()));
33 }
34
35 content::WebContents* GetActiveWebContents() {
36 return browser()->tab_strip_model()->GetActiveWebContents();
37 }
38
39 bool IsPluginPeripheral(const char* element_id) {
40 std::string script = base::StringPrintf(
41 "var plugin = window.document.getElementById('%s');"
42 "if (plugin != undefined) {"
43 " var b = plugin.postMessage == undefined || plugin.isPeripheral();"
44 " window.domAutomationController.send(b);"
45 "}",
46 element_id);
47
48 bool result = false;
49 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(GetActiveWebContents(),
50 script, &result));
51 return result;
52 }
53
54 // This sends a simulated click at |point| and waits (by polling) for the
55 // plugin to be marked essential and run. Simply cycling the message loops
56 // does not work, as the renderer process must mark the plugin essential.
57 void SimulateClickAndAwaitMarkedEssential(const char* element_id,
58 const gfx::Point& point) {
59 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */,
60 blink::WebMouseEvent::ButtonLeft,
61 point);
62
63 std::string script = base::StringPrintf(
64 "function checkEssential() {"
65 " var plugin = window.document.getElementById('%s');"
66 " if (plugin == undefined) {"
67 " window.domAutomationController.send(false);"
68 " return;"
69 " }"
70 " if (plugin.postMessage != undefined && !plugin.isPeripheral()) {"
71 " window.domAutomationController.send(true);"
72 " } else {"
73 " setTimeout(checkEssential, 50);"
74 " }"
75 "}"
76 "checkEssential();",
77 element_id);
78
79 bool result = false;
80 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(GetActiveWebContents(),
81 script, &result));
82 EXPECT_TRUE(result);
83 }
84 };
85
86 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) {
87 LoadHTML(
88 "<object id='plugin' data='fake.swf' "
89 "type='application/x-ppapi-tests' width='400' height='100'></object>");
90 EXPECT_FALSE(IsPluginPeripheral("plugin"));
91 }
92
93 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) {
94 LoadHTML(
95 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
96 "type='application/x-ppapi-tests' width='400' height='100'></object>");
97 EXPECT_TRUE(IsPluginPeripheral("plugin"));
98
99 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50));
100 }
101
102 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) {
103 LoadHTML(
104 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
105 "type='application/x-ppapi-tests' width='400' height='500'></object>");
106 EXPECT_FALSE(IsPluginPeripheral("plugin"));
107 }
108
109 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargePluginsUsePosters) {
110 LoadHTML(
111 "<object id='plugin' type='application/x-ppapi-tests' "
112 " width='400' height='500'>"
113 " <param name='poster' value='snapshot1x.png 1x, snapshot2x.png 2x' />"
114 "</object>");
115 EXPECT_TRUE(IsPluginPeripheral("plugin"));
116 }
117
118 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) {
119 LoadHTML(
120 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' "
121 "type='application/x-ppapi-tests' width='400' height='100'></object>"
122 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' "
123 "type='application/x-ppapi-tests' width='400' height='500'></object>");
124 EXPECT_FALSE(IsPluginPeripheral("plugin1"));
125 EXPECT_FALSE(IsPluginPeripheral("plugin2"));
126 }
127
128 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) {
129 LoadHTML(
130 "<div style='width: 100px; height: 100px; overflow: hidden;'>"
131 " <object id='plugin' data='http://otherorigin.com/fake.swf' "
132 " type='application/x-ppapi-tests' width='400' height='500'></object>"
133 "</div>");
134 EXPECT_TRUE(IsPluginPeripheral("plugin"));
135 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/renderer/pepper/message_channel.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698