| 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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 301 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
| 302 "x.parentNode.removeChild(x);"); | 302 "x.parentNode.removeChild(x);"); |
| 303 ProcessPendingMessages(); | 303 ProcessPendingMessages(); |
| 304 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 304 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
| 305 BrowserPluginHostMsg_PluginDestroyed::ID)); | 305 BrowserPluginHostMsg_PluginDestroyed::ID)); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_F(BrowserPluginTest, CustomEvents) { | 308 TEST_F(BrowserPluginTest, CustomEvents) { |
| 309 const char* kAddEventListener = | 309 const char* kAddEventListener = |
| 310 "var url;" | 310 "var url;" |
| 311 "function nav(e) {" | 311 "function nav(u) {" |
| 312 " url = e.url;" | 312 " url = u.url;" |
| 313 "}" | 313 "}" |
| 314 "document.getElementById('browserplugin')." | 314 "document.getElementById('browserplugin')." |
| 315 " addEventListener('navigation', nav);"; | 315 " addEventListener('loadCommit', nav);"; |
| 316 const char* kRemoveEventListener = | 316 const char* kRemoveEventListener = |
| 317 "document.getElementById('browserplugin')." | 317 "document.getElementById('browserplugin')." |
| 318 " removeEventListener('navigation', nav);"; | 318 " removeEventListener('loadCommit', nav);"; |
| 319 const char* kGetProcessID = | 319 const char* kGetProcessID = |
| 320 "document.getElementById('browserplugin').getProcessId()"; | 320 "document.getElementById('browserplugin').getProcessId()"; |
| 321 const char* kGoogleURL = "http://www.google.com/"; | 321 const char* kGoogleURL = "http://www.google.com/"; |
| 322 const char* kGoogleNewsURL = "http://news.google.com/"; | 322 const char* kGoogleNewsURL = "http://news.google.com/"; |
| 323 | 323 |
| 324 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 324 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
| 325 ExecuteJavaScript(kAddEventListener); | 325 ExecuteJavaScript(kAddEventListener); |
| 326 // Grab the BrowserPlugin's instance ID from its resize message. | 326 // Grab the BrowserPlugin's instance ID from its resize message. |
| 327 const IPC::Message* msg = | 327 const IPC::Message* msg = |
| 328 browser_plugin_manager()->sink().GetFirstMessageMatching( | 328 browser_plugin_manager()->sink().GetFirstMessageMatching( |
| 329 BrowserPluginHostMsg_ResizeGuest::ID); | 329 BrowserPluginHostMsg_ResizeGuest::ID); |
| 330 ASSERT_TRUE(msg); | 330 ASSERT_TRUE(msg); |
| 331 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); | 331 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); |
| 332 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; | 332 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; |
| 333 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); | 333 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); |
| 334 int instance_id = resize_params.a; | 334 int instance_id = resize_params.a; |
| 335 | 335 |
| 336 MockBrowserPlugin* browser_plugin = | 336 MockBrowserPlugin* browser_plugin = |
| 337 static_cast<MockBrowserPlugin*>( | 337 static_cast<MockBrowserPlugin*>( |
| 338 browser_plugin_manager()->GetBrowserPlugin(instance_id)); | 338 browser_plugin_manager()->GetBrowserPlugin(instance_id)); |
| 339 ASSERT_TRUE(browser_plugin); | 339 ASSERT_TRUE(browser_plugin); |
| 340 | 340 |
| 341 { | 341 { |
| 342 BrowserPluginMsg_DidNavigate_Params navigate_params; | 342 BrowserPluginMsg_LoadCommit_Params navigate_params; |
| 343 navigate_params.url = GURL(kGoogleURL); | 343 navigate_params.url = GURL(kGoogleURL); |
| 344 navigate_params.process_id = 1337; | 344 navigate_params.process_id = 1337; |
| 345 browser_plugin->DidNavigate(navigate_params); | 345 browser_plugin->LoadCommit(navigate_params); |
| 346 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 346 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
| 347 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); | 347 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); |
| 348 } | 348 } |
| 349 ExecuteJavaScript(kRemoveEventListener); | 349 ExecuteJavaScript(kRemoveEventListener); |
| 350 { | 350 { |
| 351 BrowserPluginMsg_DidNavigate_Params navigate_params; | 351 BrowserPluginMsg_LoadCommit_Params navigate_params; |
| 352 navigate_params.url = GURL(kGoogleNewsURL); | 352 navigate_params.url = GURL(kGoogleNewsURL); |
| 353 navigate_params.process_id = 42; | 353 navigate_params.process_id = 42; |
| 354 browser_plugin->DidNavigate(navigate_params); | 354 browser_plugin->LoadCommit(navigate_params); |
| 355 // The URL variable should not change because we've removed the event | 355 // The URL variable should not change because we've removed the event |
| 356 // listener. | 356 // listener. |
| 357 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); | 357 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); |
| 358 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID)); | 358 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID)); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 TEST_F(BrowserPluginTest, StopMethod) { | 362 TEST_F(BrowserPluginTest, StopMethod) { |
| 363 const char* kCallStop = | 363 const char* kCallStop = |
| 364 "document.getElementById('browserplugin').stop();"; | 364 "document.getElementById('browserplugin').stop();"; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 EXPECT_STREQ( | 486 EXPECT_STREQ( |
| 487 "The object has already navigated, so its partition cannot be changed.", | 487 "The object has already navigated, so its partition cannot be changed.", |
| 488 title.c_str()); | 488 title.c_str()); |
| 489 | 489 |
| 490 partition_value = ExecuteScriptAndReturnString( | 490 partition_value = ExecuteScriptAndReturnString( |
| 491 "document.getElementById('browserplugin').partition"); | 491 "document.getElementById('browserplugin').partition"); |
| 492 EXPECT_STREQ("storage", partition_value.c_str()); | 492 EXPECT_STREQ("storage", partition_value.c_str()); |
| 493 } | 493 } |
| 494 | 494 |
| 495 } // namespace content | 495 } // namespace content |
| OLD | NEW |