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 "content/public/browser/browser_main_runner.h" | 16 #include "content/public/browser/browser_main_runner.h" |
17 #include "content/shell/shell_switches.h" | 17 #include "content/shell/shell_switches.h" |
18 #include "content/shell/webkit_test_runner_host.h" | 18 #include "content/shell/webkit_test_runner_host.h" |
19 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
20 #include "webkit/support/webkit_support.h" | 20 #include "webkit/support/webkit_support.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 GURL GetURLForLayoutTest(const char* test_name, | 24 GURL GetURLForLayoutTest(const std::string& test_name, |
25 bool* enable_pixel_dumping, | 25 bool* enable_pixel_dumping, |
26 std::string* expected_pixel_hash) { | 26 std::string* expected_pixel_hash) { |
27 // 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 |
28 std::string path_or_url = test_name; | 28 std::string path_or_url = test_name; |
29 std::string pixel_switch; | 29 std::string pixel_switch; |
30 std::string pixel_hash; | 30 std::string pixel_hash; |
31 std::string::size_type separator_position = path_or_url.find('\''); | 31 std::string::size_type separator_position = path_or_url.find('\''); |
32 if (separator_position != std::string::npos) { | 32 if (separator_position != std::string::npos) { |
33 pixel_switch = path_or_url.substr(separator_position + 1); | 33 pixel_switch = path_or_url.substr(separator_position + 1); |
34 path_or_url.erase(separator_position); | 34 path_or_url.erase(separator_position); |
(...skipping 21 matching lines...) Expand all Loading... | |
56 } | 56 } |
57 FilePath local_path; | 57 FilePath local_path; |
58 if (net::FileURLToFilePath(test_url, &local_path)) { | 58 if (net::FileURLToFilePath(test_url, &local_path)) { |
59 // 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. |
60 base::ThreadRestrictions::ScopedAllowIO allow_io; | 60 base::ThreadRestrictions::ScopedAllowIO allow_io; |
61 file_util::SetCurrentDirectory(local_path.DirName()); | 61 file_util::SetCurrentDirectory(local_path.DirName()); |
62 } | 62 } |
63 return test_url; | 63 return test_url; |
64 } | 64 } |
65 | 65 |
66 bool GetNextTest(const CommandLine::StringVector& args, std::string* test) { | |
67 static size_t pos = 0; | |
marja
2012/10/18 20:53:57
Uhh, can you make pos an in-out parameter instead.
jochen (gone - plz use gerrit)
2012/10/18 21:06:42
Done.
| |
68 if (pos >= args.size()) | |
69 return false; | |
70 if (args[pos] == FILE_PATH_LITERAL("-")) | |
71 return std::getline(std::cin, *test, '\n'); | |
72 #if defined(OS_WIN) | |
73 *test = WideToUTF8(args[pos++]); | |
74 #else | |
75 *test = args[pos++]; | |
76 #endif | |
77 return true; | |
78 } | |
79 | |
66 } // namespace | 80 } // namespace |
67 | 81 |
68 // Main routine for running as the Browser process. | 82 // Main routine for running as the Browser process. |
69 int ShellBrowserMain(const content::MainFunctionParams& parameters) { | 83 int ShellBrowserMain(const content::MainFunctionParams& parameters) { |
70 scoped_ptr<content::BrowserMainRunner> main_runner_( | 84 scoped_ptr<content::BrowserMainRunner> main_runner_( |
71 content::BrowserMainRunner::Create()); | 85 content::BrowserMainRunner::Create()); |
72 | 86 |
73 int exit_code = main_runner_->Initialize(parameters); | 87 int exit_code = main_runner_->Initialize(parameters); |
74 | 88 |
75 if (exit_code >= 0) | 89 if (exit_code >= 0) |
76 return exit_code; | 90 return exit_code; |
77 | 91 |
78 if (CommandLine::ForCurrentProcess()->HasSwitch( | 92 if (CommandLine::ForCurrentProcess()->HasSwitch( |
79 switches::kCheckLayoutTestSysDeps)) { | 93 switches::kCheckLayoutTestSysDeps)) { |
80 return 0; | 94 return 0; |
81 } | 95 } |
82 | 96 |
83 bool layout_test_mode = | 97 bool layout_test_mode = |
84 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); | 98 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree); |
85 | 99 |
86 if (layout_test_mode) { | 100 if (layout_test_mode) { |
87 content::WebKitTestController test_controller; | 101 content::WebKitTestController test_controller; |
102 std::string test_string; | |
103 CommandLine::StringVector args = | |
104 CommandLine::ForCurrentProcess()->GetArgs(); | |
88 | 105 |
89 char test_string[2048]; | |
90 #if defined(OS_ANDROID) | 106 #if defined(OS_ANDROID) |
91 std::cout << "#READY\n"; | 107 std::cout << "#READY\n"; |
92 std::cout.flush(); | 108 std::cout.flush(); |
93 #endif | 109 #endif |
94 | 110 |
95 while (fgets(test_string, sizeof(test_string), stdin)) { | 111 while (GetNextTest(args, &test_string)) { |
96 char *new_line_position = strchr(test_string, '\n'); | 112 if (test_string.empty()) |
97 if (new_line_position) | |
98 *new_line_position = '\0'; | |
99 if (test_string[0] == '\0') | |
100 continue; | 113 continue; |
101 if (!strcmp(test_string, "QUIT")) | 114 if (test_string == "QUIT") |
102 break; | 115 break; |
103 | 116 |
104 bool enable_pixel_dumps; | 117 bool enable_pixel_dumps; |
105 std::string pixel_hash; | 118 std::string pixel_hash; |
106 GURL test_url = GetURLForLayoutTest( | 119 GURL test_url = GetURLForLayoutTest( |
107 test_string, &enable_pixel_dumps, &pixel_hash); | 120 test_string, &enable_pixel_dumps, &pixel_hash); |
108 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( | 121 if (!content::WebKitTestController::Get()->PrepareForLayoutTest( |
109 test_url, enable_pixel_dumps, pixel_hash)) { | 122 test_url, enable_pixel_dumps, pixel_hash)) { |
110 break; | 123 break; |
111 } | 124 } |
112 | 125 |
113 main_runner_->Run(); | 126 main_runner_->Run(); |
114 | 127 |
115 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) | 128 if (!content::WebKitTestController::Get()->ResetAfterLayoutTest()) |
116 break; | 129 break; |
117 } | 130 } |
118 exit_code = 0; | 131 exit_code = 0; |
119 } else { | 132 } else { |
120 exit_code = main_runner_->Run(); | 133 exit_code = main_runner_->Run(); |
121 } | 134 } |
122 | 135 |
123 main_runner_->Shutdown(); | 136 main_runner_->Shutdown(); |
124 | 137 |
125 return exit_code; | 138 return exit_code; |
126 } | 139 } |
OLD | NEW |