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" |
| 11 #include "base/file_util.h" |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/sys_string_conversions.h" |
12 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
13 #include "content/public/browser/browser_main_runner.h" | 16 #include "content/public/browser/browser_main_runner.h" |
14 #include "content/shell/shell_switches.h" | 17 #include "content/shell/shell_switches.h" |
15 #include "content/shell/webkit_test_runner_host.h" | 18 #include "content/shell/webkit_test_runner_host.h" |
| 19 #include "net/base/net_util.h" |
16 #include "webkit/support/webkit_support.h" | 20 #include "webkit/support/webkit_support.h" |
17 | 21 |
18 namespace { | 22 namespace { |
19 | 23 |
20 GURL GetURLForLayoutTest(const char* test_name, | 24 GURL GetURLForLayoutTest(const char* test_name, |
21 bool* enable_pixel_dumping, | 25 bool* enable_pixel_dumping, |
22 std::string* expected_pixel_hash) { | 26 std::string* expected_pixel_hash) { |
23 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash | 27 // A test name is formated like file:///path/to/test'--pixel-test'pixelhash |
24 std::string path_or_url = test_name; | 28 std::string path_or_url = test_name; |
25 std::string pixel_switch; | 29 std::string pixel_switch; |
26 std::string pixel_hash; | 30 std::string pixel_hash; |
27 std::string::size_type separator_position = path_or_url.find('\''); | 31 std::string::size_type separator_position = path_or_url.find('\''); |
28 if (separator_position != std::string::npos) { | 32 if (separator_position != std::string::npos) { |
29 pixel_switch = path_or_url.substr(separator_position + 1); | 33 pixel_switch = path_or_url.substr(separator_position + 1); |
30 path_or_url.erase(separator_position); | 34 path_or_url.erase(separator_position); |
31 } | 35 } |
32 separator_position = pixel_switch.find('\''); | 36 separator_position = pixel_switch.find('\''); |
33 if (separator_position != std::string::npos) { | 37 if (separator_position != std::string::npos) { |
34 pixel_hash = pixel_switch.substr(separator_position + 1); | 38 pixel_hash = pixel_switch.substr(separator_position + 1); |
35 pixel_switch.erase(separator_position); | 39 pixel_switch.erase(separator_position); |
36 } | 40 } |
37 if (enable_pixel_dumping) { | 41 if (enable_pixel_dumping) { |
38 *enable_pixel_dumping = | 42 *enable_pixel_dumping = |
39 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); | 43 (pixel_switch == "--pixel-test" || pixel_switch == "-p"); |
40 } | 44 } |
41 if (expected_pixel_hash) | 45 if (expected_pixel_hash) |
42 *expected_pixel_hash = pixel_hash; | 46 *expected_pixel_hash = pixel_hash; |
43 GURL test_url = webkit_support::CreateURLForPathOrURL(path_or_url); | 47 GURL test_url(path_or_url); |
44 { | 48 if (!(test_url.is_valid() && test_url.has_scheme())) { |
| 49 #if defined(OS_WIN) |
| 50 std::wstring wide_path_or_url = |
| 51 base::SysNativeMBToWide(path_or_url); |
| 52 test_url = net::FilePathToFileURL(FilePath(wide_path_or_url)); |
| 53 #else |
| 54 test_url = net::FilePathToFileURL(FilePath(path_or_url)); |
| 55 #endif |
| 56 } |
| 57 FilePath local_path; |
| 58 if (net::FileURLToFilePath(test_url, &local_path)) { |
45 // We're outside of the message loop here, and this is a test. | 59 // We're outside of the message loop here, and this is a test. |
46 base::ThreadRestrictions::ScopedAllowIO allow_io; | 60 base::ThreadRestrictions::ScopedAllowIO allow_io; |
47 webkit_support::SetCurrentDirectoryForFileURL(test_url); | 61 file_util::SetCurrentDirectory(local_path.DirName()); |
48 } | 62 } |
49 return test_url; | 63 return test_url; |
50 } | 64 } |
51 | 65 |
52 } // namespace | 66 } // namespace |
53 | 67 |
54 // Main routine for running as the Browser process. | 68 // Main routine for running as the Browser process. |
55 int ShellBrowserMain(const content::MainFunctionParams& parameters) { | 69 int ShellBrowserMain(const content::MainFunctionParams& parameters) { |
56 scoped_ptr<content::BrowserMainRunner> main_runner_( | 70 scoped_ptr<content::BrowserMainRunner> main_runner_( |
57 content::BrowserMainRunner::Create()); | 71 content::BrowserMainRunner::Create()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 117 } |
104 exit_code = 0; | 118 exit_code = 0; |
105 } else { | 119 } else { |
106 exit_code = main_runner_->Run(); | 120 exit_code = main_runner_->Run(); |
107 } | 121 } |
108 | 122 |
109 main_runner_->Shutdown(); | 123 main_runner_->Shutdown(); |
110 | 124 |
111 return exit_code; | 125 return exit_code; |
112 } | 126 } |
OLD | NEW |