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 } // namespace | 44 } // namespace |
34 | 45 |
35 namespace content { | 46 namespace content { |
36 | 47 |
37 BrowserPluginTest::BrowserPluginTest() {} | 48 BrowserPluginTest::BrowserPluginTest() {} |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 browser_plugin->DidNavigate(GURL(kGoogleURL)); | 327 browser_plugin->DidNavigate(GURL(kGoogleURL)); |
317 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 328 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
318 | 329 |
319 ExecuteJavaScript(kRemoveEventListener); | 330 ExecuteJavaScript(kRemoveEventListener); |
320 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); | 331 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); |
321 // The URL variable should not change because we've removed the event | 332 // The URL variable should not change because we've removed the event |
322 // listener. | 333 // listener. |
323 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 334 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
324 } | 335 } |
325 | 336 |
| 337 |
| 338 // Verify that the 'partition' attribute on the browser plugin is parsed |
| 339 // correctly. |
| 340 TEST_F(BrowserPluginTest, PartitionAttribute) { |
| 341 std::string html = StringPrintf(kHTMLForPartitionedPluginObject, |
| 342 content::kBrowserPluginNewMimeType); |
| 343 LoadHTML(html.c_str()); |
| 344 std::string partition_value = ExecuteScriptAndReturnString( |
| 345 "document.getElementById('browserplugin').partition"); |
| 346 EXPECT_STREQ("someid", partition_value.c_str()); |
| 347 |
| 348 html = StringPrintf(kHTMLForPartitionedPersistedPluginObject, |
| 349 content::kBrowserPluginNewMimeType); |
| 350 LoadHTML(html.c_str()); |
| 351 partition_value = ExecuteScriptAndReturnString( |
| 352 "document.getElementById('browserplugin').partition"); |
| 353 EXPECT_STREQ("persist:someid", partition_value.c_str()); |
| 354 |
| 355 // Verify that once HTML has defined a source and partition, we cannot change |
| 356 // the partition anymore. |
| 357 ExecuteJavaScript( |
| 358 "try {" |
| 359 " document.getElementById('browserplugin').partition = 'foo';" |
| 360 " document.title = 'success';" |
| 361 "} catch (e) { document.title = e.message; }"); |
| 362 std::string title = ExecuteScriptAndReturnString("document.title"); |
| 363 EXPECT_STREQ( |
| 364 "The object has already navigated, so its partition cannot be changed.", |
| 365 title.c_str()); |
| 366 |
| 367 // Load a browser tag without 'src' defined. |
| 368 html = StringPrintf(kHTMLForSourcelessPluginObject, |
| 369 content::kBrowserPluginNewMimeType); |
| 370 LoadHTML(html.c_str()); |
| 371 |
| 372 // Ensure we don't parse just "persist:" string and return exception. |
| 373 ExecuteJavaScript( |
| 374 "try {" |
| 375 " document.getElementById('browserplugin').partition = 'persist:';" |
| 376 " document.title = 'success';" |
| 377 "} catch (e) { document.title = e.message; }"); |
| 378 title = ExecuteScriptAndReturnString("document.title"); |
| 379 EXPECT_STREQ("Invalid empty partition attribute.", title.c_str()); |
| 380 } |
| 381 |
| 382 // Test to verify that after the first navigation, the partition attribute |
| 383 // cannot be modified. |
| 384 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { |
| 385 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, |
| 386 content::kBrowserPluginNewMimeType); |
| 387 LoadHTML(html.c_str()); |
| 388 |
| 389 ExecuteJavaScript( |
| 390 "document.getElementById('browserplugin').partition = 'storage'"); |
| 391 std::string partition_value = ExecuteScriptAndReturnString( |
| 392 "document.getElementById('browserplugin').partition"); |
| 393 EXPECT_STREQ("storage", partition_value.c_str()); |
| 394 |
| 395 std::string src_value = ExecuteScriptAndReturnString( |
| 396 "document.getElementById('browserplugin').src"); |
| 397 EXPECT_STREQ("", src_value.c_str()); |
| 398 |
| 399 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 400 { |
| 401 const IPC::Message* msg = |
| 402 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 403 BrowserPluginHostMsg_NavigateGuest::ID); |
| 404 ASSERT_TRUE(msg); |
| 405 |
| 406 int instance_id; |
| 407 long long frame_id; |
| 408 std::string src; |
| 409 gfx::Size size; |
| 410 BrowserPluginHostMsg_NavigateGuest::Read( |
| 411 msg, |
| 412 &instance_id, |
| 413 &frame_id, |
| 414 &src, |
| 415 &size); |
| 416 EXPECT_STREQ("bar", src.c_str()); |
| 417 } |
| 418 |
| 419 // Setting the partition should throw an exception and the value should not |
| 420 // change. |
| 421 ExecuteJavaScript( |
| 422 "try {" |
| 423 " document.getElementById('browserplugin').partition = 'someid';" |
| 424 " document.title = 'success';" |
| 425 "} catch (e) { document.title = e.message; }"); |
| 426 |
| 427 std::string title = ExecuteScriptAndReturnString("document.title"); |
| 428 EXPECT_STREQ( |
| 429 "The object has already navigated, so its partition cannot be changed.", |
| 430 title.c_str()); |
| 431 |
| 432 partition_value = ExecuteScriptAndReturnString( |
| 433 "document.getElementById('browserplugin').partition"); |
| 434 EXPECT_STREQ("storage", partition_value.c_str()); |
| 435 } |
| 436 |
326 } // namespace content | 437 } // namespace content |
OLD | NEW |