| Index: chrome/browser/plugins/plugin_power_saver_browsertest.cc
|
| diff --git a/chrome/browser/plugins/plugin_power_saver_browsertest.cc b/chrome/browser/plugins/plugin_power_saver_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a50b2bba93a459049ea762be394fd1f420380e34
|
| --- /dev/null
|
| +++ b/chrome/browser/plugins/plugin_power_saver_browsertest.cc
|
| @@ -0,0 +1,84 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/command_line.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/common/chrome_switches.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "chrome/test/base/ui_test_utils.h"
|
| +#include "content/public/test/browser_test_utils.h"
|
| +#include "content/public/test/ppapi_test_utils.h"
|
| +
|
| +class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest {
|
| + public:
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + command_line->AppendSwitch(switches::kEnablePluginPowerSaver);
|
| +
|
| + ppapi::RegisterTestLibrary(command_line);
|
| + }
|
| +
|
| + protected:
|
| + void LoadHTML(const char* html) {
|
| + std::string url_str = "data:text/html;charset=utf-8,";
|
| + url_str.append(html);
|
| + ui_test_utils::NavigateToURL(browser(), GURL(url_str));
|
| + }
|
| +
|
| + bool IsPluginPeripheral(const char* element_id) {
|
| + std::string script = base::StringPrintf(
|
| + "var plugin = window.document.getElementById('%s');"
|
| + "if (plugin != undefined) {"
|
| + " var b = plugin.postMessage == undefined || plugin.isPeripheral();"
|
| + " window.domAutomationController.send(b);"
|
| + "}",
|
| + element_id);
|
| +
|
| + bool result = false;
|
| + EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
|
| + browser()->tab_strip_model()->GetActiveWebContents(), script, &result));
|
| + return result;
|
| + }
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) {
|
| + LoadHTML(
|
| + "<object id='plugin' data='fake.swf' "
|
| + "type='application/x-ppapi-tests' width='400' height='100'></object>");
|
| + EXPECT_FALSE(IsPluginPeripheral("plugin"));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) {
|
| + LoadHTML(
|
| + "<object id='plugin' data='http://otherorigin.com/fake.swf' "
|
| + "type='application/x-ppapi-tests' width='400' height='100'></object>");
|
| + EXPECT_TRUE(IsPluginPeripheral("plugin"));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) {
|
| + LoadHTML(
|
| + "<object id='plugin' data='http://otherorigin.com/fake.swf' "
|
| + "type='application/x-ppapi-tests' width='400' height='500'></object>");
|
| + EXPECT_FALSE(IsPluginPeripheral("plugin"));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) {
|
| + LoadHTML(
|
| + "<object id='plugin1' data='http://otherorigin.com/fake1.swf' "
|
| + "type='application/x-ppapi-tests' width='400' height='100'></object>"
|
| + "<object id='plugin2' data='http://otherorigin.com/fake2.swf' "
|
| + "type='application/x-ppapi-tests' width='400' height='500'></object>");
|
| + EXPECT_FALSE(IsPluginPeripheral("plugin1"));
|
| + EXPECT_FALSE(IsPluginPeripheral("plugin2"));
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) {
|
| + LoadHTML(
|
| + "<div style='width: 100px; height: 100px; overflow: hidden;'>"
|
| + " <object id='plugin' data='http://otherorigin.com/fake.swf' "
|
| + " type='application/x-ppapi-tests' width='400' height='500'></object>"
|
| + "</div>");
|
| + EXPECT_TRUE(IsPluginPeripheral("plugin"));
|
| +}
|
|
|