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/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
17 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "content/public/browser/browser_main_runner.h" | 19 #include "content/public/browser/browser_main_runner.h" |
20 #include "content/shell/shell_switches.h" | 20 #include "content/shell/shell_switches.h" |
21 #include "content/shell/webkit_test_controller.h" | 21 #include "content/shell/webkit_test_controller.h" |
22 #include "net/base/net_util.h" | 22 #include "net/base/net_util.h" |
23 #include "webkit/support/webkit_support.h" | 23 #include "webkit/support/webkit_support.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 GURL GetURLForLayoutTest(const std::string& test_name, | 27 GURL GetURLForLayoutTest(const std::string& test_name, |
28 FilePath* current_working_directory, | 28 base::FilePath* current_working_directory, |
29 bool* enable_pixel_dumping, | 29 bool* enable_pixel_dumping, |
30 std::string* expected_pixel_hash) { | 30 std::string* expected_pixel_hash) { |
31 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 31 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
32 std::string path_or_url = test_name; | 32 std::string path_or_url = test_name; |
33 std::string pixel_switch; | 33 std::string pixel_switch; |
34 std::string pixel_hash; | 34 std::string pixel_hash; |
35 std::string::size_type separator_position = path_or_url.find('\''); | 35 std::string::size_type separator_position = path_or_url.find('\''); |
36 if (separator_position != std::string::npos) { | 36 if (separator_position != std::string::npos) { |
37 pixel_switch = path_or_url.substr(separator_position + 1); | 37 pixel_switch = path_or_url.substr(separator_position + 1); |
38 path_or_url.erase(separator_position); | 38 path_or_url.erase(separator_position); |
39 } | 39 } |
40 separator_position = pixel_switch.find('\''); | 40 separator_position = pixel_switch.find('\''); |
41 if (separator_position != std::string::npos) { | 41 if (separator_position != std::string::npos) { |
42 pixel_hash = pixel_switch.substr(separator_position + 1); | 42 pixel_hash = pixel_switch.substr(separator_position + 1); |
43 pixel_switch.erase(separator_position); | 43 pixel_switch.erase(separator_position); |
44 } | 44 } |
45 if (enable_pixel_dumping) { | 45 if (enable_pixel_dumping) { |
46 *enable_pixel_dumping = | 46 *enable_pixel_dumping = |
47 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); | 47 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); |
48 } | 48 } |
49 if (expected_pixel_hash) | 49 if (expected_pixel_hash) |
50 *expected_pixel_hash = pixel_hash; | 50 *expected_pixel_hash = pixel_hash; |
51 GURL test_url(path_or_url); | 51 GURL test_url(path_or_url); |
52 if (!(test_url.is_valid() && test_url.has_scheme())) { | 52 if (!(test_url.is_valid() && test_url.has_scheme())) { |
53 // We're outside of the message loop here, and this is a test. | 53 // We're outside of the message loop here, and this is a test. |
54 base::ThreadRestrictions::ScopedAllowIO allow_io; | 54 base::ThreadRestrictions::ScopedAllowIO allow_io; |
55 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
56 std::wstring wide_path_or_url = | 56 std::wstring wide_path_or_url = |
57 base::SysNativeMBToWide(path_or_url); | 57 base::SysNativeMBToWide(path_or_url); |
58 FilePath local_file(wide_path_or_url); | 58 base::FilePath local_file(wide_path_or_url); |
59 #else | 59 #else |
60 FilePath local_file(path_or_url); | 60 base::FilePath local_file(path_or_url); |
61 #endif | 61 #endif |
62 file_util::AbsolutePath(&local_file); | 62 file_util::AbsolutePath(&local_file); |
63 test_url = net::FilePathToFileURL(local_file); | 63 test_url = net::FilePathToFileURL(local_file); |
64 } | 64 } |
65 FilePath local_path; | 65 base::FilePath local_path; |
66 if (current_working_directory) { | 66 if (current_working_directory) { |
67 // We're outside of the message loop here, and this is a test. | 67 // We're outside of the message loop here, and this is a test. |
68 base::ThreadRestrictions::ScopedAllowIO allow_io; | 68 base::ThreadRestrictions::ScopedAllowIO allow_io; |
69 if (net::FileURLToFilePath(test_url, &local_path)) | 69 if (net::FileURLToFilePath(test_url, &local_path)) |
70 *current_working_directory = local_path.DirName(); | 70 *current_working_directory = local_path.DirName(); |
71 else | 71 else |
72 file_util::GetCurrentDirectory(current_working_directory); | 72 file_util::GetCurrentDirectory(current_working_directory); |
73 } | 73 } |
74 return test_url; | 74 return test_url; |
75 } | 75 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 #endif | 135 #endif |
136 | 136 |
137 while (GetNextTest(args, &command_line_position, &test_string)) { | 137 while (GetNextTest(args, &command_line_position, &test_string)) { |
138 if (test_string.empty()) | 138 if (test_string.empty()) |
139 continue; | 139 continue; |
140 if (test_string == "QUIT") | 140 if (test_string == "QUIT") |
141 break; | 141 break; |
142 | 142 |
143 bool enable_pixel_dumps; | 143 bool enable_pixel_dumps; |
144 std::string pixel_hash; | 144 std::string pixel_hash; |
145 FilePath cwd; | 145 base::FilePath cwd; |
146 GURL test_url = GetURLForLayoutTest( | 146 GURL test_url = GetURLForLayoutTest( |
147 test_string, &cwd, &enable_pixel_dumps, &pixel_hash); | 147 test_string, &cwd, &enable_pixel_dumps, &pixel_hash); |
148 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( | 148 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( |
149 test_url, cwd, enable_pixel_dumps, pixel_hash)) { | 149 test_url, cwd, enable_pixel_dumps, pixel_hash)) { |
150 break; | 150 break; |
151 } | 151 } |
152 | 152 |
153 ran_at_least_once = true; | 153 ran_at_least_once = true; |
154 main_runner_->Run(); | 154 main_runner_->Run(); |
155 | 155 |
156 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) | 156 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) |
157 break; | 157 break; |
158 } | 158 } |
159 if (!ran_at_least_once) { | 159 if (!ran_at_least_once) { |
160 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 160 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
161 main_runner_->Run(); | 161 main_runner_->Run(); |
162 } | 162 } |
163 exit_code = 0; | 163 exit_code = 0; |
164 } else { | 164 } else { |
165 exit_code = main_runner_->Run(); | 165 exit_code = main_runner_->Run(); |
166 } | 166 } |
167 | 167 |
168 main_runner_->Shutdown(); | 168 main_runner_->Shutdown(); |
169 | 169 |
170 return exit_code; | 170 return exit_code; |
171 } | 171 } |
OLD | NEW |