| 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_enumerator.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 #endif // !defined(OS_MACOSX) | 389 #endif // !defined(OS_MACOSX) |
| 390 EXPECT_EQ(kDefaultOptions.window_size.width(), window_width); | 390 EXPECT_EQ(kDefaultOptions.window_size.width(), window_width); |
| 391 EXPECT_EQ(kDefaultOptions.window_size.height(), window_height); | 391 EXPECT_EQ(kDefaultOptions.window_size.height(), window_height); |
| 392 } | 392 } |
| 393 | 393 |
| 394 namespace { | 394 namespace { |
| 395 | 395 |
| 396 class ProtocolHandlerWithCookies | 396 class ProtocolHandlerWithCookies |
| 397 : public net::URLRequestJobFactory::ProtocolHandler { | 397 : public net::URLRequestJobFactory::ProtocolHandler { |
| 398 public: | 398 public: |
| 399 ProtocolHandlerWithCookies(net::CookieList* sent_cookies); | 399 explicit ProtocolHandlerWithCookies(net::CookieList* sent_cookies); |
| 400 ~ProtocolHandlerWithCookies() override {} | 400 ~ProtocolHandlerWithCookies() override {} |
| 401 | 401 |
| 402 net::URLRequestJob* MaybeCreateJob( | 402 net::URLRequestJob* MaybeCreateJob( |
| 403 net::URLRequest* request, | 403 net::URLRequest* request, |
| 404 net::NetworkDelegate* network_delegate) const override; | 404 net::NetworkDelegate* network_delegate) const override; |
| 405 | 405 |
| 406 private: | 406 private: |
| 407 net::CookieList* sent_cookies_; // Not owned. | 407 net::CookieList* sent_cookies_; // Not owned. |
| 408 | 408 |
| 409 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerWithCookies); | 409 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerWithCookies); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 | 623 |
| 624 // We should have sent the matching cookies this time. | 624 // We should have sent the matching cookies this time. |
| 625 EXPECT_EQ(1u, sent_cookies.size()); | 625 EXPECT_EQ(1u, sent_cookies.size()); |
| 626 EXPECT_EQ("shape", sent_cookies[0].Name()); | 626 EXPECT_EQ("shape", sent_cookies[0].Name()); |
| 627 EXPECT_EQ("oblong", sent_cookies[0].Value()); | 627 EXPECT_EQ("oblong", sent_cookies[0].Value()); |
| 628 } | 628 } |
| 629 | 629 |
| 630 // TODO(skyostil): This test currently relies on being able to run a shell | 630 // TODO(skyostil): This test currently relies on being able to run a shell |
| 631 // script. | 631 // script. |
| 632 #if defined(OS_POSIX) | 632 #if defined(OS_POSIX) |
| 633 #define MAYBE_RendererCommandPrefixTest RendererCommandPrefixTest | 633 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, RendererCommandPrefixTest) { |
| 634 #else | |
| 635 #define MAYBE_RendererCommandPrefixTest DISABLED_RendererCommandPrefixTest | |
| 636 #endif // defined(OS_POSIX) | |
| 637 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, MAYBE_RendererCommandPrefixTest) { | |
| 638 base::ThreadRestrictions::SetIOAllowed(true); | 634 base::ThreadRestrictions::SetIOAllowed(true); |
| 639 base::FilePath launcher_stamp; | 635 base::FilePath launcher_stamp; |
| 640 base::CreateTemporaryFile(&launcher_stamp); | 636 base::CreateTemporaryFile(&launcher_stamp); |
| 641 | 637 |
| 642 base::FilePath launcher_script; | 638 base::FilePath launcher_script; |
| 643 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); | 639 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); |
| 644 fprintf(launcher_file, "#!/bin/sh\n"); | 640 fprintf(launcher_file, "#!/bin/sh\n"); |
| 645 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); | 641 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); |
| 646 fprintf(launcher_file, "exec $@\n"); | 642 fprintf(launcher_file, "exec $@\n"); |
| 647 fclose(launcher_file); | 643 fclose(launcher_file); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 665 EXPECT_TRUE(WaitForLoad(web_contents)); | 661 EXPECT_TRUE(WaitForLoad(web_contents)); |
| 666 | 662 |
| 667 // Make sure the launcher was invoked when starting the renderer. | 663 // Make sure the launcher was invoked when starting the renderer. |
| 668 std::string stamp; | 664 std::string stamp; |
| 669 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); | 665 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); |
| 670 EXPECT_GE(stamp.find("--type=renderer"), 0u); | 666 EXPECT_GE(stamp.find("--type=renderer"), 0u); |
| 671 | 667 |
| 672 base::DeleteFile(launcher_script, false); | 668 base::DeleteFile(launcher_script, false); |
| 673 base::DeleteFile(launcher_stamp, false); | 669 base::DeleteFile(launcher_stamp, false); |
| 674 } | 670 } |
| 671 #endif // defined(OS_POSIX) |
| 675 | 672 |
| 676 class CrashReporterTest : public HeadlessBrowserTest, | 673 class CrashReporterTest : public HeadlessBrowserTest, |
| 677 public HeadlessWebContents::Observer, | 674 public HeadlessWebContents::Observer, |
| 678 inspector::ExperimentalObserver { | 675 inspector::ExperimentalObserver { |
| 679 public: | 676 public: |
| 680 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} | 677 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} |
| 681 ~CrashReporterTest() override {} | 678 ~CrashReporterTest() override {} |
| 682 | 679 |
| 683 void SetUp() override { | 680 void SetUp() override { |
| 684 base::ThreadRestrictions::SetIOAllowed(true); | 681 base::ThreadRestrictions::SetIOAllowed(true); |
| 685 base::CreateNewTempDirectory("CrashReporterTest", &crash_dumps_dir_); | 682 base::CreateNewTempDirectory(FILE_PATH_LITERAL("CrashReporterTest"), |
| 683 &crash_dumps_dir_); |
| 686 EXPECT_FALSE(options()->enable_crash_reporter); | 684 EXPECT_FALSE(options()->enable_crash_reporter); |
| 687 options()->enable_crash_reporter = true; | 685 options()->enable_crash_reporter = true; |
| 688 options()->crash_dumps_dir = crash_dumps_dir_; | 686 options()->crash_dumps_dir = crash_dumps_dir_; |
| 689 HeadlessBrowserTest::SetUp(); | 687 HeadlessBrowserTest::SetUp(); |
| 690 } | 688 } |
| 691 | 689 |
| 692 void TearDown() override { | 690 void TearDown() override { |
| 693 base::ThreadRestrictions::SetIOAllowed(true); | 691 base::ThreadRestrictions::SetIOAllowed(true); |
| 694 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); | 692 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); |
| 695 } | 693 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 { | 741 { |
| 744 #if defined(OS_MACOSX) | 742 #if defined(OS_MACOSX) |
| 745 // Mac outputs dumps in the 'completed' directory. | 743 // Mac outputs dumps in the 'completed' directory. |
| 746 crash_dumps_dir_ = crash_dumps_dir_.Append("completed"); | 744 crash_dumps_dir_ = crash_dumps_dir_.Append("completed"); |
| 747 #endif | 745 #endif |
| 748 base::ThreadRestrictions::SetIOAllowed(true); | 746 base::ThreadRestrictions::SetIOAllowed(true); |
| 749 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, | 747 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, |
| 750 base::FileEnumerator::FILES); | 748 base::FileEnumerator::FILES); |
| 751 base::FilePath minidump = it.Next(); | 749 base::FilePath minidump = it.Next(); |
| 752 EXPECT_FALSE(minidump.empty()); | 750 EXPECT_FALSE(minidump.empty()); |
| 753 EXPECT_EQ(".dmp", minidump.Extension()); | 751 EXPECT_EQ(FILE_PATH_LITERAL(".dmp"), minidump.Extension()); |
| 754 EXPECT_TRUE(it.Next().empty()); | 752 EXPECT_TRUE(it.Next().empty()); |
| 755 } | 753 } |
| 756 | 754 |
| 757 web_contents_->RemoveObserver(this); | 755 web_contents_->RemoveObserver(this); |
| 758 web_contents_->Close(); | 756 web_contents_->Close(); |
| 759 web_contents_ = nullptr; | 757 web_contents_ = nullptr; |
| 760 | 758 |
| 761 browser_context_->Close(); | 759 browser_context_->Close(); |
| 762 browser_context_ = nullptr; | 760 browser_context_ = nullptr; |
| 763 } | 761 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 785 content::PermissionType::NOTIFICATIONS, url, url)); | 783 content::PermissionType::NOTIFICATIONS, url, url)); |
| 786 } | 784 } |
| 787 | 785 |
| 788 class HeadlessBrowserTestWithNetLog : public HeadlessBrowserTest { | 786 class HeadlessBrowserTestWithNetLog : public HeadlessBrowserTest { |
| 789 public: | 787 public: |
| 790 HeadlessBrowserTestWithNetLog() {} | 788 HeadlessBrowserTestWithNetLog() {} |
| 791 | 789 |
| 792 void SetUp() override { | 790 void SetUp() override { |
| 793 base::ThreadRestrictions::SetIOAllowed(true); | 791 base::ThreadRestrictions::SetIOAllowed(true); |
| 794 EXPECT_TRUE(base::CreateTemporaryFile(&net_log_)); | 792 EXPECT_TRUE(base::CreateTemporaryFile(&net_log_)); |
| 795 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII("--log-net-log", | 793 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 796 net_log_.value()); | 794 "--log-net-log", net_log_.MaybeAsASCII()); |
| 797 HeadlessBrowserTest::SetUp(); | 795 HeadlessBrowserTest::SetUp(); |
| 798 } | 796 } |
| 799 | 797 |
| 800 void TearDown() override { | 798 void TearDown() override { |
| 801 HeadlessBrowserTest::TearDown(); | 799 HeadlessBrowserTest::TearDown(); |
| 802 base::DeleteFile(net_log_, false); | 800 base::DeleteFile(net_log_, false); |
| 803 } | 801 } |
| 804 | 802 |
| 805 protected: | 803 protected: |
| 806 base::FilePath net_log_; | 804 base::FilePath net_log_; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 | 889 |
| 892 TraceHelper helper(this, target); | 890 TraceHelper helper(this, target); |
| 893 RunAsynchronousTest(); | 891 RunAsynchronousTest(); |
| 894 | 892 |
| 895 std::unique_ptr<base::ListValue> tracing_data = helper.TakeTracingData(); | 893 std::unique_ptr<base::ListValue> tracing_data = helper.TakeTracingData(); |
| 896 EXPECT_TRUE(tracing_data); | 894 EXPECT_TRUE(tracing_data); |
| 897 EXPECT_LT(0u, tracing_data->GetSize()); | 895 EXPECT_LT(0u, tracing_data->GetSize()); |
| 898 } | 896 } |
| 899 | 897 |
| 900 } // namespace headless | 898 } // namespace headless |
| OLD | NEW |