OLD | NEW |
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 Loading... |
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 |
34 const char kHTMLForSourcelessPluginObject[] = | 39 const char kHTMLForSourcelessPluginObject[] = |
35 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; | 40 "<object id='browserplugin' width='640px' height='480px' type='%s'>"; |
36 | 41 |
37 std::string GetHTMLForBrowserPluginObject() { | 42 std::string GetHTMLForBrowserPluginObject() { |
38 return base::StringPrintf(kHTMLForBrowserPluginObject, | 43 return base::StringPrintf(kHTMLForBrowserPluginObject, |
39 kBrowserPluginMimeType); | 44 kBrowserPluginMimeType); |
40 } | 45 } |
41 | 46 |
42 } // namespace | 47 } // namespace |
43 | 48 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 170 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
166 // Verify that the information in Attach is correct. | 171 // Verify that the information in Attach is correct. |
167 BrowserPluginHostMsg_Attach_Params params; | 172 BrowserPluginHostMsg_Attach_Params params; |
168 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); | 173 MockBrowserPlugin* browser_plugin = GetCurrentPluginWithAttachParams(¶ms); |
169 | 174 |
170 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); | 175 EXPECT_EQ(640, params.resize_guest_params.view_size.width()); |
171 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); | 176 EXPECT_EQ(480, params.resize_guest_params.view_size.height()); |
172 ASSERT_TRUE(browser_plugin); | 177 ASSERT_TRUE(browser_plugin); |
173 } | 178 } |
174 | 179 |
| 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 |
175 TEST_F(BrowserPluginTest, ResizeFlowControl) { | 206 TEST_F(BrowserPluginTest, ResizeFlowControl) { |
176 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); | 207 LoadHTML(GetHTMLForBrowserPluginObject().c_str()); |
177 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); | 208 MockBrowserPlugin* browser_plugin = GetCurrentPlugin(); |
178 ASSERT_TRUE(browser_plugin); | 209 ASSERT_TRUE(browser_plugin); |
179 int instance_id = browser_plugin->guest_instance_id(); | 210 int instance_id = browser_plugin->guest_instance_id(); |
180 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a | 211 // Send an UpdateRect to the BrowserPlugin to make sure the browser sees a |
181 // resize related (SetAutoSize) message. | 212 // resize related (SetAutoSize) message. |
182 { | 213 { |
183 // We send a stale UpdateRect to the BrowserPlugin. | 214 // We send a stale UpdateRect to the BrowserPlugin. |
184 BrowserPluginMsg_UpdateRect_Params update_rect_params; | 215 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 LoadHTML(html.c_str()); | 301 LoadHTML(html.c_str()); |
271 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 302 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
272 BrowserPluginHostMsg_PluginDestroyed::ID)); | 303 BrowserPluginHostMsg_PluginDestroyed::ID)); |
273 ExecuteJavaScript("x = document.getElementById('browserplugin'); " | 304 ExecuteJavaScript("x = document.getElementById('browserplugin'); " |
274 "x.parentNode.removeChild(x);"); | 305 "x.parentNode.removeChild(x);"); |
275 ProcessPendingMessages(); | 306 ProcessPendingMessages(); |
276 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( | 307 EXPECT_FALSE(browser_plugin_manager()->sink().GetUniqueMessageMatching( |
277 BrowserPluginHostMsg_PluginDestroyed::ID)); | 308 BrowserPluginHostMsg_PluginDestroyed::ID)); |
278 } | 309 } |
279 | 310 |
| 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(¶ms); |
| 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, ¶m); |
| 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 |
280 } // namespace content | 384 } // namespace content |
OLD | NEW |