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" |
(...skipping 12 matching lines...) Expand all Loading... |
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 std::string GetHTMLForBrowserPluginObject() { | 28 std::string GetHTMLForBrowserPluginObject() { |
29 return StringPrintf(kHTMLForBrowserPluginObject, | 29 return StringPrintf(kHTMLForBrowserPluginObject, |
30 content::kBrowserPluginNewMimeType); | 30 content::kBrowserPluginNewMimeType); |
31 } | 31 } |
32 | 32 |
| 33 const char kHTMLForPartitionedPluginObject[] = |
| 34 "<object id='browserplugin' width='640px' height='480px'" |
| 35 " src='foo' type='%s' partition='someid'>"; |
| 36 |
| 37 const char kHTMLForPartitionedPersistedPluginObject[] = |
| 38 "<object id='browserplugin' width='640px' height='480px'" |
| 39 " src='foo' type='%s' partition='someid' persist>"; |
| 40 |
33 } | 41 } |
34 | 42 |
35 namespace content { | 43 namespace content { |
36 | 44 |
37 BrowserPluginTest::BrowserPluginTest() {} | 45 BrowserPluginTest::BrowserPluginTest() {} |
38 | 46 |
39 BrowserPluginTest::~BrowserPluginTest() {} | 47 BrowserPluginTest::~BrowserPluginTest() {} |
40 | 48 |
41 void BrowserPluginTest::SetUp() { | 49 void BrowserPluginTest::SetUp() { |
42 GetContentClient()->set_renderer_for_testing(&content_renderer_client_); | 50 GetContentClient()->set_renderer_for_testing(&content_renderer_client_); |
(...skipping 14 matching lines...) Expand all Loading... |
57 if (value.IsEmpty() || !value->IsString()) | 65 if (value.IsEmpty() || !value->IsString()) |
58 return std::string(); | 66 return std::string(); |
59 | 67 |
60 v8::Local<v8::String> v8_str = value->ToString(); | 68 v8::Local<v8::String> v8_str = value->ToString(); |
61 int length = v8_str->Utf8Length() + 1; | 69 int length = v8_str->Utf8Length() + 1; |
62 scoped_array<char> str(new char[length]); | 70 scoped_array<char> str(new char[length]); |
63 v8_str->WriteUtf8(str.get(), length); | 71 v8_str->WriteUtf8(str.get(), length); |
64 return str.get(); | 72 return str.get(); |
65 } | 73 } |
66 | 74 |
| 75 bool BrowserPluginTest::ExecuteScriptAndReturnBool( |
| 76 const std::string& script, |
| 77 bool& result) { |
| 78 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue( |
| 79 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str()))); |
| 80 if (value.IsEmpty() || !value->IsBoolean()) |
| 81 return false; |
| 82 |
| 83 result = value->BooleanValue(); |
| 84 return true; |
| 85 } |
| 86 |
67 // This test verifies that an initial resize occurs when we instantiate the | 87 // This test verifies that an initial resize occurs when we instantiate the |
68 // browser plugin. This test also verifies that the browser plugin is waiting | 88 // browser plugin. This test also verifies that the browser plugin is waiting |
69 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and | 89 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and |
70 // we observe an UpdateRect_ACK, with the resize_pending_ reset, indiciating | 90 // we observe an UpdateRect_ACK, with the resize_pending_ reset, indiciating |
71 // that the BrowserPlugin is not waiting for any more UpdateRects to | 91 // that the BrowserPlugin is not waiting for any more UpdateRects to |
72 // satisfy its resize request. | 92 // satisfy its resize request. |
73 TEST_F(BrowserPluginTest, InitialResize) { | 93 TEST_F(BrowserPluginTest, InitialResize) { |
74 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 94 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
75 // Verify that the information based on ResizeGuest is correct, and | 95 // Verify that the information based on ResizeGuest is correct, and |
76 // use its TransportDIB::Id to paint. | 96 // use its TransportDIB::Id to paint. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 browser_plugin->DidNavigate(GURL(kGoogleURL)); | 332 browser_plugin->DidNavigate(GURL(kGoogleURL)); |
313 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 333 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
314 | 334 |
315 ExecuteJavaScript(kRemoveEventListener); | 335 ExecuteJavaScript(kRemoveEventListener); |
316 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); | 336 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); |
317 // The URL variable should not change because we've removed the event | 337 // The URL variable should not change because we've removed the event |
318 // listener. | 338 // listener. |
319 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 339 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
320 } | 340 } |
321 | 341 |
| 342 // Verify that the 'partition' attribute on the browser plugin is parsed |
| 343 // correctly. |
| 344 TEST_F(BrowserPluginTest, PartitionAttribute) { |
| 345 std::string html = StringPrintf(kHTMLForPartitionedPluginObject, |
| 346 content::kBrowserPluginNewMimeType); |
| 347 LoadHTML(html.c_str()); |
| 348 |
| 349 std::string partition_value = ExecuteScriptAndReturnString( |
| 350 "document.getElementById('browserplugin').partition"); |
| 351 EXPECT_EQ("someid", partition_value); |
| 352 |
| 353 // Ensure that setting the partition attribute, once it has been set, has |
| 354 // no effect. |
| 355 ExecuteJavaScript( |
| 356 "document.getElementById('browserplugin').partition = 'bar'"); |
| 357 |
| 358 partition_value = ExecuteScriptAndReturnString( |
| 359 "document.getElementById('browserplugin').partition"); |
| 360 EXPECT_EQ("someid", partition_value); |
| 361 } |
| 362 |
| 363 // Verify that the 'persist' attribute on the browser plugin is parsed |
| 364 // correctly. |
| 365 TEST_F(BrowserPluginTest, PersistAttribute) { |
| 366 std::string html = StringPrintf(kHTMLForPartitionedPersistedPluginObject, |
| 367 content::kBrowserPluginNewMimeType); |
| 368 LoadHTML(html.c_str()); |
| 369 |
| 370 bool persist_value = false; |
| 371 // Check that the value has been properly parsed. |
| 372 EXPECT_TRUE(ExecuteScriptAndReturnBool( |
| 373 "document.getElementById('browserplugin').persist", persist_value)); |
| 374 EXPECT_TRUE(persist_value); |
| 375 |
| 376 // Ensure that setting the value, once it is initialized, has no effect. |
| 377 ExecuteJavaScript( |
| 378 "document.getElementById('browserplugin').persist = false"); |
| 379 EXPECT_TRUE(ExecuteScriptAndReturnBool( |
| 380 "document.getElementById('browserplugin').persist", persist_value)); |
| 381 EXPECT_TRUE(persist_value); |
| 382 |
| 383 // Verify that missing persist attribute defaults to false. |
| 384 html = StringPrintf(kHTMLForPartitionedPluginObject, |
| 385 content::kBrowserPluginNewMimeType); |
| 386 LoadHTML(html.c_str()); |
| 387 |
| 388 EXPECT_TRUE(ExecuteScriptAndReturnBool( |
| 389 "document.getElementById('browserplugin').persist", persist_value)); |
| 390 EXPECT_FALSE(persist_value); |
| 391 } |
| 392 |
| 393 // Test to verify that after the first navigation, the partition and persist |
| 394 // properties cannot be modified. |
| 395 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { |
| 396 const char kHtml[] = |
| 397 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; |
| 398 std::string html = StringPrintf(kHtml, content::kBrowserPluginNewMimeType); |
| 399 LoadHTML(html.c_str()); |
| 400 |
| 401 ExecuteJavaScript( |
| 402 "document.getElementById('browserplugin').partition = 'storage'"); |
| 403 std::string partition_value = ExecuteScriptAndReturnString( |
| 404 "document.getElementById('browserplugin').partition"); |
| 405 EXPECT_STREQ("storage", partition_value.c_str()); |
| 406 |
| 407 std::string src_value = ExecuteScriptAndReturnString( |
| 408 "document.getElementById('browserplugin').src"); |
| 409 EXPECT_STREQ("", src_value.c_str()); |
| 410 |
| 411 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); |
| 412 { |
| 413 const IPC::Message* msg = |
| 414 browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 415 BrowserPluginHostMsg_NavigateOrCreateGuest::ID); |
| 416 ASSERT_TRUE(msg); |
| 417 |
| 418 int instance_id; |
| 419 long long frame_id; |
| 420 std::string src; |
| 421 BrowserPluginHostMsg_NavigateOrCreateGuest::Read( |
| 422 msg, |
| 423 &instance_id, |
| 424 &frame_id, |
| 425 &src); |
| 426 EXPECT_STREQ("bar", src.c_str()); |
| 427 } |
| 428 |
| 429 ExecuteJavaScript( |
| 430 "document.getElementById('browserplugin').partition = 'someid'"); |
| 431 partition_value = ExecuteScriptAndReturnString( |
| 432 "document.getElementById('browserplugin').partition"); |
| 433 EXPECT_STREQ("storage", partition_value.c_str()); |
| 434 |
| 435 bool persist_value = false; |
| 436 ExecuteJavaScript( |
| 437 "document.getElementById('browserplugin').persist = true"); |
| 438 EXPECT_TRUE(ExecuteScriptAndReturnBool( |
| 439 "document.getElementById('browserplugin').persist", persist_value)); |
| 440 EXPECT_FALSE(persist_value); |
| 441 } |
| 442 |
322 } // namespace content | 443 } // namespace content |
OLD | NEW |