Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: chrome/browser/chrome_site_per_process_browsertest.cc

Issue 2538353002: fix external protocol handling for OOPIFs (Closed)
Patch Set: add check if runner is necessary Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/debug/stack_trace.h"
alexmos 2016/12/12 21:11:39 Don't forget to remove.
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
6 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
7 #include "base/macros.h" 8 #include "base/macros.h"
8 #include "base/path_service.h" 9 #include "base/path_service.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/external_protocol/external_protocol_handler.h"
13 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h"
11 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
16 #include "components/guest_view/browser/guest_view_manager_delegate.h" 19 #include "components/guest_view/browser/guest_view_manager_delegate.h"
17 #include "components/guest_view/browser/test_guest_view_manager.h" 20 #include "components/guest_view/browser/test_guest_view_manager.h"
18 #include "content/public/browser/interstitial_page.h" 21 #include "content/public/browser/interstitial_page.h"
19 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 359
357 // Now detach the frame and observe that the guest is destroyed. 360 // Now detach the frame and observe that the guest is destroyed.
358 content::WebContentsDestroyedWatcher observer(guest_web_contents); 361 content::WebContentsDestroyedWatcher observer(guest_web_contents);
359 EXPECT_TRUE(ExecuteScript( 362 EXPECT_TRUE(ExecuteScript(
360 active_web_contents, 363 active_web_contents,
361 "document.body.removeChild(document.querySelector('iframe'));")); 364 "document.body.removeChild(document.querySelector('iframe'));"));
362 observer.Wait(); 365 observer.Wait();
363 EXPECT_EQ(0U, test_guest_view_manager()->GetNumGuestsActive()); 366 EXPECT_EQ(0U, test_guest_view_manager()->GetNumGuestsActive());
364 } 367 }
365 368
369 // a helper class to verify that a "mailto:" external protocol
alexmos 2016/12/12 21:11:39 nit: capitalize A and end sentence with period.
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
370 // request succeeds during unit tests
alexmos 2016/12/12 21:11:40 This is not a unit test but rather a browser test,
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
371 class MailtoExternalProtocolHandlerDelegate
372 : public ExternalProtocolHandler::Delegate {
373 public:
374 bool has_triggered_external_protocol() {
375 return has_triggered_external_protocol_;
376 }
377
378 std::string getURL() { return url_path_; }
alexmos 2016/12/12 21:11:40 For simple accessors like this, we typically don't
alexmos 2016/12/12 21:11:40 I'd just store the full GURL and return this from
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
379
380 content::WebContents* getWebContents() { return web_contents_; }
alexmos 2016/12/12 21:11:40 Similarly, you can rename this to web_contents().
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
381
382 void RunExternalProtocolDialog(const GURL& url,
383 int render_process_host_id,
384 int routing_id,
385 ui::PageTransition page_transition,
386 bool has_user_gesture) override {}
387
388 scoped_refptr<shell_integration::DefaultProtocolClientWorker>
389 CreateShellWorker(
390 const shell_integration::DefaultWebClientWorkerCallback& callback,
391 const std::string& protocol) override {
392 return new shell_integration::DefaultProtocolClientWorker(callback,
393 protocol);
394 }
395
396 ExternalProtocolHandler::BlockState GetBlockState(
397 const std::string& scheme) override {
398 return ExternalProtocolHandler::GetBlockState(scheme);
399 }
400
401 void BlockRequest() override {}
402
403 void LaunchUrlWithoutSecurityCheck(
404 const GURL& url,
405 content::WebContents* web_contents) override {
406 if (message_loop_runner_) {
407 LOG(INFO) << "message_loop_runner_ is not null!";
alexmos 2016/12/12 21:11:39 Don't forget to remove the LOGs once you're done d
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
408 } else {
409 LOG(INFO) << "message_loop_runner_ is null!";
410 }
411 url_path_ = url.path();
412 web_contents_ = web_contents;
413 if (web_contents) {
alexmos 2016/12/12 21:11:39 nit: no need for { here and below.
alexmos 2016/12/12 21:11:40 I don't think you need to check if (web_contents)
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
414 has_triggered_external_protocol_ = true;
415 }
416 if (message_loop_runner_) {
417 message_loop_runner_->Quit();
418 }
419 }
420
421 void Wait() {
422 if (has_triggered_external_protocol_) {
423 LOG(INFO) << "was going to start waiting, but it wasn't necessary!";
424 } else {
425 LOG(INFO) << "starting wait";
426 message_loop_runner_ = new content::MessageLoopRunner();
427 message_loop_runner_->Run();
428 }
429 }
430
431 void FinishedProcessingCheck() override {}
432
433 private:
434 bool has_triggered_external_protocol_ = false;
435 std::string url_path_ = "";
alexmos 2016/12/12 21:11:40 no need for this assignment, std::string is going
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
436 content::WebContents* web_contents_ = nullptr;
437 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
438 };
439
440 // This test verifies that external protocol requests succeed when made from a
441 // OOPIF (https://crbug.com/668289).
442 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest,
443 LaunchExternalProtocolFromSubframe) {
444 GURL start_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
445
446 ui_test_utils::NavigateToURL(browser(), start_url);
447
448 // Navigate to a page with a cross-site iframe that triggers a mailto:
449 // external protocol request.
450 // The test did not start by navigating to this URL because that would mask
451 // the bug. Instead, navigating the main frame to another page will cause a
452 // cross-process transfer, which will avoid a situation where the OOPIF's
453 // swapped-out RenderViewHost and the main frame's active RenderViewHost get
454 // the same routing IDs, causing an accidental success.
455
alexmos 2016/12/12 21:11:39 nit: no blank line.
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
456 GURL mailto_main_frame_url(
457 embedded_test_server()->GetURL("b.com", "/iframe.html"));
458
459 ui_test_utils::NavigateToURL(browser(), mailto_main_frame_url);
460
461 MailtoExternalProtocolHandlerDelegate delegate;
462 ChromeResourceDispatcherHostDelegate::
463 SetExternalProtocolHandlerDelegateForTesting(&delegate);
464
465 GURL mailto_subframe_url(
466 embedded_test_server()->GetURL("c.com", "/page_with_mailto.html"));
467
alexmos 2016/12/12 21:11:39 nit: no blank line (this whole block is about navi
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
468 content::WebContents* active_web_contents =
469 browser()->tab_strip_model()->GetActiveWebContents();
470 EXPECT_TRUE(
471 NavigateIframeToURL(active_web_contents, "test", mailto_subframe_url));
472
473 delegate.Wait();
474
475 EXPECT_TRUE(delegate.has_triggered_external_protocol());
476 EXPECT_EQ(delegate.getURL(), "mail@example.org");
alexmos 2016/12/12 21:11:39 Let's also validate that the scheme of the URL is
davidsac (gone - try alexmos) 2016/12/13 23:02:32 Done.
477 EXPECT_EQ(active_web_contents, delegate.getWebContents());
478 ChromeResourceDispatcherHostDelegate::
479 SetExternalProtocolHandlerDelegateForTesting(nullptr);
480 }
481
366 // Verify that a popup can be opened after navigating a remote frame. This has 482 // Verify that a popup can be opened after navigating a remote frame. This has
367 // to be a chrome/ test to ensure that the popup blocker doesn't block the 483 // to be a chrome/ test to ensure that the popup blocker doesn't block the
368 // popup. See https://crbug.com/670770. 484 // popup. See https://crbug.com/670770.
369 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, 485 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest,
370 NavigateRemoteFrameAndOpenPopup) { 486 NavigateRemoteFrameAndOpenPopup) {
371 // Start on a page with an <iframe>. 487 // Start on a page with an <iframe>.
372 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html")); 488 GURL main_url(embedded_test_server()->GetURL("a.com", "/iframe.html"));
373 ui_test_utils::NavigateToURL(browser(), main_url); 489 ui_test_utils::NavigateToURL(browser(), main_url);
374 490
375 // Navigate the iframe cross-site. 491 // Navigate the iframe cross-site.
(...skipping 15 matching lines...) Expand all
391 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" 507 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n"
392 "var w = window.open('about:blank');\n" 508 "var w = window.open('about:blank');\n"
393 "window.domAutomationController.send(!!w);\n", 509 "window.domAutomationController.send(!!w);\n",
394 &popup_handle_is_valid)); 510 &popup_handle_is_valid));
395 popup_observer.Wait(); 511 popup_observer.Wait();
396 512
397 // The popup shouldn't be blocked. 513 // The popup shouldn't be blocked.
398 EXPECT_TRUE(popup_handle_is_valid); 514 EXPECT_TRUE(popup_handle_is_valid);
399 ASSERT_EQ(2, browser()->tab_strip_model()->count()); 515 ASSERT_EQ(2, browser()->tab_strip_model()->count());
400 } 516 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698