| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/string_piece.h" | 6 #include "base/strings/string_piece.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 12 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "content/public/common/content_switches.h" |
| 13 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
| 14 #include "content/public/test/ppapi_test_utils.h" | 15 #include "content/public/test/ppapi_test_utils.h" |
| 15 #include "ppapi/shared_impl/ppapi_switches.h" | 16 #include "ppapi/shared_impl/ppapi_switches.h" |
| 16 #include "third_party/WebKit/public/web/WebInputEvent.h" | 17 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 17 #include "ui/base/window_open_disposition.h" | 18 #include "ui/base/window_open_disposition.h" |
| 18 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 std::string RunTestScript(base::StringPiece test_script, | 23 std::string RunTestScript(base::StringPiece test_script, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 EXPECT_TRUE(PluginLoaded(contents, element_id)); | 91 EXPECT_TRUE(PluginLoaded(contents, element_id)); |
| 91 } | 92 } |
| 92 | 93 |
| 93 } // namespace | 94 } // namespace |
| 94 | 95 |
| 95 class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest { | 96 class PluginPowerSaverBrowserTest : virtual public InProcessBrowserTest { |
| 96 public: | 97 public: |
| 97 void SetUpCommandLine(base::CommandLine* command_line) override { | 98 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 98 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); | 99 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); |
| 99 command_line->AppendSwitch(switches::kEnablePepperTesting); | 100 command_line->AppendSwitch(switches::kEnablePepperTesting); |
| 101 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); |
| 100 | 102 |
| 101 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); | 103 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 protected: | 106 protected: |
| 105 void LoadHTML(const char* html) { | 107 void LoadHTML(const char* html) { |
| 106 std::string url_str = "data:text/html;charset=utf-8,"; | 108 std::string url_str = "data:text/html;charset=utf-8,"; |
| 107 url_str.append(html); | 109 url_str.append(html); |
| 108 ui_test_utils::NavigateToURL(browser(), GURL(url_str)); | 110 ui_test_utils::NavigateToURL(browser(), GURL(url_str)); |
| 109 EXPECT_TRUE(content::WaitForRenderFrameReady( | 111 EXPECT_TRUE(content::WaitForRenderFrameReady( |
| 110 GetActiveWebContents()->GetMainFrame())); | 112 GetActiveWebContents()->GetMainFrame())); |
| 111 } | 113 } |
| 112 | 114 |
| 113 content::WebContents* GetActiveWebContents() { | 115 content::WebContents* GetActiveWebContents() { |
| 114 return browser()->tab_strip_model()->GetActiveWebContents(); | 116 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 // This sends a simulated click at |point| and waits for test plugin to send | 119 // This sends a simulated click at |point| and waits for test plugin to send |
| 118 // a status message indicating that it is essential. The test plugin sends a | 120 // a status message indicating that it is essential. The test plugin sends a |
| 119 // status message during: | 121 // status message during: |
| 120 // - Plugin creation, to handle a plugin freshly created from a poster. | 122 // - Plugin creation, to handle a plugin freshly created from a poster. |
| 121 // - Peripheral status change. | 123 // - Peripheral status change. |
| 122 // - In response to the explicit 'getPowerSaverStatus' request, in case the | 124 // - In response to the explicit 'getPowerSaverStatus' request, in case the |
| 123 // test has missed the above two events. | 125 // test has missed the above two events. |
| 124 void SimulateClickAndAwaitMarkedEssential(const char* element_id, | 126 void SimulateClickAndAwaitMarkedEssential(const char* element_id, |
| 125 const gfx::Point& point) { | 127 const gfx::Point& point) { |
| 128 // Waits for the placeholder to be ready to be clicked first. |
| 129 std::string result = RunTestScript( |
| 130 "function handleEvent(event) {" |
| 131 " if (event.data === 'placeholderLoaded') {" |
| 132 " window.domAutomationController.send('ready');" |
| 133 " plugin.removeEventListener('message', handleEvent);" |
| 134 " }" |
| 135 "}" |
| 136 "plugin.addEventListener('message', handleEvent);" |
| 137 "if (plugin.hasAttribute('placeholderLoaded')) {" |
| 138 " window.domAutomationController.send('ready');" |
| 139 " plugin.removeEventListener('message', handleEvent);" |
| 140 "}", |
| 141 GetActiveWebContents(), element_id); |
| 142 EXPECT_EQ("ready", result); |
| 143 |
| 126 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, | 144 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, |
| 127 blink::WebMouseEvent::ButtonLeft, point); | 145 blink::WebMouseEvent::ButtonLeft, point); |
| 128 | 146 |
| 129 VerifyPluginMarkedEssential(GetActiveWebContents(), element_id); | 147 VerifyPluginMarkedEssential(GetActiveWebContents(), element_id); |
| 130 } | 148 } |
| 131 }; | 149 }; |
| 132 | 150 |
| 133 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { | 151 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { |
| 134 LoadHTML( | 152 LoadHTML( |
| 135 "<object id='plugin' data='fake.swf' " | 153 "<object id='plugin' data='fake.swf' " |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 " width='400' height='500'" | 192 " width='400' height='500'" |
| 175 " poster='snapshot1x.png 1x, snapshot2x.png 2x'></embed>"); | 193 " poster='snapshot1x.png 1x, snapshot2x.png 2x'></embed>"); |
| 176 | 194 |
| 177 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_src")); | 195 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_src")); |
| 178 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_srcset")); | 196 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_srcset")); |
| 179 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_legacy_syntax")); | 197 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_legacy_syntax")); |
| 180 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_src")); | 198 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_src")); |
| 181 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_srcset")); | 199 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_srcset")); |
| 182 } | 200 } |
| 183 | 201 |
| 184 // flaky: crbug.com/481687 | |
| 185 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, | 202 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, |
| 186 DISABLED_PluginMarkedEssentialAfterPosterClicked) { | 203 PluginMarkedEssentialAfterPosterClicked) { |
| 187 LoadHTML( | 204 LoadHTML( |
| 188 "<object id='plugin' type='application/x-ppapi-tests' " | 205 "<object id='plugin' type='application/x-ppapi-tests' " |
| 189 " width='400' height='100' poster='snapshot1x.png'></object>"); | 206 " width='400' height='100' poster='snapshot1x.png'></object>"); |
| 190 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin")); | 207 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin")); |
| 191 | 208 |
| 192 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 209 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
| 193 } | 210 } |
| 194 | 211 |
| 195 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { | 212 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { |
| 196 LoadHTML( | 213 LoadHTML( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 248 |
| 232 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); | 249 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); |
| 233 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); | 250 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); |
| 234 | 251 |
| 235 browser()->tab_strip_model()->SelectNextTab(); | 252 browser()->tab_strip_model()->SelectNextTab(); |
| 236 EXPECT_EQ(background_contents, GetActiveWebContents()); | 253 EXPECT_EQ(background_contents, GetActiveWebContents()); |
| 237 | 254 |
| 238 VerifyPluginMarkedEssential(background_contents, "same_origin"); | 255 VerifyPluginMarkedEssential(background_contents, "same_origin"); |
| 239 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); | 256 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); |
| 240 } | 257 } |
| OLD | NEW |