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 "components/ui/zoom/zoom_controller.h" | 13 #include "components/ui/zoom/zoom_controller.h" |
14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
15 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/ppapi_test_utils.h" | 16 #include "content/public/test/ppapi_test_utils.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | |
18 #include "net/test/embedded_test_server/http_request.h" | |
19 #include "net/test/embedded_test_server/http_response.h" | |
17 #include "ppapi/shared_impl/ppapi_switches.h" | 20 #include "ppapi/shared_impl/ppapi_switches.h" |
18 #include "third_party/WebKit/public/web/WebInputEvent.h" | 21 #include "third_party/WebKit/public/web/WebInputEvent.h" |
19 #include "ui/base/window_open_disposition.h" | 22 #include "ui/base/window_open_disposition.h" |
20 #include "ui/gfx/geometry/point.h" | 23 #include "ui/gfx/geometry/point.h" |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 std::string RunTestScript(base::StringPiece test_script, | 27 std::string RunTestScript(base::StringPiece test_script, |
25 content::WebContents* contents, | 28 content::WebContents* contents, |
26 const std::string& element_id) { | 29 const std::string& element_id) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 "}" | 88 "}" |
86 "plugin.addEventListener('message', handleEvent);" | 89 "plugin.addEventListener('message', handleEvent);" |
87 "if (plugin.postMessage !== undefined) {" | 90 "if (plugin.postMessage !== undefined) {" |
88 " plugin.postMessage('getPowerSaverStatus');" | 91 " plugin.postMessage('getPowerSaverStatus');" |
89 "}", | 92 "}", |
90 contents, element_id); | 93 contents, element_id); |
91 EXPECT_EQ("essential", result); | 94 EXPECT_EQ("essential", result); |
92 EXPECT_TRUE(PluginLoaded(contents, element_id)); | 95 EXPECT_TRUE(PluginLoaded(contents, element_id)); |
93 } | 96 } |
94 | 97 |
98 static scoped_ptr<net::test_server::HttpResponse> RespondWithHTML( | |
99 const char* html, | |
groby-ooo-7-16
2015/09/12 01:24:00
Why const char? (You'll pass on a string ref, you
tommycli
2015/09/14 20:23:56
Done.
| |
100 const net::test_server::HttpRequest& request) { | |
101 scoped_ptr<net::test_server::BasicHttpResponse> response( | |
102 new net::test_server::BasicHttpResponse()); | |
103 response->set_content_type("text/html"); | |
104 response->set_content(html); | |
105 return response.Pass(); | |
106 } | |
107 | |
95 } // namespace | 108 } // namespace |
96 | 109 |
97 class PluginPowerSaverBrowserTest : public InProcessBrowserTest { | 110 class PluginPowerSaverBrowserTest : public InProcessBrowserTest { |
98 public: | 111 public: |
112 void SetUpOnMainThread() override { | |
113 InProcessBrowserTest::SetUpOnMainThread(); | |
114 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | |
115 } | |
116 | |
99 void SetUpCommandLine(base::CommandLine* command_line) override { | 117 void SetUpCommandLine(base::CommandLine* command_line) override { |
100 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); | 118 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); |
101 command_line->AppendSwitch(switches::kEnablePepperTesting); | 119 command_line->AppendSwitch(switches::kEnablePepperTesting); |
102 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); | 120 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); |
103 command_line->AppendSwitchASCII( | 121 command_line->AppendSwitchASCII( |
104 switches::kOverridePluginPowerSaverForTesting, "ignore-list"); | 122 switches::kOverridePluginPowerSaverForTesting, "ignore-list"); |
105 | 123 |
106 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); | 124 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); |
107 } | 125 } |
108 | 126 |
109 protected: | 127 protected: |
110 void LoadHTML(const char* html) { | 128 void LoadHTML(const char* html) { |
111 std::string url_str = "data:text/html;charset=utf-8,"; | 129 ASSERT_TRUE(embedded_test_server()->Started()); |
112 url_str.append(html); | 130 embedded_test_server()->RegisterRequestHandler( |
113 ui_test_utils::NavigateToURL(browser(), GURL(url_str)); | 131 base::Bind(&RespondWithHTML, html)); |
132 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); | |
114 EXPECT_TRUE(content::WaitForRenderFrameReady( | 133 EXPECT_TRUE(content::WaitForRenderFrameReady( |
115 GetActiveWebContents()->GetMainFrame())); | 134 GetActiveWebContents()->GetMainFrame())); |
116 } | 135 } |
117 | 136 |
118 content::WebContents* GetActiveWebContents() { | 137 content::WebContents* GetActiveWebContents() { |
119 return browser()->tab_strip_model()->GetActiveWebContents(); | 138 return browser()->tab_strip_model()->GetActiveWebContents(); |
120 } | 139 } |
121 | 140 |
122 // This sends a simulated click at |point| and waits for test plugin to send | 141 // This sends a simulated click at |point| and waits for test plugin to send |
123 // a status message indicating that it is essential. The test plugin sends a | 142 // a status message indicating that it is essential. The test plugin sends a |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 269 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
251 " type='application/x-ppapi-tests' width='400' height='80'></object>"); | 270 " type='application/x-ppapi-tests' width='400' height='80'></object>"); |
252 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 271 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
253 | 272 |
254 std::string script = "window.document.getElementById('plugin').height = 400;"; | 273 std::string script = "window.document.getElementById('plugin').height = 400;"; |
255 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); | 274 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); |
256 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 275 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
257 } | 276 } |
258 | 277 |
259 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { | 278 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, BackgroundTabPlugins) { |
260 std::string url_str = | 279 const char html[] = |
261 "data:text/html;charset=utf-8," | 280 "<object id='same_origin' data='fake.swf' " |
262 "<object id='same_origin' type='application/x-ppapi-tests'></object>" | 281 " type='application/x-ppapi-tests'></object>" |
263 "<object id='small_cross_origin' data='http://otherorigin.com/fake1.swf' " | 282 "<object id='small_cross_origin' data='http://otherorigin.com/fake1.swf' " |
264 " type='application/x-ppapi-tests' width='400' height='100'></object>"; | 283 " type='application/x-ppapi-tests' width='400' height='100'></object>"; |
284 embedded_test_server()->RegisterRequestHandler( | |
285 base::Bind(&RespondWithHTML, html)); | |
265 ui_test_utils::NavigateToURLWithDisposition( | 286 ui_test_utils::NavigateToURLWithDisposition( |
266 browser(), GURL(url_str), NEW_BACKGROUND_TAB, | 287 browser(), embedded_test_server()->base_url(), NEW_BACKGROUND_TAB, |
267 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 288 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
268 | 289 |
269 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 290 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
270 content::WebContents* background_contents = | 291 content::WebContents* background_contents = |
271 browser()->tab_strip_model()->GetWebContentsAt(1); | 292 browser()->tab_strip_model()->GetWebContentsAt(1); |
272 EXPECT_TRUE( | 293 EXPECT_TRUE( |
273 content::WaitForRenderFrameReady(background_contents->GetMainFrame())); | 294 content::WaitForRenderFrameReady(background_contents->GetMainFrame())); |
274 | 295 |
275 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); | 296 EXPECT_FALSE(PluginLoaded(background_contents, "same_origin")); |
276 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); | 297 EXPECT_FALSE(PluginLoaded(background_contents, "small_cross_origin")); |
277 | 298 |
278 browser()->tab_strip_model()->SelectNextTab(); | 299 browser()->tab_strip_model()->SelectNextTab(); |
279 EXPECT_EQ(background_contents, GetActiveWebContents()); | 300 EXPECT_EQ(background_contents, GetActiveWebContents()); |
280 | 301 |
281 VerifyPluginMarkedEssential(background_contents, "same_origin"); | 302 VerifyPluginMarkedEssential(background_contents, "same_origin"); |
282 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); | 303 VerifyPluginIsThrottled(background_contents, "small_cross_origin"); |
283 } | 304 } |
284 | 305 |
285 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { | 306 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { |
286 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) | 307 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) |
287 ->SetZoomLevel(4.0); | 308 ->SetZoomLevel(4.0); |
288 LoadHTML( | 309 LoadHTML( |
289 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 310 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
290 " type='application/x-ppapi-tests' width='400' height='200'>" | 311 " type='application/x-ppapi-tests' width='400' height='200'>" |
291 "</object>"); | 312 "</object>"); |
292 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 313 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
293 } | 314 } |
OLD | NEW |