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'>"; |
| 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( |
| 360 "The object has already navigated, so its partition cannot be changed.", |
| 361 title.c_str()); |
| 362 |
| 363 // Load a browser tag without 'src' defined. |
| 364 html = StringPrintf(kHTMLForSourcelessPluginObject, |
| 365 content::kBrowserPluginNewMimeType); |
| 366 LoadHTML(html.c_str()); |
| 367 |
| 368 // Ensure we don't parse just "persist:" string and return exception. |
| 369 ExecuteJavaScript( |
| 370 "try {" |
| 371 " document.getElementById('browserplugin').partition = 'persist:';" |
| 372 " document.title = 'success';" |
| 373 "} catch (e) { document.title = e.message; }"); |
| 374 title = ExecuteScriptAndReturnString("document.title"); |
| 375 EXPECT_STREQ("Invalid empty partition attribute.", title.c_str()); |
| 376 |
| 377 // Verify we can't set the partition attribute twice. |
| 378 ExecuteJavaScript( |
| 379 "document.getElementById('browserplugin').partition = 'foo'"); |
| 380 partition_value = ExecuteScriptAndReturnString( |
| 381 "document.getElementById('browserplugin').partition"); |
| 382 EXPECT_STREQ("foo", partition_value.c_str()); |
| 383 |
| 384 ExecuteJavaScript( |
| 385 "try {" |
| 386 " document.getElementById('browserplugin').partition = 'bar';" |
| 387 " document.title = 'success';" |
| 388 "} catch (e) { document.title = e.message; }"); |
| 389 title = ExecuteScriptAndReturnString("document.title"); |
| 390 EXPECT_STREQ("The partition attribute has already been set.", title.c_str()); |
| 391 } |
| 392 |
| 393 // Test to verify that after the first navigation, the partition attribute |
| 394 // cannot be modified. |
| 395 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { |
| 396 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, |
| 397 content::kBrowserPluginNewMimeType); |
| 398 LoadHTML(html.c_str()); |
| 399 |
| 400 ExecuteJavaScript( |
| 401 "document.getElementById('browserplugin').partition = 'storage'"); |
| 402 std::string partition_value = ExecuteScriptAndReturnString( |
| 403 "document.getElementById('browserplugin').partition"); |
| 404 EXPECT_STREQ("storage", partition_value.c_str()); |
| 405 |
| 406 std::string src_value = ExecuteScriptAndReturnString( |
| 407 "document.getElementById('browserplugin').src"); |
| 408 EXPECT_STREQ("", src_value.c_str()); |
| 409 |
| 410 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 411 { |
| 412 const IPC::Message* msg = |
| 413 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 414 BrowserPluginHostMsg_NavigateOrCreateGuest::ID); |
| 415 ASSERT_TRUE(msg); |
| 416 |
| 417 int instance_id; |
| 418 long long frame_id; |
| 419 std::string src; |
| 420 BrowserPluginHostMsg_NavigateOrCreateGuest::Read( |
| 421 msg, |
| 422 &instance_id, |
| 423 &frame_id, |
| 424 &src); |
| 425 EXPECT_STREQ("bar", src.c_str()); |
| 426 } |
| 427 |
| 428 // Setting the partition should throw an exception and the value should not |
| 429 // change. |
| 430 ExecuteJavaScript( |
| 431 "try {" |
| 432 " document.getElementById('browserplugin').partition = 'someid';" |
| 433 " document.title = 'success';" |
| 434 "} catch (e) { document.title = e.message; }"); |
| 435 |
| 436 std::string title = ExecuteScriptAndReturnString("document.title"); |
| 437 EXPECT_STREQ("The object has already navigated.", title.c_str()); |
| 438 |
| 439 partition_value = ExecuteScriptAndReturnString( |
| 440 "document.getElementById('browserplugin').partition"); |
| 441 EXPECT_STREQ("storage", partition_value.c_str()); |
| 442 } |
| 443 |
| 444 // Test to ensure that the partition attribute can handle non-ASCII strings. |
| 445 // The test uses cyrillic and chinese strings. |
| 446 TEST_F(BrowserPluginTest, PartitionAttributeEncoding) { |
| 447 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, |
| 448 content::kBrowserPluginNewMimeType); |
| 449 LoadHTML(html.c_str()); |
| 450 |
| 451 // The cyrillic test string. |
| 452 std::string cyrillic("\u0445\u0440\u043E\u043C"); |
| 453 std::string js("document.getElementById('browserplugin').partition = '"); |
| 454 js.append(cyrillic).append("'"); |
| 455 |
| 456 ExecuteJavaScript(js.c_str()); |
| 457 std::string partition_value = ExecuteScriptAndReturnString( |
| 458 "document.getElementById('browserplugin').partition"); |
| 459 EXPECT_STREQ(cyrillic.c_str(), partition_value.c_str()); |
| 460 |
| 461 LoadHTML(html.c_str()); |
| 462 |
| 463 // A random string of chinese characters, not meant to be meaningful. |
| 464 std::string chinese("\u94EC\u927B\U00029A72\U00009C61\U00021C56"); |
| 465 std::string persist = std::string("persist:").append(chinese); |
| 466 js = "document.getElementById('browserplugin').partition = '"; |
| 467 js.append(persist).append("'"); |
| 468 |
| 469 ExecuteJavaScript(js.c_str()); |
| 470 partition_value = ExecuteScriptAndReturnString( |
| 471 "document.getElementById('browserplugin').partition"); |
| 472 EXPECT_STREQ(persist.c_str(), partition_value.c_str()); |
| 473 } |
| 474 |
322 } // namespace content | 475 } // namespace content |
OLD | NEW |