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