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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 | 393 |
394 // True if the request method is "safe" (per section 4.2.1 of RFC 7231). | 394 // True if the request method is "safe" (per section 4.2.1 of RFC 7231). |
395 bool IsMethodSafe(const std::string& method) { | 395 bool IsMethodSafe(const std::string& method) { |
396 return method == "GET" || method == "HEAD" || method == "OPTIONS" || | 396 return method == "GET" || method == "HEAD" || method == "OPTIONS" || |
397 method == "TRACE"; | 397 method == "TRACE"; |
398 } | 398 } |
399 | 399 |
400 class ProtocolHandlerWithCookies | 400 class ProtocolHandlerWithCookies |
401 : public net::URLRequestJobFactory::ProtocolHandler { | 401 : public net::URLRequestJobFactory::ProtocolHandler { |
402 public: | 402 public: |
403 ProtocolHandlerWithCookies(net::CookieList* sent_cookies); | 403 explicit ProtocolHandlerWithCookies(net::CookieList* sent_cookies); |
404 ~ProtocolHandlerWithCookies() override {} | 404 ~ProtocolHandlerWithCookies() override {} |
405 | 405 |
406 net::URLRequestJob* MaybeCreateJob( | 406 net::URLRequestJob* MaybeCreateJob( |
407 net::URLRequest* request, | 407 net::URLRequest* request, |
408 net::NetworkDelegate* network_delegate) const override; | 408 net::NetworkDelegate* network_delegate) const override; |
409 | 409 |
410 private: | 410 private: |
411 net::CookieList* sent_cookies_; // Not owned. | 411 net::CookieList* sent_cookies_; // Not owned. |
412 | 412 |
413 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerWithCookies); | 413 DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerWithCookies); |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 627 |
628 // We should have sent the matching cookies this time. | 628 // We should have sent the matching cookies this time. |
629 EXPECT_EQ(1u, sent_cookies.size()); | 629 EXPECT_EQ(1u, sent_cookies.size()); |
630 EXPECT_EQ("shape", sent_cookies[0].Name()); | 630 EXPECT_EQ("shape", sent_cookies[0].Name()); |
631 EXPECT_EQ("oblong", sent_cookies[0].Value()); | 631 EXPECT_EQ("oblong", sent_cookies[0].Value()); |
632 } | 632 } |
633 | 633 |
634 // TODO(skyostil): This test currently relies on being able to run a shell | 634 // TODO(skyostil): This test currently relies on being able to run a shell |
635 // script. | 635 // script. |
636 #if defined(OS_POSIX) | 636 #if defined(OS_POSIX) |
637 #define MAYBE_RendererCommandPrefixTest RendererCommandPrefixTest | 637 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, RendererCommandPrefixTest) { |
638 #else | |
639 #define MAYBE_RendererCommandPrefixTest DISABLED_RendererCommandPrefixTest | |
640 #endif // defined(OS_POSIX) | |
641 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, MAYBE_RendererCommandPrefixTest) { | |
642 base::ThreadRestrictions::SetIOAllowed(true); | 638 base::ThreadRestrictions::SetIOAllowed(true); |
643 base::FilePath launcher_stamp; | 639 base::FilePath launcher_stamp; |
644 base::CreateTemporaryFile(&launcher_stamp); | 640 base::CreateTemporaryFile(&launcher_stamp); |
645 | 641 |
646 base::FilePath launcher_script; | 642 base::FilePath launcher_script; |
647 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); | 643 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); |
648 fprintf(launcher_file, "#!/bin/sh\n"); | 644 fprintf(launcher_file, "#!/bin/sh\n"); |
649 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); | 645 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); |
650 fprintf(launcher_file, "exec $@\n"); | 646 fprintf(launcher_file, "exec $@\n"); |
651 fclose(launcher_file); | 647 fclose(launcher_file); |
(...skipping 17 matching lines...) Expand all Loading... |
669 EXPECT_TRUE(WaitForLoad(web_contents)); | 665 EXPECT_TRUE(WaitForLoad(web_contents)); |
670 | 666 |
671 // Make sure the launcher was invoked when starting the renderer. | 667 // Make sure the launcher was invoked when starting the renderer. |
672 std::string stamp; | 668 std::string stamp; |
673 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); | 669 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); |
674 EXPECT_GE(stamp.find("--type=renderer"), 0u); | 670 EXPECT_GE(stamp.find("--type=renderer"), 0u); |
675 | 671 |
676 base::DeleteFile(launcher_script, false); | 672 base::DeleteFile(launcher_script, false); |
677 base::DeleteFile(launcher_stamp, false); | 673 base::DeleteFile(launcher_stamp, false); |
678 } | 674 } |
| 675 #endif // defined(OS_POSIX) |
679 | 676 |
680 class CrashReporterTest : public HeadlessBrowserTest, | 677 class CrashReporterTest : public HeadlessBrowserTest, |
681 public HeadlessWebContents::Observer, | 678 public HeadlessWebContents::Observer, |
682 inspector::ExperimentalObserver { | 679 inspector::ExperimentalObserver { |
683 public: | 680 public: |
684 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} | 681 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} |
685 ~CrashReporterTest() override {} | 682 ~CrashReporterTest() override {} |
686 | 683 |
687 void SetUp() override { | 684 void SetUp() override { |
688 base::ThreadRestrictions::SetIOAllowed(true); | 685 base::ThreadRestrictions::SetIOAllowed(true); |
689 base::CreateNewTempDirectory("CrashReporterTest", &crash_dumps_dir_); | 686 base::CreateNewTempDirectory(FILE_PATH_LITERAL("CrashReporterTest"), |
| 687 &crash_dumps_dir_); |
690 EXPECT_FALSE(options()->enable_crash_reporter); | 688 EXPECT_FALSE(options()->enable_crash_reporter); |
691 options()->enable_crash_reporter = true; | 689 options()->enable_crash_reporter = true; |
692 options()->crash_dumps_dir = crash_dumps_dir_; | 690 options()->crash_dumps_dir = crash_dumps_dir_; |
693 HeadlessBrowserTest::SetUp(); | 691 HeadlessBrowserTest::SetUp(); |
694 } | 692 } |
695 | 693 |
696 void TearDown() override { | 694 void TearDown() override { |
697 base::ThreadRestrictions::SetIOAllowed(true); | 695 base::ThreadRestrictions::SetIOAllowed(true); |
698 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); | 696 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); |
699 } | 697 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // The target has crashed and should no longer be there. | 740 // The target has crashed and should no longer be there. |
743 EXPECT_FALSE(web_contents_->GetDevToolsTarget()); | 741 EXPECT_FALSE(web_contents_->GetDevToolsTarget()); |
744 | 742 |
745 // Check that one minidump got created. | 743 // Check that one minidump got created. |
746 { | 744 { |
747 base::ThreadRestrictions::SetIOAllowed(true); | 745 base::ThreadRestrictions::SetIOAllowed(true); |
748 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, | 746 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, |
749 base::FileEnumerator::FILES); | 747 base::FileEnumerator::FILES); |
750 base::FilePath minidump = it.Next(); | 748 base::FilePath minidump = it.Next(); |
751 EXPECT_FALSE(minidump.empty()); | 749 EXPECT_FALSE(minidump.empty()); |
752 EXPECT_EQ(".dmp", minidump.Extension()); | 750 EXPECT_EQ(FILE_PATH_LITERAL(".dmp"), minidump.Extension()); |
753 EXPECT_TRUE(it.Next().empty()); | 751 EXPECT_TRUE(it.Next().empty()); |
754 } | 752 } |
755 | 753 |
756 web_contents_->RemoveObserver(this); | 754 web_contents_->RemoveObserver(this); |
757 web_contents_->Close(); | 755 web_contents_->Close(); |
758 web_contents_ = nullptr; | 756 web_contents_ = nullptr; |
759 | 757 |
760 browser_context_->Close(); | 758 browser_context_->Close(); |
761 browser_context_ = nullptr; | 759 browser_context_ = nullptr; |
762 } | 760 } |
(...skipping 15 matching lines...) Expand all Loading... |
778 web_contents->browser_context()->GetPermissionManager(); | 776 web_contents->browser_context()->GetPermissionManager(); |
779 EXPECT_NE(nullptr, permission_manager); | 777 EXPECT_NE(nullptr, permission_manager); |
780 | 778 |
781 // Check that the permission manager returns ASK for a given permission type. | 779 // Check that the permission manager returns ASK for a given permission type. |
782 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, | 780 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, |
783 permission_manager->GetPermissionStatus( | 781 permission_manager->GetPermissionStatus( |
784 content::PermissionType::NOTIFICATIONS, url, url)); | 782 content::PermissionType::NOTIFICATIONS, url, url)); |
785 } | 783 } |
786 | 784 |
787 } // namespace headless | 785 } // namespace headless |
OLD | NEW |