Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_enumerator.h" | |
| 8 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 9 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "content/public/common/url_constants.h" | |
| 12 #include "content/public/test/browser_test.h" | 14 #include "content/public/test/browser_test.h" |
| 15 #include "headless/public/devtools/domains/inspector.h" | |
| 13 #include "headless/public/devtools/domains/network.h" | 16 #include "headless/public/devtools/domains/network.h" |
| 14 #include "headless/public/devtools/domains/page.h" | 17 #include "headless/public/devtools/domains/page.h" |
| 15 #include "headless/public/headless_browser.h" | 18 #include "headless/public/headless_browser.h" |
| 16 #include "headless/public/headless_devtools_client.h" | 19 #include "headless/public/headless_devtools_client.h" |
| 17 #include "headless/public/headless_devtools_target.h" | 20 #include "headless/public/headless_devtools_target.h" |
| 18 #include "headless/public/headless_web_contents.h" | 21 #include "headless/public/headless_web_contents.h" |
| 19 #include "headless/test/headless_browser_test.h" | 22 #include "headless/test/headless_browser_test.h" |
| 20 #include "headless/test/test_protocol_handler.h" | 23 #include "headless/test/test_protocol_handler.h" |
| 21 #include "headless/test/test_url_request_job.h" | 24 #include "headless/test/test_url_request_job.h" |
| 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 25 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 635 | 638 |
| 636 // Make sure the launcher was invoked when starting the renderer. | 639 // Make sure the launcher was invoked when starting the renderer. |
| 637 std::string stamp; | 640 std::string stamp; |
| 638 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); | 641 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); |
| 639 EXPECT_GE(stamp.find("--type=renderer"), 0u); | 642 EXPECT_GE(stamp.find("--type=renderer"), 0u); |
| 640 | 643 |
| 641 base::DeleteFile(launcher_script, false); | 644 base::DeleteFile(launcher_script, false); |
| 642 base::DeleteFile(launcher_stamp, false); | 645 base::DeleteFile(launcher_stamp, false); |
| 643 } | 646 } |
| 644 | 647 |
| 648 class CrashReporterTest : public HeadlessBrowserTest, | |
| 649 public HeadlessWebContents::Observer, | |
| 650 inspector::ExperimentalObserver { | |
| 651 public: | |
| 652 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} | |
| 653 ~CrashReporterTest() override {} | |
| 654 | |
| 655 void SetUp() override { | |
| 656 base::ThreadRestrictions::SetIOAllowed(true); | |
| 657 base::CreateNewTempDirectory("CrashReporterTest", &crash_dumps_dir_); | |
| 658 EXPECT_FALSE(options()->enable_crash_reporter); | |
| 659 options()->enable_crash_reporter = true; | |
| 660 options()->crash_dumps_dir = crash_dumps_dir_; | |
| 661 HeadlessBrowserTest::SetUp(); | |
| 662 } | |
| 663 | |
| 664 void TearDown() override { | |
| 665 base::ThreadRestrictions::SetIOAllowed(true); | |
| 666 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); | |
| 667 } | |
| 668 | |
| 669 // HeadlessWebContents::Observer implementation: | |
| 670 void DevToolsTargetReady() override { | |
| 671 EXPECT_TRUE(web_contents_->GetDevToolsTarget()); | |
| 672 web_contents_->GetDevToolsTarget()->AttachClient(devtools_client_.get()); | |
| 673 devtools_client_->GetInspector()->GetExperimental()->AddObserver(this); | |
| 674 } | |
| 675 | |
| 676 // inspector::ExperimentalObserver implementation: | |
| 677 void OnTargetCrashed(const inspector::TargetCrashedParams&) override { | |
| 678 FinishAsynchronousTest(); | |
| 679 } | |
| 680 | |
| 681 protected: | |
| 682 HeadlessBrowserContext* browser_context_ = nullptr; | |
| 683 HeadlessWebContents* web_contents_ = nullptr; | |
| 684 std::unique_ptr<HeadlessDevToolsClient> devtools_client_; | |
| 685 base::FilePath crash_dumps_dir_; | |
| 686 }; | |
| 687 | |
| 688 // TODO(skyostil): Minidump generation currently is only supported on Linux. | |
| 689 #if defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 690 #define MAYBE_GenerateMinidump GenerateMinidump | |
| 691 #else | |
| 692 #define MAYBE_GenerateMinidump DISABLED_GenerateMinidump | |
| 693 #endif // defined(OS_POSIX) && !defined(OS_MACOSX) | |
| 694 IN_PROC_BROWSER_TEST_F(CrashReporterTest, MAYBE_GenerateMinidump) { | |
| 695 // Navigates a tab to chrome://crash and checks that a minidump is generated. | |
| 696 // Note that we only test renderer crashes here -- browser crashes need to be | |
| 697 // tested with a separate harness. | |
| 698 // | |
| 699 // The case where crash reporting is disabled is covered by | |
| 700 // HeadlessCrashObserverTest. | |
| 701 HeadlessBrowserContext::Builder builder = | |
|
alex clarke (OOO till 29th)
2017/02/14 15:14:08
Do we need this temporary?
Sami
2017/02/14 18:36:46
Not really, removed.
| |
| 702 browser()->CreateBrowserContextBuilder(); | |
| 703 browser_context_ = builder.Build(); | |
| 704 | |
| 705 web_contents_ = browser_context_->CreateWebContentsBuilder() | |
| 706 .SetInitialURL(GURL(content::kChromeUICrashURL)) | |
| 707 .Build(); | |
| 708 | |
| 709 web_contents_->AddObserver(this); | |
| 710 RunAsynchronousTest(); | |
| 711 | |
| 712 // The target has crashed and should no longer be there. | |
| 713 EXPECT_FALSE(web_contents_->GetDevToolsTarget()); | |
| 714 | |
| 715 // Check that one minidump got created. | |
| 716 { | |
| 717 base::ThreadRestrictions::SetIOAllowed(true); | |
| 718 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, | |
| 719 base::FileEnumerator::FILES); | |
| 720 base::FilePath minidump = it.Next(); | |
| 721 EXPECT_FALSE(minidump.empty()); | |
| 722 EXPECT_EQ(".dmp", minidump.Extension()); | |
| 723 EXPECT_TRUE(it.Next().empty()); | |
| 724 } | |
| 725 | |
| 726 web_contents_->RemoveObserver(this); | |
| 727 web_contents_->Close(); | |
| 728 web_contents_ = nullptr; | |
| 729 | |
| 730 browser_context_->Close(); | |
| 731 browser_context_ = nullptr; | |
| 732 } | |
| 733 | |
| 645 } // namespace headless | 734 } // namespace headless |
| OLD | NEW |