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

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.h » ('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
15 class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest {
16 public:
17 void SetUpCommandLine(base::CommandLine* command_line) override {
18 command_line->AppendSwitch(switches::kEnablePluginPowerSaver);
19
20 ppapi::RegisterTestLibrary(command_line);
21 }
22
23 protected:
24 void LoadHTML(const char* html) {
25 std::string url_str = "data:text/html;charset=utf-8,";
26 url_str.append(html);
27 ui_test_utils::NavigateToURL(browser(), GURL(url_str));
28 }
29
30 bool IsPluginPeripheral(const char* element_id) {
31 std::string script = base::StringPrintf(
32 "var plugin = window.document.getElementById('%s');"
33 "if (plugin != undefined) {"
34 " var b = plugin.postMessage == undefined || plugin.isPeripheral();"
35 " window.domAutomationController.send(b);"
36 "}",
37 element_id);
38
39 bool result = false;
40 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
41 browser()->tab_strip_model()->GetActiveWebContents(), script, &result));
42 return result;
43 }
44 };
45
46 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) {
47 LoadHTML(
48 "<object id='plugin' data='fake.swf' "
49 "type='application/x-ppapi-tests' width='400' height='100'></object>");
50 EXPECT_FALSE(IsPluginPeripheral("plugin"));
51 }
52
53 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) {
54 LoadHTML(
55 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
56 "type='application/x-ppapi-tests' width='400' height='100'></object>");
57 EXPECT_TRUE(IsPluginPeripheral("plugin"));
58 }
59
60 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) {
61 LoadHTML(
62 "<object id='plugin' data='http://otherorigin.com/fake.swf' "
63 "type='application/x-ppapi-tests' width='400' height='500'></object>");
64 EXPECT_FALSE(IsPluginPeripheral("plugin"));
65 }
66
67 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) {
68 LoadHTML(
69 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' "
70 "type='application/x-ppapi-tests' width='400' height='100'></object>"
71 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' "
72 "type='application/x-ppapi-tests' width='400' height='500'></object>");
73 EXPECT_FALSE(IsPluginPeripheral("plugin1"));
74 EXPECT_FALSE(IsPluginPeripheral("plugin2"));
75 }
76
77 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) {
78 LoadHTML(
79 "<div style='width: 100px; height: 100px; overflow: hidden;'>"
80 " <object id='plugin' data='http://otherorigin.com/fake.swf' "
81 " type='application/x-ppapi-tests' width='400' height='500'></object>"
82 "</div>");
83 EXPECT_TRUE(IsPluginPeripheral("plugin"));
84 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_tests.gypi » ('j') | content/renderer/pepper/message_channel.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698