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

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: 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 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')."
lazyboy 2012/09/20 19:47:04 nit: next line fits in this line
Fady Samuel 2012/09/20 21:58:05 Done.
308 " getProcessId()";
296 const char* kGoogleURL = "http://www.google.com/"; 309 const char* kGoogleURL = "http://www.google.com/";
297 const char* kGoogleNewsURL = "http://news.google.com/"; 310 const char* kGoogleNewsURL = "http://news.google.com/";
298 311
299 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 312 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
300 ExecuteJavaScript(kAddEventListener); 313 ExecuteJavaScript(kAddEventListener);
301 // Grab the BrowserPlugin's instance ID from its resize message. 314 // Grab the BrowserPlugin's instance ID from its resize message.
302 const IPC::Message* msg = 315 const IPC::Message* msg =
303 browser_plugin_manager()->sink().GetFirstMessageMatching( 316 browser_plugin_manager()->sink().GetFirstMessageMatching(
304 BrowserPluginHostMsg_ResizeGuest::ID); 317 BrowserPluginHostMsg_ResizeGuest::ID);
305 ASSERT_TRUE(msg); 318 ASSERT_TRUE(msg);
306 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg); 319 PickleIterator iter = IPC::SyncMessage::GetDataIterator(msg);
307 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params; 320 BrowserPluginHostMsg_ResizeGuest::SendParam resize_params;
308 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params)); 321 ASSERT_TRUE(IPC::ReadParam(msg, &iter, &resize_params));
309 int instance_id = resize_params.a; 322 int instance_id = resize_params.a;
310 323
311 MockBrowserPlugin* browser_plugin = 324 MockBrowserPlugin* browser_plugin =
312 static_cast<MockBrowserPlugin*>( 325 static_cast<MockBrowserPlugin*>(
313 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 326 browser_plugin_manager()->GetBrowserPlugin(instance_id));
314 ASSERT_TRUE(browser_plugin); 327 ASSERT_TRUE(browser_plugin);
315 328
316 browser_plugin->DidNavigate(GURL(kGoogleURL)); 329 browser_plugin->DidNavigate(GURL(kGoogleURL), 1337);
lazyboy 2012/09/20 19:47:04 ASSERT browser_plugin->getProcessId() == 0 if we h
Fady Samuel 2012/09/20 21:58:05 I believe 0 is a valid RenderProcessHost ID. I thi
317 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 330 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
331 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
318 332
319 ExecuteJavaScript(kRemoveEventListener); 333 ExecuteJavaScript(kRemoveEventListener);
320 browser_plugin->DidNavigate(GURL(kGoogleNewsURL)); 334 browser_plugin->DidNavigate(GURL(kGoogleNewsURL), 42);
321 // The URL variable should not change because we've removed the event 335 // The URL variable should not change because we've removed the event
322 // listener. 336 // listener.
323 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url")); 337 EXPECT_EQ(kGoogleURL, ExecuteScriptAndReturnString("url"));
338 EXPECT_EQ(42, ExecuteScriptAndReturnInt(kGetProcessID));
324 } 339 }
325 340
326 } // namespace content 341 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698