OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/shell/shell_browser_main.h" | 5 #include "content/shell/shell_browser_main.h" |
6 | 6 |
7 #include <iostream> | 7 #include <iostream> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/utf_string_conversions.h" |
16 #include "content/public/browser/browser_main_runner.h" | 17 #include "content/public/browser/browser_main_runner.h" |
17 #include "content/shell/shell_switches.h" | 18 #include "content/shell/shell_switches.h" |
18 #include "content/shell/webkit_test_runner_host.h" | 19 #include "content/shell/webkit_test_runner_host.h" |
19 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
20 #include "webkit/support/webkit_support.h" | 21 #include "webkit/support/webkit_support.h" |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 GURL GetURLForLayoutTest(const char* test_name, | 25 GURL GetURLForLayoutTest(const std::string& test_name, |
25 bool* enable_pixel_dumping, | 26 bool* enable_pixel_dumping, |
26 std::string* expected_pixel_hash) { | 27 std::string* expected_pixel_hash) { |
27 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 28 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
28 std::string path_or_url = test_name; | 29 std::string path_or_url = test_name; |
29 std::string pixel_switch; | 30 std::string pixel_switch; |
30 std::string pixel_hash; | 31 std::string pixel_hash; |
31 std::string::size_type separator_position = path_or_url.find('\''); | 32 std::string::size_type separator_position = path_or_url.find('\''); |
32 if (separator_position != std::string::npos) { | 33 if (separator_position != std::string::npos) { |
33 pixel_switch = path_or_url.substr(separator_position + 1); | 34 pixel_switch = path_or_url.substr(separator_position + 1); |
34 path_or_url.erase(separator_position); | 35 path_or_url.erase(separator_position); |
(...skipping 21 matching lines...) Expand all Loading... |
56 } | 57 } |
57 FilePath local_path; | 58 FilePath local_path; |
58 if (net::FileURLToFilePath(test_url, &local_path)) { | 59 if (net::FileURLToFilePath(test_url, &local_path)) { |
59 // We're outside of the message loop here, and this is a test. | 60 // We're outside of the message loop here, and this is a test. |
60 base::ThreadRestrictions::ScopedAllowIO allow_io; | 61 base::ThreadRestrictions::ScopedAllowIO allow_io; |
61 file_util::SetCurrentDirectory(local_path.DirName()); | 62 file_util::SetCurrentDirectory(local_path.DirName()); |
62 } | 63 } |
63 return test_url; | 64 return test_url; |
64 } | 65 } |
65 | 66 |
| 67 bool GetNextTest(const CommandLine::StringVector& args, |
| 68 size_t* position, |
| 69 std::string* test) { |
| 70 if (*position >= args.size()) |
| 71 return false; |
| 72 if (args[*position] == FILE_PATH_LITERAL("-")) |
| 73 return !!std::getline(std::cin, *test, '\n'); |
| 74 #if defined(OS_WIN) |
| 75 *test = WideToUTF8(args[(*position)++]); |
| 76 #else |
| 77 *test = args[(*position)++]; |
| 78 #endif |
| 79 return true; |
| 80 } |
| 81 |
66 } // namespace | 82 } // namespace |
67 | 83 |
68 // Main routine for running as the Browser process. | 84 // Main routine for running as the Browser process. |
69 int ShellBrowserMain(const content::MainFunctionParams& parameters) { | 85 int ShellBrowserMain(const content::MainFunctionParams& parameters) { |
70 scoped_ptr<content::BrowserMainRunner> main_runner_( | 86 scoped_ptr<content::BrowserMainRunner> main_runner_( |
71 content::BrowserMainRunner::Create()); | 87 content::BrowserMainRunner::Create()); |
72 | 88 |
73 int exit_code = main_runner_->Initialize(parameters); | 89 int exit_code = main_runner_->Initialize(parameters); |
74 | 90 |
75 if (exit_code >= 0) | 91 if (exit_code >= 0) |
76 return exit_code; | 92 return exit_code; |
77 | 93 |
78 if (CommandLine::ForCurrentProcess()->HasSwitch( | 94 if (CommandLine::ForCurrentProcess()->HasSwitch( |
79 switches::kCheckLayoutTestSysDeps)) { | 95 switches::kCheckLayoutTestSysDeps)) { |
80 return 0; | 96 return 0; |
81 } | 97 } |
82 | 98 |
83 bool layout_test_mode = | 99 bool layout_test_mode = |
84 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | 100 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
85 | 101 |
86 if (layout_test_mode) { | 102 if (layout_test_mode) { |
87 content::WebKitTestController test_controller; | 103 content::WebKitTestController test_controller; |
| 104 std::string test_string; |
| 105 CommandLine::StringVector args = |
| 106 CommandLine::ForCurrentProcess()->GetArgs(); |
| 107 size_t command_line_position = 0; |
88 | 108 |
89 char test_string[2048]; | |
90 #if defined(OS_ANDROID) | 109 #if defined(OS_ANDROID) |
91 std::cout << "#READY\n"; | 110 std::cout << "#READY\n"; |
92 std::cout.flush(); | 111 std::cout.flush(); |
93 #endif | 112 #endif |
94 | 113 |
95 while (fgets(test_string, sizeof(test_string), stdin)) { | 114 while (GetNextTest(args, &command_line_position, &test_string)) { |
96 char *new_line_position = strchr(test_string, '\n'); | 115 if (test_string.empty()) |
97 if (new_line_position) | |
98 *new_line_position = '\0'; | |
99 if (test_string[0] == '\0') | |
100 continue; | 116 continue; |
101 if (!strcmp(test_string, "QUIT")) | 117 if (test_string == "QUIT") |
102 break; | 118 break; |
103 | 119 |
104 bool enable_pixel_dumps; | 120 bool enable_pixel_dumps; |
105 std::string pixel_hash; | 121 std::string pixel_hash; |
106 GURL test_url = GetURLForLayoutTest( | 122 GURL test_url = GetURLForLayoutTest( |
107 test_string, &enable_pixel_dumps, &pixel_hash); | 123 test_string, &enable_pixel_dumps, &pixel_hash); |
108 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( | 124 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( |
109 test_url, enable_pixel_dumps, pixel_hash)) { | 125 test_url, enable_pixel_dumps, pixel_hash)) { |
110 break; | 126 break; |
111 } | 127 } |
112 | 128 |
113 main_runner_->Run(); | 129 main_runner_->Run(); |
114 | 130 |
115 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) | 131 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) |
116 break; | 132 break; |
117 } | 133 } |
118 exit_code = 0; | 134 exit_code = 0; |
119 } else { | 135 } else { |
120 exit_code = main_runner_->Run(); | 136 exit_code = main_runner_->Run(); |
121 } | 137 } |
122 | 138 |
123 main_runner_->Shutdown(); | 139 main_runner_->Shutdown(); |
124 | 140 |
125 return exit_code; | 141 return exit_code; |
126 } | 142 } |
OLD | NEW |