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" |
| 8 #include "base/files/file_util.h" |
7 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
8 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
9 #include "content/public/test/browser_test.h" | 11 #include "content/public/test/browser_test.h" |
10 #include "headless/public/domains/network.h" | 12 #include "headless/public/domains/network.h" |
11 #include "headless/public/domains/page.h" | 13 #include "headless/public/domains/page.h" |
12 #include "headless/public/headless_browser.h" | 14 #include "headless/public/headless_browser.h" |
13 #include "headless/public/headless_devtools_client.h" | 15 #include "headless/public/headless_devtools_client.h" |
14 #include "headless/public/headless_devtools_target.h" | 16 #include "headless/public/headless_devtools_target.h" |
15 #include "headless/public/headless_web_contents.h" | 17 #include "headless/public/headless_web_contents.h" |
16 #include "headless/test/headless_browser_test.h" | 18 #include "headless/test/headless_browser_test.h" |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 EXPECT_FALSE(EvaluateScript(web_contents, "window.location.reload();") | 588 EXPECT_FALSE(EvaluateScript(web_contents, "window.location.reload();") |
587 ->HasExceptionDetails()); | 589 ->HasExceptionDetails()); |
588 EXPECT_TRUE(WaitForLoad(web_contents)); | 590 EXPECT_TRUE(WaitForLoad(web_contents)); |
589 | 591 |
590 // We should have sent the matching cookies this time. | 592 // We should have sent the matching cookies this time. |
591 EXPECT_EQ(1u, sent_cookies.size()); | 593 EXPECT_EQ(1u, sent_cookies.size()); |
592 EXPECT_EQ("shape", sent_cookies[0].Name()); | 594 EXPECT_EQ("shape", sent_cookies[0].Name()); |
593 EXPECT_EQ("oblong", sent_cookies[0].Value()); | 595 EXPECT_EQ("oblong", sent_cookies[0].Value()); |
594 } | 596 } |
595 | 597 |
| 598 // TODO(skyostil): This test currently relies on being able to run a shell |
| 599 // script. |
| 600 #if defined(OS_POSIX) |
| 601 #define MAYBE_RendererCommandPrefixTest RendererCommandPrefixTest |
| 602 #else |
| 603 #define MAYBE_RendererCommandPrefixTest DISABLED_RendererCommandPrefixTest |
| 604 #endif // defined(OS_POSIX) |
| 605 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, MAYBE_RendererCommandPrefixTest) { |
| 606 base::FilePath launcher_stamp; |
| 607 base::CreateTemporaryFile(&launcher_stamp); |
| 608 |
| 609 base::FilePath launcher_script; |
| 610 FILE* launcher_file = base::CreateAndOpenTemporaryFile(&launcher_script); |
| 611 fprintf(launcher_file, "#!/bin/sh\n"); |
| 612 fprintf(launcher_file, "echo $@ > %s\n", launcher_stamp.value().c_str()); |
| 613 fprintf(launcher_file, "exec $@\n"); |
| 614 fclose(launcher_file); |
| 615 base::SetPosixFilePermissions(launcher_script, |
| 616 base::FILE_PERMISSION_READ_BY_USER | |
| 617 base::FILE_PERMISSION_EXECUTE_BY_USER); |
| 618 |
| 619 base::CommandLine::ForCurrentProcess()->AppendSwitch("--no-sandbox"); |
| 620 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 621 "--renderer-cmd-prefix", launcher_script.value()); |
| 622 |
| 623 EXPECT_TRUE(embedded_test_server()->Start()); |
| 624 |
| 625 HeadlessBrowserContext* browser_context = |
| 626 browser()->CreateBrowserContextBuilder().Build(); |
| 627 |
| 628 HeadlessWebContents* web_contents = |
| 629 browser_context->CreateWebContentsBuilder() |
| 630 .SetInitialURL(embedded_test_server()->GetURL("/hello.html")) |
| 631 .Build(); |
| 632 EXPECT_TRUE(WaitForLoad(web_contents)); |
| 633 |
| 634 // Make sure the launcher was invoked when starting the renderer. |
| 635 std::string stamp; |
| 636 EXPECT_TRUE(base::ReadFileToString(launcher_stamp, &stamp)); |
| 637 EXPECT_GE(stamp.find("--type=renderer"), 0u); |
| 638 |
| 639 base::DeleteFile(launcher_script, false); |
| 640 base::DeleteFile(launcher_stamp, false); |
| 641 } |
| 642 |
596 } // namespace headless | 643 } // namespace headless |
OLD | NEW |