| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin_browsertest.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_browsertest.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
| 11 #include "content/public/common/content_constants.h" | 11 #include "content/public/common/content_constants.h" |
| 12 #include "content/renderer/browser_plugin/browser_plugin.h" | 12 #include "content/renderer/browser_plugin/browser_plugin.h" |
| 13 #include "content/renderer/browser_plugin/mock_browser_plugin.h" | 13 #include "content/renderer/browser_plugin/mock_browser_plugin.h" |
| 14 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" | 14 #include "content/renderer/browser_plugin/mock_browser_plugin_manager.h" |
| 15 #include "content/renderer/browser_plugin/mock_browser_plugin_texture_provider.h
" |
| 15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
| 16 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 17 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
| 17 #include "content/shell/shell_main_delegate.h" | 18 #include "content/shell/shell_main_delegate.h" |
| 18 #include "skia/ext/platform_canvas.h" | 19 #include "skia/ext/platform_canvas.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 const char kHTMLForBrowserPluginObject[] = | 25 const char kHTMLForBrowserPluginObject[] = |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 108 } |
| 108 | 109 |
| 109 // Verify that the src attribute on the browser plugin works as expected. | 110 // Verify that the src attribute on the browser plugin works as expected. |
| 110 TEST_F(BrowserPluginTest, SrcAttribute) { | 111 TEST_F(BrowserPluginTest, SrcAttribute) { |
| 111 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 112 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 112 // Verify that we're reporting the correct URL to navigate to based on the | 113 // Verify that we're reporting the correct URL to navigate to based on the |
| 113 // src attribute. | 114 // src attribute. |
| 114 { | 115 { |
| 115 const IPC::Message* msg = | 116 const IPC::Message* msg = |
| 116 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 117 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 117 BrowserPluginHostMsg_NavigateOrCreateGuest::ID); | 118 BrowserPluginHostMsg_NavigateGuest::ID); |
| 118 ASSERT_TRUE(msg); | 119 ASSERT_TRUE(msg); |
| 119 | 120 |
| 120 int instance_id; | 121 int instance_id; |
| 121 long long frame_id; | 122 long long frame_id; |
| 122 std::string src; | 123 std::string src; |
| 123 gfx::Size size; | 124 gfx::Size size; |
| 124 BrowserPluginHostMsg_NavigateOrCreateGuest::Read( | 125 BrowserPluginHostMsg_Surface_Params params; |
| 126 BrowserPluginHostMsg_NavigateGuest::Read( |
| 125 msg, | 127 msg, |
| 126 &instance_id, | 128 &instance_id, |
| 127 &frame_id, | 129 &frame_id, |
| 128 &src, | 130 &src, |
| 129 &size); | 131 &size, |
| 132 ¶ms); |
| 130 EXPECT_EQ("foo", src); | 133 EXPECT_EQ("foo", src); |
| 131 } | 134 } |
| 132 | 135 |
| 133 browser_plugin_manager()->sink().ClearMessages(); | 136 browser_plugin_manager()->sink().ClearMessages(); |
| 134 // Navigate to bar and observe the associated | 137 // Navigate to bar and observe the associated |
| 135 // BrowserPluginHostMsg_NavigateOrCreateGuest message. | 138 // BrowserPluginHostMsg_NavigateOrCreateGuest message. |
| 136 // Verify that the src attribute is updated as well. | 139 // Verify that the src attribute is updated as well. |
| 137 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | 140 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 138 { | 141 { |
| 139 const IPC::Message* msg = | 142 const IPC::Message* msg = |
| 140 browser_plugin_manager()->sink().GetUniqueMessageMatching( | 143 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 141 BrowserPluginHostMsg_NavigateOrCreateGuest::ID); | 144 BrowserPluginHostMsg_NavigateGuest::ID); |
| 142 ASSERT_TRUE(msg); | 145 ASSERT_TRUE(msg); |
| 143 | 146 |
| 144 int instance_id; | 147 int instance_id; |
| 145 long long frame_id; | 148 long long frame_id; |
| 146 std::string src; | 149 std::string src; |
| 147 gfx::Size size; | 150 gfx::Size size; |
| 148 BrowserPluginHostMsg_NavigateOrCreateGuest::Read( | 151 BrowserPluginHostMsg_Surface_Params params; |
| 152 BrowserPluginHostMsg_NavigateGuest::Read( |
| 149 msg, | 153 msg, |
| 150 &instance_id, | 154 &instance_id, |
| 151 &frame_id, | 155 &frame_id, |
| 152 &src, | 156 &src, |
| 153 &size); | 157 &size, |
| 158 ¶ms); |
| 154 EXPECT_EQ("bar", src); | 159 EXPECT_EQ("bar", src); |
| 155 std::string src_value = | 160 std::string src_value = |
| 156 ExecuteScriptAndReturnString( | 161 ExecuteScriptAndReturnString( |
| 157 "document.getElementById('browserplugin').src"); | 162 "document.getElementById('browserplugin').src"); |
| 158 EXPECT_EQ("bar", src_value); | 163 EXPECT_EQ("bar", src_value); |
| 159 } | 164 } |
| 160 } | 165 } |
| 161 | 166 |
| 162 TEST_F(BrowserPluginTest, ResizeFlowControl) { | 167 TEST_F(BrowserPluginTest, ResizeFlowControl) { |
| 163 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 168 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 browser_plugin->DidNavigate(GURL(kGoogleURL)); | 321 browser_plugin->DidNavigate(GURL(kGoogleURL)); |
| 317 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 322 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
| 318 | 323 |
| 319 ExecuteJavaScript(kRemoveEventListener); | 324 ExecuteJavaScript(kRemoveEventListener); |
| 320 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); | 325 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); |
| 321 // The URL variable should not change because we've removed the event | 326 // The URL variable should not change because we've removed the event |
| 322 // listener. | 327 // listener. |
| 323 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 328 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
| 324 } | 329 } |
| 325 | 330 |
| 331 TEST_F(BrowserPluginTest, CompositingSwitch) { |
| 332 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 333 |
| 334 const IPC::Message* msg = |
| 335 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 336 BrowserPluginHostMsg_ResizeGuest::ID); |
| 337 ASSERT_TRUE(msg); |
| 338 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); |
| 339 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; |
| 340 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); |
| 341 int instance_id = resize_params.a; |
| 342 |
| 343 MockBrowserPlugin* browser_plugin = |
| 344 static_cast<MockBrowserPlugin*>( |
| 345 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 346 ASSERT_TRUE(browser_plugin); |
| 347 |
| 348 EXPECT_FALSE(browser_plugin->ignoringInput()); |
| 349 EXPECT_FALSE(browser_plugin->hasTextureProvider()); |
| 350 |
| 351 MockBrowserPluginTextureProvider* provider = |
| 352 new MockBrowserPluginTextureProvider( |
| 353 browser_plugin->instance_id(), |
| 354 browser_plugin->render_view()->GetRoutingID(), |
| 355 0); |
| 356 |
| 357 using ::testing::Mock; |
| 358 |
| 359 // Check initial resize |
| 360 { |
| 361 using ::testing::_; |
| 362 using ::testing::Return; |
| 363 |
| 364 // Arbitrary constants |
| 365 gfx::Size size(50, 20); |
| 366 |
| 367 // The plugin should use its own instance ID, but the routing ID is really |
| 368 // an internal detail |
| 369 EXPECT_CALL(*browser_plugin, |
| 370 CreateTextureProvider(browser_plugin->instance_id(), _)) |
| 371 .WillOnce(Return(provider)); |
| 372 EXPECT_CALL( |
| 373 *provider, |
| 374 Resize(gfx::Size(browser_plugin->width(), browser_plugin->height()))); |
| 375 EXPECT_CALL(*provider, SurfaceResize(size)); |
| 376 |
| 377 browser_plugin->SurfaceResize(size); |
| 378 |
| 379 EXPECT_FALSE(browser_plugin->ignoringInput()); |
| 380 ASSERT_TRUE(browser_plugin->hasTextureProvider()); |
| 381 |
| 382 Mock::VerifyAndClear(provider); |
| 383 } |
| 384 |
| 385 // Check subsequent resize |
| 386 { |
| 387 // Arbitrary constants |
| 388 gfx::Size size(5223, 25626); |
| 389 |
| 390 EXPECT_CALL(*provider, SurfaceResize(size)); |
| 391 |
| 392 browser_plugin->SurfaceResize(size); |
| 393 |
| 394 EXPECT_FALSE(browser_plugin->ignoringInput()); |
| 395 |
| 396 Mock::VerifyAndClear(provider); |
| 397 } |
| 398 |
| 399 // Check buffer swap |
| 400 { |
| 401 using ::testing::_; |
| 402 |
| 403 // Arbitrary constant |
| 404 int surface_id = 453; |
| 405 |
| 406 EXPECT_CALL(*provider, SetDelayedSwap(surface_id, _)); |
| 407 |
| 408 // TODO: Verify that the Info arg is correct |
| 409 browser_plugin->BuffersSwapped(surface_id, BrowserPlugin_SwapInfo()); |
| 410 |
| 411 EXPECT_TRUE(browser_plugin->ignoringInput()); |
| 412 |
| 413 // Check to make sure it is actually ignoring input |
| 414 WebKit::WebCursorInfo cursor_info; |
| 415 bool handled = browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), |
| 416 cursor_info); |
| 417 EXPECT_TRUE(handled); |
| 418 ASSERT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 419 BrowserPluginHostMsg_HandleInputEvent::ID)); |
| 420 |
| 421 Mock::VerifyAndClear(provider); |
| 422 } |
| 423 |
| 424 // Check completion |
| 425 { |
| 426 browser_plugin->TextureProviderIsReady(); |
| 427 |
| 428 EXPECT_FALSE(browser_plugin->ignoringInput()); |
| 429 |
| 430 WebKit::WebCursorInfo cursor_info; |
| 431 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), |
| 432 cursor_info); |
| 433 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 434 BrowserPluginHostMsg_HandleInputEvent::ID)); |
| 435 } |
| 436 |
| 437 // Check subsequent resize |
| 438 { |
| 439 // Arbitrary constants |
| 440 gfx::Size size(1, 1); |
| 441 |
| 442 EXPECT_CALL(*provider, SurfaceResize(size)); |
| 443 |
| 444 browser_plugin->SurfaceResize(size); |
| 445 |
| 446 EXPECT_FALSE(browser_plugin->ignoringInput()); |
| 447 |
| 448 Mock::VerifyAndClear(provider); |
| 449 } |
| 450 } |
| 451 |
| 452 /* |
| 453 namespace { |
| 454 |
| 455 class MockTextureProviderClient |
| 456 : WebKit::WebExternalTextureProvider::Client { |
| 457 public: |
| 458 MOCK_METHOD0(stopUsingProvider, void()); |
| 459 MOCK_METHOD0(didReceiveFrame, void()); |
| 460 MOCK_METHOD0(insertSyncPoint, unsigned()); |
| 461 }; |
| 462 |
| 463 } |
| 464 */ |
| 465 |
| 466 TEST_F(BrowserPluginTest, TextureProviderSingleThreaded) { |
| 467 // Arbitrary constants |
| 468 int instance_id = 4; |
| 469 int routing_id = 4523; |
| 470 |
| 471 BrowserPluginTextureProvider* provider = new BrowserPluginTextureProvider( |
| 472 instance_id, |
| 473 routing_id, |
| 474 0); |
| 475 |
| 476 // TODO: Provide a ChannelProxy equivalent to IPC::TestSink and use to get |
| 477 // messages. In the meanwhile, test the only thing we can. |
| 478 { |
| 479 EXPECT_TRUE(provider->flipped()); |
| 480 EXPECT_TRUE(provider->premultipliedAlpha()); |
| 481 |
| 482 provider->Resize(gfx::Size(4, 4)); |
| 483 provider->SurfaceResize(gfx::Size(8, 8)); |
| 484 |
| 485 // TODO: Not do floating point comparisons here. It works in this case |
| 486 // because it's powers of 2. |
| 487 EXPECT_EQ(provider->uvRect(), WebKit::WebFloatRect(0, 0, 0.5, 0.5)); |
| 488 } |
| 489 |
| 490 provider->Destroy(); |
| 491 } |
| 492 |
| 326 } // namespace content | 493 } // namespace content |
| OLD | NEW |