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 <string> |
| 6 |
5 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" |
6 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
7 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_window.h" |
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
10 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/test_switches.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
13 #include "components/ui/zoom/zoom_controller.h" | 18 #include "components/ui/zoom/zoom_controller.h" |
| 19 #include "content/public/browser/readback_types.h" |
| 20 #include "content/public/browser/render_frame_host.h" |
| 21 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/render_widget_host.h" |
14 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
15 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/ppapi_test_utils.h" | 25 #include "content/public/test/ppapi_test_utils.h" |
17 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
18 #include "net/test/embedded_test_server/http_request.h" | 27 #include "net/test/embedded_test_server/http_request.h" |
19 #include "net/test/embedded_test_server/http_response.h" | 28 #include "net/test/embedded_test_server/http_response.h" |
20 #include "ppapi/shared_impl/ppapi_switches.h" | 29 #include "ppapi/shared_impl/ppapi_switches.h" |
21 #include "third_party/WebKit/public/web/WebInputEvent.h" | 30 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" |
22 #include "ui/base/window_open_disposition.h" | 32 #include "ui/base/window_open_disposition.h" |
| 33 #include "ui/gfx/codec/png_codec.h" |
23 #include "ui/gfx/geometry/point.h" | 34 #include "ui/gfx/geometry/point.h" |
| 35 #include "ui/gfx/screen.h" |
24 | 36 |
25 namespace { | 37 namespace { |
26 | 38 |
| 39 // Use fixed browser dimensions for pixel tests. |
| 40 const int kBrowserWidth = 600; |
| 41 const int kBrowserHeight = 700; |
| 42 |
| 43 // Compare only a portion of the snapshots, as different platforms will |
| 44 // capture different sized snapshots (due to differences in browser chrome). |
| 45 const int kComparisonWidth = 500; |
| 46 const int kComparisonHeight = 600; |
| 47 |
| 48 // Different platforms have slightly different pixel output, due to different |
| 49 // graphics implementations. Slightly different pixels (in BGR space) are still |
| 50 // counted as a matching pixel by this simple manhattan distance threshold. |
| 51 const int kPixelManhattanDistanceTolerance = 8; |
| 52 |
27 std::string RunTestScript(base::StringPiece test_script, | 53 std::string RunTestScript(base::StringPiece test_script, |
28 content::WebContents* contents, | 54 content::WebContents* contents, |
29 const std::string& element_id) { | 55 const std::string& element_id) { |
30 std::string script = base::StringPrintf( | 56 std::string script = base::StringPrintf( |
31 "var plugin = window.document.getElementById('%s');" | 57 "var plugin = window.document.getElementById('%s');" |
32 "if (plugin === undefined ||" | 58 "if (plugin === undefined ||" |
33 " (plugin.nodeName !== 'OBJECT' && plugin.nodeName !== 'EMBED')) {" | 59 " (plugin.nodeName !== 'OBJECT' && plugin.nodeName !== 'EMBED')) {" |
34 " window.domAutomationController.send('error');" | 60 " window.domAutomationController.send('error');" |
35 "} else {" | 61 "} else {" |
36 " %s" | 62 " %s" |
37 "}", | 63 "}", |
38 element_id.c_str(), test_script.data()); | 64 element_id.c_str(), test_script.data()); |
39 std::string result; | 65 std::string result; |
40 EXPECT_TRUE( | 66 EXPECT_TRUE( |
41 content::ExecuteScriptAndExtractString(contents, script, &result)); | 67 content::ExecuteScriptAndExtractString(contents, script, &result)); |
42 return result; | 68 return result; |
43 } | 69 } |
44 | 70 |
45 // This also tests that we have JavaScript access to the underlying plugin. | 71 // This also tests that we have JavaScript access to the underlying plugin. |
46 bool PluginLoaded(content::WebContents* contents, const char* element_id) { | 72 bool PluginLoaded(content::WebContents* contents, |
| 73 const std::string& element_id) { |
47 std::string result = RunTestScript( | 74 std::string result = RunTestScript( |
48 "if (plugin.postMessage === undefined) {" | 75 "if (plugin.postMessage === undefined) {" |
49 " window.domAutomationController.send('poster_only');" | 76 " window.domAutomationController.send('poster_only');" |
50 "} else {" | 77 "} else {" |
51 " window.domAutomationController.send('plugin_loaded');" | 78 " window.domAutomationController.send('plugin_loaded');" |
52 "}", | 79 "}", |
53 contents, element_id); | 80 contents, element_id); |
54 EXPECT_NE("error", result); | 81 EXPECT_NE("error", result); |
55 return result == "plugin_loaded"; | 82 return result == "plugin_loaded"; |
56 } | 83 } |
57 | 84 |
| 85 // Blocks until the placeholder is ready. |
| 86 void WaitForPlaceholderReady(content::WebContents* contents, |
| 87 const std::string& element_id) { |
| 88 std::string result = RunTestScript( |
| 89 "function handleEvent(event) {" |
| 90 " if (event.data === 'placeholderReady') {" |
| 91 " window.domAutomationController.send('ready');" |
| 92 " plugin.removeEventListener('message', handleEvent);" |
| 93 " }" |
| 94 "}" |
| 95 "plugin.addEventListener('message', handleEvent);" |
| 96 "if (plugin.hasAttribute('placeholderReady')) {" |
| 97 " window.domAutomationController.send('ready');" |
| 98 " plugin.removeEventListener('message', handleEvent);" |
| 99 "}", |
| 100 contents, element_id); |
| 101 ASSERT_EQ("ready", result); |
| 102 } |
| 103 |
58 // Also waits for the placeholder UI overlay to finish loading. | 104 // Also waits for the placeholder UI overlay to finish loading. |
59 void VerifyPluginIsThrottled(content::WebContents* contents, | 105 void VerifyPluginIsThrottled(content::WebContents* contents, |
60 const char* element_id) { | 106 const std::string& element_id) { |
61 std::string result = RunTestScript( | 107 std::string result = RunTestScript( |
62 "function handleEvent(event) {" | 108 "function handleEvent(event) {" |
63 " if (event.data.isPeripheral && event.data.isThrottled && " | 109 " if (event.data.isPeripheral && event.data.isThrottled && " |
64 " event.data.isHiddenForPlaceholder) {" | 110 " event.data.isHiddenForPlaceholder) {" |
65 " window.domAutomationController.send('throttled');" | 111 " window.domAutomationController.send('throttled');" |
66 " plugin.removeEventListener('message', handleEvent);" | 112 " plugin.removeEventListener('message', handleEvent);" |
67 " }" | 113 " }" |
68 "}" | 114 "}" |
69 "plugin.addEventListener('message', handleEvent);" | 115 "plugin.addEventListener('message', handleEvent);" |
70 "if (plugin.postMessage !== undefined) {" | 116 "if (plugin.postMessage !== undefined) {" |
71 " plugin.postMessage('getPowerSaverStatus');" | 117 " plugin.postMessage('getPowerSaverStatus');" |
72 "}", | 118 "}", |
73 contents, element_id); | 119 contents, element_id); |
74 EXPECT_EQ("throttled", result); | 120 EXPECT_EQ("throttled", result); |
75 | 121 |
76 // Page should continue to have JavaScript access to all throttled plugins. | 122 // Page should continue to have JavaScript access to all throttled plugins. |
77 EXPECT_TRUE(PluginLoaded(contents, element_id)); | 123 EXPECT_TRUE(PluginLoaded(contents, element_id)); |
| 124 |
| 125 WaitForPlaceholderReady(contents, element_id); |
78 } | 126 } |
79 | 127 |
80 void VerifyPluginMarkedEssential(content::WebContents* contents, | 128 void VerifyPluginMarkedEssential(content::WebContents* contents, |
81 const char* element_id) { | 129 const std::string& element_id) { |
82 std::string result = RunTestScript( | 130 std::string result = RunTestScript( |
83 "function handleEvent(event) {" | 131 "function handleEvent(event) {" |
84 " if (event.data.isPeripheral === false) {" | 132 " if (event.data.isPeripheral === false) {" |
85 " window.domAutomationController.send('essential');" | 133 " window.domAutomationController.send('essential');" |
86 " plugin.removeEventListener('message', handleEvent);" | 134 " plugin.removeEventListener('message', handleEvent);" |
87 " }" | 135 " }" |
88 "}" | 136 "}" |
89 "plugin.addEventListener('message', handleEvent);" | 137 "plugin.addEventListener('message', handleEvent);" |
90 "if (plugin.postMessage !== undefined) {" | 138 "if (plugin.postMessage !== undefined) {" |
91 " plugin.postMessage('getPowerSaverStatus');" | 139 " plugin.postMessage('getPowerSaverStatus');" |
92 "}", | 140 "}", |
93 contents, element_id); | 141 contents, element_id); |
94 EXPECT_EQ("essential", result); | 142 EXPECT_EQ("essential", result); |
95 EXPECT_TRUE(PluginLoaded(contents, element_id)); | 143 EXPECT_TRUE(PluginLoaded(contents, element_id)); |
96 } | 144 } |
97 | 145 |
98 scoped_ptr<net::test_server::HttpResponse> RespondWithHTML( | 146 scoped_ptr<net::test_server::HttpResponse> RespondWithHTML( |
99 const std::string& html, | 147 const std::string& html, |
100 const net::test_server::HttpRequest& request) { | 148 const net::test_server::HttpRequest& request) { |
101 scoped_ptr<net::test_server::BasicHttpResponse> response( | 149 scoped_ptr<net::test_server::BasicHttpResponse> response( |
102 new net::test_server::BasicHttpResponse()); | 150 new net::test_server::BasicHttpResponse()); |
103 response->set_content_type("text/html"); | 151 response->set_content_type("text/html"); |
104 response->set_content(html); | 152 response->set_content(html); |
105 return response.Pass(); | 153 return response.Pass(); |
106 } | 154 } |
107 | 155 |
| 156 void VerifyVisualStateUpdated(const base::Closure& done_cb, |
| 157 bool visual_state_updated) { |
| 158 ASSERT_TRUE(visual_state_updated); |
| 159 done_cb.Run(); |
| 160 } |
| 161 |
| 162 bool SnapshotMatches(const base::FilePath& reference, const SkBitmap& bitmap) { |
| 163 if (bitmap.width() < kComparisonWidth || |
| 164 bitmap.height() < kComparisonHeight) { |
| 165 return false; |
| 166 } |
| 167 |
| 168 std::string reference_data; |
| 169 if (!base::ReadFileToString(reference, &reference_data)) |
| 170 return false; |
| 171 |
| 172 int w = 0; |
| 173 int h = 0; |
| 174 std::vector<unsigned char> decoded; |
| 175 if (!gfx::PNGCodec::Decode( |
| 176 reinterpret_cast<unsigned char*>(string_as_array(&reference_data)), |
| 177 reference_data.size(), gfx::PNGCodec::FORMAT_BGRA, &decoded, &w, |
| 178 &h)) { |
| 179 return false; |
| 180 } |
| 181 |
| 182 if (w < kComparisonWidth || h < kComparisonHeight) |
| 183 return false; |
| 184 |
| 185 int32_t* ref_pixels = reinterpret_cast<int32_t*>(vector_as_array(&decoded)); |
| 186 SkAutoLockPixels lock_image(bitmap); |
| 187 int32_t* pixels = static_cast<int32_t*>(bitmap.getPixels()); |
| 188 |
| 189 int stride = bitmap.rowBytes(); |
| 190 for (int y = 0; y < kComparisonHeight; ++y) { |
| 191 for (int x = 0; x < kComparisonWidth; ++x) { |
| 192 int32_t pixel = pixels[y * stride / sizeof(int32_t) + x]; |
| 193 int pixel_b = pixel & 0xFF; |
| 194 int pixel_g = (pixel >> 8) & 0xFF; |
| 195 int pixel_r = (pixel >> 16) & 0xFF; |
| 196 |
| 197 int32_t ref_pixel = ref_pixels[y * w + x]; |
| 198 int ref_pixel_b = ref_pixel & 0xFF; |
| 199 int ref_pixel_g = (ref_pixel >> 8) & 0xFF; |
| 200 int ref_pixel_r = (ref_pixel >> 16) & 0xFF; |
| 201 |
| 202 int manhattan_distance = abs(pixel_b - ref_pixel_b) + |
| 203 abs(pixel_g - ref_pixel_g) + |
| 204 abs(pixel_r - ref_pixel_r); |
| 205 |
| 206 if (manhattan_distance > kPixelManhattanDistanceTolerance) |
| 207 return false; |
| 208 } |
| 209 } |
| 210 |
| 211 return true; |
| 212 } |
| 213 |
| 214 // |snapshot_matches| is set to true if the snapshot matches the reference and |
| 215 // the test passes. Otherwise, set to false. |
| 216 void CompareSnapshotToReference(const base::FilePath& reference, |
| 217 bool* snapshot_matches, |
| 218 const base::Closure& done_cb, |
| 219 const SkBitmap& bitmap, |
| 220 content::ReadbackResponse response) { |
| 221 DCHECK(snapshot_matches); |
| 222 if (response != content::READBACK_SUCCESS) { |
| 223 *snapshot_matches = false; |
| 224 done_cb.Run(); |
| 225 return; |
| 226 } |
| 227 |
| 228 *snapshot_matches = SnapshotMatches(reference, bitmap); |
| 229 |
| 230 // When rebaselining the pixel test, the test will fail, and we will |
| 231 // overwrite the reference file. On the next try through, the test will then |
| 232 // pass, since we just overwrote the reference file. A bit wonky. |
| 233 if (!(*snapshot_matches) && |
| 234 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 235 switches::kRebaselinePixelTests)) { |
| 236 SkBitmap clipped_bitmap; |
| 237 bitmap.extractSubset(&clipped_bitmap, |
| 238 SkIRect::MakeWH(kComparisonWidth, kComparisonHeight)); |
| 239 std::vector<unsigned char> png_data; |
| 240 ASSERT_TRUE( |
| 241 gfx::PNGCodec::EncodeBGRASkBitmap(clipped_bitmap, false, &png_data)); |
| 242 ASSERT_EQ(static_cast<int>(png_data.size()), |
| 243 base::WriteFile(reference, reinterpret_cast<const char*>( |
| 244 vector_as_array(&png_data)), |
| 245 png_data.size())); |
| 246 } |
| 247 |
| 248 done_cb.Run(); |
| 249 } |
| 250 |
108 } // namespace | 251 } // namespace |
109 | 252 |
110 class PluginPowerSaverBrowserTest : public InProcessBrowserTest { | 253 class PluginPowerSaverBrowserTest : public InProcessBrowserTest { |
111 public: | 254 public: |
| 255 void SetUp() override { |
| 256 EnablePixelOutput(); |
| 257 InProcessBrowserTest::SetUp(); |
| 258 } |
| 259 |
112 void SetUpOnMainThread() override { | 260 void SetUpOnMainThread() override { |
113 InProcessBrowserTest::SetUpOnMainThread(); | 261 InProcessBrowserTest::SetUpOnMainThread(); |
114 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 262 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 263 |
| 264 embedded_test_server()->ServeFilesFromDirectory( |
| 265 ui_test_utils::GetTestFilePath( |
| 266 base::FilePath(FILE_PATH_LITERAL("plugin_power_saver")), |
| 267 base::FilePath())); |
115 } | 268 } |
116 | 269 |
117 void SetUpCommandLine(base::CommandLine* command_line) override { | 270 void SetUpCommandLine(base::CommandLine* command_line) override { |
118 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); | 271 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); |
119 command_line->AppendSwitch(switches::kEnablePepperTesting); | 272 command_line->AppendSwitch(switches::kEnablePepperTesting); |
120 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); | 273 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); |
121 command_line->AppendSwitchASCII( | 274 command_line->AppendSwitchASCII( |
122 switches::kOverridePluginPowerSaverForTesting, "ignore-list"); | 275 switches::kOverridePluginPowerSaverForTesting, "ignore-list"); |
123 | 276 |
124 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); | 277 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); |
125 } | 278 } |
126 | 279 |
127 protected: | 280 protected: |
128 void LoadHTML(const std::string& html) { | 281 void LoadHTML(const std::string& html) { |
| 282 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); |
| 283 gfx::Rect screen_bounds = |
| 284 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds(); |
| 285 ASSERT_GT(screen_bounds.width(), kBrowserWidth); |
| 286 ASSERT_GT(screen_bounds.height(), kBrowserHeight); |
| 287 browser()->window()->SetBounds(bounds); |
| 288 |
129 ASSERT_TRUE(embedded_test_server()->Started()); | 289 ASSERT_TRUE(embedded_test_server()->Started()); |
130 embedded_test_server()->RegisterRequestHandler( | 290 embedded_test_server()->RegisterRequestHandler( |
131 base::Bind(&RespondWithHTML, html)); | 291 base::Bind(&RespondWithHTML, html)); |
132 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); | 292 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); |
133 EXPECT_TRUE(content::WaitForRenderFrameReady( | 293 EXPECT_TRUE(content::WaitForRenderFrameReady( |
134 GetActiveWebContents()->GetMainFrame())); | 294 GetActiveWebContents()->GetMainFrame())); |
135 } | 295 } |
136 | 296 |
137 content::WebContents* GetActiveWebContents() { | 297 content::WebContents* GetActiveWebContents() { |
138 return browser()->tab_strip_model()->GetActiveWebContents(); | 298 return browser()->tab_strip_model()->GetActiveWebContents(); |
139 } | 299 } |
140 | 300 |
141 // This sends a simulated click at |point| and waits for test plugin to send | 301 // This sends a simulated click at |point| and waits for test plugin to send |
142 // a status message indicating that it is essential. The test plugin sends a | 302 // a status message indicating that it is essential. The test plugin sends a |
143 // status message during: | 303 // status message during: |
144 // - Plugin creation, to handle a plugin freshly created from a poster. | 304 // - Plugin creation, to handle a plugin freshly created from a poster. |
145 // - Peripheral status change. | 305 // - Peripheral status change. |
146 // - In response to the explicit 'getPowerSaverStatus' request, in case the | 306 // - In response to the explicit 'getPowerSaverStatus' request, in case the |
147 // test has missed the above two events. | 307 // test has missed the above two events. |
148 void SimulateClickAndAwaitMarkedEssential(const char* element_id, | 308 void SimulateClickAndAwaitMarkedEssential(const std::string& element_id, |
149 const gfx::Point& point) { | 309 const gfx::Point& point) { |
150 // Waits for the placeholder to be ready to be clicked first. | 310 WaitForPlaceholderReady(GetActiveWebContents(), element_id); |
151 std::string result = RunTestScript( | |
152 "function handleEvent(event) {" | |
153 " if (event.data === 'placeholderLoaded') {" | |
154 " window.domAutomationController.send('ready');" | |
155 " plugin.removeEventListener('message', handleEvent);" | |
156 " }" | |
157 "}" | |
158 "plugin.addEventListener('message', handleEvent);" | |
159 "if (plugin.hasAttribute('placeholderLoaded')) {" | |
160 " window.domAutomationController.send('ready');" | |
161 " plugin.removeEventListener('message', handleEvent);" | |
162 "}", | |
163 GetActiveWebContents(), element_id); | |
164 ASSERT_EQ("ready", result); | |
165 | |
166 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, | 311 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, |
167 blink::WebMouseEvent::ButtonLeft, point); | 312 blink::WebMouseEvent::ButtonLeft, point); |
168 | 313 |
169 VerifyPluginMarkedEssential(GetActiveWebContents(), element_id); | 314 VerifyPluginMarkedEssential(GetActiveWebContents(), element_id); |
170 } | 315 } |
| 316 |
| 317 // |element_id| must be an element on the foreground tab. |
| 318 void VerifyPluginIsPosterOnly(const std::string& element_id) { |
| 319 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), element_id)); |
| 320 WaitForPlaceholderReady(GetActiveWebContents(), element_id); |
| 321 } |
| 322 |
| 323 bool VerifySnapshot(const base::FilePath::StringType& expected_filename) { |
| 324 base::FilePath reference = ui_test_utils::GetTestFilePath( |
| 325 base::FilePath(FILE_PATH_LITERAL("plugin_power_saver")), |
| 326 base::FilePath(expected_filename)); |
| 327 |
| 328 GetActiveWebContents()->GetMainFrame()->InsertVisualStateCallback( |
| 329 base::Bind(&VerifyVisualStateUpdated, |
| 330 base::MessageLoop::QuitWhenIdleClosure())); |
| 331 content::RunMessageLoop(); |
| 332 |
| 333 content::RenderWidgetHost* rwh = |
| 334 GetActiveWebContents()->GetRenderViewHost()->GetWidget(); |
| 335 |
| 336 // When a widget is first shown, it can take some time before it is ready |
| 337 // for copying from its backing store. This is a transient condition, and |
| 338 // so it is not being treated as a test failure. |
| 339 if (!rwh->CanCopyFromBackingStore()) |
| 340 return false; |
| 341 |
| 342 bool snapshot_matches = false; |
| 343 rwh->CopyFromBackingStore( |
| 344 gfx::Rect(), gfx::Size(), |
| 345 base::Bind(&CompareSnapshotToReference, reference, &snapshot_matches, |
| 346 base::MessageLoop::QuitWhenIdleClosure()), |
| 347 kN32_SkColorType); |
| 348 |
| 349 content::RunMessageLoop(); |
| 350 |
| 351 return snapshot_matches; |
| 352 } |
171 }; | 353 }; |
172 | 354 |
173 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { | 355 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { |
174 LoadHTML( | 356 LoadHTML( |
175 "<object id='plugin' data='fake.swf' " | 357 "<object id='plugin' data='fake.swf' " |
176 " type='application/x-ppapi-tests' width='400' height='100'>" | 358 " type='application/x-ppapi-tests' width='400' height='100'>" |
177 "</object>"); | 359 "</object>"); |
178 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 360 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
179 } | 361 } |
180 | 362 |
181 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) { | 363 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) { |
182 LoadHTML( | 364 LoadHTML( |
183 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 365 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
184 " type='application/x-ppapi-tests' width='400' height='100'>" | 366 " type='application/x-ppapi-tests' width='400' height='100'>" |
| 367 "</object>" |
| 368 "<br>" |
| 369 "<object id='plugin_poster' data='http://otherorigin.com/fake.swf' " |
| 370 " type='application/x-ppapi-tests' width='400' height='100' " |
| 371 " poster='click_me.png'>" |
185 "</object>"); | 372 "</object>"); |
| 373 |
186 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 374 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 375 VerifyPluginIsPosterOnly("plugin_poster"); |
| 376 |
| 377 EXPECT_TRUE( |
| 378 VerifySnapshot(FILE_PATH_LITERAL("small_cross_origin_expected.png"))); |
187 | 379 |
188 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 380 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
| 381 SimulateClickAndAwaitMarkedEssential("plugin_poster", gfx::Point(50, 150)); |
189 } | 382 } |
190 | 383 |
191 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) { | 384 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) { |
192 LoadHTML( | 385 LoadHTML( |
193 "<object id='large' data='http://otherorigin.com/fake.swf' " | 386 "<object id='large' data='http://otherorigin.com/fake.swf' " |
194 " type='application/x-ppapi-tests' width='400' height='500'>" | 387 " type='application/x-ppapi-tests' width='400' height='500'>" |
195 "</object>" | 388 "</object>" |
196 "<object id='medium_16_9' data='http://otherorigin.com/fake.swf' " | 389 "<object id='medium_16_9' data='http://otherorigin.com/fake.swf' " |
197 " type='application/x-ppapi-tests' width='480' height='270'>" | 390 " type='application/x-ppapi-tests' width='480' height='270'>" |
198 "</object>"); | 391 "</object>"); |
199 VerifyPluginMarkedEssential(GetActiveWebContents(), "large"); | 392 VerifyPluginMarkedEssential(GetActiveWebContents(), "large"); |
200 VerifyPluginMarkedEssential(GetActiveWebContents(), "medium_16_9"); | 393 VerifyPluginMarkedEssential(GetActiveWebContents(), "medium_16_9"); |
201 } | 394 } |
202 | 395 |
| 396 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallerThanPlayIcon) { |
| 397 LoadHTML( |
| 398 "<object id='plugin_16' type='application/x-ppapi-tests' " |
| 399 " width='16' height='16'></object>" |
| 400 "<object id='plugin_32' type='application/x-ppapi-tests' " |
| 401 " width='32' height='32'></object>" |
| 402 "<object id='plugin_16_64' type='application/x-ppapi-tests' " |
| 403 " width='16' height='64'></object>" |
| 404 "<object id='plugin_64_16' type='application/x-ppapi-tests' " |
| 405 " width='64' height='16'></object>"); |
| 406 |
| 407 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_16"); |
| 408 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_32"); |
| 409 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_16_64"); |
| 410 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_64_16"); |
| 411 |
| 412 EXPECT_TRUE( |
| 413 VerifySnapshot(FILE_PATH_LITERAL("smaller_than_play_icon_expected.png"))); |
| 414 } |
| 415 |
| 416 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, PosterTests) { |
| 417 // This test simultaneously verifies the varied supported poster syntaxes, |
| 418 // as well as verifies that the poster is rendered correctly with various |
| 419 // mismatched aspect ratios and sizes, following the same rules as VIDEO. |
| 420 LoadHTML( |
| 421 "<object id='plugin_src' type='application/x-ppapi-tests' " |
| 422 " width='100' height='100' poster='click_me.png'></object>" |
| 423 "<object id='plugin_srcset' type='application/x-ppapi-tests' " |
| 424 " width='100' height='100' " |
| 425 " poster='click_me.png 1x, click_me.png 2x'></object>" |
| 426 "<br>" |
| 427 |
| 428 "<object id='plugin_poster_param' type='application/x-ppapi-tests' " |
| 429 " width='100' height='100'>" |
| 430 " <param name='poster' value='click_me.png 1x, click_me.png 2x'>" |
| 431 "</object>" |
| 432 "<embed id='plugin_embed_src' type='application/x-ppapi-tests' " |
| 433 " width='100' height='100' poster='click_me.png'></embed>" |
| 434 "<embed id='plugin_embed_srcset' type='application/x-ppapi-tests' " |
| 435 " width='100' height='100'" |
| 436 " poster='click_me.png 1x, click_me.png 2x'></embed>" |
| 437 "<br>" |
| 438 |
| 439 "<object id='poster_missing' type='application/x-ppapi-tests' " |
| 440 " width='100' height='100' poster='missing.png'></object>" |
| 441 "<object id='poster_too_small' type='application/x-ppapi-tests' " |
| 442 " width='100' height='50' poster='click_me.png'></object>" |
| 443 "<object id='poster_too_big' type='application/x-ppapi-tests' " |
| 444 " width='100' height='150' poster='click_me.png'></object>" |
| 445 "<br>" |
| 446 |
| 447 "<object id='poster_16' type='application/x-ppapi-tests' " |
| 448 " width='16' height='16' poster='click_me.png'></object>" |
| 449 "<object id='poster_32' type='application/x-ppapi-tests' " |
| 450 " width='32' height='32' poster='click_me.png'></object>" |
| 451 "<object id='poster_16_64' type='application/x-ppapi-tests' " |
| 452 " width='16' height='64' poster='click_me.png'></object>" |
| 453 "<object id='poster_64_16' type='application/x-ppapi-tests' " |
| 454 " width='64' height='16' poster='click_me.png'></object>" |
| 455 "<br>" |
| 456 |
| 457 "<div id='container' " |
| 458 " style='width: 400px; height: 100px; overflow: hidden;'>" |
| 459 " <object id='poster_obscured' data='http://otherorigin.com/fake.swf' " |
| 460 " type='application/x-ppapi-tests' width='400' height='500' " |
| 461 " poster='click_me.png'>" |
| 462 " </object>" |
| 463 "</div>"); |
| 464 |
| 465 VerifyPluginIsPosterOnly("plugin_src"); |
| 466 VerifyPluginIsPosterOnly("plugin_srcset"); |
| 467 |
| 468 VerifyPluginIsPosterOnly("plugin_poster_param"); |
| 469 VerifyPluginIsPosterOnly("plugin_embed_src"); |
| 470 VerifyPluginIsPosterOnly("plugin_embed_srcset"); |
| 471 |
| 472 VerifyPluginIsPosterOnly("poster_missing"); |
| 473 VerifyPluginIsPosterOnly("poster_too_small"); |
| 474 VerifyPluginIsPosterOnly("poster_too_big"); |
| 475 |
| 476 VerifyPluginIsPosterOnly("poster_16"); |
| 477 VerifyPluginIsPosterOnly("poster_32"); |
| 478 VerifyPluginIsPosterOnly("poster_16_64"); |
| 479 VerifyPluginIsPosterOnly("poster_64_16"); |
| 480 |
| 481 VerifyPluginIsPosterOnly("poster_obscured"); |
| 482 |
| 483 EXPECT_TRUE(VerifySnapshot(FILE_PATH_LITERAL("poster_tests_expected.png"))); |
| 484 } |
| 485 |
203 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargePostersNotThrottled) { | 486 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargePostersNotThrottled) { |
204 // This test verifies that small posters are throttled, large posters are not, | 487 // This test verifies that small posters are throttled, large posters are not, |
205 // and that large posters can whitelist origins for other plugins. | 488 // and that large posters can whitelist origins for other plugins. |
206 LoadHTML( | 489 LoadHTML( |
207 "<object id='poster_small' data='http://a.com/fake.swf' " | 490 "<object id='poster_small' data='http://a.com/fake.swf' " |
208 " type='application/x-ppapi-tests' width='50' height='50' " | 491 " type='application/x-ppapi-tests' width='50' height='50' " |
209 " poster='click_me.png'></object>" | 492 " poster='click_me.png'></object>" |
210 "<object id='poster_whitelisted_origin' data='http://b.com/fake.swf' " | 493 "<object id='poster_whitelisted_origin' data='http://b.com/fake.swf' " |
211 " type='application/x-ppapi-tests' width='50' height='50' " | 494 " type='application/x-ppapi-tests' width='50' height='50' " |
212 " poster='click_me.png'></object>" | 495 " poster='click_me.png'></object>" |
213 "<object id='plugin_whitelisted_origin' data='http://b.com/fake.swf' " | 496 "<object id='plugin_whitelisted_origin' data='http://b.com/fake.swf' " |
214 " type='application/x-ppapi-tests' width='50' height='50'></object>" | 497 " type='application/x-ppapi-tests' width='50' height='50'></object>" |
215 "<br>" | 498 "<br>" |
216 "<object id='poster_large' data='http://b.com/fake.swf' " | 499 "<object id='poster_large' data='http://b.com/fake.swf' " |
217 " type='application/x-ppapi-tests' width='400' height='300' " | 500 " type='application/x-ppapi-tests' width='400' height='300' " |
218 " poster='click_me.png'></object>"); | 501 " poster='click_me.png'></object>"); |
219 | 502 |
220 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_small")); | 503 VerifyPluginIsPosterOnly("poster_small"); |
221 VerifyPluginMarkedEssential(GetActiveWebContents(), | 504 VerifyPluginMarkedEssential(GetActiveWebContents(), |
222 "poster_whitelisted_origin"); | 505 "poster_whitelisted_origin"); |
223 VerifyPluginMarkedEssential(GetActiveWebContents(), | 506 VerifyPluginMarkedEssential(GetActiveWebContents(), |
224 "plugin_whitelisted_origin"); | 507 "plugin_whitelisted_origin"); |
225 VerifyPluginMarkedEssential(GetActiveWebContents(), "poster_large"); | 508 VerifyPluginMarkedEssential(GetActiveWebContents(), "poster_large"); |
226 } | 509 } |
227 | 510 |
228 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, | 511 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, |
229 PluginMarkedEssentialAfterPosterClicked) { | 512 PluginMarkedEssentialAfterPosterClicked) { |
230 LoadHTML( | 513 LoadHTML( |
231 "<object id='plugin' type='application/x-ppapi-tests' " | 514 "<object id='plugin' type='application/x-ppapi-tests' " |
232 " width='400' height='100' poster='snapshot1x.png'></object>"); | 515 " width='400' height='100' poster='snapshot1x.png'></object>"); |
233 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin")); | 516 VerifyPluginIsPosterOnly("plugin"); |
234 | 517 |
235 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 518 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
236 } | 519 } |
237 | 520 |
238 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { | 521 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { |
239 LoadHTML( | 522 LoadHTML( |
240 "<object id='plugin_small' data='http://a.com/fake1.swf' " | 523 "<object id='plugin_small' data='http://a.com/fake1.swf' " |
241 " type='application/x-ppapi-tests' width='100' height='100'></object>" | 524 " type='application/x-ppapi-tests' width='100' height='100'></object>" |
242 "<object id='plugin_small_poster' data='http://a.com/fake1.swf' " | 525 "<object id='plugin_small_poster' data='http://a.com/fake1.swf' " |
243 " type='application/x-ppapi-tests' width='100' height='100' " | 526 " type='application/x-ppapi-tests' width='100' height='100' " |
244 " poster='click_me.png'></object>" | 527 " poster='click_me.png'></object>" |
245 "<object id='plugin_large' data='http://a.com/fake2.swf' " | 528 "<object id='plugin_large' data='http://a.com/fake2.swf' " |
246 " type='application/x-ppapi-tests' width='400' height='500'>" | 529 " type='application/x-ppapi-tests' width='400' height='500'>" |
247 "</object>"); | 530 "</object>"); |
248 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin_small"); | 531 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin_small"); |
249 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin_small_poster"); | 532 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin_small_poster"); |
250 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin_large"); | 533 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin_large"); |
251 } | 534 } |
252 | 535 |
253 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { | 536 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { |
254 LoadHTML( | 537 LoadHTML( |
255 "<div id='container' " | 538 "<div id='container' " |
256 " style='width: 400px; height: 100px; overflow: hidden;'>" | 539 " style='width: 100px; height: 400px; overflow: hidden;'>" |
257 " <object id='plugin' data='http://otherorigin.com/fake.swf' " | 540 " <object id='plugin' data='http://otherorigin.com/fake.swf' " |
258 " type='application/x-ppapi-tests' width='400' height='500'>" | 541 " type='application/x-ppapi-tests' width='400' height='500' " |
| 542 " style='float: right;'>" |
259 " </object>" | 543 " </object>" |
260 "</div>"); | 544 "</div>"); |
261 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 545 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 546 EXPECT_TRUE(VerifySnapshot( |
| 547 FILE_PATH_LITERAL("large_cross_origin_obscured_expected.png"))); |
262 | 548 |
263 // Test that's unthrottled if it is unobscured. | 549 // Test that's unthrottled if it is unobscured. |
264 std::string script = | 550 std::string script = |
265 "var container = window.document.getElementById('container');" | 551 "var container = window.document.getElementById('container');" |
266 "container.setAttribute('style', 'width: 400px; height: 400px;');"; | 552 "container.setAttribute('style', 'width: 400px; height: 400px;');"; |
267 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); | 553 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); |
268 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 554 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
269 } | 555 } |
270 | 556 |
271 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingSmallPlugin) { | 557 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingSmallPlugin) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 595 |
310 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { | 596 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { |
311 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) | 597 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) |
312 ->SetZoomLevel(4.0); | 598 ->SetZoomLevel(4.0); |
313 LoadHTML( | 599 LoadHTML( |
314 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 600 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
315 " type='application/x-ppapi-tests' width='400' height='200'>" | 601 " type='application/x-ppapi-tests' width='400' height='200'>" |
316 "</object>"); | 602 "</object>"); |
317 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 603 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
318 } | 604 } |
OLD | NEW |