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