Chromium Code Reviews| 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 "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" |
| 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 11 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 12 #include "content/browser/browser_plugin/test_browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/test_browser_plugin_embedder.h" |
| 13 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" | 13 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" |
| 14 #include "content/browser/renderer_host/render_view_host_impl.h" | 14 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
| 16 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 19 #include "content/public/browser/render_view_host_observer.h" | 19 #include "content/public/browser/render_view_host_observer.h" |
| 20 #include "content/public/browser/render_widget_host_view.h" | |
| 20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 21 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
| 22 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 23 #include "content/shell/shell.h" | 24 #include "content/shell/shell.h" |
| 24 #include "content/test/content_browser_test_utils.h" | 25 #include "content/test/content_browser_test_utils.h" |
| 25 #include "content/test/content_browser_test.h" | 26 #include "content/test/content_browser_test.h" |
| 26 #include "net/base/net_util.h" | 27 #include "net/base/net_util.h" |
| 27 #include "net/test/test_server.h" | 28 #include "net/test/test_server.h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 29 | 30 |
| 30 using WebKit::WebInputEvent; | 31 using WebKit::WebInputEvent; |
| 31 using WebKit::WebMouseEvent; | 32 using WebKit::WebMouseEvent; |
| 32 using content::BrowserPluginEmbedder; | 33 using content::BrowserPluginEmbedder; |
| 33 using content::BrowserPluginGuest; | 34 using content::BrowserPluginGuest; |
| 34 using content::BrowserPluginHostFactory; | 35 using content::BrowserPluginHostFactory; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 const char* kHTMLForGuest = | 39 const char kHTMLForGuest[] = |
| 39 "data:text/html,<html><body>hello world</body></html>"; | 40 "data:text/html,<html><body>hello world</body></html>"; |
| 40 const char* kHTMLForGuestInfiniteLoop = | 41 const char kHTMLForGuestInfiniteLoop[] = |
| 41 "data:text/html,<html><head><script type=\"text/javascript\">" | 42 "data:text/html,<html><head><script type=\"text/javascript\">" |
| 42 "function StartInfiniteLoop() {" | 43 "function StartInfiniteLoop() {" |
| 43 " setTimeout(function () {while (true) {} }, 0);" | 44 " setTimeout(function () {while (true) {} }, 0);" |
| 44 "}" | 45 "}" |
| 45 "</script></head><body></body></html>"; | 46 "</script></head><body></body></html>"; |
| 46 const char kHTMLForGuestTouchHandler[] = | 47 const char kHTMLForGuestTouchHandler[] = |
| 47 "data:text/html,<html><body><div id=\"touch\">With touch</div></body>" | 48 "data:text/html,<html><body><div id=\"touch\">With touch</div></body>" |
| 48 "<script type=\"text/javascript\">" | 49 "<script type=\"text/javascript\">" |
| 49 "function handler() {}" | 50 "function handler() {}" |
| 50 "function InstallTouchHandler() { " | 51 "function InstallTouchHandler() { " |
| 51 " document.getElementById(\"touch\").addEventListener(\"touchstart\", " | 52 " document.getElementById(\"touch\").addEventListener(\"touchstart\", " |
| 52 " handler);" | 53 " handler);" |
| 53 "}" | 54 "}" |
| 54 "function UninstallTouchHandler() { " | 55 "function UninstallTouchHandler() { " |
| 55 " document.getElementById(\"touch\").removeEventListener(\"touchstart\", " | 56 " document.getElementById(\"touch\").removeEventListener(\"touchstart\", " |
| 56 " handler);" | 57 " handler);" |
| 57 "}" | 58 "}" |
| 58 "</script></html>"; | 59 "</script></html>"; |
| 59 const char* kHTMLForGuestWithTitle = | 60 const char kHTMLForGuestWithTitle[] = |
| 60 "data:text/html," | 61 "data:text/html," |
| 61 "<html><head><title>%s</title></head>" | 62 "<html><head><title>%s</title></head>" |
| 62 "<body>hello world</body>" | 63 "<body>hello world</body>" |
| 63 "</html>"; | 64 "</html>"; |
| 65 const char kHTMLForGuestAcceptDrag[] = | |
| 66 "data:text/html,<html><body>" | |
| 67 "<script>" | |
| 68 "function dropped() {" | |
| 69 " document.title = \"DROPPED\";" | |
| 70 "}" | |
| 71 "</script>" | |
| 72 "<textarea id=\"text\" style=\"width:100%; height: 100%\"" | |
| 73 " ondrop=\"dropped();\">" | |
| 74 "</textarea>" | |
| 75 "</body></html>"; | |
| 64 | 76 |
| 65 std::string GetHTMLForGuestWithTitle(const std::string& title) { | 77 std::string GetHTMLForGuestWithTitle(const std::string& title) { |
| 66 return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); | 78 return StringPrintf(kHTMLForGuestWithTitle, title.c_str()); |
| 67 } | 79 } |
| 68 | 80 |
| 69 } // namespace | 81 } // namespace |
| 70 | 82 |
| 71 namespace content { | 83 namespace content { |
| 72 | 84 |
| 73 // Test factory for creating test instances of BrowserPluginEmbedder and | 85 // Test factory for creating test instances of BrowserPluginEmbedder and |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 238 |
| 227 static void SimulateTabKeyPress(WebContents* web_contents) { | 239 static void SimulateTabKeyPress(WebContents* web_contents) { |
| 228 SimulateKeyPress(web_contents, | 240 SimulateKeyPress(web_contents, |
| 229 ui::VKEY_TAB, | 241 ui::VKEY_TAB, |
| 230 false, // control. | 242 false, // control. |
| 231 false, // shift. | 243 false, // shift. |
| 232 false, // alt. | 244 false, // alt. |
| 233 false); // command. | 245 false); // command. |
| 234 } | 246 } |
| 235 | 247 |
| 248 // Executes the javascript sunchronously and makes sure the returned value is | |
|
Charlie Reis
2012/10/11 21:28:20
nit: synchronously
sadrul
2012/10/12 00:18:47
Done.
| |
| 249 // freed properly. | |
| 250 void ExecuteSyncJSFunction(RenderViewHost* rvh, const string16& jscript) { | |
| 251 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( | |
| 252 string16(), jscript)); | |
| 253 } | |
| 254 | |
| 236 // This helper method does the following: | 255 // This helper method does the following: |
| 237 // 1. Start the test server and navigate the shell to |embedder_url|. | 256 // 1. Start the test server and navigate the shell to |embedder_url|. |
| 238 // 2. Execute custom pre-navigation |embedder_code| if provided. | 257 // 2. Execute custom pre-navigation |embedder_code| if provided. |
| 239 // 3. Navigate the guest to the |guest_url|. | 258 // 3. Navigate the guest to the |guest_url|. |
| 240 // 4. Verify that the guest has been created and has begun painting | 259 // 4. Verify that the guest has been created and has begun painting |
| 241 // pixels. | 260 // pixels. |
| 242 void StartBrowserPluginTest(const std::string& embedder_url, | 261 void StartBrowserPluginTest(const std::string& embedder_url, |
| 243 const std::string& guest_url, | 262 const std::string& guest_url, |
| 244 bool is_guest_data_url, | 263 bool is_guest_data_url, |
| 245 const std::string& embedder_code) { | 264 const std::string& embedder_code) { |
| 246 ASSERT_TRUE(test_server()->Start()); | 265 ASSERT_TRUE(test_server()->Start()); |
| 247 GURL test_url(test_server()->GetURL(embedder_url)); | 266 GURL test_url(test_server()->GetURL(embedder_url)); |
| 248 NavigateToURL(shell(), test_url); | 267 NavigateToURL(shell(), test_url); |
| 249 | 268 |
| 250 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( | 269 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( |
| 251 shell()->web_contents()); | 270 shell()->web_contents()); |
| 252 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 271 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 253 embedder_web_contents->GetRenderViewHost()); | 272 embedder_web_contents->GetRenderViewHost()); |
| 254 | 273 |
| 255 // Allow the test to do some operations on the embedder before we perform | 274 // Allow the test to do some operations on the embedder before we perform |
| 256 // the first navigation of the guest. | 275 // the first navigation of the guest. |
| 257 if (!embedder_code.empty()) { | 276 if (!embedder_code.empty()) |
| 258 rvh->ExecuteJavascriptAndGetValue(string16(), | 277 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(embedder_code)); |
| 259 ASCIIToUTF16(embedder_code)); | |
| 260 } | |
| 261 | 278 |
| 262 if (!is_guest_data_url) { | 279 if (!is_guest_data_url) { |
| 263 test_url = test_server()->GetURL(guest_url); | 280 test_url = test_server()->GetURL(guest_url); |
| 264 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 281 ExecuteSyncJSFunction(rvh, |
| 265 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); | 282 ASCIIToUTF16(StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); |
| 266 } else { | 283 } else { |
| 267 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 284 ExecuteSyncJSFunction(rvh, |
| 268 StringPrintf("SetSrc('%s');", guest_url.c_str()))); | 285 ASCIIToUTF16(StringPrintf("SetSrc('%s');", guest_url.c_str()))); |
| 269 } | 286 } |
| 270 | 287 |
| 271 // Wait to make sure embedder is created/attached to WebContents. | 288 // Wait to make sure embedder is created/attached to WebContents. |
| 272 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); | 289 TestBrowserPluginHostFactory::GetInstance()->WaitForEmbedderCreation(); |
| 273 | 290 |
| 274 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( | 291 test_embedder_ = static_cast<TestBrowserPluginEmbedder*>( |
| 275 embedder_web_contents->GetBrowserPluginEmbedder()); | 292 embedder_web_contents->GetBrowserPluginEmbedder()); |
| 276 ASSERT_TRUE(test_embedder_); | 293 ASSERT_TRUE(test_embedder_); |
| 277 test_embedder_->WaitForGuestAdded(); | 294 test_embedder_->WaitForGuestAdded(); |
| 278 | 295 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 303 // RenderViewGone to be called and times out. http://crbug.com/151190. | 320 // RenderViewGone to be called and times out. http://crbug.com/151190. |
| 304 #if defined(OS_WIN) | 321 #if defined(OS_WIN) |
| 305 #define MAYBE_NavigateGuest DISABLED_NavigateGuest | 322 #define MAYBE_NavigateGuest DISABLED_NavigateGuest |
| 306 #else | 323 #else |
| 307 #define MAYBE_NavigateGuest NavigateGuest | 324 #define MAYBE_NavigateGuest NavigateGuest |
| 308 #endif | 325 #endif |
| 309 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_NavigateGuest) { | 326 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, MAYBE_NavigateGuest) { |
| 310 // Override the hang timeout for guest to be very small. | 327 // Override the hang timeout for guest to be very small. |
| 311 content::BrowserPluginGuest::set_factory_for_testing( | 328 content::BrowserPluginGuest::set_factory_for_testing( |
| 312 TestShortHangTimeoutGuestFactory::GetInstance()); | 329 TestShortHangTimeoutGuestFactory::GetInstance()); |
| 313 const char* kEmbedderURL = "files/browser_plugin_embedder_crash.html"; | 330 const char kEmbedderURL[] = "files/browser_plugin_embedder_crash.html"; |
| 314 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestInfiniteLoop, true, ""); | 331 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestInfiniteLoop, true, ""); |
| 315 | 332 |
| 316 test_guest()->web_contents()-> | 333 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), |
| 317 GetRenderViewHost()->ExecuteJavascriptAndGetValue( | 334 ASCIIToUTF16("StartInfiniteLoop();")); |
| 318 string16(), ASCIIToUTF16("StartInfiniteLoop();")); | |
| 319 | 335 |
| 320 // Send a mouse event to the guest. | 336 // Send a mouse event to the guest. |
| 321 SimulateMouseClick(test_embedder()->web_contents()); | 337 SimulateMouseClick(test_embedder()->web_contents()); |
| 322 | 338 |
| 323 // Expect the guest to crash. | 339 // Expect the guest to crash. |
| 324 test_guest()->WaitForCrashed(); | 340 test_guest()->WaitForCrashed(); |
| 325 } | 341 } |
| 326 | 342 |
| 327 // This test ensures that if guest isn't there and we resize the guest (from | 343 // This test ensures that if guest isn't there and we resize the guest (from |
| 328 // js), it remembers the size correctly. | 344 // js), it remembers the size correctly. |
| 329 // | 345 // |
| 330 // Initially we load an embedder with a guest without a src attribute (which has | 346 // Initially we load an embedder with a guest without a src attribute (which has |
| 331 // dimension 640x480), resize it to 100x200, and then we set the source to a | 347 // dimension 640x480), resize it to 100x200, and then we set the source to a |
| 332 // sample guest. In the end we verify that the correct size has been set. | 348 // sample guest. In the end we verify that the correct size has been set. |
| 333 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { | 349 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) { |
| 334 const gfx::Size nxt_size = gfx::Size(100, 200); | 350 const gfx::Size nxt_size = gfx::Size(100, 200); |
| 335 const std::string embedder_code = | 351 const std::string embedder_code = |
| 336 StringPrintf("SetSize(%d, %d);", nxt_size.width(), nxt_size.height()); | 352 StringPrintf("SetSize(%d, %d);", nxt_size.width(), nxt_size.height()); |
| 337 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 353 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 338 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code); | 354 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code); |
| 339 | 355 |
| 340 // Wait for the guest to receive a damage buffer of size 100x200. | 356 // Wait for the guest to receive a damage buffer of size 100x200. |
| 341 // This means the guest will be painted properly at that size. | 357 // This means the guest will be painted properly at that size. |
| 342 test_guest()->WaitForDamageBufferWithSize(nxt_size); | 358 test_guest()->WaitForDamageBufferWithSize(nxt_size); |
| 343 } | 359 } |
| 344 | 360 |
| 345 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) { | 361 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) { |
| 346 const char* kEmbedderURL = "files/browser_plugin_focus.html"; | 362 const char kEmbedderURL[] = "files/browser_plugin_focus.html"; |
| 347 const char* kGuestURL = "files/browser_plugin_focus_child.html"; | 363 const char* kGuestURL = "files/browser_plugin_focus_child.html"; |
| 348 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); | 364 StartBrowserPluginTest(kEmbedderURL, kGuestURL, false, ""); |
| 349 | 365 |
| 350 SimulateMouseClick(test_embedder()->web_contents()); | 366 SimulateMouseClick(test_embedder()->web_contents()); |
| 351 BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents()); | 367 BrowserPluginHostTest::SimulateTabKeyPress(test_embedder()->web_contents()); |
| 352 // Wait until we focus into the guest. | 368 // Wait until we focus into the guest. |
| 353 test_guest()->WaitForFocus(); | 369 test_guest()->WaitForFocus(); |
| 354 | 370 |
| 355 // TODO(fsamuel): A third Tab key press should not be necessary. | 371 // TODO(fsamuel): A third Tab key press should not be necessary. |
| 356 // The browser plugin will take keyboard focus but it will not | 372 // The browser plugin will take keyboard focus but it will not |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 367 // a RenderViewHost swap in the web_contents. We verify that the embedder in the | 383 // a RenderViewHost swap in the web_contents. We verify that the embedder in the |
| 368 // web_contents gets cleared properly. | 384 // web_contents gets cleared properly. |
| 369 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderChangedAfterSwap) { | 385 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderChangedAfterSwap) { |
| 370 net::TestServer https_server( | 386 net::TestServer https_server( |
| 371 net::TestServer::TYPE_HTTPS, | 387 net::TestServer::TYPE_HTTPS, |
| 372 net::TestServer::kLocalhost, | 388 net::TestServer::kLocalhost, |
| 373 FilePath(FILE_PATH_LITERAL("content/test/data"))); | 389 FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 374 ASSERT_TRUE(https_server.Start()); | 390 ASSERT_TRUE(https_server.Start()); |
| 375 | 391 |
| 376 // 1. Load an embedder page with one guest in it. | 392 // 1. Load an embedder page with one guest in it. |
| 377 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 393 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 378 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 394 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 379 | 395 |
| 380 // 2. Navigate to a URL in https, so we trigger a RenderViewHost swap. | 396 // 2. Navigate to a URL in https, so we trigger a RenderViewHost swap. |
| 381 GURL test_https_url(https_server.GetURL( | 397 GURL test_https_url(https_server.GetURL( |
| 382 "files/browser_plugin_title_change.html")); | 398 "files/browser_plugin_title_change.html")); |
| 383 content::WindowedNotificationObserver swap_observer( | 399 content::WindowedNotificationObserver swap_observer( |
| 384 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, | 400 content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 385 content::Source<WebContents>(test_embedder()->web_contents())); | 401 content::Source<WebContents>(test_embedder()->web_contents())); |
| 386 NavigateToURL(shell(), test_https_url); | 402 NavigateToURL(shell(), test_https_url); |
| 387 swap_observer.Wait(); | 403 swap_observer.Wait(); |
| 388 | 404 |
| 389 TestBrowserPluginEmbedder* test_embedder_after_swap = | 405 TestBrowserPluginEmbedder* test_embedder_after_swap = |
| 390 static_cast<TestBrowserPluginEmbedder*>( | 406 static_cast<TestBrowserPluginEmbedder*>( |
| 391 static_cast<WebContentsImpl*>(shell()->web_contents())-> | 407 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 392 GetBrowserPluginEmbedder()); | 408 GetBrowserPluginEmbedder()); |
| 393 // Verify we have a no embedder in web_contents (since the new page doesn't | 409 // Verify we have a no embedder in web_contents (since the new page doesn't |
| 394 // have any browser plugin). | 410 // have any browser plugin). |
| 395 ASSERT_TRUE(!test_embedder_after_swap); | 411 ASSERT_TRUE(!test_embedder_after_swap); |
| 396 ASSERT_NE(test_embedder(), test_embedder_after_swap); | 412 ASSERT_NE(test_embedder(), test_embedder_after_swap); |
| 397 } | 413 } |
| 398 | 414 |
| 399 // This test opens two pages in http and there is no RenderViewHost swap, | 415 // This test opens two pages in http and there is no RenderViewHost swap, |
| 400 // therefore the embedder created on first page navigation stays the same in | 416 // therefore the embedder created on first page navigation stays the same in |
| 401 // web_contents. | 417 // web_contents. |
| 402 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderSameAfterNav) { | 418 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderSameAfterNav) { |
| 403 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 419 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 404 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 420 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 405 WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); | 421 WebContentsImpl* embedder_web_contents = test_embedder()->web_contents(); |
| 406 | 422 |
| 407 // Navigate to another page in same host and port, so RenderViewHost swap | 423 // Navigate to another page in same host and port, so RenderViewHost swap |
| 408 // does not happen and existing embedder doesn't change in web_contents. | 424 // does not happen and existing embedder doesn't change in web_contents. |
| 409 GURL test_url_new(test_server()->GetURL( | 425 GURL test_url_new(test_server()->GetURL( |
| 410 "files/browser_plugin_title_change.html")); | 426 "files/browser_plugin_title_change.html")); |
| 411 const string16 expected_title = ASCIIToUTF16("done"); | 427 const string16 expected_title = ASCIIToUTF16("done"); |
| 412 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); | 428 content::TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
| 413 NavigateToURL(shell(), test_url_new); | 429 NavigateToURL(shell(), test_url_new); |
| 414 LOG(INFO) << "Start waiting for title"; | 430 LOG(INFO) << "Start waiting for title"; |
| 415 string16 actual_title = title_watcher.WaitAndGetTitle(); | 431 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 416 EXPECT_EQ(expected_title, actual_title); | 432 EXPECT_EQ(expected_title, actual_title); |
| 417 LOG(INFO) << "Done navigating to second page"; | 433 LOG(INFO) << "Done navigating to second page"; |
| 418 | 434 |
| 419 TestBrowserPluginEmbedder* test_embedder_after_nav = | 435 TestBrowserPluginEmbedder* test_embedder_after_nav = |
| 420 static_cast<TestBrowserPluginEmbedder*>( | 436 static_cast<TestBrowserPluginEmbedder*>( |
| 421 embedder_web_contents->GetBrowserPluginEmbedder()); | 437 embedder_web_contents->GetBrowserPluginEmbedder()); |
| 422 // Embedder must not change in web_contents. | 438 // Embedder must not change in web_contents. |
| 423 ASSERT_EQ(test_embedder_after_nav, test_embedder()); | 439 ASSERT_EQ(test_embedder_after_nav, test_embedder()); |
| 424 } | 440 } |
| 425 | 441 |
| 426 // This test verifies that hiding the embedder also hides the guest. | 442 // This test verifies that hiding the embedder also hides the guest. |
| 427 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) { | 443 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, BrowserPluginVisibilityChanged) { |
| 428 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 444 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 429 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 445 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 430 | 446 |
| 431 // Hide the Browser Plugin. | 447 // Hide the Browser Plugin. |
| 432 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 448 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 433 test_embedder()->web_contents()->GetRenderViewHost()); | 449 test_embedder()->web_contents()->GetRenderViewHost()); |
| 434 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 450 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 435 "document.getElementById('plugin').style.visibility = 'hidden'")); | 451 "document.getElementById('plugin').style.visibility = 'hidden'")); |
| 436 | 452 |
| 437 // Make sure that the guest is hidden. | 453 // Make sure that the guest is hidden. |
| 438 test_guest()->WaitUntilHidden(); | 454 test_guest()->WaitUntilHidden(); |
| 439 } | 455 } |
| 440 | 456 |
| 441 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) { | 457 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, EmbedderVisibilityChanged) { |
| 442 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 458 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 443 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 459 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 444 | 460 |
| 445 // Hide the embedder. | 461 // Hide the embedder. |
| 446 test_embedder()->web_contents()->WasHidden(); | 462 test_embedder()->web_contents()->WasHidden(); |
| 447 | 463 |
| 448 // Make sure that hiding the embedder also hides the guest. | 464 // Make sure that hiding the embedder also hides the guest. |
| 449 test_guest()->WaitUntilHidden(); | 465 test_guest()->WaitUntilHidden(); |
| 450 } | 466 } |
| 451 | 467 |
| 452 // This test verifies that calling the reload method reloads the guest. | 468 // This test verifies that calling the reload method reloads the guest. |
| 453 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { | 469 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadGuest) { |
| 454 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 470 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 455 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 471 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 456 | 472 |
| 457 test_guest()->ResetUpdateRectCount(); | 473 test_guest()->ResetUpdateRectCount(); |
| 458 | 474 |
| 459 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 475 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 460 test_embedder()->web_contents()->GetRenderViewHost()); | 476 test_embedder()->web_contents()->GetRenderViewHost()); |
| 461 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 477 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 462 "document.getElementById('plugin').reload()")); | 478 "document.getElementById('plugin').reload()")); |
| 463 test_guest()->WaitForReload(); | 479 test_guest()->WaitForReload(); |
| 464 } | 480 } |
| 465 | 481 |
| 466 // This test verifies that calling the stop method forwards the stop request | 482 // This test verifies that calling the stop method forwards the stop request |
| 467 // to the guest's WebContents. | 483 // to the guest's WebContents. |
| 468 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { | 484 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, StopGuest) { |
| 469 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 485 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 470 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 486 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 471 | 487 |
| 472 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 488 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 473 test_embedder()->web_contents()->GetRenderViewHost()); | 489 test_embedder()->web_contents()->GetRenderViewHost()); |
| 474 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 490 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 475 "document.getElementById('plugin').stop()")); | 491 "document.getElementById('plugin').stop()")); |
| 476 test_guest()->WaitForStop(); | 492 test_guest()->WaitForStop(); |
| 477 } | 493 } |
| 478 | 494 |
| 479 // Verifies that installing/uninstalling touch-event handlers in the guest | 495 // Verifies that installing/uninstalling touch-event handlers in the guest |
| 480 // plugin correctly updates the touch-event handling state in the embedder. | 496 // plugin correctly updates the touch-event handling state in the embedder. |
| 481 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { | 497 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptTouchEvents) { |
| 482 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 498 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 483 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestTouchHandler, true, ""); | 499 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestTouchHandler, true, ""); |
| 484 | 500 |
| 485 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 501 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 486 test_embedder()->web_contents()->GetRenderViewHost()); | 502 test_embedder()->web_contents()->GetRenderViewHost()); |
| 487 // The embedder should not have any touch event handlers at this point. | 503 // The embedder should not have any touch event handlers at this point. |
| 488 EXPECT_FALSE(rvh->has_touch_handler()); | 504 EXPECT_FALSE(rvh->has_touch_handler()); |
| 489 | 505 |
| 490 // Install the touch handler in the guest. This should cause the embedder to | 506 // Install the touch handler in the guest. This should cause the embedder to |
| 491 // start listening for touch events too. | 507 // start listening for touch events too. |
| 492 RenderViewHostMessageObserver observer(rvh, | 508 RenderViewHostMessageObserver observer(rvh, |
| 493 ViewHostMsg_HasTouchEventHandlers::ID); | 509 ViewHostMsg_HasTouchEventHandlers::ID); |
| 494 test_guest()->web_contents()-> | 510 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), |
| 495 GetRenderViewHost()->ExecuteJavascriptAndGetValue( | 511 ASCIIToUTF16("InstallTouchHandler();")); |
| 496 string16(), ASCIIToUTF16("InstallTouchHandler();")); | |
| 497 observer.WaitUntilMessageReceived(); | 512 observer.WaitUntilMessageReceived(); |
| 498 EXPECT_TRUE(rvh->has_touch_handler()); | 513 EXPECT_TRUE(rvh->has_touch_handler()); |
| 499 | 514 |
| 500 // Uninstalling the touch-handler in guest should cause the embedder to stop | 515 // Uninstalling the touch-handler in guest should cause the embedder to stop |
| 501 // listening for touch events. | 516 // listening for touch events. |
| 502 observer.ResetState(); | 517 observer.ResetState(); |
| 503 test_guest()->web_contents()-> | 518 ExecuteSyncJSFunction(test_guest()->web_contents()->GetRenderViewHost(), |
| 504 GetRenderViewHost()->ExecuteJavascriptAndGetValue( | 519 ASCIIToUTF16("UninstallTouchHandler();")); |
| 505 string16(), ASCIIToUTF16("UninstallTouchHandler();")); | |
| 506 observer.WaitUntilMessageReceived(); | 520 observer.WaitUntilMessageReceived(); |
| 507 EXPECT_FALSE(rvh->has_touch_handler()); | 521 EXPECT_FALSE(rvh->has_touch_handler()); |
| 508 } | 522 } |
| 509 | 523 |
| 510 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { | 524 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, Renavigate) { |
| 511 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 525 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 512 StartBrowserPluginTest( | 526 StartBrowserPluginTest( |
| 513 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, ""); | 527 kEmbedderURL, GetHTMLForGuestWithTitle("P1"), true, ""); |
| 514 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 528 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 515 test_embedder()->web_contents()->GetRenderViewHost()); | 529 test_embedder()->web_contents()->GetRenderViewHost()); |
| 516 | 530 |
| 517 // Navigate to P2 and verify that the navigation occurred. | 531 // Navigate to P2 and verify that the navigation occurred. |
| 518 { | 532 { |
| 519 const string16 expected_title = ASCIIToUTF16("P2"); | 533 const string16 expected_title = ASCIIToUTF16("P2"); |
| 520 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 534 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 521 expected_title); | 535 expected_title); |
| 522 | 536 |
| 523 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 537 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetSrc('%s');", |
| 524 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P2").c_str()))); | 538 GetHTMLForGuestWithTitle("P2").c_str()))); |
| 525 | 539 |
| 526 string16 actual_title = title_watcher.WaitAndGetTitle(); | 540 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 527 EXPECT_EQ(expected_title, actual_title); | 541 EXPECT_EQ(expected_title, actual_title); |
| 528 } | 542 } |
| 529 | 543 |
| 530 // Navigate to P3 and verify that the navigation occurred. | 544 // Navigate to P3 and verify that the navigation occurred. |
| 531 { | 545 { |
| 532 const string16 expected_title = ASCIIToUTF16("P3"); | 546 const string16 expected_title = ASCIIToUTF16("P3"); |
| 533 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 547 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 534 expected_title); | 548 expected_title); |
| 535 | 549 |
| 536 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 550 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetSrc('%s');", |
| 537 StringPrintf("SetSrc('%s');", GetHTMLForGuestWithTitle("P3").c_str()))); | 551 GetHTMLForGuestWithTitle("P3").c_str()))); |
| 538 | 552 |
| 539 string16 actual_title = title_watcher.WaitAndGetTitle(); | 553 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 540 EXPECT_EQ(expected_title, actual_title); | 554 EXPECT_EQ(expected_title, actual_title); |
| 541 } | 555 } |
| 542 | 556 |
| 543 // Go back and verify that we're back at P2. | 557 // Go back and verify that we're back at P2. |
| 544 { | 558 { |
| 545 const string16 expected_title = ASCIIToUTF16("P2"); | 559 const string16 expected_title = ASCIIToUTF16("P2"); |
| 546 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 560 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 547 expected_title); | 561 expected_title); |
| 548 | 562 |
| 549 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Back();")); | 563 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Back();")); |
| 550 | |
| 551 string16 actual_title = title_watcher.WaitAndGetTitle(); | 564 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 552 EXPECT_EQ(expected_title, actual_title); | 565 EXPECT_EQ(expected_title, actual_title); |
| 553 } | 566 } |
| 554 | 567 |
| 555 // Go forward and verify that we're back at P3. | 568 // Go forward and verify that we're back at P3. |
| 556 { | 569 { |
| 557 const string16 expected_title = ASCIIToUTF16("P3"); | 570 const string16 expected_title = ASCIIToUTF16("P3"); |
| 558 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 571 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 559 expected_title); | 572 expected_title); |
| 560 | 573 |
| 561 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Forward();")); | 574 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Forward();")); |
| 562 | |
| 563 string16 actual_title = title_watcher.WaitAndGetTitle(); | 575 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 564 EXPECT_EQ(expected_title, actual_title); | 576 EXPECT_EQ(expected_title, actual_title); |
| 565 } | 577 } |
| 566 | 578 |
| 567 // Go back two entries and verify that we're back at P1. | 579 // Go back two entries and verify that we're back at P1. |
| 568 { | 580 { |
| 569 const string16 expected_title = ASCIIToUTF16("P1"); | 581 const string16 expected_title = ASCIIToUTF16("P1"); |
| 570 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 582 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 571 expected_title); | 583 expected_title); |
| 572 | 584 |
| 573 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); | 585 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Go(-2);")); |
| 574 | |
| 575 string16 actual_title = title_watcher.WaitAndGetTitle(); | 586 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 576 EXPECT_EQ(expected_title, actual_title); | 587 EXPECT_EQ(expected_title, actual_title); |
| 577 } | 588 } |
| 578 } | 589 } |
| 579 | 590 |
| 580 // This tests verifies that reloading the embedder does not crash the browser | 591 // This tests verifies that reloading the embedder does not crash the browser |
| 581 // and that the guest is reset. | 592 // and that the guest is reset. |
| 582 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { | 593 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { |
| 583 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 594 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 584 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 595 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 585 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 596 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 586 test_embedder()->web_contents()->GetRenderViewHost()); | 597 test_embedder()->web_contents()->GetRenderViewHost()); |
| 587 | 598 |
| 588 // Change the title of the page to 'modified' so that we know that | 599 // Change the title of the page to 'modified' so that we know that |
| 589 // the page has successfully reloaded when it goes back to 'embedder' | 600 // the page has successfully reloaded when it goes back to 'embedder' |
| 590 // in the next step. | 601 // in the next step. |
| 591 { | 602 { |
| 592 const string16 expected_title = ASCIIToUTF16("modified"); | 603 const string16 expected_title = ASCIIToUTF16("modified"); |
| 593 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 604 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 594 expected_title); | 605 expected_title); |
| 595 | 606 |
| 596 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 607 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetTitle('%s');", |
| 597 StringPrintf("SetTitle('%s');", "modified"))); | 608 "modified"))); |
| 598 | 609 |
| 599 string16 actual_title = title_watcher.WaitAndGetTitle(); | 610 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 600 EXPECT_EQ(expected_title, actual_title); | 611 EXPECT_EQ(expected_title, actual_title); |
| 601 } | 612 } |
| 602 | 613 |
| 603 // Reload the embedder page, and verify that the reload was successful. | 614 // Reload the embedder page, and verify that the reload was successful. |
| 604 // Then navigate the guest to verify that the browser process does not crash. | 615 // Then navigate the guest to verify that the browser process does not crash. |
| 605 { | 616 { |
| 606 const string16 expected_title = ASCIIToUTF16("embedder"); | 617 const string16 expected_title = ASCIIToUTF16("embedder"); |
| 607 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 618 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 608 expected_title); | 619 expected_title); |
| 609 | 620 |
| 610 test_embedder()->web_contents()->GetController().Reload(false); | 621 test_embedder()->web_contents()->GetController().Reload(false); |
| 611 string16 actual_title = title_watcher.WaitAndGetTitle(); | 622 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 612 EXPECT_EQ(expected_title, actual_title); | 623 EXPECT_EQ(expected_title, actual_title); |
| 613 | 624 |
| 614 test_embedder()->web_contents()->GetRenderViewHost()-> | 625 ExecuteSyncJSFunction(test_embedder()->web_contents()->GetRenderViewHost(), |
| 615 ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 626 ASCIIToUTF16(StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
| 616 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | |
| 617 | 627 |
| 618 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = | 628 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = |
| 619 test_embedder()->guest_web_contents_for_testing(); | 629 test_embedder()->guest_web_contents_for_testing(); |
| 620 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 630 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
| 621 instance_map.begin()->second); | 631 instance_map.begin()->second); |
| 622 TestBrowserPluginGuest* new_test_guest = | 632 TestBrowserPluginGuest* new_test_guest = |
| 623 static_cast<TestBrowserPluginGuest*>( | 633 static_cast<TestBrowserPluginGuest*>( |
| 624 test_guest_web_contents->GetBrowserPluginGuest()); | 634 test_guest_web_contents->GetBrowserPluginGuest()); |
| 625 | 635 |
| 626 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 636 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
| 627 new_test_guest->WaitForUpdateRectMsg(); | 637 new_test_guest->WaitForUpdateRectMsg(); |
| 628 } | 638 } |
| 629 } | 639 } |
| 630 | 640 |
| 631 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { | 641 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { |
| 632 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 642 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 633 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 643 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
| 634 | 644 |
| 635 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 645 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 636 test_embedder()->web_contents()->GetRenderViewHost()); | 646 test_embedder()->web_contents()->GetRenderViewHost()); |
| 637 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 647 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 638 "document.getElementById('plugin').terminate()")); | 648 "document.getElementById('plugin').terminate()")); |
| 639 | 649 |
| 640 // Expect the guest to crash. | 650 // Expect the guest to crash. |
| 641 test_guest()->WaitForCrashed(); | 651 test_guest()->WaitForCrashed(); |
| 642 } | 652 } |
| 643 | 653 |
| 644 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { | 654 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { |
| 645 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 655 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 646 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 656 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
| 647 | 657 |
| 648 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); | 658 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); |
| 649 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 659 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 650 expected_title); | 660 expected_title); |
| 651 // Renavigate the guest to |kHTMLForGuest|. | 661 // Renavigate the guest to |kHTMLForGuest|. |
| 652 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 662 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 653 test_embedder()->web_contents()->GetRenderViewHost()); | 663 test_embedder()->web_contents()->GetRenderViewHost()); |
| 654 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 664 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 655 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | 665 StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
| 656 | 666 |
| 657 string16 actual_title = title_watcher.WaitAndGetTitle(); | 667 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 658 EXPECT_EQ(expected_title, actual_title); | 668 EXPECT_EQ(expected_title, actual_title); |
| 659 } | 669 } |
| 660 | 670 |
| 661 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { | 671 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { |
| 662 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 672 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 663 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 673 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
| 664 | 674 |
| 665 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); | 675 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); |
| 666 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 676 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 667 expected_title); | 677 expected_title); |
| 668 | 678 |
| 669 // Renavigate the guest to "close-socket". | 679 // Renavigate the guest to "close-socket". |
| 670 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 680 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 671 test_embedder()->web_contents()->GetRenderViewHost()); | 681 test_embedder()->web_contents()->GetRenderViewHost()); |
| 672 GURL test_url = test_server()->GetURL("close-socket"); | 682 GURL test_url = test_server()->GetURL("close-socket"); |
| 673 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 683 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 674 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); | 684 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); |
| 675 | 685 |
| 676 string16 actual_title = title_watcher.WaitAndGetTitle(); | 686 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 677 EXPECT_EQ(expected_title, actual_title); | 687 EXPECT_EQ(expected_title, actual_title); |
| 678 } | 688 } |
| 679 | 689 |
| 680 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { | 690 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
| 681 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 691 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
| 682 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 692 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
| 683 | 693 |
| 684 const string16 expected_title = ASCIIToUTF16("redirected"); | 694 const string16 expected_title = ASCIIToUTF16("redirected"); |
| 685 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 695 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
| 686 expected_title); | 696 expected_title); |
| 687 | 697 |
| 688 // Navigate with a redirect and wait until the title changes. | 698 // Navigate with a redirect and wait until the title changes. |
| 689 GURL redirect_url(test_server()->GetURL( | 699 GURL redirect_url(test_server()->GetURL( |
| 690 "server-redirect?files/title1.html")); | 700 "server-redirect?files/title1.html")); |
| 691 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 701 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 692 test_embedder()->web_contents()->GetRenderViewHost()); | 702 test_embedder()->web_contents()->GetRenderViewHost()); |
| 693 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 703 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
| 694 StringPrintf("SetSrc('%s');", redirect_url.spec().c_str()))); | 704 StringPrintf("SetSrc('%s');", redirect_url.spec().c_str()))); |
| 695 | 705 |
| 696 string16 actual_title = title_watcher.WaitAndGetTitle(); | 706 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 697 EXPECT_EQ(expected_title, actual_title); | 707 EXPECT_EQ(expected_title, actual_title); |
| 698 | 708 |
| 699 // Verify that we heard a loadRedirect during the navigation. | 709 // Verify that we heard a loadRedirect during the navigation. |
| 700 base::Value* v = rvh->ExecuteJavascriptAndGetValue( | 710 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( |
| 701 string16(), ASCIIToUTF16("redirectOldUrl")); | 711 string16(), ASCIIToUTF16("redirectOldUrl"))); |
| 702 std::string result; | 712 std::string result; |
| 703 EXPECT_TRUE(v->GetAsString(&result)); | 713 EXPECT_TRUE(value->GetAsString(&result)); |
| 704 EXPECT_EQ(redirect_url.spec().c_str(), result); | 714 EXPECT_EQ(redirect_url.spec().c_str(), result); |
| 705 | 715 |
| 706 v = rvh->ExecuteJavascriptAndGetValue( | 716 value.reset(rvh->ExecuteJavascriptAndGetValue( |
| 707 string16(), ASCIIToUTF16("redirectNewUrl")); | 717 string16(), ASCIIToUTF16("redirectNewUrl"))); |
| 708 EXPECT_TRUE(v->GetAsString(&result)); | 718 EXPECT_TRUE(value->GetAsString(&result)); |
| 709 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); | 719 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); |
| 710 } | 720 } |
| 711 | 721 |
| 722 // Tests that a drag-n-drop over the browser plugin in the embedder happens | |
| 723 // correctly. | |
| 724 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptDragEvents) { | |
| 725 const char kEmbedderURL[] = "files/browser_plugin_dragging.html"; | |
| 726 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestAcceptDrag, true, ""); | |
| 727 | |
| 728 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
| 729 test_embedder()->web_contents()->GetRenderViewHost()); | |
| 730 | |
| 731 // Get a location in the embedder outside of the plugin. | |
| 732 base::ListValue *start, *end; | |
| 733 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), | |
| 734 ASCIIToUTF16("dragLocation()"))); | |
| 735 ASSERT_TRUE(value->GetAsList(&start) && start->GetSize() == 2); | |
| 736 double start_x, start_y; | |
| 737 ASSERT_TRUE(start->GetDouble(0, &start_x) && start->GetDouble(1, &start_y)); | |
| 738 | |
| 739 // Get a location in the embedder that falls inside the plugin. | |
| 740 value.reset(rvh->ExecuteJavascriptAndGetValue(string16(), | |
| 741 ASCIIToUTF16("dropLocation()"))); | |
| 742 ASSERT_TRUE(value->GetAsList(&end) && end->GetSize() == 2); | |
| 743 double end_x, end_y; | |
| 744 ASSERT_TRUE(end->GetDouble(0, &end_x) && end->GetDouble(1, &end_y)); | |
| 745 | |
| 746 WebDropData drop_data; | |
| 747 GURL url = GURL("https://www.domain.com/index.html"); | |
| 748 drop_data.url = url; | |
| 749 | |
| 750 // Pretend that the URL is being dragged over the embedder. Start the drag | |
| 751 // from outside the plugin, then move the drag inside the plugin and drop. | |
| 752 // This should trigger appropriate messages from the embedder to the guest, | |
| 753 // and end with a drop on the guest. The guest changes title when a drop | |
| 754 // happens. | |
| 755 const string16 expected_title = ASCIIToUTF16("DROPPED"); | |
| 756 content::TitleWatcher title_watcher(test_guest()->web_contents(), | |
| 757 expected_title); | |
| 758 | |
| 759 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), | |
| 760 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); | |
| 761 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), | |
| 762 WebKit::WebDragOperationEvery, 0); | |
| 763 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); | |
| 764 | |
| 765 string16 actual_title = title_watcher.WaitAndGetTitle(); | |
| 766 EXPECT_EQ(expected_title, actual_title); | |
| 767 } | |
| 768 | |
| 712 } // namespace content | 769 } // namespace content |
| OLD | NEW |