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

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

Issue 10965017: Browser Plugin: Implement getProcessId (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 if (value.IsEmpty() || !value->IsString()) 57 if (value.IsEmpty() || !value->IsString())
58 return std::string(); 58 return std::string();
59 59
60 v8::Local<v8::String> v8_str = value->ToString(); 60 v8::Local<v8::String> v8_str = value->ToString();
61 int length = v8_str->Utf8Length() + 1; 61 int length = v8_str->Utf8Length() + 1;
62 scoped_array<char> str(new char[length]); 62 scoped_array<char> str(new char[length]);
63 v8_str->WriteUtf8(str.get(), length); 63 v8_str->WriteUtf8(str.get(), length);
64 return str.get(); 64 return str.get();
65 } 65 }
66 66
67 int BrowserPluginTest::ExecuteScriptAndReturnInt(
68 const std::string& script) {
69 v8::Handle<v8::Value> value = GetMainFrame()->executeScriptAndReturnValue(
70 WebKit::WebScriptSource(WebKit::WebString::fromUTF8(script.c_str())));
71 if (value.IsEmpty() || !value->IsInt32())
72 return 0;
73
74 return value->Int32Value();
75 }
76
67 // This test verifies that an initial resize occurs when we instantiate the 77 // This test verifies that an initial resize occurs when we instantiate the
68 // browser plugin. This test also verifies that the browser plugin is waiting 78 // browser plugin. This test also verifies that the browser plugin is waiting
69 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and 79 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and
70 // we observe an UpdateRect_ACK, with the resize_pending_ reset, indiciating 80 // we observe an UpdateRect_ACK, with the resize_pending_ reset, indiciating
71 // that the BrowserPlugin is not waiting for any more UpdateRects to 81 // that the BrowserPlugin is not waiting for any more UpdateRects to
72 // satisfy its resize request. 82 // satisfy its resize request.
73 TEST_F(BrowserPluginTest, InitialResize) { 83 TEST_F(BrowserPluginTest, InitialResize) {
74 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 84 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
75 // Verify that the information based on ResizeGuest is correct, and 85 // Verify that the information based on ResizeGuest is correct, and
76 // use its TransportDIB::Id to paint. 86 // use its TransportDIB::Id to paint.
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 const char* kAddEventListener = 296 const char* kAddEventListener =
287 "var url;" 297 "var url;"
288 "function nav(u) {" 298 "function nav(u) {"
289 " url = u;" 299 " url = u;"
290 "}" 300 "}"
291 "document.getElementById('browserplugin')." 301 "document.getElementById('browserplugin')."
292 " addEventListener('navigation', nav);"; 302 " addEventListener('navigation', nav);";
293 const char* kRemoveEventListener = 303 const char* kRemoveEventListener =
294 "document.getElementById('browserplugin')." 304 "document.getElementById('browserplugin')."
295 " removeEventListener('navigation', nav);"; 305 " removeEventListener('navigation', nav);";
306 const char* kGetProcessID =
307 "document.getElementById('browserplugin').getProcessId()";
296 const char* kGoogleURL = "http://www.google.com/"; 308 const char* kGoogleURL = "http://www.google.com/";
297 const char* kGoogleNewsURL = "http://news.google.com/"; 309 const char* kGoogleNewsURL = "http://news.google.com/";
298 310
299 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 311 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
300 ExecuteJavaScript(kAddEventListener); 312 ExecuteJavaScript(kAddEventListener);
301 // Grab the BrowserPlugin's instance ID from its resize message. 313 // Grab the BrowserPlugin's instance ID from its resize message.
302 const IPC::Message* msg = 314 const IPC::Message* msg =
303 browser_plugin_manager()->sink().GetFirstMessageMatching( 315 browser_plugin_manager()->sink().GetFirstMessageMatching(
304 BrowserPluginHostMsg_ResizeGuest::ID); 316 BrowserPluginHostMsg_ResizeGuest::ID);
305 ASSERT_TRUE(msg); 317 ASSERT_TRUE(msg);
306 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); 318 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg);
307 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; 319 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params;
308 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); 320 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params));
309 int instance_id = resize_params.a; 321 int instance_id = resize_params.a;
310 322
311 MockBrowserPlugin* browser_plugin = 323 MockBrowserPlugin* browser_plugin =
312 static_cast<MockBrowserPlugin*>( 324 static_cast<MockBrowserPlugin*>(
313 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 325 browser_plugin_manager()->GetBrowserPlugin(instance_id));
314 ASSERT_TRUE(browser_plugin); 326 ASSERT_TRUE(browser_plugin);
315 327
316 browser_plugin->DidNavigate(GURL(kGoogleURL)); 328 browser_plugin->DidNavigate(GURL(kGoogleURL), 1337);
317 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 329 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
330 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
318 331
319 ExecuteJavaScript(kRemoveEventListener); 332 ExecuteJavaScript(kRemoveEventListener);
320 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); 333 browser_plugin->DidNavigate(GURL(kGoogleNewsURL), 42);
321 // The URL variable should not change because we've removed the event 334 // The URL variable should not change because we've removed the event
322 // listener. 335 // listener.
323 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 336 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
337 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID));
324 } 338 }
325 339
326 TEST_F(BrowserPluginTest, StopMethod) { 340 TEST_F(BrowserPluginTest, StopMethod) {
327 const char* kCallStop = 341 const char* kCallStop =
328 "document.getElementById('browserplugin').stop();"; 342 "document.getElementById('browserplugin').stop();";
329 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 343 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
330 ExecuteJavaScript(kCallStop); 344 ExecuteJavaScript(kCallStop);
331 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 345 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
332 BrowserPluginHostMsg_Stop::ID)); 346 BrowserPluginHostMsg_Stop::ID));
333 } 347 }
334 348
335 TEST_F(BrowserPluginTest, ReloadMethod) { 349 TEST_F(BrowserPluginTest, ReloadMethod) {
336 const char* kCallReload = 350 const char* kCallReload =
337 "document.getElementById('browserplugin').reload();"; 351 "document.getElementById('browserplugin').reload();";
338 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 352 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
339 ExecuteJavaScript(kCallReload); 353 ExecuteJavaScript(kCallReload);
340 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 354 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
341 BrowserPluginHostMsg_Reload::ID)); 355 BrowserPluginHostMsg_Reload::ID));
342 } 356 }
343 357
344 } // namespace content 358 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698