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" |
| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 main_lost_focus = true; | 246 main_lost_focus = true; |
| 243 if (status == "\"popup-got-focus\"") | 247 if (status == "\"popup-got-focus\"") |
| 244 popup_got_focus = true; | 248 popup_got_focus = true; |
| 245 if (main_lost_focus && popup_got_focus) | 249 if (main_lost_focus && popup_got_focus) |
| 246 break; | 250 break; |
| 247 } | 251 } |
| 248 | 252 |
| 249 // The popup should be focused now. | 253 // The popup should be focused now. |
| 250 EXPECT_EQ(popup, browser()->tab_strip_model()->GetActiveWebContents()); | 254 EXPECT_EQ(popup, browser()->tab_strip_model()->GetActiveWebContents()); |
| 251 } | 255 } |
| 256 | |
| 257 class ChromeSitePerProcessPDFTest : public ChromeSitePerProcessTest { | |
| 258 public: | |
| 259 ChromeSitePerProcessPDFTest() | |
| 260 : factory_(new guest_view::TestGuestViewManagerFactory()) {} | |
| 261 ~ChromeSitePerProcessPDFTest() override {} | |
| 262 | |
| 263 void SetUpOnMainThread() override { | |
| 264 ChromeSitePerProcessTest::SetUpOnMainThread(); | |
| 265 guest_view::GuestViewManager::set_factory_for_testing(factory_.get()); | |
| 266 } | |
| 267 | |
| 268 guest_view::TestGuestViewManager* GetGuestViewManager() { | |
| 269 guest_view::TestGuestViewManager* manager = | |
| 270 static_cast<guest_view::TestGuestViewManager*>( | |
| 271 guest_view::TestGuestViewManager::FromBrowserContext( | |
| 272 browser()->profile())); | |
| 273 // TestGuestViewManager::WaitForSingleGuestCreated may and will get called | |
| 274 // before a guest is created. | |
| 275 if (!manager) { | |
| 276 manager = static_cast<guest_view::TestGuestViewManager*>( | |
| 277 guest_view::GuestViewManager::CreateWithDelegate( | |
| 278 browser()->profile(), | |
| 279 extensions::ExtensionsAPIClient::Get() | |
| 280 ->CreateGuestViewManagerDelegate(browser()->profile()))); | |
| 281 } | |
| 282 return manager; | |
| 283 } | |
| 284 | |
| 285 private: | |
| 286 std::unique_ptr<guest_view::TestGuestViewManagerFactory> factory_; | |
| 287 | |
| 288 DISALLOW_COPY_AND_ASSIGN(ChromeSitePerProcessPDFTest); | |
| 289 }; | |
| 290 | |
| 291 // This test verifies that when navigating an OOPIF to a page with <embed>-ed | |
| 292 // PDF, the guest is properly created. | |
| 293 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessPDFTest, | |
| 294 EmbeddedPDFInsideCrossOriginFrame) { | |
| 295 // Navigate to a page with an <iframe>. | |
| 296 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); | |
| 297 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 298 | |
| 299 guest_view::TestGuestViewManager* guest_view_manager = GetGuestViewManager(); | |
| 300 | |
| 301 // Initially, no guests are created. | |
| 302 EXPECT_EQ(0U, guest_view_manager->num_guests_created()); | |
| 303 | |
| 304 // Navigate subframe to a page with an embedded PDF. | |
|
Charlie Reis
2016/10/18 22:52:20
nit: to a cross-site page with
EhsanK
2016/10/20 21:41:17
Done.
| |
| 305 content::WebContents* active_web_contents = | |
| 306 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 307 GURL frame_url = | |
| 308 embedded_test_server()->GetURL("b.com", "/page_with_embedded_pdf.html"); | |
| 309 | |
| 310 // Ensure the page finishes loading without crashing. | |
| 311 EXPECT_TRUE(NavigateIframeToURL(active_web_contents, "test", frame_url)); | |
| 312 | |
| 313 // Wait until the guest for PDF is created. | |
| 314 guest_view_manager->WaitForNumGuestsCreated(1U); | |
| 315 } | |
| OLD | NEW |