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

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

Issue 12767006: [Cleanup] Remove StringPrintf from global namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, once more Created 7 years, 9 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_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.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 29 matching lines...) Expand all
40 40
41 const char kHTMLForInvalidPartitionedPluginObject[] = 41 const char kHTMLForInvalidPartitionedPluginObject[] =
42 "<object id='browserplugin' width='640px' height='480px'" 42 "<object id='browserplugin' width='640px' height='480px'"
43 " type='%s' partition='persist:'>"; 43 " type='%s' partition='persist:'>";
44 44
45 const char kHTMLForPartitionedPersistedPluginObject[] = 45 const char kHTMLForPartitionedPersistedPluginObject[] =
46 "<object id='browserplugin' width='640px' height='480px'" 46 "<object id='browserplugin' width='640px' height='480px'"
47 " src='foo' type='%s' partition='persist:someid'>"; 47 " src='foo' type='%s' partition='persist:someid'>";
48 48
49 std::string GetHTMLForBrowserPluginObject() { 49 std::string GetHTMLForBrowserPluginObject() {
50 return StringPrintf(kHTMLForBrowserPluginObject, 50 return base::StringPrintf(kHTMLForBrowserPluginObject,
51 content::kBrowserPluginMimeType); 51 content::kBrowserPluginMimeType);
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 namespace content { 56 namespace content {
57 57
58 class TestContentRendererClient : public ContentRendererClient { 58 class TestContentRendererClient : public ContentRendererClient {
59 public: 59 public:
60 TestContentRendererClient() : ContentRendererClient() { 60 TestContentRendererClient() : ContentRendererClient() {
61 } 61 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 update_rect_params.needs_ack = true; 191 update_rect_params.needs_ack = true;
192 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params); 192 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
193 browser_plugin->OnMessageReceived(msg); 193 browser_plugin->OnMessageReceived(msg);
194 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get()); 194 EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
195 } 195 }
196 196
197 // This test verifies that all attributes (present at the time of writing) are 197 // This test verifies that all attributes (present at the time of writing) are
198 // parsed on initialization. However, this test does minimal checking of 198 // parsed on initialization. However, this test does minimal checking of
199 // correct behavior. 199 // correct behavior.
200 TEST_F(BrowserPluginTest, ParseAllAttributes) { 200 TEST_F(BrowserPluginTest, ParseAllAttributes) {
201 std::string html = StringPrintf(kHTMLForBrowserPluginWithAllAttributes, 201 std::string html = base::StringPrintf(kHTMLForBrowserPluginWithAllAttributes,
202 content::kBrowserPluginMimeType); 202 content::kBrowserPluginMimeType);
203 LoadHTML(html.c_str()); 203 LoadHTML(html.c_str());
204 bool result; 204 bool result;
205 bool has_value = ExecuteScriptAndReturnBool( 205 bool has_value = ExecuteScriptAndReturnBool(
206 "document.getElementById('browserplugin').autosize", &result); 206 "document.getElementById('browserplugin').autosize", &result);
207 EXPECT_TRUE(has_value); 207 EXPECT_TRUE(has_value);
208 EXPECT_TRUE(result); 208 EXPECT_TRUE(result);
209 int maxHeight = ExecuteScriptAndReturnInt( 209 int maxHeight = ExecuteScriptAndReturnInt(
210 "document.getElementById('browserplugin').maxheight"); 210 "document.getElementById('browserplugin').maxheight");
211 EXPECT_EQ(600, maxHeight); 211 EXPECT_EQ(600, maxHeight);
212 int maxWidth = ExecuteScriptAndReturnInt( 212 int maxWidth = ExecuteScriptAndReturnInt(
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 441 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
442 "x.parentNode.removeChild(x);"); 442 "x.parentNode.removeChild(x);");
443 ProcessPendingMessages(); 443 ProcessPendingMessages();
444 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 444 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
445 BrowserPluginHostMsg_PluginDestroyed::ID)); 445 BrowserPluginHostMsg_PluginDestroyed::ID));
446 } 446 }
447 447
448 // This test verifies that PluginDestroyed messages do not get sent from a 448 // This test verifies that PluginDestroyed messages do not get sent from a
449 // BrowserPlugin that has never navigated. 449 // BrowserPlugin that has never navigated.
450 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) { 450 TEST_F(BrowserPluginTest, RemovePluginBeforeNavigation) {
451 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, 451 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
452 content::kBrowserPluginMimeType); 452 content::kBrowserPluginMimeType);
453 LoadHTML(html.c_str()); 453 LoadHTML(html.c_str());
454 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 454 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
455 BrowserPluginHostMsg_PluginDestroyed::ID)); 455 BrowserPluginHostMsg_PluginDestroyed::ID));
456 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 456 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
457 "x.parentNode.removeChild(x);"); 457 "x.parentNode.removeChild(x);");
458 ProcessPendingMessages(); 458 ProcessPendingMessages();
459 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 459 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
460 BrowserPluginHostMsg_PluginDestroyed::ID)); 460 BrowserPluginHostMsg_PluginDestroyed::ID));
461 } 461 }
462 462
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 537 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
538 ExecuteJavaScript(kCallReload); 538 ExecuteJavaScript(kCallReload);
539 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 539 EXPECT_TRUE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
540 BrowserPluginHostMsg_Reload::ID)); 540 BrowserPluginHostMsg_Reload::ID));
541 } 541 }
542 542
543 543
544 // Verify that the 'partition' attribute on the browser plugin is parsed 544 // Verify that the 'partition' attribute on the browser plugin is parsed
545 // correctly. 545 // correctly.
546 TEST_F(BrowserPluginTest, PartitionAttribute) { 546 TEST_F(BrowserPluginTest, PartitionAttribute) {
547 std::string html = StringPrintf(kHTMLForPartitionedPluginObject, 547 std::string html = base::StringPrintf(kHTMLForPartitionedPluginObject,
548 content::kBrowserPluginMimeType); 548 content::kBrowserPluginMimeType);
549 LoadHTML(html.c_str()); 549 LoadHTML(html.c_str());
550 std::string partition_value = ExecuteScriptAndReturnString( 550 std::string partition_value = ExecuteScriptAndReturnString(
551 "document.getElementById('browserplugin').partition"); 551 "document.getElementById('browserplugin').partition");
552 EXPECT_STREQ("someid", partition_value.c_str()); 552 EXPECT_STREQ("someid", partition_value.c_str());
553 553
554 html = StringPrintf(kHTMLForPartitionedPersistedPluginObject, 554 html = base::StringPrintf(kHTMLForPartitionedPersistedPluginObject,
555 content::kBrowserPluginMimeType); 555 content::kBrowserPluginMimeType);
556 LoadHTML(html.c_str()); 556 LoadHTML(html.c_str());
557 partition_value = ExecuteScriptAndReturnString( 557 partition_value = ExecuteScriptAndReturnString(
558 "document.getElementById('browserplugin').partition"); 558 "document.getElementById('browserplugin').partition");
559 EXPECT_STREQ("persist:someid", partition_value.c_str()); 559 EXPECT_STREQ("persist:someid", partition_value.c_str());
560 560
561 // Verify that once HTML has defined a source and partition, we cannot change 561 // Verify that once HTML has defined a source and partition, we cannot change
562 // the partition anymore. 562 // the partition anymore.
563 ExecuteJavaScript( 563 ExecuteJavaScript(
564 "try {" 564 "try {"
565 " document.getElementById('browserplugin').partition = 'foo';" 565 " document.getElementById('browserplugin').partition = 'foo';"
566 " document.title = 'success';" 566 " document.title = 'success';"
567 "} catch (e) { document.title = e.message; }"); 567 "} catch (e) { document.title = e.message; }");
568 std::string title = ExecuteScriptAndReturnString("document.title"); 568 std::string title = ExecuteScriptAndReturnString("document.title");
569 EXPECT_STREQ( 569 EXPECT_STREQ(
570 "The object has already navigated, so its partition cannot be changed.", 570 "The object has already navigated, so its partition cannot be changed.",
571 title.c_str()); 571 title.c_str());
572 572
573 // Load a browser tag without 'src' defined. 573 // Load a browser tag without 'src' defined.
574 html = StringPrintf(kHTMLForSourcelessPluginObject, 574 html = base::StringPrintf(kHTMLForSourcelessPluginObject,
575 content::kBrowserPluginMimeType); 575 content::kBrowserPluginMimeType);
576 LoadHTML(html.c_str()); 576 LoadHTML(html.c_str());
577 577
578 // Ensure we don't parse just "persist:" string and return exception. 578 // Ensure we don't parse just "persist:" string and return exception.
579 ExecuteJavaScript( 579 ExecuteJavaScript(
580 "try {" 580 "try {"
581 " document.getElementById('browserplugin').partition = 'persist:';" 581 " document.getElementById('browserplugin').partition = 'persist:';"
582 " document.title = 'success';" 582 " document.title = 'success';"
583 "} catch (e) { document.title = e.message; }"); 583 "} catch (e) { document.title = e.message; }");
584 title = ExecuteScriptAndReturnString("document.title"); 584 title = ExecuteScriptAndReturnString("document.title");
585 EXPECT_STREQ("Invalid partition attribute.", title.c_str()); 585 EXPECT_STREQ("Invalid partition attribute.", title.c_str());
586 } 586 }
587 587
588 // This test verifies that BrowserPlugin enters an error state when the 588 // This test verifies that BrowserPlugin enters an error state when the
589 // partition attribute is invalid. 589 // partition attribute is invalid.
590 TEST_F(BrowserPluginTest, InvalidPartition) { 590 TEST_F(BrowserPluginTest, InvalidPartition) {
591 std::string html = StringPrintf(kHTMLForInvalidPartitionedPluginObject, 591 std::string html = base::StringPrintf(kHTMLForInvalidPartitionedPluginObject,
592 content::kBrowserPluginMimeType); 592 content::kBrowserPluginMimeType);
593 LoadHTML(html.c_str()); 593 LoadHTML(html.c_str());
594 // Attempt to navigate with an invalid partition. 594 // Attempt to navigate with an invalid partition.
595 { 595 {
596 ExecuteJavaScript( 596 ExecuteJavaScript(
597 "try {" 597 "try {"
598 " document.getElementById('browserplugin').src = 'bar';" 598 " document.getElementById('browserplugin').src = 'bar';"
599 " document.title = 'success';" 599 " document.title = 'success';"
600 "} catch (e) { document.title = e.message; }"); 600 "} catch (e) { document.title = e.message; }");
601 std::string title = ExecuteScriptAndReturnString("document.title"); 601 std::string title = ExecuteScriptAndReturnString("document.title");
602 EXPECT_STREQ("Invalid partition attribute.", title.c_str()); 602 EXPECT_STREQ("Invalid partition attribute.", title.c_str());
(...skipping 24 matching lines...) Expand all
627 title.c_str()); 627 title.c_str());
628 ExecuteJavaScript("document.getElementById('browserplugin').src = '42'"); 628 ExecuteJavaScript("document.getElementById('browserplugin').src = '42'");
629 EXPECT_EQ("42", ExecuteScriptAndReturnString( 629 EXPECT_EQ("42", ExecuteScriptAndReturnString(
630 "document.getElementById('browserplugin').src")); 630 "document.getElementById('browserplugin').src"));
631 } 631 }
632 } 632 }
633 633
634 // Test to verify that after the first navigation, the partition attribute 634 // Test to verify that after the first navigation, the partition attribute
635 // cannot be modified. 635 // cannot be modified.
636 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) { 636 TEST_F(BrowserPluginTest, ImmutableAttributesAfterNavigation) {
637 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, 637 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
638 content::kBrowserPluginMimeType); 638 content::kBrowserPluginMimeType);
639 LoadHTML(html.c_str()); 639 LoadHTML(html.c_str());
640 640
641 ExecuteJavaScript( 641 ExecuteJavaScript(
642 "document.getElementById('browserplugin').partition = 'storage'"); 642 "document.getElementById('browserplugin').partition = 'storage'");
643 std::string partition_value = ExecuteScriptAndReturnString( 643 std::string partition_value = ExecuteScriptAndReturnString(
644 "document.getElementById('browserplugin').partition"); 644 "document.getElementById('browserplugin').partition");
645 EXPECT_STREQ("storage", partition_value.c_str()); 645 EXPECT_STREQ("storage", partition_value.c_str());
646 646
647 std::string src_value = ExecuteScriptAndReturnString( 647 std::string src_value = ExecuteScriptAndReturnString(
648 "document.getElementById('browserplugin').src"); 648 "document.getElementById('browserplugin').src");
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 BrowserPluginMsg_GuestGone msg( 821 BrowserPluginMsg_GuestGone msg(
822 instance_id, 0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED); 822 instance_id, 0, base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
823 browser_plugin->OnMessageReceived(msg); 823 browser_plugin->OnMessageReceived(msg);
824 824
825 ProcessPendingMessages(); 825 ProcessPendingMessages();
826 826
827 EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id)); 827 EXPECT_EQ(NULL, browser_plugin_manager()->GetBrowserPlugin(instance_id));
828 } 828 }
829 829
830 TEST_F(BrowserPluginTest, AutoSizeAttributes) { 830 TEST_F(BrowserPluginTest, AutoSizeAttributes) {
831 std::string html = StringPrintf(kHTMLForSourcelessPluginObject, 831 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
832 content::kBrowserPluginMimeType); 832 content::kBrowserPluginMimeType);
833 LoadHTML(html.c_str()); 833 LoadHTML(html.c_str());
834 const char* kSetAutoSizeParametersAndNavigate = 834 const char* kSetAutoSizeParametersAndNavigate =
835 "var browserplugin = document.getElementById('browserplugin');" 835 "var browserplugin = document.getElementById('browserplugin');"
836 "browserplugin.autosize = true;" 836 "browserplugin.autosize = true;"
837 "browserplugin.minwidth = 42;" 837 "browserplugin.minwidth = 42;"
838 "browserplugin.minheight = 43;" 838 "browserplugin.minheight = 43;"
839 "browserplugin.maxwidth = 1337;" 839 "browserplugin.maxwidth = 1337;"
840 "browserplugin.maxheight = 1338;" 840 "browserplugin.maxheight = 1338;"
841 "browserplugin.src = 'foobar';"; 841 "browserplugin.src = 'foobar';";
842 const char* kDisableAutoSize = 842 const char* kDisableAutoSize =
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 // These value are not populated (as an optimization) if autosize is 911 // These value are not populated (as an optimization) if autosize is
912 // disabled. 912 // disabled.
913 EXPECT_EQ(0, auto_size_params.min_size.width()); 913 EXPECT_EQ(0, auto_size_params.min_size.width());
914 EXPECT_EQ(0, auto_size_params.min_size.height()); 914 EXPECT_EQ(0, auto_size_params.min_size.height());
915 EXPECT_EQ(0, auto_size_params.max_size.width()); 915 EXPECT_EQ(0, auto_size_params.max_size.width());
916 EXPECT_EQ(0, auto_size_params.max_size.height()); 916 EXPECT_EQ(0, auto_size_params.max_size.height());
917 } 917 }
918 } 918 }
919 919
920 } // namespace content 920 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698