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

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

Issue 11092023: Browser Plugin: Implement CanGoBack/CanGoForward (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated Navigation Event 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 307 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
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(e) {"
318 " url = u;" 318 " url = e.url;"
319 "}" 319 "}"
320 "document.getElementById('browserplugin')." 320 "document.getElementById('browserplugin')."
321 " addEventListener('navigation', nav);"; 321 " addEventListener('navigation', nav);";
322 const char* kRemoveEventListener = 322 const char* kRemoveEventListener =
323 "document.getElementById('browserplugin')." 323 "document.getElementById('browserplugin')."
324 " removeEventListener('navigation', nav);"; 324 " removeEventListener('navigation', 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 {
348 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 348 BrowserPluginMsg_DidNavigate_Params navigate_params;
349 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); 349 navigate_params.url = GURL(kGoogleURL);
350 350 navigate_params.process_id = 1337;
351 browser_plugin->DidNavigate(navigate_params);
352 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
353 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
354 }
351 ExecuteJavaScript(kRemoveEventListener); 355 ExecuteJavaScript(kRemoveEventListener);
352 browser_plugin->DidNavigate(GURL(kGoogleNewsURL), 42); 356 {
353 // The URL variable should not change because we've removed the event 357 BrowserPluginMsg_DidNavigate_Params navigate_params;
354 // listener. 358 navigate_params.url = GURL(kGoogleNewsURL);
355 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 359 navigate_params.process_id = 42;
356 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID)); 360 browser_plugin->DidNavigate(navigate_params);
361 // The URL variable should not change because we've removed the event
362 // listener.
363 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
364 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID));
365 }
357 } 366 }
358 367
359 TEST_F(BrowserPluginTest, StopMethod) { 368 TEST_F(BrowserPluginTest, StopMethod) {
360 const char* kCallStop = 369 const char* kCallStop =
361 "document.getElementById('browserplugin').stop();"; 370 "document.getElementById('browserplugin').stop();";
362 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 371 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
363 ExecuteJavaScript(kCallStop); 372 ExecuteJavaScript(kCallStop);
364 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 373 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
365 BrowserPluginHostMsg_Stop::ID)); 374 BrowserPluginHostMsg_Stop::ID));
366 } 375 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 EXPECT_STREQ( 492 EXPECT_STREQ(
484 "The object has already navigated, so its partition cannot be changed.", 493 "The object has already navigated, so its partition cannot be changed.",
485 title.c_str()); 494 title.c_str());
486 495
487 partition_value = ExecuteScriptAndReturnString( 496 partition_value = ExecuteScriptAndReturnString(
488 "document.getElementById('browserplugin').partition"); 497 "document.getElementById('browserplugin').partition");
489 EXPECT_STREQ("storage", partition_value.c_str()); 498 EXPECT_STREQ("storage", partition_value.c_str());
490 } 499 }
491 500
492 } // namespace content 501 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698