OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/public/test/content_browser_test.h" | 5 #include "content/public/test/content_browser_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/process/launch.h" |
9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/launcher/test_launcher.h" |
11 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_process_host_observer.h" |
| 16 #include "content/public/browser/web_contents.h" |
12 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
13 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
14 #include "content/public/test/content_browser_test_utils.h" | 19 #include "content/public/test/content_browser_test_utils.h" |
| 20 #include "content/public/test/test_launcher.h" |
15 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
16 #include "content/shell/browser/shell.h" | 22 #include "content/shell/browser/shell.h" |
| 23 #include "content/shell/common/shell_switches.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
18 | 25 |
19 namespace content { | 26 namespace content { |
20 | 27 |
| 28 // On Android symbolization happens in one step after all the tests ran, so this |
| 29 // test doesn't work there. |
| 30 // TODO(mac): figure out why symbolization doesn't happen in the renderer. |
| 31 #if !defined(OS_ANDROID) && !defined(OS_MACOSX) |
| 32 |
21 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, MANUAL_ShouldntRun) { | 33 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, MANUAL_ShouldntRun) { |
22 // Ensures that tests with MANUAL_ prefix don't run automatically. | 34 // Ensures that tests with MANUAL_ prefix don't run automatically. |
23 ASSERT_TRUE(false); | 35 ASSERT_TRUE(false); |
24 } | 36 } |
25 | 37 |
| 38 class CrashObserver : public RenderProcessHostObserver { |
| 39 public: |
| 40 CrashObserver(const base::Closure& quit_closure) |
| 41 : quit_closure_(quit_closure) {} |
| 42 void RenderProcessExited(RenderProcessHost* host, |
| 43 base::TerminationStatus status, |
| 44 int exit_code) override { |
| 45 ASSERT_TRUE(status == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 46 status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION); |
| 47 quit_closure_.Run(); |
| 48 } |
| 49 |
| 50 private: |
| 51 base::Closure quit_closure_; |
| 52 }; |
| 53 |
| 54 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, MANUAL_RendererCrash) { |
| 55 scoped_refptr<MessageLoopRunner> message_loop_runner = new MessageLoopRunner; |
| 56 CrashObserver crash_observer(message_loop_runner->QuitClosure()); |
| 57 shell()->web_contents()->GetRenderProcessHost()->AddObserver(&crash_observer); |
| 58 |
| 59 NavigateToURL(shell(), GURL("chrome:crash")); |
| 60 message_loop_runner->Run(); |
| 61 } |
| 62 |
| 63 // Tests that browser tests print the callstack when a child process crashes. |
| 64 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, RendererCrashCallStack) { |
| 65 base::ScopedTempDir temp_dir; |
| 66 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 67 base::CommandLine new_test = |
| 68 base::CommandLine(base::CommandLine::ForCurrentProcess()->GetProgram()); |
| 69 new_test.AppendSwitchASCII(base::kGTestFilterFlag, |
| 70 "ContentBrowserTest.MANUAL_RendererCrash"); |
| 71 new_test.AppendSwitch(kRunManualTestsFlag); |
| 72 new_test.AppendSwitch(kSingleProcessTestsFlag); |
| 73 |
| 74 #if defined(ADDRESS_SANITIZER) |
| 75 // Per https://www.chromium.org/developers/testing/addresssanitizer, there are |
| 76 // ASAN bots that run without the sandbox which this test will pass for. The |
| 77 // other ones pipe the output to a symbolizer script. |
| 78 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoSandbox)) { |
| 79 new_test.AppendSwitch(switches::kNoSandbox); |
| 80 } else { |
| 81 LOG(INFO) << "Couldn't run ContentBrowserTest.RendererCrashCallStack since " |
| 82 << "sandbox is enabled and ASAN requires piping to an external " |
| 83 << "script."; |
| 84 return; |
| 85 } |
| 86 #endif |
| 87 |
| 88 std::string output; |
| 89 base::GetAppOutputAndError(new_test, &output); |
| 90 |
| 91 std::string crash_string = |
| 92 "content::RenderFrameImpl::PrepareRenderViewForNavigation"; |
| 93 |
| 94 if (output.find(crash_string) == std::string::npos) { |
| 95 GTEST_FAIL() << "Couldn't find\n" << crash_string << "\n in output\n " |
| 96 << output; |
| 97 } |
| 98 } |
| 99 |
| 100 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, MANUAL_BrowserCrash) { |
| 101 CHECK(false); |
| 102 } |
| 103 |
| 104 // Tests that browser tests print the callstack on asserts. |
| 105 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, BrowserCrashCallStack) { |
| 106 base::ScopedTempDir temp_dir; |
| 107 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 108 base::CommandLine new_test = |
| 109 base::CommandLine(base::CommandLine::ForCurrentProcess()->GetProgram()); |
| 110 new_test.AppendSwitchASCII(base::kGTestFilterFlag, |
| 111 "ContentBrowserTest.MANUAL_BrowserCrash"); |
| 112 new_test.AppendSwitch(kRunManualTestsFlag); |
| 113 new_test.AppendSwitch(kSingleProcessTestsFlag); |
| 114 std::string output; |
| 115 base::GetAppOutputAndError(new_test, &output); |
| 116 |
| 117 std::string crash_string = |
| 118 "content::ContentBrowserTest_MANUAL_BrowserCrash_Test::RunTestOnMainThread
"; |
| 119 |
| 120 if (output.find(crash_string) == std::string::npos) { |
| 121 GTEST_FAIL() << "Couldn't find\n" << crash_string << "\n in output\n " |
| 122 << output; |
| 123 } |
| 124 } |
| 125 |
| 126 #endif |
| 127 |
26 class ContentBrowserTestSanityTest : public ContentBrowserTest { | 128 class ContentBrowserTestSanityTest : public ContentBrowserTest { |
27 public: | 129 public: |
28 void SetUpCommandLine(base::CommandLine* command_line) override { | 130 void SetUpCommandLine(base::CommandLine* command_line) override { |
29 const testing::TestInfo* const test_info = | 131 const testing::TestInfo* const test_info = |
30 testing::UnitTest::GetInstance()->current_test_info(); | 132 testing::UnitTest::GetInstance()->current_test_info(); |
31 if (std::string(test_info->name()) == "SingleProcess") | 133 if (std::string(test_info->name()) == "SingleProcess") |
32 command_line->AppendSwitch(switches::kSingleProcess); | 134 command_line->AppendSwitch(switches::kSingleProcess); |
33 } | 135 } |
34 | 136 |
35 void Test() { | 137 void Test() { |
(...skipping 16 matching lines...) Expand all Loading... |
52 } | 154 } |
53 | 155 |
54 namespace { | 156 namespace { |
55 | 157 |
56 void CallbackChecker(bool* non_nested_task_ran) { | 158 void CallbackChecker(bool* non_nested_task_ran) { |
57 *non_nested_task_ran = true; | 159 *non_nested_task_ran = true; |
58 } | 160 } |
59 | 161 |
60 } // namespace | 162 } // namespace |
61 | 163 |
62 IN_PROC_BROWSER_TEST_F(ContentBrowserTestSanityTest, NonNestableTask) { | 164 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, NonNestableTask) { |
63 bool non_nested_task_ran = false; | 165 bool non_nested_task_ran = false; |
64 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( | 166 base::ThreadTaskRunnerHandle::Get()->PostNonNestableTask( |
65 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran)); | 167 FROM_HERE, base::Bind(&CallbackChecker, &non_nested_task_ran)); |
66 content::RunAllPendingInMessageLoop(); | 168 content::RunAllPendingInMessageLoop(); |
67 ASSERT_TRUE(non_nested_task_ran); | 169 ASSERT_TRUE(non_nested_task_ran); |
68 } | 170 } |
69 | 171 |
70 } // namespace content | 172 } // namespace content |
OLD | NEW |