Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 return test_guest_view_manager_; | 313 return test_guest_view_manager_; |
| 314 } | 314 } |
| 315 | 315 |
| 316 private: | 316 private: |
| 317 guest_view::TestGuestViewManagerFactory factory_; | 317 guest_view::TestGuestViewManagerFactory factory_; |
| 318 guest_view::TestGuestViewManager* test_guest_view_manager_; | 318 guest_view::TestGuestViewManager* test_guest_view_manager_; |
| 319 | 319 |
| 320 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessPDFTest); | 320 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessPDFTest); |
| 321 }; | 321 }; |
| 322 | 322 |
| 323 // Helper class to wait until a given WebContents is destroyed. | |
| 324 class WebContentsDestructionObserver : content::WebContentsObserver { | |
|
alexmos
2016/11/23 00:23:51
There's a WebContentsDestroyedWatcher in content/p
EhsanK
2016/11/23 00:51:39
Yes indeed. Thanks for the suggestion.
| |
| 325 public: | |
| 326 explicit WebContentsDestructionObserver(content::WebContents* web_contents) | |
| 327 : content::WebContentsObserver(web_contents), | |
| 328 web_contents_destroyed_(false) {} | |
| 329 ~WebContentsDestructionObserver() override {} | |
| 330 | |
| 331 void Wait() { | |
| 332 if (web_contents_destroyed_) | |
| 333 return; | |
| 334 message_loop_runner_ = new content::MessageLoopRunner(); | |
| 335 message_loop_runner_->Run(); | |
| 336 } | |
| 337 | |
| 338 private: | |
| 339 void WebContentsDestroyed() override { | |
| 340 web_contents_destroyed_ = true; | |
| 341 if (message_loop_runner_) | |
| 342 message_loop_runner_->Quit(); | |
| 343 } | |
| 344 | |
| 345 bool web_contents_destroyed_; | |
| 346 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 347 | |
| 348 DISALLOW_COPY_AND_ASSIGN(WebContentsDestructionObserver); | |
| 349 }; | |
| 350 | |
| 323 // TODO(ekaramad): This test is flaky on Windows 7. Enable it when the issue is | 351 // TODO(ekaramad): This test is flaky on Windows 7. Enable it when the issue is |
| 324 // fixed ((https://crbug.com/666379). | 352 // fixed ((https://crbug.com/666379). |
| 325 #if defined(OS_WIN) | 353 #if defined(OS_WIN) |
| 326 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ | 354 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ |
| 327 DISABLED_EmbeddedPDFInsideCrossOriginFrame | 355 DISABLED_EmbeddedPDFInsideCrossOriginFrame |
| 328 #else | 356 #else |
| 329 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ | 357 #define MAYBE_EmbeddedPDFInsideCrossOriginFrame \ |
| 330 EmbeddedPDFInsideCrossOriginFrame | 358 EmbeddedPDFInsideCrossOriginFrame |
| 331 #endif | 359 #endif |
| 332 // This test verifies that when navigating an OOPIF to a page with <embed>-ed | 360 // This test verifies that when navigating an OOPIF to a page with <embed>-ed |
| 333 // PDF, the guest is properly created (https://crbug.com/649856). | 361 // PDF, the guest is properly created, and by removing the embedder frame, the |
| 362 // guest is properly destroyed (https://crbug.com/649856). | |
| 334 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessPDFTest, | 363 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessPDFTest, |
| 335 MAYBE_EmbeddedPDFInsideCrossOriginFrame) { | 364 MAYBE_EmbeddedPDFInsideCrossOriginFrame) { |
| 336 // Navigate to a page with an <iframe>. | 365 // Navigate to a page with an <iframe>. |
| 337 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | 366 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
| 338 ui_test_utils::NavigateToURL(browser(), main_url); | 367 ui_test_utils::NavigateToURL(browser(), main_url); |
| 339 | 368 |
| 340 // Initially, no guests are created. | 369 // Initially, no guests are created. |
| 341 EXPECT_EQ(0U, test_guest_view_manager()->num_guests_created()); | 370 EXPECT_EQ(0U, test_guest_view_manager()->num_guests_created()); |
| 342 | 371 |
| 343 // Navigate subframe to a cross-site page with an embedded PDF. | 372 // Navigate subframe to a cross-site page with an embedded PDF. |
| 344 content::WebContents* active_web_contents = | 373 content::WebContents* active_web_contents = |
| 345 browser()->tab_strip_model()->GetActiveWebContents(); | 374 browser()->tab_strip_model()->GetActiveWebContents(); |
| 346 GURL frame_url = | 375 GURL frame_url = |
| 347 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html"); | 376 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html"); |
| 348 | 377 |
| 349 // Ensure the page finishes loading without crashing. | 378 // Ensure the page finishes loading without crashing. |
| 350 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); | 379 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); |
| 351 | 380 |
| 352 // Wait until the guest for PDF is created. | 381 // Wait until the guest for PDF is created. |
| 353 test_guest_view_manager()->WaitForSingleGuestCreated(); | 382 test_guest_view_manager()->WaitForSingleGuestCreated(); |
|
alexmos
2016/11/23 00:23:51
Can you save the result of this and use it below,
EhsanK
2016/11/23 00:51:39
Acknowledged.
| |
| 383 | |
| 384 // Now detach the frame and observe that the guest is destroyed. | |
| 385 WebContentsDestructionObserver observer( | |
| 386 test_guest_view_manager()->GetLastGuestCreated()); | |
| 387 EXPECT_TRUE(ExecuteScript( | |
| 388 active_web_contents, | |
| 389 "document.body.removeChild(document.querySelector('iframe'));")); | |
| 390 observer.Wait(); | |
|
alexmos
2016/11/23 00:23:51
Would it be useful to also check that GetNumGuests
EhsanK
2016/11/23 00:51:39
Acknowledged.
| |
| 354 } | 391 } |
| OLD | NEW |