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 synchronously and makes sure the returned value is |
| 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 base::Value* value = | 567 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), |
555 rvh->ExecuteJavascriptAndGetValue(string16(), | 568 ASCIIToUTF16("CanGoBack()"))); |
556 ASCIIToUTF16("CanGoBack()")); | |
557 bool result = false; | 569 bool result = false; |
558 ASSERT_TRUE(value->GetAsBoolean(&result)); | 570 ASSERT_TRUE(value->GetAsBoolean(&result)); |
559 EXPECT_TRUE(result); | 571 EXPECT_TRUE(result); |
560 | 572 |
561 value = rvh->ExecuteJavascriptAndGetValue(string16(), | 573 value.reset(rvh->ExecuteJavascriptAndGetValue(string16(), |
562 ASCIIToUTF16("CanGoForward()")); | 574 ASCIIToUTF16("CanGoForward()"))); |
563 result = false; | 575 result = false; |
564 ASSERT_TRUE(value->GetAsBoolean(&result)); | 576 ASSERT_TRUE(value->GetAsBoolean(&result)); |
565 EXPECT_TRUE(result); | 577 EXPECT_TRUE(result); |
566 } | 578 } |
567 | 579 |
568 // Go forward and verify that we're back at P3. | 580 // Go forward and verify that we're back at P3. |
569 { | 581 { |
570 const string16 expected_title = ASCIIToUTF16("P3"); | 582 const string16 expected_title = ASCIIToUTF16("P3"); |
571 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 583 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
572 expected_title); | 584 expected_title); |
573 | 585 |
574 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Forward();")); | 586 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Forward();")); |
575 | |
576 string16 actual_title = title_watcher.WaitAndGetTitle(); | 587 string16 actual_title = title_watcher.WaitAndGetTitle(); |
577 EXPECT_EQ(expected_title, actual_title); | 588 EXPECT_EQ(expected_title, actual_title); |
578 | 589 |
579 base::Value* value = | 590 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), |
580 rvh->ExecuteJavascriptAndGetValue(string16(), | 591 ASCIIToUTF16("CanGoForward()"))); |
581 ASCIIToUTF16("CanGoForward()")); | |
582 bool result = true; | 592 bool result = true; |
583 ASSERT_TRUE(value->GetAsBoolean(&result)); | 593 ASSERT_TRUE(value->GetAsBoolean(&result)); |
584 EXPECT_FALSE(result); | 594 EXPECT_FALSE(result); |
585 } | 595 } |
586 | 596 |
587 // Go back two entries and verify that we're back at P1. | 597 // Go back two entries and verify that we're back at P1. |
588 { | 598 { |
589 const string16 expected_title = ASCIIToUTF16("P1"); | 599 const string16 expected_title = ASCIIToUTF16("P1"); |
590 content::TitleWatcher title_watcher(test_guest()->web_contents(), | 600 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
591 expected_title); | 601 expected_title); |
592 | 602 |
593 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16("Go(-2);")); | 603 ExecuteSyncJSFunction(rvh, ASCIIToUTF16("Go(-2);")); |
594 | |
595 string16 actual_title = title_watcher.WaitAndGetTitle(); | 604 string16 actual_title = title_watcher.WaitAndGetTitle(); |
596 EXPECT_EQ(expected_title, actual_title); | 605 EXPECT_EQ(expected_title, actual_title); |
597 | 606 |
598 base::Value* value = | 607 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), |
599 rvh->ExecuteJavascriptAndGetValue(string16(), | 608 ASCIIToUTF16("CanGoBack()"))); |
600 ASCIIToUTF16("CanGoBack()")); | |
601 bool result = true; | 609 bool result = true; |
602 ASSERT_TRUE(value->GetAsBoolean(&result)); | 610 ASSERT_TRUE(value->GetAsBoolean(&result)); |
603 EXPECT_FALSE(result); | 611 EXPECT_FALSE(result); |
604 } | 612 } |
605 } | 613 } |
606 | 614 |
607 // This tests verifies that reloading the embedder does not crash the browser | 615 // This tests verifies that reloading the embedder does not crash the browser |
608 // and that the guest is reset. | 616 // and that the guest is reset. |
609 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { | 617 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, ReloadEmbedder) { |
610 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 618 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
611 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 619 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
612 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 620 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
613 test_embedder()->web_contents()->GetRenderViewHost()); | 621 test_embedder()->web_contents()->GetRenderViewHost()); |
614 | 622 |
615 // Change the title of the page to 'modified' so that we know that | 623 // Change the title of the page to 'modified' so that we know that |
616 // the page has successfully reloaded when it goes back to 'embedder' | 624 // the page has successfully reloaded when it goes back to 'embedder' |
617 // in the next step. | 625 // in the next step. |
618 { | 626 { |
619 const string16 expected_title = ASCIIToUTF16("modified"); | 627 const string16 expected_title = ASCIIToUTF16("modified"); |
620 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 628 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
621 expected_title); | 629 expected_title); |
622 | 630 |
623 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 631 ExecuteSyncJSFunction(rvh, ASCIIToUTF16(StringPrintf("SetTitle('%s');", |
624 StringPrintf("SetTitle('%s');", "modified"))); | 632 "modified"))); |
625 | 633 |
626 string16 actual_title = title_watcher.WaitAndGetTitle(); | 634 string16 actual_title = title_watcher.WaitAndGetTitle(); |
627 EXPECT_EQ(expected_title, actual_title); | 635 EXPECT_EQ(expected_title, actual_title); |
628 } | 636 } |
629 | 637 |
630 // Reload the embedder page, and verify that the reload was successful. | 638 // Reload the embedder page, and verify that the reload was successful. |
631 // Then navigate the guest to verify that the browser process does not crash. | 639 // Then navigate the guest to verify that the browser process does not crash. |
632 { | 640 { |
633 const string16 expected_title = ASCIIToUTF16("embedder"); | 641 const string16 expected_title = ASCIIToUTF16("embedder"); |
634 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 642 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
635 expected_title); | 643 expected_title); |
636 | 644 |
637 test_embedder()->web_contents()->GetController().Reload(false); | 645 test_embedder()->web_contents()->GetController().Reload(false); |
638 string16 actual_title = title_watcher.WaitAndGetTitle(); | 646 string16 actual_title = title_watcher.WaitAndGetTitle(); |
639 EXPECT_EQ(expected_title, actual_title); | 647 EXPECT_EQ(expected_title, actual_title); |
640 | 648 |
641 test_embedder()->web_contents()->GetRenderViewHost()-> | 649 ExecuteSyncJSFunction(test_embedder()->web_contents()->GetRenderViewHost(), |
642 ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 650 ASCIIToUTF16(StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
643 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | |
644 | 651 |
645 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = | 652 const BrowserPluginEmbedder::ContainerInstanceMap& instance_map = |
646 test_embedder()->guest_web_contents_for_testing(); | 653 test_embedder()->guest_web_contents_for_testing(); |
647 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( | 654 WebContentsImpl* test_guest_web_contents = static_cast<WebContentsImpl*>( |
648 instance_map.begin()->second); | 655 instance_map.begin()->second); |
649 TestBrowserPluginGuest* new_test_guest = | 656 TestBrowserPluginGuest* new_test_guest = |
650 static_cast<TestBrowserPluginGuest*>( | 657 static_cast<TestBrowserPluginGuest*>( |
651 test_guest_web_contents->GetBrowserPluginGuest()); | 658 test_guest_web_contents->GetBrowserPluginGuest()); |
652 | 659 |
653 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. | 660 // Wait for the guest to send an UpdateRectMsg, meaning it is ready. |
654 new_test_guest->WaitForUpdateRectMsg(); | 661 new_test_guest->WaitForUpdateRectMsg(); |
655 } | 662 } |
656 } | 663 } |
657 | 664 |
658 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { | 665 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, TerminateGuest) { |
659 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 666 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
660 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); | 667 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, ""); |
661 | 668 |
662 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 669 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
663 test_embedder()->web_contents()->GetRenderViewHost()); | 670 test_embedder()->web_contents()->GetRenderViewHost()); |
664 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 671 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
665 "document.getElementById('plugin').terminate()")); | 672 "document.getElementById('plugin').terminate()")); |
666 | 673 |
667 // Expect the guest to crash. | 674 // Expect the guest to crash. |
668 test_guest()->WaitForCrashed(); | 675 test_guest()->WaitForCrashed(); |
669 } | 676 } |
670 | 677 |
671 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { | 678 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadStart) { |
672 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 679 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
673 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 680 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
674 | 681 |
675 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); | 682 const string16 expected_title = ASCIIToUTF16(kHTMLForGuest); |
676 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 683 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
677 expected_title); | 684 expected_title); |
678 // Renavigate the guest to |kHTMLForGuest|. | 685 // Renavigate the guest to |kHTMLForGuest|. |
679 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 686 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
680 test_embedder()->web_contents()->GetRenderViewHost()); | 687 test_embedder()->web_contents()->GetRenderViewHost()); |
681 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 688 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
682 StringPrintf("SetSrc('%s');", kHTMLForGuest))); | 689 StringPrintf("SetSrc('%s');", kHTMLForGuest))); |
683 | 690 |
684 string16 actual_title = title_watcher.WaitAndGetTitle(); | 691 string16 actual_title = title_watcher.WaitAndGetTitle(); |
685 EXPECT_EQ(expected_title, actual_title); | 692 EXPECT_EQ(expected_title, actual_title); |
686 } | 693 } |
687 | 694 |
688 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { | 695 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadAbort) { |
689 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 696 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
690 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 697 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
691 | 698 |
692 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); | 699 const string16 expected_title = ASCIIToUTF16("ERR_EMPTY_RESPONSE"); |
693 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 700 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
694 expected_title); | 701 expected_title); |
695 | 702 |
696 // Renavigate the guest to "close-socket". | 703 // Renavigate the guest to "close-socket". |
697 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 704 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
698 test_embedder()->web_contents()->GetRenderViewHost()); | 705 test_embedder()->web_contents()->GetRenderViewHost()); |
699 GURL test_url = test_server()->GetURL("close-socket"); | 706 GURL test_url = test_server()->GetURL("close-socket"); |
700 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 707 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
701 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); | 708 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); |
702 | 709 |
703 string16 actual_title = title_watcher.WaitAndGetTitle(); | 710 string16 actual_title = title_watcher.WaitAndGetTitle(); |
704 EXPECT_EQ(expected_title, actual_title); | 711 EXPECT_EQ(expected_title, actual_title); |
705 } | 712 } |
706 | 713 |
707 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { | 714 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, LoadRedirect) { |
708 const char* kEmbedderURL = "files/browser_plugin_embedder.html"; | 715 const char kEmbedderURL[] = "files/browser_plugin_embedder.html"; |
709 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); | 716 StartBrowserPluginTest(kEmbedderURL, "about:blank", true, ""); |
710 | 717 |
711 const string16 expected_title = ASCIIToUTF16("redirected"); | 718 const string16 expected_title = ASCIIToUTF16("redirected"); |
712 content::TitleWatcher title_watcher(test_embedder()->web_contents(), | 719 content::TitleWatcher title_watcher(test_embedder()->web_contents(), |
713 expected_title); | 720 expected_title); |
714 | 721 |
715 // Navigate with a redirect and wait until the title changes. | 722 // Navigate with a redirect and wait until the title changes. |
716 GURL redirect_url(test_server()->GetURL( | 723 GURL redirect_url(test_server()->GetURL( |
717 "server-redirect?files/title1.html")); | 724 "server-redirect?files/title1.html")); |
718 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 725 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
719 test_embedder()->web_contents()->GetRenderViewHost()); | 726 test_embedder()->web_contents()->GetRenderViewHost()); |
720 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | 727 ExecuteSyncJSFunction(rvh, ASCIIToUTF16( |
721 StringPrintf("SetSrc('%s');", redirect_url.spec().c_str()))); | 728 StringPrintf("SetSrc('%s');", redirect_url.spec().c_str()))); |
722 | 729 |
723 string16 actual_title = title_watcher.WaitAndGetTitle(); | 730 string16 actual_title = title_watcher.WaitAndGetTitle(); |
724 EXPECT_EQ(expected_title, actual_title); | 731 EXPECT_EQ(expected_title, actual_title); |
725 | 732 |
726 // Verify that we heard a loadRedirect during the navigation. | 733 // Verify that we heard a loadRedirect during the navigation. |
727 base::Value* v = rvh->ExecuteJavascriptAndGetValue( | 734 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue( |
728 string16(), ASCIIToUTF16("redirectOldUrl")); | 735 string16(), ASCIIToUTF16("redirectOldUrl"))); |
729 std::string result; | 736 std::string result; |
730 EXPECT_TRUE(v->GetAsString(&result)); | 737 EXPECT_TRUE(value->GetAsString(&result)); |
731 EXPECT_EQ(redirect_url.spec().c_str(), result); | 738 EXPECT_EQ(redirect_url.spec().c_str(), result); |
732 | 739 |
733 v = rvh->ExecuteJavascriptAndGetValue( | 740 value.reset(rvh->ExecuteJavascriptAndGetValue( |
734 string16(), ASCIIToUTF16("redirectNewUrl")); | 741 string16(), ASCIIToUTF16("redirectNewUrl"))); |
735 EXPECT_TRUE(v->GetAsString(&result)); | 742 EXPECT_TRUE(value->GetAsString(&result)); |
736 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); | 743 EXPECT_EQ(test_server()->GetURL("files/title1.html").spec().c_str(), result); |
737 } | 744 } |
738 | 745 |
| 746 // Tests that a drag-n-drop over the browser plugin in the embedder happens |
| 747 // correctly. |
| 748 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AcceptDragEvents) { |
| 749 const char kEmbedderURL[] = "files/browser_plugin_dragging.html"; |
| 750 StartBrowserPluginTest(kEmbedderURL, kHTMLForGuestAcceptDrag, true, ""); |
| 751 |
| 752 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 753 test_embedder()->web_contents()->GetRenderViewHost()); |
| 754 |
| 755 // Get a location in the embedder outside of the plugin. |
| 756 base::ListValue *start, *end; |
| 757 scoped_ptr<base::Value> value(rvh->ExecuteJavascriptAndGetValue(string16(), |
| 758 ASCIIToUTF16("dragLocation()"))); |
| 759 ASSERT_TRUE(value->GetAsList(&start) && start->GetSize() == 2); |
| 760 double start_x, start_y; |
| 761 ASSERT_TRUE(start->GetDouble(0, &start_x) && start->GetDouble(1, &start_y)); |
| 762 |
| 763 // Get a location in the embedder that falls inside the plugin. |
| 764 value.reset(rvh->ExecuteJavascriptAndGetValue(string16(), |
| 765 ASCIIToUTF16("dropLocation()"))); |
| 766 ASSERT_TRUE(value->GetAsList(&end) && end->GetSize() == 2); |
| 767 double end_x, end_y; |
| 768 ASSERT_TRUE(end->GetDouble(0, &end_x) && end->GetDouble(1, &end_y)); |
| 769 |
| 770 WebDropData drop_data; |
| 771 GURL url = GURL("https://www.domain.com/index.html"); |
| 772 drop_data.url = url; |
| 773 |
| 774 // Pretend that the URL is being dragged over the embedder. Start the drag |
| 775 // from outside the plugin, then move the drag inside the plugin and drop. |
| 776 // This should trigger appropriate messages from the embedder to the guest, |
| 777 // and end with a drop on the guest. The guest changes title when a drop |
| 778 // happens. |
| 779 const string16 expected_title = ASCIIToUTF16("DROPPED"); |
| 780 content::TitleWatcher title_watcher(test_guest()->web_contents(), |
| 781 expected_title); |
| 782 |
| 783 rvh->DragTargetDragEnter(drop_data, gfx::Point(start_x, start_y), |
| 784 gfx::Point(start_x, start_y), WebKit::WebDragOperationEvery, 0); |
| 785 rvh->DragTargetDragOver(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), |
| 786 WebKit::WebDragOperationEvery, 0); |
| 787 rvh->DragTargetDrop(gfx::Point(end_x, end_y), gfx::Point(end_x, end_y), 0); |
| 788 |
| 789 string16 actual_title = title_watcher.WaitAndGetTitle(); |
| 790 EXPECT_EQ(expected_title, actual_title); |
| 791 } |
| 792 |
739 } // namespace content | 793 } // namespace content |
OLD | NEW |