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 explicit ProtocolHandlerWithCookies(net::CookieList* sent_cookies); | 403 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 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, RendererCommandPrefixTest) { | 637 #define MAYBE_RendererCommandPrefixTest RendererCommandPrefixTest |
| 638 #else |
| 639 #define MAYBE_RendererCommandPrefixTest DISABLED_RendererCommandPrefixTest |
| 640 #endif // defined(OS_POSIX) |
| 641 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, MAYBE_RendererCommandPrefixTest) { |
638 base::ThreadRestrictions::SetIOAllowed(true); | 642 base::ThreadRestrictions::SetIOAllowed(true); |
639 base::FilePath launcher_stamp; | 643 base::FilePath launcher_stamp; |
640 base::CreateTemporaryFile(&launcher_stamp); | 644 base::CreateTemporaryFile(&launcher_stamp); |
641 | 645 |
642 base::FilePath launcher_script; | 646 base::FilePath launcher_script; |
643 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); | 647 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); |
644 fprintf(launcher_file, "#!/bin/sh\n"); | 648 fprintf(launcher_file, "#!/bin/sh\n"); |
645 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); | 649 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); |
646 fprintf(launcher_file, "exec $@\n"); | 650 fprintf(launcher_file, "exec $@\n"); |
647 fclose(launcher_file); | 651 fclose(launcher_file); |
(...skipping 17 matching lines...) Expand all Loading... |
665 EXPECT_TRUE(WaitForLoad(web_contents)); | 669 EXPECT_TRUE(WaitForLoad(web_contents)); |
666 | 670 |
667 // Make sure the launcher was invoked when starting the renderer. | 671 // Make sure the launcher was invoked when starting the renderer. |
668 std::string stamp; | 672 std::string stamp; |
669 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); | 673 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); |
670 EXPECT_GE(stamp.find("--type=renderer"), 0u); | 674 EXPECT_GE(stamp.find("--type=renderer"), 0u); |
671 | 675 |
672 base::DeleteFile(launcher_script, false); | 676 base::DeleteFile(launcher_script, false); |
673 base::DeleteFile(launcher_stamp, false); | 677 base::DeleteFile(launcher_stamp, false); |
674 } | 678 } |
675 #endif // defined(OS_POSIX) | |
676 | 679 |
677 class CrashReporterTest : public HeadlessBrowserTest, | 680 class CrashReporterTest : public HeadlessBrowserTest, |
678 public HeadlessWebContents::Observer, | 681 public HeadlessWebContents::Observer, |
679 inspector::ExperimentalObserver { | 682 inspector::ExperimentalObserver { |
680 public: | 683 public: |
681 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} | 684 CrashReporterTest() : devtools_client_(HeadlessDevToolsClient::Create()) {} |
682 ~CrashReporterTest() override {} | 685 ~CrashReporterTest() override {} |
683 | 686 |
684 void SetUp() override { | 687 void SetUp() override { |
685 base::ThreadRestrictions::SetIOAllowed(true); | 688 base::ThreadRestrictions::SetIOAllowed(true); |
686 base::CreateNewTempDirectory(FILE_PATH_LITERAL("CrashReporterTest"), | 689 base::CreateNewTempDirectory("CrashReporterTest", &crash_dumps_dir_); |
687 &crash_dumps_dir_); | |
688 EXPECT_FALSE(options()->enable_crash_reporter); | 690 EXPECT_FALSE(options()->enable_crash_reporter); |
689 options()->enable_crash_reporter = true; | 691 options()->enable_crash_reporter = true; |
690 options()->crash_dumps_dir = crash_dumps_dir_; | 692 options()->crash_dumps_dir = crash_dumps_dir_; |
691 HeadlessBrowserTest::SetUp(); | 693 HeadlessBrowserTest::SetUp(); |
692 } | 694 } |
693 | 695 |
694 void TearDown() override { | 696 void TearDown() override { |
695 base::ThreadRestrictions::SetIOAllowed(true); | 697 base::ThreadRestrictions::SetIOAllowed(true); |
696 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); | 698 base::DeleteFile(crash_dumps_dir_, /* recursive */ false); |
697 } | 699 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 // The target has crashed and should no longer be there. | 742 // The target has crashed and should no longer be there. |
741 EXPECT_FALSE(web_contents_->GetDevToolsTarget()); | 743 EXPECT_FALSE(web_contents_->GetDevToolsTarget()); |
742 | 744 |
743 // Check that one minidump got created. | 745 // Check that one minidump got created. |
744 { | 746 { |
745 base::ThreadRestrictions::SetIOAllowed(true); | 747 base::ThreadRestrictions::SetIOAllowed(true); |
746 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, | 748 base::FileEnumerator it(crash_dumps_dir_, /* recursive */ false, |
747 base::FileEnumerator::FILES); | 749 base::FileEnumerator::FILES); |
748 base::FilePath minidump = it.Next(); | 750 base::FilePath minidump = it.Next(); |
749 EXPECT_FALSE(minidump.empty()); | 751 EXPECT_FALSE(minidump.empty()); |
750 EXPECT_EQ(FILE_PATH_LITERAL(".dmp"), minidump.Extension()); | 752 EXPECT_EQ(".dmp", minidump.Extension()); |
751 EXPECT_TRUE(it.Next().empty()); | 753 EXPECT_TRUE(it.Next().empty()); |
752 } | 754 } |
753 | 755 |
754 web_contents_->RemoveObserver(this); | 756 web_contents_->RemoveObserver(this); |
755 web_contents_->Close(); | 757 web_contents_->Close(); |
756 web_contents_ = nullptr; | 758 web_contents_ = nullptr; |
757 | 759 |
758 browser_context_->Close(); | 760 browser_context_->Close(); |
759 browser_context_ = nullptr; | 761 browser_context_ = nullptr; |
760 } | 762 } |
(...skipping 15 matching lines...) Expand all Loading... |
776 web_contents->browser_context()->GetPermissionManager(); | 778 web_contents->browser_context()->GetPermissionManager(); |
777 EXPECT_NE(nullptr, permission_manager); | 779 EXPECT_NE(nullptr, permission_manager); |
778 | 780 |
779 // Check that the permission manager returns ASK for a given permission type. | 781 // Check that the permission manager returns ASK for a given permission type. |
780 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, | 782 EXPECT_EQ(blink::mojom::PermissionStatus::ASK, |
781 permission_manager->GetPermissionStatus( | 783 permission_manager->GetPermissionStatus( |
782 content::PermissionType::NOTIFICATIONS, url, url)); | 784 content::PermissionType::NOTIFICATIONS, url, url)); |
783 } | 785 } |
784 | 786 |
785 } // namespace headless | 787 } // namespace headless |
OLD | NEW |