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

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

Issue 10829225: Browser Plugin: Add HTML5-like postMessage support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT. Added subframe targeting + 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 ASSERT_TRUE(browser_plugin); 266 ASSERT_TRUE(browser_plugin);
267 267
268 WebKit::WebCursorInfo cursor_info; 268 WebKit::WebCursorInfo cursor_info;
269 // Send an event and verify that the event is deported. 269 // Send an event and verify that the event is deported.
270 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), 270 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(),
271 cursor_info); 271 cursor_info);
272 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 272 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
273 BrowserPluginHostMsg_HandleInputEvent::ID)); 273 BrowserPluginHostMsg_HandleInputEvent::ID));
274 browser_plugin_manager()->sink().ClearMessages(); 274 browser_plugin_manager()->sink().ClearMessages();
275 275
276 const char* kAddEventListener = 276 const char* kAddCustomEventListener =
277 "var msg;" 277 "var msg;"
278 "function crashListener() {" 278 "function crashListener() {"
279 " msg = 'crashed';" 279 " msg = 'crashed';"
280 "}" 280 "}"
281 "document.getElementById('browserplugin')." 281 "document.getElementById('browserplugin')."
282 " addEventListener('crash', crashListener);"; 282 " addCustomEventListener('crash', crashListener);";
283 283
284 ExecuteJavaScript(kAddEventListener); 284 ExecuteJavaScript(kAddCustomEventListener);
285 285
286 // Pretend that the guest has crashed 286 // Pretend that the guest has crashed
287 browser_plugin->GuestCrashed(); 287 browser_plugin->GuestCrashed();
288 288
289 // Verify that our event listener has fired. 289 // Verify that our event listener has fired.
290 EXPECT_EQ("crashed", ExecuteScriptAndReturnString("msg")); 290 EXPECT_EQ("crashed", ExecuteScriptAndReturnString("msg"));
291 291
292 // Send an event and verify that events are no longer deported. 292 // Send an event and verify that events are no longer deported.
293 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), 293 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(),
294 cursor_info); 294 cursor_info);
(...skipping 10 matching lines...) Expand all
305 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 305 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
306 BrowserPluginHostMsg_PluginDestroyed::ID)); 306 BrowserPluginHostMsg_PluginDestroyed::ID));
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* kAddCustomEventListener =
316 "var url;" 316 "var url;"
317 "function nav(u) {" 317 "function nav(u) {"
318 " url = u;" 318 " url = u;"
319 "}" 319 "}"
320 "document.getElementById('browserplugin')." 320 "document.getElementById('browserplugin')."
321 " addEventListener('navigation', nav);"; 321 " addCustomEventListener('navigation', nav);";
322 const char* kRemoveEventListener = 322 const char* kRemoveCustomEventListener =
323 "document.getElementById('browserplugin')." 323 "document.getElementById('browserplugin')."
324 " removeEventListener('navigation', nav);"; 324 " removeCustomEventListener('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(kAddCustomEventListener);
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->DidNavigate(GURL(kGoogleURL), 1337);
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(kRemoveCustomEventListener);
352 browser_plugin->DidNavigate(GURL(kGoogleNewsURL), 42); 352 browser_plugin->DidNavigate(GURL(kGoogleNewsURL), 42);
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();";
(...skipping 121 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