Chromium Code Reviews| 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/browser_window.h" | |
| 9 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
| 13 #include "components/ui/zoom/zoom_controller.h" | 14 #include "components/ui/zoom/zoom_controller.h" |
| 15 #include "content/public/browser/readback_types.h" | |
| 16 #include "content/public/browser/render_view_host.h" | |
| 17 #include "content/public/browser/render_widget_host.h" | |
| 14 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/ppapi_test_utils.h" | 20 #include "content/public/test/ppapi_test_utils.h" |
| 17 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 18 #include "net/test/embedded_test_server/http_request.h" | 22 #include "net/test/embedded_test_server/http_request.h" |
| 19 #include "net/test/embedded_test_server/http_response.h" | 23 #include "net/test/embedded_test_server/http_response.h" |
| 20 #include "ppapi/shared_impl/ppapi_switches.h" | 24 #include "ppapi/shared_impl/ppapi_switches.h" |
| 21 #include "third_party/WebKit/public/web/WebInputEvent.h" | 25 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 26 #include "third_party/skia/include/core/SkBitmap.h" | |
| 22 #include "ui/base/window_open_disposition.h" | 27 #include "ui/base/window_open_disposition.h" |
| 28 #include "ui/gfx/codec/png_codec.h" | |
| 23 #include "ui/gfx/geometry/point.h" | 29 #include "ui/gfx/geometry/point.h" |
| 30 #include "ui/gfx/screen.h" | |
| 24 | 31 |
| 25 namespace { | 32 namespace { |
| 26 | 33 |
| 34 // Use fixed browser dimensions for pixel tests. | |
| 35 const int kBrowserWidth = 600; | |
| 36 const int kBrowserHeight = 700; | |
| 37 | |
| 38 // Compare only a portion of the snapshots, as different platforms will | |
| 39 // capture different sized snapshots (due to differences in browser chrome). | |
| 40 const int kComparisonWidth = 500; | |
| 41 const int kComparisonHeight = 600; | |
| 42 | |
| 43 // Different platforms have slightly different pixel output, due to different | |
| 44 // graphics implementations. Slightly different pixels (in BGR space) are still | |
| 45 // counted as a matching pixel by this simple manhattan distance threshold. | |
| 46 const int kPixelManhattanDistanceTolerance = 8; | |
| 47 | |
| 27 std::string RunTestScript(base::StringPiece test_script, | 48 std::string RunTestScript(base::StringPiece test_script, |
| 28 content::WebContents* contents, | 49 content::WebContents* contents, |
| 29 const std::string& element_id) { | 50 const std::string& element_id) { |
| 30 std::string script = base::StringPrintf( | 51 std::string script = base::StringPrintf( |
| 31 "var plugin = window.document.getElementById('%s');" | 52 "var plugin = window.document.getElementById('%s');" |
| 32 "if (plugin === undefined ||" | 53 "if (plugin === undefined ||" |
| 33 " (plugin.nodeName !== 'OBJECT' && plugin.nodeName !== 'EMBED')) {" | 54 " (plugin.nodeName !== 'OBJECT' && plugin.nodeName !== 'EMBED')) {" |
| 34 " window.domAutomationController.send('error');" | 55 " window.domAutomationController.send('error');" |
| 35 "} else {" | 56 "} else {" |
| 36 " %s" | 57 " %s" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 scoped_ptr<net::test_server::HttpResponse> RespondWithHTML( | 119 scoped_ptr<net::test_server::HttpResponse> RespondWithHTML( |
| 99 const std::string& html, | 120 const std::string& html, |
| 100 const net::test_server::HttpRequest& request) { | 121 const net::test_server::HttpRequest& request) { |
| 101 scoped_ptr<net::test_server::BasicHttpResponse> response( | 122 scoped_ptr<net::test_server::BasicHttpResponse> response( |
| 102 new net::test_server::BasicHttpResponse()); | 123 new net::test_server::BasicHttpResponse()); |
| 103 response->set_content_type("text/html"); | 124 response->set_content_type("text/html"); |
| 104 response->set_content(html); | 125 response->set_content(html); |
| 105 return response.Pass(); | 126 return response.Pass(); |
| 106 } | 127 } |
| 107 | 128 |
| 129 bool SnapshotMatches(const base::FilePath& reference, const SkBitmap& bitmap) { | |
| 130 base::File::Info info; | |
| 131 if (!base::GetFileInfo(reference, &info)) | |
| 132 return false; | |
| 133 int size = static_cast<size_t>(info.size); | |
| 134 scoped_ptr<char[]> data(new char[size]); | |
|
Lei Zhang
2015/10/21 07:24:52
Just use a std::vector, sans scoped_ptr. vector_as
tommycli
2015/10/21 18:16:04
Done.
| |
| 135 if (base::ReadFile(reference, data.get(), size) != size) | |
|
Lei Zhang
2015/10/21 07:24:52
Or just use ReadFileToString().
tommycli
2015/10/21 18:16:04
Done.
| |
| 136 return false; | |
| 137 | |
| 138 int w, h; | |
|
Lei Zhang
2015/10/21 07:24:52
1 decl per line
tommycli
2015/10/21 18:16:04
Done.
| |
| 139 std::vector<unsigned char> decoded; | |
| 140 if (!gfx::PNGCodec::Decode(reinterpret_cast<unsigned char*>(data.get()), size, | |
| 141 gfx::PNGCodec::FORMAT_BGRA, &decoded, &w, &h)) { | |
| 142 return false; | |
| 143 } | |
| 144 | |
| 145 if (bitmap.width() < kComparisonWidth || w < kComparisonWidth || | |
|
Lei Zhang
2015/10/21 07:24:52
You could have done this first without even openin
tommycli
2015/10/21 18:16:04
Done.
| |
| 146 bitmap.height() < kComparisonHeight || h < kComparisonHeight) { | |
| 147 return false; | |
| 148 } | |
| 149 | |
| 150 int32* ref_pixels = reinterpret_cast<int32*>(&decoded[0]); | |
|
Lei Zhang
2015/10/21 07:24:52
Use stdint.h types - int32_t
tommycli
2015/10/21 18:16:04
Done.
| |
| 151 | |
| 152 SkAutoLockPixels lock_image(bitmap); | |
| 153 int32* pixels = static_cast<int32*>(bitmap.getPixels()); | |
| 154 | |
| 155 int stride = bitmap.rowBytes(); | |
| 156 for (int y = 0; y < kComparisonHeight; ++y) { | |
| 157 for (int x = 0; x < kComparisonWidth; ++x) { | |
| 158 int32 pixel = pixels[y * stride / sizeof(int32) + x]; | |
| 159 int pixel_b = pixel & 0xFF; | |
| 160 int pixel_g = (pixel >> 8) & 0xFF; | |
| 161 int pixel_r = (pixel >> 16) & 0xFF; | |
| 162 | |
| 163 int32 ref_pixel = ref_pixels[y * w + x]; | |
| 164 int ref_pixel_b = ref_pixel & 0xFF; | |
| 165 int ref_pixel_g = (ref_pixel >> 8) & 0xFF; | |
| 166 int ref_pixel_r = (ref_pixel >> 16) & 0xFF; | |
| 167 | |
| 168 int manhattan_distance = abs(pixel_b - ref_pixel_b) + | |
| 169 abs(pixel_g - ref_pixel_g) + | |
| 170 abs(pixel_r - ref_pixel_r); | |
| 171 | |
| 172 if (manhattan_distance > kPixelManhattanDistanceTolerance) | |
| 173 return false; | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 return true; | |
| 178 } | |
| 179 | |
| 180 // |snapshot_matches| is set to true if the snapshot matches the reference and | |
| 181 // the test passes. Otherwise, set to false. | |
| 182 void CompareSnapshotToReference(const base::FilePath& reference, | |
| 183 bool* snapshot_matches, | |
| 184 const base::Closure& done_cb, | |
| 185 const SkBitmap& bitmap, | |
| 186 content::ReadbackResponse response) { | |
| 187 DCHECK(snapshot_matches); | |
| 188 if (response != content::READBACK_SUCCESS) { | |
| 189 *snapshot_matches = false; | |
| 190 done_cb.Run(); | |
| 191 return; | |
| 192 } | |
| 193 | |
| 194 *snapshot_matches = SnapshotMatches(reference, bitmap); | |
| 195 | |
| 196 // When rebaselining the pixel test, the test will fail, and we will | |
| 197 // overwrite the reference file. On the next try through, the test will then | |
| 198 // pass, since we just overwrote the reference file. A bit wonky. | |
| 199 if (!(*snapshot_matches) && | |
| 200 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
|
Lei Zhang
2015/10/21 07:24:52
This is just for convenience, right?
tommycli
2015/10/21 18:16:04
Yeah exactly. I'm not married to this. Since kCCRe
| |
| 201 switches::kRebaselinePixelTests)) { | |
| 202 SkBitmap clipped_bitmap; | |
| 203 bitmap.extractSubset(&clipped_bitmap, | |
| 204 SkIRect::MakeWH(kComparisonWidth, kComparisonHeight)); | |
| 205 std::vector<unsigned char> png_data; | |
| 206 gfx::PNGCodec::EncodeBGRASkBitmap(clipped_bitmap, false, &png_data); | |
| 207 base::WriteFile(reference, reinterpret_cast<char*>(&png_data[0]), | |
|
Lei Zhang
2015/10/21 07:24:52
Use vector_as_array.
tommycli
2015/10/21 18:16:04
Done.
| |
| 208 png_data.size()); | |
| 209 } | |
| 210 | |
| 211 done_cb.Run(); | |
| 212 } | |
| 213 | |
| 108 } // namespace | 214 } // namespace |
| 109 | 215 |
| 110 class PluginPowerSaverBrowserTest : public InProcessBrowserTest { | 216 class PluginPowerSaverBrowserTest : public InProcessBrowserTest { |
| 111 public: | 217 public: |
| 218 void SetUp() override { | |
| 219 EnablePixelOutput(); | |
| 220 InProcessBrowserTest::SetUp(); | |
| 221 } | |
| 222 | |
| 112 void SetUpOnMainThread() override { | 223 void SetUpOnMainThread() override { |
| 113 InProcessBrowserTest::SetUpOnMainThread(); | 224 InProcessBrowserTest::SetUpOnMainThread(); |
| 114 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 225 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 226 | |
| 227 // Reuse an image from the printing tests as a poster image. | |
|
Lei Zhang
2015/10/21 07:24:52
You are adding a plugin_power_saver dir. Use your
tommycli
2015/10/21 18:16:04
Done.
| |
| 228 embedded_test_server()->ServeFilesFromDirectory( | |
| 229 ui_test_utils::GetTestFilePath( | |
| 230 base::FilePath(FILE_PATH_LITERAL("printing")), base::FilePath())); | |
| 115 } | 231 } |
| 116 | 232 |
| 117 void SetUpCommandLine(base::CommandLine* command_line) override { | 233 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 118 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); | 234 command_line->AppendSwitch(switches::kEnablePluginPowerSaver); |
| 119 command_line->AppendSwitch(switches::kEnablePepperTesting); | 235 command_line->AppendSwitch(switches::kEnablePepperTesting); |
| 120 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); | 236 command_line->AppendSwitch(switches::kEnablePluginPlaceholderTesting); |
| 121 command_line->AppendSwitchASCII( | 237 command_line->AppendSwitchASCII( |
| 122 switches::kOverridePluginPowerSaverForTesting, "ignore-list"); | 238 switches::kOverridePluginPowerSaverForTesting, "ignore-list"); |
| 123 | 239 |
| 124 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); | 240 ASSERT_TRUE(ppapi::RegisterPowerSaverTestPlugin(command_line)); |
| 125 } | 241 } |
| 126 | 242 |
| 127 protected: | 243 protected: |
| 128 void LoadHTML(const std::string& html) { | 244 void LoadHTML(const std::string& html) { |
| 245 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); | |
| 246 gfx::Rect screen_bounds = | |
| 247 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds(); | |
| 248 ASSERT_GT(screen_bounds.width(), kBrowserWidth); | |
| 249 ASSERT_GT(screen_bounds.height(), kBrowserHeight); | |
| 250 browser()->window()->SetBounds(bounds); | |
| 251 | |
| 129 ASSERT_TRUE(embedded_test_server()->Started()); | 252 ASSERT_TRUE(embedded_test_server()->Started()); |
| 130 embedded_test_server()->RegisterRequestHandler( | 253 embedded_test_server()->RegisterRequestHandler( |
| 131 base::Bind(&RespondWithHTML, html)); | 254 base::Bind(&RespondWithHTML, html)); |
| 132 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); | 255 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->base_url()); |
| 133 EXPECT_TRUE(content::WaitForRenderFrameReady( | 256 EXPECT_TRUE(content::WaitForRenderFrameReady( |
| 134 GetActiveWebContents()->GetMainFrame())); | 257 GetActiveWebContents()->GetMainFrame())); |
| 135 } | 258 } |
| 136 | 259 |
| 137 content::WebContents* GetActiveWebContents() { | 260 content::WebContents* GetActiveWebContents() { |
| 138 return browser()->tab_strip_model()->GetActiveWebContents(); | 261 return browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 161 " plugin.removeEventListener('message', handleEvent);" | 284 " plugin.removeEventListener('message', handleEvent);" |
| 162 "}", | 285 "}", |
| 163 GetActiveWebContents(), element_id); | 286 GetActiveWebContents(), element_id); |
| 164 ASSERT_EQ("ready", result); | 287 ASSERT_EQ("ready", result); |
| 165 | 288 |
| 166 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, | 289 content::SimulateMouseClickAt(GetActiveWebContents(), 0 /* modifiers */, |
| 167 blink::WebMouseEvent::ButtonLeft, point); | 290 blink::WebMouseEvent::ButtonLeft, point); |
| 168 | 291 |
| 169 VerifyPluginMarkedEssential(GetActiveWebContents(), element_id); | 292 VerifyPluginMarkedEssential(GetActiveWebContents(), element_id); |
| 170 } | 293 } |
| 294 | |
| 295 bool VerifySnapshot(const std::string& expected_filename) { | |
| 296 // If we are rebaselining, give the placeholders an extra 2 seconds to | |
|
Lei Zhang
2015/10/21 07:24:52
What if your machine has a bad day? Are you going
tommycli
2015/10/21 18:16:04
Yes... and there's no real way to tell that it's t
Lei Zhang
2015/10/21 23:25:32
Are there any JS / DOM events that corrolates with
tommycli
2015/10/21 23:57:22
Oh - I tried so hard believe me, the existing Veri
Lei Zhang
2015/10/22 00:16:13
Can you ask the compositor folks if there's a bett
tommycli
2015/10/22 19:17:24
Yes - I'll reach out to piman / some other composi
tommycli
2015/10/22 22:32:42
I have trying to implement pixel tests for Plugin
piman
2015/10/23 01:45:31
Well, it's not exactly simple to do it accurately.
| |
| 297 // settle, so we write the correct reference images. See comment below. | |
| 298 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 299 switches::kRebaselinePixelTests)) { | |
| 300 base::MessageLoop::current()->task_runner()->PostDelayedTask( | |
| 301 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(), | |
| 302 base::TimeDelta::FromSeconds(2)); | |
| 303 content::RunMessageLoop(); | |
| 304 } | |
| 305 | |
| 306 // Because of how Pepper painting works, even if the plugin is ready, the | |
| 307 // image data may not have arrived in the backing store. Retry verifying | |
| 308 // the snapshot with a timeout. | |
| 309 return ui_test_utils::RunLoopUntil( | |
|
Lei Zhang
2015/10/21 07:24:52
So if the test is going to fail, we'll retry a bun
tommycli
2015/10/21 18:16:04
Yes, we keep retrying, but there's a timeout of 5
| |
| 310 base::Bind(&PluginPowerSaverBrowserTest::TryVerifySnapshot, | |
| 311 base::Unretained(this), expected_filename)); | |
| 312 } | |
| 313 | |
| 314 private: | |
| 315 bool TryVerifySnapshot(const std::string& expected_filename) { | |
| 316 bool snapshot_matches = false; | |
| 317 base::FilePath reference = ui_test_utils::GetTestFilePath( | |
| 318 base::FilePath(FILE_PATH_LITERAL("plugin_power_saver")), | |
| 319 base::FilePath().AppendASCII(expected_filename)); | |
|
Lei Zhang
2015/10/21 07:24:52
Pass |expected_filename| as a FilePath all the way
tommycli
2015/10/21 18:16:04
Done. It is converted to a FilePath in VerifySnaps
Lei Zhang
2015/10/21 23:25:32
Why not keep going and change VerifySnapshot() too
tommycli
2015/10/21 23:57:22
Ah... because it would cause me to write ui_test_u
Lei Zhang
2015/10/22 00:16:13
Can we do this?
bool VerifySnapshot(const base::F
tommycli
2015/10/22 19:17:24
Done. Yeah that's fine with me.
| |
| 320 content::RenderWidgetHost* rwh = | |
| 321 GetActiveWebContents()->GetRenderViewHost()->GetWidget(); | |
| 322 | |
| 323 // When a widget is first shown, it can take some time before it is ready | |
| 324 // for copying from its backing store. This is a transient condition, and | |
| 325 // so it is not being treated as a test failure. | |
| 326 if (!rwh->CanCopyFromBackingStore()) | |
| 327 return false; | |
| 328 | |
| 329 rwh->CopyFromBackingStore( | |
| 330 gfx::Rect(), gfx::Size(), | |
| 331 base::Bind(&CompareSnapshotToReference, reference, &snapshot_matches, | |
| 332 base::MessageLoop::QuitWhenIdleClosure()), | |
| 333 kN32_SkColorType); | |
| 334 | |
| 335 content::RunMessageLoop(); | |
| 336 | |
| 337 return snapshot_matches; | |
| 338 } | |
| 171 }; | 339 }; |
| 172 | 340 |
| 173 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { | 341 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallSameOrigin) { |
| 174 LoadHTML( | 342 LoadHTML( |
| 175 "<object id='plugin' data='fake.swf' " | 343 "<object id='plugin' data='fake.swf' " |
| 176 " type='application/x-ppapi-tests' width='400' height='100'>" | 344 " type='application/x-ppapi-tests' width='400' height='100'>" |
| 177 "</object>"); | 345 "</object>"); |
| 178 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 346 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
| 179 } | 347 } |
| 180 | 348 |
| 181 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) { | 349 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallCrossOrigin) { |
| 182 LoadHTML( | 350 LoadHTML( |
| 183 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 351 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 184 " type='application/x-ppapi-tests' width='400' height='100'>" | 352 " type='application/x-ppapi-tests' width='400' height='100'>" |
| 353 "</object>" | |
| 354 "<br>" | |
| 355 "<object id='plugin_poster' data='http://otherorigin.com/fake.swf' " | |
| 356 " type='application/x-ppapi-tests' width='400' height='100' " | |
| 357 " poster='click_me.png'>" | |
| 185 "</object>"); | 358 "</object>"); |
| 359 | |
| 186 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 360 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 361 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_poster")); | |
| 362 | |
| 363 EXPECT_TRUE(VerifySnapshot("small_cross_origin_expected.png")); | |
| 187 | 364 |
| 188 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 365 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
| 366 SimulateClickAndAwaitMarkedEssential("plugin_poster", gfx::Point(50, 150)); | |
| 189 } | 367 } |
| 190 | 368 |
| 191 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) { | 369 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOrigin) { |
| 192 LoadHTML( | 370 LoadHTML( |
| 193 "<object id='large' data='http://otherorigin.com/fake.swf' " | 371 "<object id='large' data='http://otherorigin.com/fake.swf' " |
| 194 " type='application/x-ppapi-tests' width='400' height='500'>" | 372 " type='application/x-ppapi-tests' width='400' height='500'>" |
| 195 "</object>" | 373 "</object>" |
| 196 "<object id='medium_16_9' data='http://otherorigin.com/fake.swf' " | 374 "<object id='medium_16_9' data='http://otherorigin.com/fake.swf' " |
| 197 " type='application/x-ppapi-tests' width='480' height='270'>" | 375 " type='application/x-ppapi-tests' width='480' height='270'>" |
| 198 "</object>"); | 376 "</object>"); |
| 199 VerifyPluginMarkedEssential(GetActiveWebContents(), "large"); | 377 VerifyPluginMarkedEssential(GetActiveWebContents(), "large"); |
| 200 VerifyPluginMarkedEssential(GetActiveWebContents(), "medium_16_9"); | 378 VerifyPluginMarkedEssential(GetActiveWebContents(), "medium_16_9"); |
| 201 } | 379 } |
| 202 | 380 |
| 203 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, | 381 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, SmallerThanPlayIcon) { |
| 204 LargePluginsPeripheralWhenPosterSpecified) { | 382 LoadHTML( |
| 383 "<object id='plugin_16' type='application/x-ppapi-tests' " | |
| 384 " width='16' height='16'></object>" | |
| 385 "<object id='plugin_32' type='application/x-ppapi-tests' " | |
| 386 " width='32' height='32'></object>" | |
| 387 "<object id='plugin_16_64' type='application/x-ppapi-tests' " | |
| 388 " width='16' height='64'></object>" | |
| 389 "<object id='plugin_64_16' type='application/x-ppapi-tests' " | |
| 390 " width='64' height='16'></object>"); | |
| 391 | |
| 392 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_16"); | |
| 393 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_32"); | |
| 394 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_16_64"); | |
| 395 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin_64_16"); | |
| 396 | |
| 397 EXPECT_TRUE(VerifySnapshot("smaller_than_play_icon_expected.png")); | |
| 398 } | |
| 399 | |
| 400 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, PosterTests) { | |
| 401 // This test simulateously verifies the varied supported poster syntaxes, | |
|
Lei Zhang
2015/10/21 07:24:52
typo
tommycli
2015/10/21 18:16:04
Done.
| |
| 402 // as well as verifies that the poster is rendered correctly with various | |
| 403 // mismatched aspect ratios and sizes, following the same rules as VIDEO. | |
| 205 LoadHTML( | 404 LoadHTML( |
| 206 "<object id='plugin_src' type='application/x-ppapi-tests' " | 405 "<object id='plugin_src' type='application/x-ppapi-tests' " |
| 207 " width='400' height='500' poster='snapshot1x.png'></object>" | 406 " width='100' height='100' poster='click_me.png'></object>" |
| 208 "<object id='plugin_srcset' type='application/x-ppapi-tests' " | 407 "<object id='plugin_srcset' type='application/x-ppapi-tests' " |
| 209 " width='400' height='500' " | 408 " width='100' height='100' " |
| 210 " poster='snapshot1x.png 1x, snapshot2x.png 2x'></object>" | 409 " poster='click_me.png 1x, click_me.png 2x'></object>" |
| 211 "<object id='plugin_legacy_syntax' type='application/x-ppapi-tests' " | 410 "<br>" |
| 212 " width='400' height='500'>" | 411 |
| 213 " <param name='poster' value='snapshot1x.png 1x, snapshot2x.png 2x'>" | 412 "<object id='plugin_poster_param' type='application/x-ppapi-tests' " |
| 413 " width='100' height='100'>" | |
| 414 " <param name='poster' value='click_me.png 1x, click_me.png 2x'>" | |
| 214 "</object>" | 415 "</object>" |
| 215 "<embed id='plugin_embed_src' type='application/x-ppapi-tests' " | 416 "<embed id='plugin_embed_src' type='application/x-ppapi-tests' " |
| 216 " width='400' height='500' poster='snapshot1x.png'></embed>" | 417 " width='100' height='100' poster='click_me.png'></embed>" |
| 217 "<embed id='plugin_embed_srcset' type='application/x-ppapi-tests' " | 418 "<embed id='plugin_embed_srcset' type='application/x-ppapi-tests' " |
| 218 " width='400' height='500'" | 419 " width='100' height='100'" |
| 219 " poster='snapshot1x.png 1x, snapshot2x.png 2x'></embed>"); | 420 " poster='click_me.png 1x, click_me.png 2x'></embed>" |
| 421 "<br>" | |
| 422 | |
| 423 "<object id='poster_missing' type='application/x-ppapi-tests' " | |
| 424 " width='100' height='100' poster='missing.png'></object>" | |
| 425 "<object id='poster_too_small' type='application/x-ppapi-tests' " | |
| 426 " width='100' height='50' poster='click_me.png'></object>" | |
| 427 "<object id='poster_too_big' type='application/x-ppapi-tests' " | |
| 428 " width='100' height='150' poster='click_me.png'></object>" | |
| 429 "<br>" | |
| 430 | |
| 431 "<object id='poster_16' type='application/x-ppapi-tests' " | |
| 432 " width='16' height='16' poster='click_me.png'></object>" | |
| 433 "<object id='poster_32' type='application/x-ppapi-tests' " | |
| 434 " width='32' height='32' poster='click_me.png'></object>" | |
| 435 "<object id='poster_16_64' type='application/x-ppapi-tests' " | |
| 436 " width='16' height='64' poster='click_me.png'></object>" | |
| 437 "<object id='poster_64_16' type='application/x-ppapi-tests' " | |
| 438 " width='64' height='16' poster='click_me.png'></object>" | |
| 439 "<br>" | |
| 440 | |
| 441 "<div id='container' " | |
| 442 " style='width: 400px; height: 100px; overflow: hidden;'>" | |
| 443 " <object id='poster_obscured' data='http://otherorigin.com/fake.swf' " | |
| 444 " type='application/x-ppapi-tests' width='400' height='500' " | |
| 445 " poster='click_me.png'>" | |
| 446 " </object>" | |
| 447 "</div>"); | |
| 220 | 448 |
| 221 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_src")); | 449 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_src")); |
| 222 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_srcset")); | 450 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_srcset")); |
| 223 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_legacy_syntax")); | 451 |
| 452 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_poster_param")); | |
| 224 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_src")); | 453 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_src")); |
| 225 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_srcset")); | 454 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin_embed_srcset")); |
| 455 | |
| 456 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_missing")); | |
| 457 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_too_small")); | |
| 458 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_too_big")); | |
| 459 | |
| 460 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_16")); | |
| 461 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_32")); | |
| 462 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_16_64")); | |
| 463 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_64_16")); | |
| 464 | |
| 465 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "poster_obscured")); | |
| 466 | |
| 467 EXPECT_TRUE(VerifySnapshot("poster_tests_expected.png")); | |
| 226 } | 468 } |
| 227 | 469 |
| 228 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, | 470 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, |
| 229 PluginMarkedEssentialAfterPosterClicked) { | 471 PluginMarkedEssentialAfterPosterClicked) { |
| 230 LoadHTML( | 472 LoadHTML( |
| 231 "<object id='plugin' type='application/x-ppapi-tests' " | 473 "<object id='plugin' type='application/x-ppapi-tests' " |
| 232 " width='400' height='100' poster='snapshot1x.png'></object>"); | 474 " width='400' height='100' poster='snapshot1x.png'></object>"); |
| 233 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin")); | 475 EXPECT_FALSE(PluginLoaded(GetActiveWebContents(), "plugin")); |
| 234 | 476 |
| 235 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); | 477 SimulateClickAndAwaitMarkedEssential("plugin", gfx::Point(50, 50)); |
| 236 } | 478 } |
| 237 | 479 |
| 238 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { | 480 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, OriginWhitelisting) { |
| 239 LoadHTML( | 481 LoadHTML( |
| 240 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' " | 482 "<object id='plugin1' data='http://otherorigin.com/fake1.swf' " |
| 241 " type='application/x-ppapi-tests' width='400' height='100'></object>" | 483 " type='application/x-ppapi-tests' width='400' height='100'></object>" |
| 242 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' " | 484 "<object id='plugin2' data='http://otherorigin.com/fake2.swf' " |
| 243 " type='application/x-ppapi-tests' width='400' height='500'>" | 485 " type='application/x-ppapi-tests' width='400' height='500'>" |
| 244 "</object>"); | 486 "</object>"); |
| 245 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin1"); | 487 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin1"); |
| 246 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin2"); | 488 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin2"); |
| 247 } | 489 } |
| 248 | 490 |
| 249 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { | 491 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, LargeCrossOriginObscured) { |
| 250 LoadHTML( | 492 LoadHTML( |
| 251 "<div id='container' " | 493 "<div id='container' " |
| 252 " style='width: 400px; height: 100px; overflow: hidden;'>" | 494 " style='width: 100px; height: 400px; overflow: hidden;'>" |
| 253 " <object id='plugin' data='http://otherorigin.com/fake.swf' " | 495 " <object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 254 " type='application/x-ppapi-tests' width='400' height='500'>" | 496 " type='application/x-ppapi-tests' width='400' height='500' " |
| 497 " style='float: right;'>" | |
| 255 " </object>" | 498 " </object>" |
| 256 "</div>"); | 499 "</div>"); |
| 257 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 500 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 501 EXPECT_TRUE(VerifySnapshot("large_cross_origin_obscured_expected.png")); | |
| 258 | 502 |
| 259 // Test that's unthrottled if it is unobscured. | 503 // Test that's unthrottled if it is unobscured. |
| 260 std::string script = | 504 std::string script = |
| 261 "var container = window.document.getElementById('container');" | 505 "var container = window.document.getElementById('container');" |
| 262 "container.setAttribute('style', 'width: 400px; height: 400px;');"; | 506 "container.setAttribute('style', 'width: 400px; height: 400px;');"; |
| 263 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); | 507 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), script)); |
| 264 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); | 508 VerifyPluginMarkedEssential(GetActiveWebContents(), "plugin"); |
| 265 } | 509 } |
| 266 | 510 |
| 267 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingSmallPlugin) { | 511 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ExpandingSmallPlugin) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 | 549 |
| 306 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { | 550 IN_PROC_BROWSER_TEST_F(PluginPowerSaverBrowserTest, ZoomIndependent) { |
| 307 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) | 551 ui_zoom::ZoomController::FromWebContents(GetActiveWebContents()) |
| 308 ->SetZoomLevel(4.0); | 552 ->SetZoomLevel(4.0); |
| 309 LoadHTML( | 553 LoadHTML( |
| 310 "<object id='plugin' data='http://otherorigin.com/fake.swf' " | 554 "<object id='plugin' data='http://otherorigin.com/fake.swf' " |
| 311 " type='application/x-ppapi-tests' width='400' height='200'>" | 555 " type='application/x-ppapi-tests' width='400' height='200'>" |
| 312 "</object>"); | 556 "</object>"); |
| 313 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); | 557 VerifyPluginIsThrottled(GetActiveWebContents(), "plugin"); |
| 314 } | 558 } |
| OLD | NEW |