Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: content/renderer/browser_plugin/browser_plugin_browsertest.cc

Issue 11035067: Add loadCommit and loadStop Event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Comments Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 305 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
306 "x.parentNode.removeChild(x);"); 306 "x.parentNode.removeChild(x);");
307 ProcessPendingMessages(); 307 ProcessPendingMessages();
308 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 308 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
309 BrowserPluginHostMsg_PluginDestroyed::ID)); 309 BrowserPluginHostMsg_PluginDestroyed::ID));
310 } 310 }
311 311
312 TEST_F(BrowserPluginTest, CustomEvents) { 312 TEST_F(BrowserPluginTest, CustomEvents) {
313 const char* kAddEventListener = 313 const char* kAddEventListener =
314 "var url;" 314 "var url;"
315 "function nav(e) {" 315 "function nav(u) {"
316 " url = e.url;" 316 " url = u.url;"
317 "}" 317 "}"
318 "document.getElementById('browserplugin')." 318 "document.getElementById('browserplugin')."
319 " addEventListener('navigation', nav);"; 319 " addEventListener('loadCommit', nav);";
320 const char* kRemoveEventListener = 320 const char* kRemoveEventListener =
321 "document.getElementById('browserplugin')." 321 "document.getElementById('browserplugin')."
322 " removeEventListener('navigation', nav);"; 322 " removeEventListener('loadCommit', nav);";
323 const char* kGetProcessID = 323 const char* kGetProcessID =
324 "document.getElementById('browserplugin').getProcessId()"; 324 "document.getElementById('browserplugin').getProcessId()";
325 const char* kGoogleURL = "http://www.google.com/"; 325 const char* kGoogleURL = "http://www.google.com/";
326 const char* kGoogleNewsURL = "http://news.google.com/"; 326 const char* kGoogleNewsURL = "http://news.google.com/";
327 327
328 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 328 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
329 ExecuteJavaScript(kAddEventListener); 329 ExecuteJavaScript(kAddEventListener);
330 // Grab the BrowserPlugin's instance ID from its resize message. 330 // Grab the BrowserPlugin's instance ID from its resize message.
331 const IPC::Message* msg = 331 const IPC::Message* msg =
332 browser_plugin_manager()->sink().GetFirstMessageMatching( 332 browser_plugin_manager()->sink().GetFirstMessageMatching(
333 BrowserPluginHostMsg_ResizeGuest::ID); 333 BrowserPluginHostMsg_ResizeGuest::ID);
334 ASSERT_TRUE(msg); 334 ASSERT_TRUE(msg);
335 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); 335 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg);
336 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; 336 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params;
337 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); 337 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params));
338 int instance_id = resize_params.a; 338 int instance_id = resize_params.a;
339 339
340 MockBrowserPlugin* browser_plugin = 340 MockBrowserPlugin* browser_plugin =
341 static_cast<MockBrowserPlugin*>( 341 static_cast<MockBrowserPlugin*>(
342 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 342 browser_plugin_manager()->GetBrowserPlugin(instance_id));
343 ASSERT_TRUE(browser_plugin); 343 ASSERT_TRUE(browser_plugin);
344 344
345 { 345 browser_plugin->LoadCommit(GURL(kGoogleURL), 1337, true);
346 BrowserPluginMsg_DidNavigate_Params navigate_params; 346 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
347 navigate_params.url = GURL(kGoogleURL); 347 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
348 navigate_params.process_id = 1337; 348
349 browser_plugin->DidNavigate(navigate_params);
350 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
351 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
352 }
353 ExecuteJavaScript(kRemoveEventListener); 349 ExecuteJavaScript(kRemoveEventListener);
354 { 350 browser_plugin->LoadCommit(GURL(kGoogleNewsURL), 42, true);
355 BrowserPluginMsg_DidNavigate_Params navigate_params; 351 // The URL variable should not change because we've removed the event
356 navigate_params.url = GURL(kGoogleNewsURL); 352 // listener.
357 navigate_params.process_id = 42; 353 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
358 browser_plugin->DidNavigate(navigate_params); 354 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID));
359 // The URL variable should not change because we've removed the event
360 // listener.
361 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
362 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID));
363 }
364 } 355 }
365 356
366 TEST_F(BrowserPluginTest, StopMethod) { 357 TEST_F(BrowserPluginTest, StopMethod) {
367 const char* kCallStop = 358 const char* kCallStop =
368 "document.getElementById('browserplugin').stop();"; 359 "document.getElementById('browserplugin').stop();";
369 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 360 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
370 ExecuteJavaScript(kCallStop); 361 ExecuteJavaScript(kCallStop);
371 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 362 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
372 BrowserPluginHostMsg_Stop::ID)); 363 BrowserPluginHostMsg_Stop::ID));
373 } 364 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_STREQ( 481 EXPECT_STREQ(
491 "The object has already navigated, so its partition cannot be changed.", 482 "The object has already navigated, so its partition cannot be changed.",
492 title.c_str()); 483 title.c_str());
493 484
494 partition_value = ExecuteScriptAndReturnString( 485 partition_value = ExecuteScriptAndReturnString(
495 "document.getElementById('browserplugin').partition"); 486 "document.getElementById('browserplugin').partition");
496 EXPECT_STREQ("storage", partition_value.c_str()); 487 EXPECT_STREQ("storage", partition_value.c_str());
497 } 488 }
498 489
499 } // namespace content 490 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698