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

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

Issue 11956022: Browser Plugin: Allocate Instance IDs in BrowserPluginEmbedder instead of BrowserPluginManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Istiaque's comments Created 7 years, 11 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/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 118
119 // This test verifies that an initial resize occurs when we instantiate the 119 // This test verifies that an initial resize occurs when we instantiate the
120 // browser plugin. This test also verifies that the browser plugin is waiting 120 // browser plugin. This test also verifies that the browser plugin is waiting
121 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and 121 // for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and
122 // we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset, 122 // we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset,
123 // indiciating that the BrowserPlugin is not waiting for any more UpdateRects to 123 // indiciating that the BrowserPlugin is not waiting for any more UpdateRects to
124 // satisfy its resize request. 124 // satisfy its resize request.
125 TEST_F(BrowserPluginTest, InitialResize) { 125 TEST_F(BrowserPluginTest, InitialResize) {
126 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 126 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
127 // Verify that the information based on ResizeGuest is correct, and 127 // Verify that the information in CreateGuest is correct.
128 // use its TransportDIB::Id to paint.
129 int instance_id = 0; 128 int instance_id = 0;
130 { 129 {
131 const IPC::Message* msg = 130 const IPC::Message* msg =
132 browser_plugin_manager()->sink().GetUniqueMessageMatching( 131 browser_plugin_manager()->sink().GetUniqueMessageMatching(
133 BrowserPluginHostMsg_ResizeGuest::ID); 132 BrowserPluginHostMsg_CreateGuest::ID);
134 ASSERT_TRUE(msg); 133 ASSERT_TRUE(msg);
135 BrowserPluginHostMsg_ResizeGuest_Params params; 134 int instance_id = 0;
136 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params); 135 BrowserPluginHostMsg_CreateGuest_Params params;
137 EXPECT_EQ(640, params.view_size.width()); 136 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
138 EXPECT_EQ(480, params.view_size.height()); 137 EXPECT_EQ(640, params.resize_guest_params.view_size.width());
138 EXPECT_EQ(480, params.resize_guest_params.view_size.height());
139 } 139 }
140 140
141 MockBrowserPlugin* browser_plugin = 141 MockBrowserPlugin* browser_plugin =
142 static_cast<MockBrowserPlugin*>( 142 static_cast<MockBrowserPlugin*>(
143 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 143 browser_plugin_manager()->GetBrowserPlugin(instance_id));
144 ASSERT_TRUE(browser_plugin); 144 ASSERT_TRUE(browser_plugin);
145 // Now the browser plugin is expecting a UpdateRect resize. 145 // Now the browser plugin is expecting a UpdateRect resize.
146 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); 146 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
147 147
148 // Send the BrowserPlugin an UpdateRect equal to its container size with 148 // Send the BrowserPlugin an UpdateRect equal to its container size with
(...skipping 10 matching lines...) Expand all
159 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); 159 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
160 } 160 }
161 161
162 // Verify that the src attribute on the browser plugin works as expected. 162 // Verify that the src attribute on the browser plugin works as expected.
163 TEST_F(BrowserPluginTest, SrcAttribute) { 163 TEST_F(BrowserPluginTest, SrcAttribute) {
164 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 164 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
165 // Verify that we're reporting the correct URL to navigate to based on the 165 // Verify that we're reporting the correct URL to navigate to based on the
166 // src attribute. 166 // src attribute.
167 { 167 {
168 // Ensure we get a CreateGuest on the initial navigation. 168 // Ensure we get a CreateGuest on the initial navigation.
169 const IPC::Message* create_msg =
170 browser_plugin_manager()->sink().GetUniqueMessageMatching(
171 BrowserPluginHostMsg_CreateGuest::ID);
172 ASSERT_TRUE(create_msg);
173
174 const IPC::Message* msg = 169 const IPC::Message* msg =
175 browser_plugin_manager()->sink().GetUniqueMessageMatching( 170 browser_plugin_manager()->sink().GetUniqueMessageMatching(
176 BrowserPluginHostMsg_NavigateGuest::ID); 171 BrowserPluginHostMsg_CreateGuest::ID);
177 ASSERT_TRUE(msg); 172 ASSERT_TRUE(msg);
178 173
179 int instance_id = 0; 174 int instance_id = 0;
180 std::string src; 175 BrowserPluginHostMsg_CreateGuest_Params params;
181 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src); 176 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
182 EXPECT_EQ("foo", src); 177 EXPECT_EQ("foo", params.src);
183 } 178 }
184 179
185 browser_plugin_manager()->sink().ClearMessages(); 180 browser_plugin_manager()->sink().ClearMessages();
186 // Navigate to bar and observe the associated 181 // Navigate to bar and observe the associated
187 // BrowserPluginHostMsg_NavigateGuest message. 182 // BrowserPluginHostMsg_NavigateGuest message.
188 // Verify that the src attribute is updated as well. 183 // Verify that the src attribute is updated as well.
189 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); 184 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
190 { 185 {
191 // Verify that we do not get a CreateGuest on subsequent navigations. 186 // Verify that we do not get a CreateGuest on subsequent navigations.
192 const IPC::Message* create_msg = 187 const IPC::Message* create_msg =
193 browser_plugin_manager()->sink().GetUniqueMessageMatching( 188 browser_plugin_manager()->sink().GetUniqueMessageMatching(
194 BrowserPluginHostMsg_CreateGuest::ID); 189 BrowserPluginHostMsg_CreateGuest::ID);
195 ASSERT_FALSE(create_msg); 190 ASSERT_FALSE(create_msg);
196 191
197 const IPC::Message* msg = 192 const IPC::Message* msg =
198 browser_plugin_manager()->sink().GetUniqueMessageMatching( 193 browser_plugin_manager()->sink().GetUniqueMessageMatching(
199 BrowserPluginHostMsg_NavigateGuest::ID); 194 BrowserPluginHostMsg_NavigateGuest::ID);
200 ASSERT_TRUE(msg); 195 ASSERT_TRUE(msg);
201 196
202 int instance_id = 0; 197 int instance_id = 0;
203 std::string src; 198 std::string src;
204 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src); 199 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src);
205 EXPECT_EQ("bar", src); 200 EXPECT_EQ("bar", src);
206 std::string src_value = 201 std::string src_value =
207 ExecuteScriptAndReturnString( 202 ExecuteScriptAndReturnString(
208 "document.getElementById('browserplugin').src"); 203 "document.getElementById('browserplugin').src");
209 EXPECT_EQ("bar", src_value); 204 EXPECT_EQ("bar", src_value);
210 } 205 }
211 } 206 }
212 207
213 TEST_F(BrowserPluginTest, ResizeFlowControl) { 208 TEST_F(BrowserPluginTest, ResizeFlowControl) {
214 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 209 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
215 int instance_id = 0; 210 int instance_id = 0;
216 { 211 {
217 // Ensure we get a NavigateGuest on the initial navigation and grab the 212 // Ensure we get a CreateGuest on the initial navigation and grab the
218 // BrowserPlugin's instance_id from there. 213 // BrowserPlugin's instance_id from there.
219 std::string src; 214 const IPC::Message* msg =
220 const IPC::Message* nav_msg = 215 browser_plugin_manager()->sink().GetUniqueMessageMatching(
221 browser_plugin_manager()->sink().GetUniqueMessageMatching( 216 BrowserPluginHostMsg_CreateGuest::ID);
222 BrowserPluginHostMsg_NavigateGuest::ID); 217 ASSERT_TRUE(msg);
223 ASSERT_TRUE(nav_msg); 218 BrowserPluginHostMsg_CreateGuest_Params params;
224 BrowserPluginHostMsg_NavigateGuest::Read(nav_msg, &instance_id, &src); 219 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
225 } 220 }
226 MockBrowserPlugin* browser_plugin = 221 MockBrowserPlugin* browser_plugin =
227 static_cast<MockBrowserPlugin*>( 222 static_cast<MockBrowserPlugin*>(
228 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 223 browser_plugin_manager()->GetBrowserPlugin(instance_id));
229 ASSERT_TRUE(browser_plugin); 224 ASSERT_TRUE(browser_plugin);
230 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get()); 225 EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
231 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage 226 // Send an UpdateRect to the BrowserPlugin to make it use the pending damage
232 // buffer. 227 // buffer.
233 { 228 {
234 // We send a stale UpdateRect to the BrowserPlugin. 229 // We send a stale UpdateRect to the BrowserPlugin.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 browser_plugin->OnMessageReceived(msg); 297 browser_plugin->OnMessageReceived(msg);
303 // The BrowserPlugin has finally received an UpdateRect that satisifes 298 // The BrowserPlugin has finally received an UpdateRect that satisifes
304 // its current size, and so it is happy. 299 // its current size, and so it is happy.
305 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); 300 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
306 } 301 }
307 } 302 }
308 303
309 TEST_F(BrowserPluginTest, GuestCrash) { 304 TEST_F(BrowserPluginTest, GuestCrash) {
310 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 305 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
311 306
312 // Grab the BrowserPlugin's instance ID from its resize message. 307 // Grab the BrowserPlugin's instance ID from its CreateGuest message.
313 int instance_id = 0; 308 int instance_id = 0;
314 { 309 {
315 const IPC::Message* msg = 310 const IPC::Message* msg =
316 browser_plugin_manager()->sink().GetFirstMessageMatching( 311 browser_plugin_manager()->sink().GetFirstMessageMatching(
317 BrowserPluginHostMsg_ResizeGuest::ID); 312 BrowserPluginHostMsg_CreateGuest::ID);
318 ASSERT_TRUE(msg); 313 ASSERT_TRUE(msg);
319 BrowserPluginHostMsg_ResizeGuest_Params params; 314 BrowserPluginHostMsg_CreateGuest_Params params;
320 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params); 315 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
321 } 316 }
322 MockBrowserPlugin* browser_plugin = 317 MockBrowserPlugin* browser_plugin =
323 static_cast<MockBrowserPlugin*>( 318 static_cast<MockBrowserPlugin*>(
324 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 319 browser_plugin_manager()->GetBrowserPlugin(instance_id));
325 ASSERT_TRUE(browser_plugin); 320 ASSERT_TRUE(browser_plugin);
326 321
327 WebKit::WebCursorInfo cursor_info; 322 WebKit::WebCursorInfo cursor_info;
328 // Send an event and verify that the event is deported. 323 // Send an event and verify that the event is deported.
329 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(), 324 browser_plugin->handleInputEvent(WebKit::WebMouseEvent(),
330 cursor_info); 325 cursor_info);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 368 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
374 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 369 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
375 BrowserPluginHostMsg_PluginDestroyed::ID)); 370 BrowserPluginHostMsg_PluginDestroyed::ID));
376 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 371 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
377 "x.parentNode.removeChild(x);"); 372 "x.parentNode.removeChild(x);");
378 ProcessPendingMessages(); 373 ProcessPendingMessages();
379 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 374 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
380 BrowserPluginHostMsg_PluginDestroyed::ID)); 375 BrowserPluginHostMsg_PluginDestroyed::ID));
381 } 376 }
382 377
378 // This test verifies that PluginDestroyed messages do not get sent from a
379 // BrowserPlugin that has never navigated.
380 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) {
381 std::string html = StringPrintf(kHTMLForSourcelessPluginObject,
382 content::kBrowserPluginMimeType);
383 LoadHTML(html.c_str());
384 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
385 BrowserPluginHostMsg_PluginDestroyed::ID));
386 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
387 "x.parentNode.removeChild(x);");
388 ProcessPendingMessages();
389 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
390 BrowserPluginHostMsg_PluginDestroyed::ID));
391 }
392
383 TEST_F(BrowserPluginTest, CustomEvents) { 393 TEST_F(BrowserPluginTest, CustomEvents) {
384 const char* kAddEventListener = 394 const char* kAddEventListener =
385 "var url;" 395 "var url;"
386 "function nav(e) {" 396 "function nav(e) {"
387 " url = JSON.parse(e.detail).url;" 397 " url = JSON.parse(e.detail).url;"
388 "}" 398 "}"
389 "document.getElementById('browserplugin')." 399 "document.getElementById('browserplugin')."
390 " addEventListener('-internal-loadcommit', nav);"; 400 " addEventListener('-internal-loadcommit', nav);";
391 const char* kRemoveEventListener = 401 const char* kRemoveEventListener =
392 "document.getElementById('browserplugin')." 402 "document.getElementById('browserplugin')."
393 " removeEventListener('-internal-loadcommit', nav);"; 403 " removeEventListener('-internal-loadcommit', nav);";
394 const char* kGetProcessID = 404 const char* kGetProcessID =
395 "document.getElementById('browserplugin').getProcessId()"; 405 "document.getElementById('browserplugin').getProcessId()";
396 const char* kGetSrc = 406 const char* kGetSrc =
397 "document.getElementById('browserplugin').src"; 407 "document.getElementById('browserplugin').src";
398 const char* kGoogleURL = "http://www.google.com/"; 408 const char* kGoogleURL = "http://www.google.com/";
399 const char* kGoogleNewsURL = "http://news.google.com/"; 409 const char* kGoogleNewsURL = "http://news.google.com/";
400 410
401 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 411 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
402 ExecuteJavaScript(kAddEventListener); 412 ExecuteJavaScript(kAddEventListener);
403 // Grab the BrowserPlugin's instance ID from its resize message. 413 // Grab the BrowserPlugin's instance ID from its resize message.
404 const IPC::Message* msg = 414 const IPC::Message* msg =
405 browser_plugin_manager()->sink().GetFirstMessageMatching( 415 browser_plugin_manager()->sink().GetFirstMessageMatching(
406 BrowserPluginHostMsg_ResizeGuest::ID); 416 BrowserPluginHostMsg_CreateGuest::ID);
407 ASSERT_TRUE(msg); 417 ASSERT_TRUE(msg);
408 int instance_id = 0; 418 int instance_id = 0;
409 BrowserPluginHostMsg_ResizeGuest_Params params; 419 BrowserPluginHostMsg_CreateGuest_Params params;
410 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params); 420 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
411 421
412 MockBrowserPlugin* browser_plugin = 422 MockBrowserPlugin* browser_plugin =
413 static_cast<MockBrowserPlugin*>( 423 static_cast<MockBrowserPlugin*>(
414 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 424 browser_plugin_manager()->GetBrowserPlugin(instance_id));
415 ASSERT_TRUE(browser_plugin); 425 ASSERT_TRUE(browser_plugin);
416 426
417 { 427 {
418 BrowserPluginMsg_LoadCommit_Params navigate_params; 428 BrowserPluginMsg_LoadCommit_Params navigate_params;
419 navigate_params.is_top_level = true; 429 navigate_params.is_top_level = true;
420 navigate_params.url = GURL(kGoogleURL); 430 navigate_params.url = GURL(kGoogleURL);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 "document.getElementById('browserplugin').src")); 535 "document.getElementById('browserplugin').src"));
526 } 536 }
527 537
528 // Verify that the BrowserPlugin accepts changes to its src attribue after 538 // Verify that the BrowserPlugin accepts changes to its src attribue after
529 // setting the partition to a valid value. 539 // setting the partition to a valid value.
530 ExecuteJavaScript( 540 ExecuteJavaScript(
531 "document.getElementById('browserplugin').partition = 'persist:foo'"); 541 "document.getElementById('browserplugin').partition = 'persist:foo'");
532 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); 542 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
533 EXPECT_EQ("bar", ExecuteScriptAndReturnString( 543 EXPECT_EQ("bar", ExecuteScriptAndReturnString(
534 "document.getElementById('browserplugin').src")); 544 "document.getElementById('browserplugin').src"));
545 ProcessPendingMessages();
535 // Verify that the BrowserPlugin does not 'deadlock': it can recover from 546 // Verify that the BrowserPlugin does not 'deadlock': it can recover from
536 // the partition ID error state. 547 // the partition ID error state.
537 { 548 {
538 ExecuteJavaScript( 549 ExecuteJavaScript(
539 "try {" 550 "try {"
540 " document.getElementById('browserplugin').partition = 'persist:1337';" 551 " document.getElementById('browserplugin').partition = 'persist:1337';"
541 " document.title = 'success';" 552 " document.title = 'success';"
542 "} catch (e) { document.title = e.message; }"); 553 "} catch (e) { document.title = e.message; }");
543 std::string title = ExecuteScriptAndReturnString("document.title"); 554 std::string title = ExecuteScriptAndReturnString("document.title");
544 EXPECT_STREQ( 555 EXPECT_STREQ(
(...skipping 16 matching lines...) Expand all
561 "document.getElementById('browserplugin').partition = 'storage'"); 572 "document.getElementById('browserplugin').partition = 'storage'");
562 std::string partition_value = ExecuteScriptAndReturnString( 573 std::string partition_value = ExecuteScriptAndReturnString(
563 "document.getElementById('browserplugin').partition"); 574 "document.getElementById('browserplugin').partition");
564 EXPECT_STREQ("storage", partition_value.c_str()); 575 EXPECT_STREQ("storage", partition_value.c_str());
565 576
566 std::string src_value = ExecuteScriptAndReturnString( 577 std::string src_value = ExecuteScriptAndReturnString(
567 "document.getElementById('browserplugin').src"); 578 "document.getElementById('browserplugin').src");
568 EXPECT_STREQ("", src_value.c_str()); 579 EXPECT_STREQ("", src_value.c_str());
569 580
570 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'"); 581 ExecuteJavaScript("document.getElementById('browserplugin').src = 'bar'");
582 ProcessPendingMessages();
571 { 583 {
572 const IPC::Message* create_msg = 584 const IPC::Message* create_msg =
573 browser_plugin_manager()->sink().GetUniqueMessageMatching( 585 browser_plugin_manager()->sink().GetUniqueMessageMatching(
574 BrowserPluginHostMsg_CreateGuest::ID); 586 BrowserPluginHostMsg_CreateGuest::ID);
575 ASSERT_TRUE(create_msg); 587 ASSERT_TRUE(create_msg);
576 588
577 int create_instance_id = 0; 589 int create_instance_id = 0;
578 BrowserPluginHostMsg_CreateGuest_Params params; 590 BrowserPluginHostMsg_CreateGuest_Params params;
579 BrowserPluginHostMsg_CreateGuest::Read( 591 BrowserPluginHostMsg_CreateGuest::Read(
580 create_msg, 592 create_msg,
581 &create_instance_id, 593 &create_instance_id,
582 &params); 594 &params);
583 EXPECT_STREQ("storage", params.storage_partition_id.c_str()); 595 EXPECT_STREQ("storage", params.storage_partition_id.c_str());
584 EXPECT_FALSE(params.persist_storage); 596 EXPECT_FALSE(params.persist_storage);
585 597 EXPECT_STREQ("bar", params.src.c_str());
586 const IPC::Message* msg =
587 browser_plugin_manager()->sink().GetUniqueMessageMatching(
588 BrowserPluginHostMsg_NavigateGuest::ID);
589 ASSERT_TRUE(msg);
590
591 int instance_id = 0;
592 std::string src;
593 BrowserPluginHostMsg_NavigateGuest::Read(msg, &instance_id, &src);
594 EXPECT_STREQ("bar", src.c_str());
595 EXPECT_EQ(create_instance_id, instance_id);
596 } 598 }
597 599
598 // Setting the partition should throw an exception and the value should not 600 // Setting the partition should throw an exception and the value should not
599 // change. 601 // change.
600 ExecuteJavaScript( 602 ExecuteJavaScript(
601 "try {" 603 "try {"
602 " document.getElementById('browserplugin').partition = 'someid';" 604 " document.getElementById('browserplugin').partition = 'someid';"
603 " document.title = 'success';" 605 " document.title = 'success';"
604 "} catch (e) { document.title = e.message; }"); 606 "} catch (e) { document.title = e.message; }");
605 607
(...skipping 19 matching lines...) Expand all
625 "}" 627 "}"
626 "document.getElementById('browserplugin')." 628 "document.getElementById('browserplugin')."
627 " addEventListener('-internal-loadcommit', nav);"; 629 " addEventListener('-internal-loadcommit', nav);";
628 const char* kGoogleURL = "http://www.google.com/"; 630 const char* kGoogleURL = "http://www.google.com/";
629 const char* kGoogleNewsURL = "http://news.google.com/"; 631 const char* kGoogleNewsURL = "http://news.google.com/";
630 const char* kGetProcessID = 632 const char* kGetProcessID =
631 "document.getElementById('browserplugin').getProcessId()"; 633 "document.getElementById('browserplugin').getProcessId()";
632 634
633 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 635 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
634 ExecuteJavaScript(kAddEventListener); 636 ExecuteJavaScript(kAddEventListener);
635 // Grab the BrowserPlugin's instance ID from its resize message. 637 // Grab the BrowserPlugin's instance ID from its CreateGuest message.
636 const IPC::Message* msg = 638 const IPC::Message* msg =
637 browser_plugin_manager()->sink().GetFirstMessageMatching( 639 browser_plugin_manager()->sink().GetFirstMessageMatching(
638 BrowserPluginHostMsg_ResizeGuest::ID); 640 BrowserPluginHostMsg_CreateGuest::ID);
639 ASSERT_TRUE(msg); 641 ASSERT_TRUE(msg);
640 int instance_id = 0; 642 int instance_id = 0;
641 BrowserPluginHostMsg_ResizeGuest_Params params; 643 BrowserPluginHostMsg_CreateGuest_Params params;
642 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params); 644 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
643 645
644 MockBrowserPlugin* browser_plugin = 646 MockBrowserPlugin* browser_plugin =
645 static_cast<MockBrowserPlugin*>( 647 static_cast<MockBrowserPlugin*>(
646 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 648 browser_plugin_manager()->GetBrowserPlugin(instance_id));
647 ASSERT_TRUE(browser_plugin); 649 ASSERT_TRUE(browser_plugin);
648 650
649 { 651 {
650 BrowserPluginMsg_LoadCommit_Params navigate_params; 652 BrowserPluginMsg_LoadCommit_Params navigate_params;
651 navigate_params.url = GURL(kGoogleURL); 653 navigate_params.url = GURL(kGoogleURL);
652 navigate_params.process_id = 1337; 654 navigate_params.process_id = 1337;
(...skipping 29 matching lines...) Expand all
682 "document.getElementById('browserplugin')." 684 "document.getElementById('browserplugin')."
683 " addEventListener('-internal-loadcommit', nava);" 685 " addEventListener('-internal-loadcommit', nava);"
684 "document.getElementById('browserplugin')." 686 "document.getElementById('browserplugin')."
685 " addEventListener('-internal-loadcommit', navb);"; 687 " addEventListener('-internal-loadcommit', navb);";
686 const char* kGoogleURL = "http://www.google.com/"; 688 const char* kGoogleURL = "http://www.google.com/";
687 const char* kGetProcessID = 689 const char* kGetProcessID =
688 "document.getElementById('browserplugin').getProcessId()"; 690 "document.getElementById('browserplugin').getProcessId()";
689 691
690 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 692 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
691 ExecuteJavaScript(kAddEventListener); 693 ExecuteJavaScript(kAddEventListener);
692 // Grab the BrowserPlugin's instance ID from its resize message. 694 // Grab the BrowserPlugin's instance ID from its CreateGuest message.
693 const IPC::Message* msg = 695 const IPC::Message* msg =
694 browser_plugin_manager()->sink().GetFirstMessageMatching( 696 browser_plugin_manager()->sink().GetFirstMessageMatching(
695 BrowserPluginHostMsg_ResizeGuest::ID); 697 BrowserPluginHostMsg_CreateGuest::ID);
696 ASSERT_TRUE(msg); 698 ASSERT_TRUE(msg);
697 int instance_id = 0; 699 int instance_id = 0;
698 BrowserPluginHostMsg_ResizeGuest_Params params; 700 BrowserPluginHostMsg_CreateGuest_Params params;
699 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params); 701 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
700 702
701 MockBrowserPlugin* browser_plugin = 703 MockBrowserPlugin* browser_plugin =
702 static_cast<MockBrowserPlugin*>( 704 static_cast<MockBrowserPlugin*>(
703 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 705 browser_plugin_manager()->GetBrowserPlugin(instance_id));
704 ASSERT_TRUE(browser_plugin); 706 ASSERT_TRUE(browser_plugin);
705 707
706 { 708 {
707 BrowserPluginMsg_LoadCommit_Params navigate_params; 709 BrowserPluginMsg_LoadCommit_Params navigate_params;
708 navigate_params.url = GURL(kGoogleURL); 710 navigate_params.url = GURL(kGoogleURL);
709 navigate_params.process_id = 1337; 711 navigate_params.process_id = 1337;
710 BrowserPluginMsg_LoadCommit msg(0, instance_id, navigate_params); 712 BrowserPluginMsg_LoadCommit msg(0, instance_id, navigate_params);
711 browser_plugin->OnMessageReceived(msg); 713 browser_plugin->OnMessageReceived(msg);
712 EXPECT_EQ(2, ExecuteScriptAndReturnInt("count")); 714 EXPECT_EQ(2, ExecuteScriptAndReturnInt("count"));
713 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID)); 715 EXPECT_EQ(1337, ExecuteScriptAndReturnInt(kGetProcessID));
714 } 716 }
715 } 717 }
716 718
717 TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) { 719 TEST_F(BrowserPluginTest, RemoveBrowserPluginOnExit) {
718 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 720 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
719 721
720 // Grab the BrowserPlugin's instance ID from its resize message. 722 // Grab the BrowserPlugin's instance ID from its CreateGuest message.
721 int instance_id = 0; 723 int instance_id = 0;
722 { 724 {
723 const IPC::Message* msg = 725 const IPC::Message* msg =
724 browser_plugin_manager()->sink().GetFirstMessageMatching( 726 browser_plugin_manager()->sink().GetFirstMessageMatching(
725 BrowserPluginHostMsg_ResizeGuest::ID); 727 BrowserPluginHostMsg_CreateGuest::ID);
726 ASSERT_TRUE(msg); 728 ASSERT_TRUE(msg);
727 BrowserPluginHostMsg_ResizeGuest_Params params; 729 BrowserPluginHostMsg_CreateGuest_Params params;
728 BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params); 730 BrowserPluginHostMsg_CreateGuest::Read(msg, &instance_id, &params);
729 } 731 }
730 732
731 MockBrowserPlugin* browser_plugin = 733 MockBrowserPlugin* browser_plugin =
732 static_cast<MockBrowserPlugin*>( 734 static_cast<MockBrowserPlugin*>(
733 browser_plugin_manager()->GetBrowserPlugin(instance_id)); 735 browser_plugin_manager()->GetBrowserPlugin(instance_id));
734 ASSERT_TRUE(browser_plugin); 736 ASSERT_TRUE(browser_plugin);
735 737
736 const char* kAddEventListener = 738 const char* kAddEventListener =
737 "function exitListener(e) {" 739 "function exitListener(e) {"
738 " if (JSON.parse(e.detail).reason == 'killed') {" 740 " if (JSON.parse(e.detail).reason == 'killed') {"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 &resize_params); 839 &resize_params);
838 EXPECT_FALSE(auto_size_params.enable); 840 EXPECT_FALSE(auto_size_params.enable);
839 EXPECT_EQ(42, auto_size_params.min_size.width()); 841 EXPECT_EQ(42, auto_size_params.min_size.width());
840 EXPECT_EQ(43, auto_size_params.min_size.height()); 842 EXPECT_EQ(43, auto_size_params.min_size.height());
841 EXPECT_EQ(1337, auto_size_params.max_size.width()); 843 EXPECT_EQ(1337, auto_size_params.max_size.width());
842 EXPECT_EQ(1338, auto_size_params.max_size.height()); 844 EXPECT_EQ(1338, auto_size_params.max_size.height());
843 } 845 }
844 } 846 }
845 847
846 } // namespace content 848 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698