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

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

Powered by Google App Engine
This is Rietveld 408576698