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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_host_browsertest.cc

Issue 11360106: Browser Plugin: Implement AutoSize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged with ToT Created 8 years, 1 month 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/singleton.h" 6 #include "base/memory/singleton.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/test/test_timeouts.h" 8 #include "base/test/test_timeouts.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "content/browser/browser_plugin/browser_plugin_guest.h" 10 #include "content/browser/browser_plugin/browser_plugin_guest.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 "data:text/html,<html><body>" 67 "data:text/html,<html><body>"
68 "<script>" 68 "<script>"
69 "function dropped() {" 69 "function dropped() {"
70 " document.title = \"DROPPED\";" 70 " document.title = \"DROPPED\";"
71 "}" 71 "}"
72 "</script>" 72 "</script>"
73 "<textarea id=\"text\" style=\"width:100%; height: 100%\"" 73 "<textarea id=\"text\" style=\"width:100%; height: 100%\""
74 " ondrop=\"dropped();\">" 74 " ondrop=\"dropped();\">"
75 "</textarea>" 75 "</textarea>"
76 "</body></html>"; 76 "</body></html>";
77 const char kHTMLForGuestWithSize[] =
78 "data:text/html,"
79 "<html>"
80 "<body style=\"margin: 0px;\">"
81 "<img style=\"width: 100%; height: 400px;\"/>"
82 "</body>"
83 "</html>";
77 84
78 std::string GetHTMLForGuestWithTitle(const std::string& title) { 85 std::string GetHTMLForGuestWithTitle(const std::string& title) {
79 return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); 86 return StringPrintf(kHTMLForGuestWithTitle, title.c_str());
80 } 87 }
81 88
82 } // namespace 89 } // namespace
83 90
84 namespace content { 91 namespace content {
85 92
86 // Test factory for creating test instances of BrowserPluginEmbedder and 93 // Test factory for creating test instances of BrowserPluginEmbedder and
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 ASCIIToUTF16("document.hasFocus()"))); 1136 ASCIIToUTF16("document.hasFocus()")));
1130 bool result = false; 1137 bool result = false;
1131 ASSERT_TRUE(value->GetAsBoolean(&result)); 1138 ASSERT_TRUE(value->GetAsBoolean(&result));
1132 EXPECT_TRUE(result); 1139 EXPECT_TRUE(result);
1133 } 1140 }
1134 // Blur the embedder. 1141 // Blur the embedder.
1135 test_embedder()->web_contents()->GetRenderViewHost()->Blur(); 1142 test_embedder()->web_contents()->GetRenderViewHost()->Blur();
1136 test_guest()->WaitForBlur(); 1143 test_guest()->WaitForBlur();
1137 } 1144 }
1138 1145
1146 // This test verifies that if a browser plugin is in autosize mode before
1147 // navigation then the guest starts auto-sized.
1148 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeBeforeNavigation) {
1149 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1150 const std::string embedder_code =
1151 "document.getElementById('plugin').minWidth = 300;"
1152 "document.getElementById('plugin').minHeight = 200;"
1153 "document.getElementById('plugin').maxWidth = 600;"
1154 "document.getElementById('plugin').maxHeight = 400;"
1155 "document.getElementById('plugin').autoSize = true;";
1156 StartBrowserPluginTest(
1157 kEmbedderURL, kHTMLForGuestWithSize, true, embedder_code);
1158 // Verify that the guest has been auto-sized.
1159 test_guest()->WaitForViewSize(gfx::Size(300, 400));
1160 }
1161
1162 // This test verifies that enabling autosize resizes the guest and triggers
1163 // a 'sizechanged' event.
1164 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AutoSizeAfterNavigation) {
1165 const char* kEmbedderURL = "files/browser_plugin_embedder.html";
1166 StartBrowserPluginTest(
1167 kEmbedderURL, kHTMLForGuestWithSize, true, "");
1168 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
1169 test_embedder()->web_contents()->GetRenderViewHost());
1170
1171 {
1172 const string16 expected_title = ASCIIToUTF16("AutoSize(300, 400)");
1173 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
1174 expected_title);
1175 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(
1176 "document.getElementById('plugin').minWidth = 300;"
1177 "document.getElementById('plugin').minHeight = 200;"
1178 "document.getElementById('plugin').maxWidth = 600;"
1179 "document.getElementById('plugin').maxHeight = 400;"
1180 "document.getElementById('plugin').autoSize = true;"));
1181 string16 actual_title = title_watcher.WaitAndGetTitle();
1182 EXPECT_EQ(expected_title, actual_title);
1183 }
1184 {
1185 // Change the minWidth and verify that it causes relayout.
1186 const string16 expected_title = ASCIIToUTF16("AutoSize(350, 400)");
1187 content::TitleWatcher title_watcher(test_embedder()->web_contents(),
1188 expected_title);
1189 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(
1190 "document.getElementById('plugin').minWidth = 350;"));
1191 string16 actual_title = title_watcher.WaitAndGetTitle();
1192 EXPECT_EQ(expected_title, actual_title);
1193 }
1194 {
1195 // Turn off autoSize and verify that the guest resizes to fit the contaienr.
1196 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(
1197 "document.getElementById('plugin').autoSize = false;"));
1198 test_guest()->WaitForViewSize(gfx::Size(640, 480));
1199 }
1200 }
1201
1139 } // namespace content 1202 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698