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" |
| 11 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
| 17 #include "components/guest_view/browser/test_guest_view_manager.h" |
15 #include "content/public/browser/interstitial_page.h" | 18 #include "content/public/browser/interstitial_page.h" |
16 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
17 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
18 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
19 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
21 #include "content/public/browser/web_contents_observer.h" | 24 #include "content/public/browser/web_contents_observer.h" |
22 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
24 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 28 #include "extensions/browser/api/extensions_api_client.h" |
25 #include "net/dns/mock_host_resolver.h" | 29 #include "net/dns/mock_host_resolver.h" |
26 #include "net/test/embedded_test_server/embedded_test_server.h" | 30 #include "net/test/embedded_test_server/embedded_test_server.h" |
27 #include "ui/display/display_switches.h" | 31 #include "ui/display/display_switches.h" |
28 #include "url/gurl.h" | 32 #include "url/gurl.h" |
29 | 33 |
30 class ChromeSitePerProcessTest : public InProcessBrowserTest { | 34 class ChromeSitePerProcessTest : public InProcessBrowserTest { |
31 public: | 35 public: |
32 ChromeSitePerProcessTest() {} | 36 ChromeSitePerProcessTest() {} |
33 ~ChromeSitePerProcessTest() override {} | 37 ~ChromeSitePerProcessTest() override {} |
34 | 38 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 content::WebContents* new_contents = new_tab_observer.GetWebContents(); | 282 content::WebContents* new_contents = new_tab_observer.GetWebContents(); |
279 | 283 |
280 // Verify that the new tab has the right contents and is in the right, new | 284 // Verify that the new tab has the right contents and is in the right, new |
281 // place in the tab strip. | 285 // place in the tab strip. |
282 EXPECT_TRUE(WaitForLoadStop(new_contents)); | 286 EXPECT_TRUE(WaitForLoadStop(new_contents)); |
283 EXPECT_EQ(2, browser()->tab_strip_model()->count()); | 287 EXPECT_EQ(2, browser()->tab_strip_model()->count()); |
284 EXPECT_EQ(new_contents, browser()->tab_strip_model()->GetWebContentsAt(1)); | 288 EXPECT_EQ(new_contents, browser()->tab_strip_model()->GetWebContentsAt(1)); |
285 GURL expected_url(embedded_test_server()->GetURL("c.com", "/title1.html")); | 289 GURL expected_url(embedded_test_server()->GetURL("c.com", "/title1.html")); |
286 EXPECT_EQ(expected_url, new_contents->GetLastCommittedURL()); | 290 EXPECT_EQ(expected_url, new_contents->GetLastCommittedURL()); |
287 } | 291 } |
| 292 |
| 293 class ChromeSitePerProcessPDFTest : public ChromeSitePerProcessTest { |
| 294 public: |
| 295 ChromeSitePerProcessPDFTest() |
| 296 : factory_(new guest_view::TestGuestViewManagerFactory()) {} |
| 297 ~ChromeSitePerProcessPDFTest() override {} |
| 298 |
| 299 void SetUpOnMainThread() override { |
| 300 ChromeSitePerProcessTest::SetUpOnMainThread(); |
| 301 guest_view::GuestViewManager::set_factory_for_testing(factory_.get()); |
| 302 } |
| 303 |
| 304 guest_view::TestGuestViewManager* GetGuestViewManager() { |
| 305 guest_view::TestGuestViewManager* manager = |
| 306 static_cast<guest_view::TestGuestViewManager*>( |
| 307 guest_view::TestGuestViewManager::FromBrowserContext( |
| 308 browser()->profile())); |
| 309 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called |
| 310 // before a guest is created. |
| 311 if (!manager) { |
| 312 manager = static_cast<guest_view::TestGuestViewManager*>( |
| 313 guest_view::GuestViewManager::CreateWithDelegate( |
| 314 browser()->profile(), |
| 315 extensions::ExtensionsAPIClient::Get() |
| 316 ->CreateGuestViewManagerDelegate(browser()->profile()))); |
| 317 } |
| 318 return manager; |
| 319 } |
| 320 |
| 321 private: |
| 322 std::unique_ptr<guest_view::TestGuestViewManagerFactory> factory_; |
| 323 |
| 324 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessPDFTest); |
| 325 }; |
| 326 |
| 327 // This test verifies that when navigating an OOPIF to a page with <embed>-ed |
| 328 // PDF, the guest is properly created. |
| 329 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessPDFTest, |
| 330 EmbeddedPDFInsideCrossOriginFrame) { |
| 331 // Navigate to a page with an <iframe>. |
| 332 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); |
| 333 ui_test_utils::NavigateToURL(browser(), main_url); |
| 334 |
| 335 guest_view::TestGuestViewManager* guest_view_manager = GetGuestViewManager(); |
| 336 |
| 337 // Initially, no guests are created. |
| 338 EXPECT_EQ(0U, guest_view_manager->num_guests_created()); |
| 339 |
| 340 // Navigate subframe to a cross-site page with an embedded PDF. |
| 341 content::WebContents* active_web_contents = |
| 342 browser()->tab_strip_model()->GetActiveWebContents(); |
| 343 GURL frame_url = |
| 344 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html"); |
| 345 |
| 346 // Ensure the page finishes loading without crashing. |
| 347 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); |
| 348 |
| 349 // Wait until the guest for PDF is created. |
| 350 guest_view_manager->WaitForNumGuestsCreated(1U); |
| 351 } |
OLD | NEW |