Chromium Code Reviews| 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/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
| 16 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 16 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
| 17 #include "content/shell/shell_main_delegate.h" | 17 #include "content/shell/shell_main_delegate.h" |
| 18 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScriptSource.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 const char kHTMLForBrowserPluginObject[] = | 24 const char kHTMLForBrowserPluginObject[] = |
| 25 "<object id='browserplugin' width='640px' height='480px'" | 25 "<object id='browserplugin' width='640px' height='480px'" |
| 26 " src='foo' type='%s'>"; | 26 " src='foo' type='%s'>"; |
| 27 | 27 |
| 28 const char kHTMLForSourcelessPluginObject[] = | |
| 29 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; | |
| 30 | |
| 31 const char kHTMLForPartitionedPluginObject[] = | |
| 32 "<object id='browserplugin' width='640px' height='480px'" | |
| 33 " src='foo' type='%s' partition='someid'>"; | |
| 34 | |
| 35 const char kHTMLForPartitionedPersistedPluginObject[] = | |
| 36 "<object id='browserplugin' width='640px' height='480px'" | |
| 37 " src='foo' type='%s' partition='persist:someid'>"; | |
|
Charlie Reis
2012/09/18 22:09:33
Is it also worth testing one with a partition and
nasko
2012/09/18 22:56:20
If you agree with my comment about setting partiti
| |
| 38 | |
| 28 std::string GetHTMLForBrowserPluginObject() { | 39 std::string GetHTMLForBrowserPluginObject() { |
| 29 return StringPrintf(kHTMLForBrowserPluginObject, | 40 return StringPrintf(kHTMLForBrowserPluginObject, |
| 30 content::kBrowserPluginNewMimeType); | 41 content::kBrowserPluginNewMimeType); |
| 31 } | 42 } |
| 32 | 43 |
| 33 } | 44 } |
| 34 | 45 |
| 35 namespace content { | 46 namespace content { |
| 36 | 47 |
| 37 BrowserPluginTest::BrowserPluginTest() {} | 48 BrowserPluginTest::BrowserPluginTest() {} |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 browser_plugin->DidNavigate(GURL(kGoogleURL)); | 323 browser_plugin->DidNavigate(GURL(kGoogleURL)); |
| 313 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 324 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
| 314 | 325 |
| 315 ExecuteJavaScript(kRemoveEventListener); | 326 ExecuteJavaScript(kRemoveEventListener); |
| 316 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); | 327 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); |
| 317 // The URL variable should not change because we've removed the event | 328 // The URL variable should not change because we've removed the event |
| 318 // listener. | 329 // listener. |
| 319 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 330 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
| 320 } | 331 } |
| 321 | 332 |
| 333 | |
| 334 // Verify that the 'partition' attribute on the browser plugin is parsed | |
| 335 // correctly. | |
| 336 TEST_F(BrowserPluginTest, PartitionAttribute) { | |
| 337 std::string html = StringPrintf(kHTMLForPartitionedPluginObject, | |
| 338 content::kBrowserPluginNewMimeType); | |
| 339 LoadHTML(html.c_str()); | |
| 340 std::string partition_value = ExecuteScriptAndReturnString( | |
| 341 "document.getElementById('browserplugin').partition"); | |
| 342 EXPECT_STREQ("someid", partition_value.c_str()); | |
| 343 | |
| 344 html = StringPrintf(kHTMLForPartitionedPersistedPluginObject, | |
| 345 content::kBrowserPluginNewMimeType); | |
| 346 LoadHTML(html.c_str()); | |
| 347 partition_value = ExecuteScriptAndReturnString( | |
| 348 "document.getElementById('browserplugin').partition"); | |
| 349 EXPECT_STREQ("persist:someid", partition_value.c_str()); | |
| 350 | |
| 351 // Verify that once HTML has defined a source and partition, we cannot change | |
| 352 // the partition anymore. | |
| 353 ExecuteJavaScript( | |
| 354 "try {" | |
| 355 " document.getElementById('browserplugin').partition = 'foo';" | |
| 356 " document.title = 'success';" | |
| 357 "} catch (e) { document.title = e.message; }"); | |
| 358 std::string title = ExecuteScriptAndReturnString("document.title"); | |
| 359 EXPECT_STREQ("The object has already navigated.", title.c_str()); | |
| 360 | |
| 361 // Load a browser tag without 'src' defined. | |
| 362 html = StringPrintf(kHTMLForSourcelessPluginObject, | |
| 363 content::kBrowserPluginNewMimeType); | |
| 364 LoadHTML(html.c_str()); | |
| 365 | |
| 366 // Ensure we don't parse just "persist:" string and return exception. | |
| 367 ExecuteJavaScript( | |
| 368 "try {" | |
| 369 " document.getElementById('browserplugin').partition = 'persist:';" | |
| 370 " document.title = 'success';" | |
| 371 "} catch (e) { document.title = e.message; }"); | |
| 372 title = ExecuteScriptAndReturnString("document.title"); | |
| 373 EXPECT_STREQ("Invalid partition attribute.", title.c_str()); | |
| 374 | |
| 375 // Verify we can't set the partition attribute twice. | |
| 376 ExecuteJavaScript( | |
| 377 "document.getElementById('browserplugin').partition = 'foo'"); | |
| 378 partition_value = ExecuteScriptAndReturnString( | |
| 379 "document.getElementById('browserplugin').partition"); | |
| 380 EXPECT_STREQ("foo", partition_value.c_str()); | |
| 381 | |
| 382 ExecuteJavaScript( | |
| 383 "try {" | |
| 384 " document.getElementById('browserplugin').partition = 'bar';" | |
| 385 " document.title = 'success';" | |
| 386 "} catch (e) { document.title = e.message; }"); | |
| 387 title = ExecuteScriptAndReturnString("document.title"); | |
| 388 EXPECT_STREQ("The partition attribute has already been set.", title.c_str()); | |
| 389 } | |
| 390 | |
| 391 // Test to verify that after the first navigation, the partition attribute | |
| 392 // cannot be modified. | |
| 393 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { | |
| 394 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, | |
| 395 content::kBrowserPluginNewMimeType); | |
| 396 LoadHTML(html.c_str()); | |
| 397 | |
| 398 ExecuteJavaScript( | |
| 399 "document.getElementById('browserplugin').partition = 'storage'"); | |
| 400 std::string partition_value = ExecuteScriptAndReturnString( | |
| 401 "document.getElementById('browserplugin').partition"); | |
| 402 EXPECT_STREQ("storage", partition_value.c_str()); | |
| 403 | |
| 404 std::string src_value = ExecuteScriptAndReturnString( | |
| 405 "document.getElementById('browserplugin').src"); | |
| 406 EXPECT_STREQ("", src_value.c_str()); | |
| 407 | |
| 408 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); | |
| 409 { | |
| 410 const IPC::Message* msg = | |
| 411 browser_plugin_manager()->sink().GetUniqueMessageMatching( | |
| 412 BrowserPluginHostMsg_NavigateOrCreateGuest::ID); | |
| 413 ASSERT_TRUE(msg); | |
| 414 | |
| 415 int instance_id; | |
| 416 long long frame_id; | |
| 417 std::string src; | |
| 418 BrowserPluginHostMsg_NavigateOrCreateGuest::Read( | |
| 419 msg, | |
| 420 &instance_id, | |
| 421 &frame_id, | |
| 422 &src); | |
| 423 EXPECT_STREQ("bar", src.c_str()); | |
| 424 } | |
| 425 | |
| 426 // Setting the partition should throw an exception and the value should not | |
| 427 // change. | |
| 428 ExecuteJavaScript( | |
| 429 "try {" | |
| 430 " document.getElementById('browserplugin').partition = 'someid';" | |
| 431 " document.title = 'success';" | |
| 432 "} catch (e) { document.title = e.message; }"); | |
| 433 | |
| 434 std::string title = ExecuteScriptAndReturnString("document.title"); | |
| 435 EXPECT_STREQ("The object has already navigated.", title.c_str()); | |
| 436 | |
| 437 partition_value = ExecuteScriptAndReturnString( | |
| 438 "document.getElementById('browserplugin').partition"); | |
| 439 EXPECT_STREQ("storage", partition_value.c_str()); | |
| 440 } | |
| 441 | |
| 442 // Test to ensure that the partition attribute can handle non-ASCII strings. | |
| 443 // The test uses cyrillic and chinese strings. | |
| 444 TEST_F(BrowserPluginTest, PartitionAttributeEncoding) { | |
| 445 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, | |
| 446 content::kBrowserPluginNewMimeType); | |
| 447 LoadHTML(html.c_str()); | |
| 448 | |
| 449 // The cyrillic test string. | |
| 450 std::string cyrillic("\u0445\u0440\u043E\u043C"); | |
| 451 std::string js("document.getElementById('browserplugin').partition = '"); | |
| 452 js.append(cyrillic).append("'"); | |
| 453 | |
| 454 ExecuteJavaScript(js.c_str()); | |
| 455 std::string partition_value = ExecuteScriptAndReturnString( | |
| 456 "document.getElementById('browserplugin').partition"); | |
| 457 EXPECT_STREQ(cyrillic.c_str(), partition_value.c_str()); | |
| 458 | |
| 459 LoadHTML(html.c_str()); | |
| 460 | |
| 461 // A random string of chinese characters, not meant to be meaningful. | |
| 462 std::string chinese("\u94EC\u927B\U00029A72\U00009C61\U00021C56"); | |
| 463 std::string persist = std::string("persist:").append(chinese); | |
| 464 js = "document.getElementById('browserplugin').partition = '"; | |
| 465 js.append(persist).append("'"); | |
| 466 | |
| 467 ExecuteJavaScript(js.c_str()); | |
| 468 partition_value = ExecuteScriptAndReturnString( | |
| 469 "document.getElementById('browserplugin').partition"); | |
| 470 EXPECT_STREQ(persist.c_str(), partition_value.c_str()); | |
| 471 } | |
| 472 | |
| 322 } // namespace content | 473 } // namespace content |
| OLD | NEW |