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

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: Addressed creis@'s 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(u) {" 315 "function nav(e) {"
316 " url = u;" 316 " url = e.url;"
317 "}" 317 "}"
318 "document.getElementById('browserplugin')." 318 "document.getElementById('browserplugin')."
319 " addEventListener('navigation', nav);"; 319 " addEventListener('navigation', nav);";
320 const char* kRemoveEventListener = 320 const char* kRemoveEventListener =
321 "document.getElementById('browserplugin')." 321 "document.getElementById('browserplugin')."
322 " removeEventListener('navigation', nav);"; 322 " removeEventListener('navigation', 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 browser_plugin->DidNavigate(GURL(kGoogleURL), 1337); 345 {
346 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 346 BrowserPluginMsg_DidNavigate_Params navigate_params;
347 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); 347 navigate_params.url = GURL(kGoogleURL);
348 348 navigate_params.process_id = 1337;
349 browser_plugin->DidNavigate(navigate_params);
350 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
351 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
352 }
349 ExecuteJavaScript(kRemoveEventListener); 353 ExecuteJavaScript(kRemoveEventListener);
350 browser_plugin->DidNavigate(GURL(kGoogleNewsURL), 42); 354 {
351 // The URL variable should not change because we've removed the event 355 BrowserPluginMsg_DidNavigate_Params navigate_params;
352 // listener. 356 navigate_params.url = GURL(kGoogleNewsURL);
353 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 357 navigate_params.process_id = 42;
354 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID)); 358 browser_plugin->DidNavigate(navigate_params);
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 }
355 } 364 }
356 365
357 TEST_F(BrowserPluginTest, StopMethod) { 366 TEST_F(BrowserPluginTest, StopMethod) {
358 const char* kCallStop = 367 const char* kCallStop =
359 "document.getElementById('browserplugin').stop();"; 368 "document.getElementById('browserplugin').stop();";
360 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 369 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
361 ExecuteJavaScript(kCallStop); 370 ExecuteJavaScript(kCallStop);
362 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 371 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
363 BrowserPluginHostMsg_Stop::ID)); 372 BrowserPluginHostMsg_Stop::ID));
364 } 373 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 EXPECT_STREQ( 490 EXPECT_STREQ(
482 "The object has already navigated, so its partition cannot be changed.", 491 "The object has already navigated, so its partition cannot be changed.",
483 title.c_str()); 492 title.c_str());
484 493
485 partition_value = ExecuteScriptAndReturnString( 494 partition_value = ExecuteScriptAndReturnString(
486 "document.getElementById('browserplugin').partition"); 495 "document.getElementById('browserplugin').partition");
487 EXPECT_STREQ("storage", partition_value.c_str()); 496 EXPECT_STREQ("storage", partition_value.c_str());
488 } 497 }
489 498
490 } // namespace content 499 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698