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

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: Fixed crash + cleanup Created 8 years, 3 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 ASSERT_TRUE(browser_plugin); 237 ASSERT_TRUE(browser_plugin);
238 238
239 WebKit::WebCursorInfo cursor_info; 239 WebKit::WebCursorInfo cursor_info;
240 // Send an event and verify that the event is deported. 240 // Send an event and verify that the event is deported.
241 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), 241 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(),
242 cursor_info); 242 cursor_info);
243 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 243 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
244 BrowserPluginHostMsg_HandleInputEvent::ID)); 244 BrowserPluginHostMsg_HandleInputEvent::ID));
245 browser_plugin_manager()->sink().ClearMessages(); 245 browser_plugin_manager()->sink().ClearMessages();
246 246
247 const char* kAddEventListener = 247 const char* kAddCustomEventListener =
248 "var msg;" 248 "var msg;"
249 "function crashListener() {" 249 "function crashListener() {"
250 " msg = 'crashed';" 250 " msg = 'crashed';"
251 "}" 251 "}"
252 "document.getElementById('browserplugin')." 252 "document.getElementById('browserplugin')."
253 " addEventListener('crash', crashListener);"; 253 " addCustomEventListener('crash', crashListener);";
254 254
255 ExecuteJavaScript(kAddEventListener); 255 ExecuteJavaScript(kAddCustomEventListener);
256 256
257 // Pretend that the guest has crashed 257 // Pretend that the guest has crashed
258 browser_plugin->GuestCrashed(); 258 browser_plugin->GuestCrashed();
259 259
260 // Verify that our event listener has fired. 260 // Verify that our event listener has fired.
261 EXPECT_EQ("crashed", ExecuteScriptAndReturnString("msg")); 261 EXPECT_EQ("crashed", ExecuteScriptAndReturnString("msg"));
262 262
263 // Send an event and verify that events are no longer deported. 263 // Send an event and verify that events are no longer deported.
264 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), 264 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(),
265 cursor_info); 265 cursor_info);
(...skipping 10 matching lines...) Expand all
276 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 276 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
277 BrowserPluginHostMsg_PluginDestroyed::ID)); 277 BrowserPluginHostMsg_PluginDestroyed::ID));
278 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 278 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
279 "x.parentNode.removeChild(x);"); 279 "x.parentNode.removeChild(x);");
280 ProcessPendingMessages(); 280 ProcessPendingMessages();
281 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 281 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
282 BrowserPluginHostMsg_PluginDestroyed::ID)); 282 BrowserPluginHostMsg_PluginDestroyed::ID));
283 } 283 }
284 284
285 TEST_F(BrowserPluginTest, CustomEvents) { 285 TEST_F(BrowserPluginTest, CustomEvents) {
286 const char* kAddEventListener = 286 const char* kAddCustomEventListener =
287 "var url;" 287 "var url;"
288 "function nav(u) {" 288 "function nav(u) {"
289 " url = u;" 289 " url = u;"
290 "}" 290 "}"
291 "document.getElementById('browserplugin')." 291 "document.getElementById('browserplugin')."
292 " addEventListener('navigation', nav);"; 292 " addCustomEventListener('navigation', nav);";
293 const char* kRemoveEventListener = 293 const char* kRemoveCustomEventListener =
294 "document.getElementById('browserplugin')." 294 "document.getElementById('browserplugin')."
295 " removeEventListener('navigation', nav);"; 295 " removeCustomEventListener('navigation', nav);";
296 const char* kGoogleURL = "http://www.google.com/"; 296 const char* kGoogleURL = "http://www.google.com/";
297 const char* kGoogleNewsURL = "http://news.google.com/"; 297 const char* kGoogleNewsURL = "http://news.google.com/";
298 298
299 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 299 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
300 ExecuteJavaScript(kAddEventListener); 300 ExecuteJavaScript(kAddCustomEventListener);
301 // Grab the BrowserPlugin's instance ID from its resize message. 301 // Grab the BrowserPlugin's instance ID from its resize message.
302 const IPC::Message* msg = 302 const IPC::Message* msg =
303 browser_plugin_manager()->sink().GetFirstMessageMatching( 303 browser_plugin_manager()->sink().GetFirstMessageMatching(
304 BrowserPluginHostMsg_ResizeGuest::ID); 304 BrowserPluginHostMsg_ResizeGuest::ID);
305 ASSERT_TRUE(msg); 305 ASSERT_TRUE(msg);
306 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); 306 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg);
307 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; 307 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params;
308 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); 308 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params));
309 int instance_id = resize_params.a; 309 int instance_id = resize_params.a;
310 310
311 MockBrowserPlugin* browser_plugin = 311 MockBrowserPlugin* browser_plugin =
312 static_cast<MockBrowserPlugin*>( 312 static_cast<MockBrowserPlugin*>(
313 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 313 browser_plugin_manager()->GetBrowserPlugin(instance_id));
314 ASSERT_TRUE(browser_plugin); 314 ASSERT_TRUE(browser_plugin);
315 315
316 browser_plugin->DidNavigate(GURL(kGoogleURL)); 316 browser_plugin->DidNavigate(GURL(kGoogleURL));
317 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 317 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
318 318
319 ExecuteJavaScript(kRemoveEventListener); 319 ExecuteJavaScript(kRemoveCustomEventListener);
320 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); 320 browser_plugin->DidNavigate(GURL(kGoogleNewsURL));
321 // The URL variable should not change because we've removed the event 321 // The URL variable should not change because we've removed the event
322 // listener. 322 // listener.
323 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 323 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
324 } 324 }
325 325
326 TEST_F(BrowserPluginTest, PostMessage) {
327 const char* kTesting = "testing123";
328 const char* kPostMessage =
329 "var msg;"
330 "function receiveMessage(event) {"
331 " msg = event.data;"
332 "}"
333 "document.getElementById('browserplugin')."
334 " addEventListener('message', receiveMessage, false);"
335 "document.getElementById('browserplugin')."
336 " postMessage('testing123', '');";
337
338 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
339 ExecuteJavaScript(kPostMessage);
340
341 const IPC::Message* msg =
342 browser_plugin_manager()->sink().GetUniqueMessageMatching(
343 BrowserPluginHostMsg_RouteMessageEvent::ID);
344 ASSERT_TRUE(msg);
345 int instance_id;
346 string16 data;
347 string16 target_origin;
348 PickleIterator iter(*msg);
349 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &instance_id));
350 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &data));
351 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &target_origin));
352
353 MockBrowserPlugin* browser_plugin =
354 static_cast<MockBrowserPlugin*>(
355 browser_plugin_manager()->GetBrowserPlugin(instance_id));
356 ASSERT_TRUE(browser_plugin);
357
358 // Fire a message event in the embedder and verify that it fires.
359 browser_plugin->ReceiveMessage(MSG_ROUTING_NONE, string16(), data);
360 ProcessPendingMessages();
361 EXPECT_EQ(kTesting, ExecuteScriptAndReturnString("msg"));
362 }
363
326 } // namespace content 364 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698