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

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

Issue 427883002: <webview>: Move autosize from content to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_frame_url
Patch Set: Initialize variable Created 6 years, 4 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
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/debug/leak_annotations.h" 7 #include "base/debug/leak_annotations.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 13 matching lines...) Expand all
24 #include "third_party/WebKit/public/web/WebScriptSource.h" 24 #include "third_party/WebKit/public/web/WebScriptSource.h"
25 25
26 namespace content { 26 namespace content {
27 27
28 namespace { 28 namespace {
29 const char kHTMLForBrowserPluginObject[] = 29 const char kHTMLForBrowserPluginObject[] =
30 "<object id='browserplugin' width='640px' height='480px'" 30 "<object id='browserplugin' width='640px' height='480px'"
31 " src='foo' type='%s'></object>" 31 " src='foo' type='%s'></object>"
32 "<script>document.querySelector('object').nonExistentAttribute;</script>"; 32 "<script>document.querySelector('object').nonExistentAttribute;</script>";
33 33
34 const char kHTMLForBrowserPluginWithAllAttributes[] =
35 "<object id='browserplugin' width='640' height='480' type='%s'"
36 " autosize maxheight='600' maxwidth='800' minheight='240'"
37 " minwidth='320' name='Jim' partition='someid' src='foo'>";
38
39 const char kHTMLForSourcelessPluginObject[] = 34 const char kHTMLForSourcelessPluginObject[] =
40 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; 35 "<object id='browserplugin' width='640px' height='480px' type='%s'>";
41 36
42 std::string GetHTMLForBrowserPluginObject() { 37 std::string GetHTMLForBrowserPluginObject() {
43 return base::StringPrintf(kHTMLForBrowserPluginObject, 38 return base::StringPrintf(kHTMLForBrowserPluginObject,
44 kBrowserPluginMimeType); 39 kBrowserPluginMimeType);
45 } 40 }
46 41
47 } // namespace 42 } // namespace
48 43
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 165 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
171 // Verify that the information in Attach is correct. 166 // Verify that the information in Attach is correct.
172 BrowserPluginHostMsg_Attach_Params params; 167 BrowserPluginHostMsg_Attach_Params params;
173 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(&params); 168 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(&params);
174 169
175 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); 170 EXPECT_EQ(640, params.resize_guest_params.view_size.width());
176 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); 171 EXPECT_EQ(480, params.resize_guest_params.view_size.height());
177 ASSERT_TRUE(browser_plugin); 172 ASSERT_TRUE(browser_plugin);
178 } 173 }
179 174
180 // This test verifies that all attributes (present at the time of writing) are
181 // parsed on initialization. However, this test does minimal checking of
182 // correct behavior.
183 TEST_F(BrowserPluginTest, ParseAllAttributes) {
184 std::string html = base::StringPrintf(kHTMLForBrowserPluginWithAllAttributes,
185 kBrowserPluginMimeType);
186 LoadHTML(html.c_str());
187 bool result;
188 bool has_value = ExecuteScriptAndReturnBool(
189 "document.getElementById('browserplugin').autosize", &result);
190 EXPECT_TRUE(has_value);
191 EXPECT_TRUE(result);
192 int maxHeight = ExecuteScriptAndReturnInt(
193 "document.getElementById('browserplugin').maxheight");
194 EXPECT_EQ(600, maxHeight);
195 int maxWidth = ExecuteScriptAndReturnInt(
196 "document.getElementById('browserplugin').maxwidth");
197 EXPECT_EQ(800, maxWidth);
198 int minHeight = ExecuteScriptAndReturnInt(
199 "document.getElementById('browserplugin').minheight");
200 EXPECT_EQ(240, minHeight);
201 int minWidth = ExecuteScriptAndReturnInt(
202 "document.getElementById('browserplugin').minwidth");
203 EXPECT_EQ(320, minWidth);
204 }
205
206 TEST_F(BrowserPluginTest, ResizeFlowControl) { 175 TEST_F(BrowserPluginTest, ResizeFlowControl) {
207 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); 176 LoadHTML(GetHTMLForBrowserPluginObject().c_str());
208 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); 177 MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
209 ASSERT_TRUE(browser_plugin); 178 ASSERT_TRUE(browser_plugin);
210 int instance_id = browser_plugin->guest_instance_id(); 179 int instance_id = browser_plugin->guest_instance_id();
211 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a 180 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a
212 // resize related (SetAutoSize) message. 181 // resize related (SetAutoSize) message.
213 { 182 {
214 // We send a stale UpdateRect to the BrowserPlugin. 183 // We send a stale UpdateRect to the BrowserPlugin.
215 BrowserPluginMsg_UpdateRect_Params update_rect_params; 184 BrowserPluginMsg_UpdateRect_Params update_rect_params;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 LoadHTML(html.c_str()); 270 LoadHTML(html.c_str());
302 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 271 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
303 BrowserPluginHostMsg_PluginDestroyed::ID)); 272 BrowserPluginHostMsg_PluginDestroyed::ID));
304 ExecuteJavaScript("x = document.getElementById('browserplugin'); " 273 ExecuteJavaScript("x = document.getElementById('browserplugin'); "
305 "x.parentNode.removeChild(x);"); 274 "x.parentNode.removeChild(x);");
306 ProcessPendingMessages(); 275 ProcessPendingMessages();
307 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( 276 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching(
308 BrowserPluginHostMsg_PluginDestroyed::ID)); 277 BrowserPluginHostMsg_PluginDestroyed::ID));
309 } 278 }
310 279
311 // Verify that the 'partition' attribute on the browser plugin is parsed
312 // correctly.
313 TEST_F(BrowserPluginTest, AutoSizeAttributes) {
314 std::string html = base::StringPrintf(kHTMLForSourcelessPluginObject,
315 kBrowserPluginMimeType);
316 LoadHTML(html.c_str());
317 const char* kSetAutoSizeParametersAndNavigate =
318 "var browserplugin = document.getElementById('browserplugin');"
319 "browserplugin.autosize = true;"
320 "browserplugin.minwidth = 42;"
321 "browserplugin.minheight = 43;"
322 "browserplugin.maxwidth = 1337;"
323 "browserplugin.maxheight = 1338;"
324 "browserplugin.src = 'foobar';";
325 const char* kDisableAutoSize =
326 "document.getElementById('browserplugin').removeAttribute('autosize');";
327
328 int instance_id = 0;
329 // Set some autosize parameters before navigating then navigate.
330 // Verify that the BrowserPluginHostMsg_Attach message contains
331 // the correct autosize parameters.
332 ExecuteJavaScript(kSetAutoSizeParametersAndNavigate);
333 ProcessPendingMessages();
334
335 BrowserPluginHostMsg_Attach_Params params;
336 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(&params);
337 ASSERT_TRUE(browser_plugin);
338
339 EXPECT_TRUE(params.auto_size_params.enable);
340 EXPECT_EQ(42, params.auto_size_params.min_size.width());
341 EXPECT_EQ(43, params.auto_size_params.min_size.height());
342 EXPECT_EQ(1337, params.auto_size_params.max_size.width());
343 EXPECT_EQ(1338, params.auto_size_params.max_size.height());
344
345 // Disable autosize. AutoSize state will not be sent to the guest until
346 // the guest has responded to the last resize request.
347 ExecuteJavaScript(kDisableAutoSize);
348 ProcessPendingMessages();
349
350 const IPC::Message* auto_size_msg =
351 browser_plugin_manager()->sink().GetUniqueMessageMatching(
352 BrowserPluginHostMsg_SetAutoSize::ID);
353 EXPECT_FALSE(auto_size_msg);
354
355 // Send the BrowserPlugin an UpdateRect equal to its |max_size|.
356 BrowserPluginMsg_UpdateRect_Params update_rect_params;
357 update_rect_params.view_size = gfx::Size(1337, 1338);
358 update_rect_params.scale_factor = 1.0f;
359 update_rect_params.is_resize_ack = true;
360 BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
361 browser_plugin->OnMessageReceived(msg);
362
363 // Verify that the autosize state has been updated.
364 {
365 const IPC::Message* auto_size_msg =
366 browser_plugin_manager()->sink().GetUniqueMessageMatching(
367 BrowserPluginHostMsg_SetAutoSize::ID);
368 ASSERT_TRUE(auto_size_msg);
369
370 BrowserPluginHostMsg_SetAutoSize::Param param;
371 BrowserPluginHostMsg_SetAutoSize::Read(auto_size_msg, &param);
372 BrowserPluginHostMsg_AutoSize_Params auto_size_params = param.b;
373 BrowserPluginHostMsg_ResizeGuest_Params resize_params = param.c;
374 EXPECT_FALSE(auto_size_params.enable);
375 // These value are not populated (as an optimization) if autosize is
376 // disabled.
377 EXPECT_EQ(0, auto_size_params.min_size.width());
378 EXPECT_EQ(0, auto_size_params.min_size.height());
379 EXPECT_EQ(0, auto_size_params.max_size.width());
380 EXPECT_EQ(0, auto_size_params.max_size.height());
381 }
382 }
383
384 } // namespace content 280 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/browser_plugin/browser_plugin_bindings.cc ('k') | extensions/browser/extension_function_histogram_value.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698