Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(658)

Unified Diff: content/shell/browser/layout_test/layout_test_browser_main.cc

Issue 1312693007: test_runner: Add TestInfoExtractor to get the list of test-urls. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mandoline-layout-test-exp
Patch Set: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/shell/browser/layout_test/layout_test_browser_main.cc
diff --git a/content/shell/browser/layout_test/layout_test_browser_main.cc b/content/shell/browser/layout_test/layout_test_browser_main.cc
index ec347517324c260f1d80ed684a99959437e615dc..d1cefcfbe8ba5b96d465b97c6d58fd04f94335c4 100644
--- a/content/shell/browser/layout_test/layout_test_browser_main.cc
+++ b/content/shell/browser/layout_test/layout_test_browser_main.cc
@@ -18,6 +18,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread_restrictions.h"
+#include "components/test_runner/test_info_extractor.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/public/common/url_constants.h"
#include "content/shell/browser/blink_test_controller.h"
@@ -33,97 +34,12 @@
namespace {
-GURL GetURLForLayoutTest(const std::string& test_name,
- base::FilePath* current_working_directory,
- bool* enable_pixel_dumping,
- std::string* expected_pixel_hash) {
- // A test name is formated like file:///path/to/test'--pixel-test'pixelhash
- std::string path_or_url = test_name;
- std::string pixel_switch;
- std::string pixel_hash;
- std::string::size_type separator_position = path_or_url.find('\'');
- if (separator_position != std::string::npos) {
- pixel_switch = path_or_url.substr(separator_position + 1);
- path_or_url.erase(separator_position);
- }
- separator_position = pixel_switch.find('\'');
- if (separator_position != std::string::npos) {
- pixel_hash = pixel_switch.substr(separator_position + 1);
- pixel_switch.erase(separator_position);
- }
- if (enable_pixel_dumping) {
- *enable_pixel_dumping =
- (pixel_switch == "--pixel-test" || pixel_switch == "-p");
- }
- if (expected_pixel_hash)
- *expected_pixel_hash = pixel_hash;
-
- GURL test_url;
-#if defined(OS_ANDROID)
- if (content::GetTestUrlForAndroid(path_or_url, &test_url))
- return test_url;
-#endif
-
- test_url = GURL(path_or_url);
- if (!(test_url.is_valid() && test_url.has_scheme())) {
- // We're outside of the message loop here, and this is a test.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
-#if defined(OS_WIN)
- base::FilePath::StringType wide_path_or_url =
- base::SysNativeMBToWide(path_or_url);
- base::FilePath local_file(wide_path_or_url);
-#else
- base::FilePath local_file(path_or_url);
-#endif
- if (!base::PathExists(local_file)) {
- local_file = content::GetWebKitRootDirFilePath()
- .Append(FILE_PATH_LITERAL("LayoutTests"))
- .Append(local_file);
- }
- test_url = net::FilePathToFileURL(base::MakeAbsoluteFilePath(local_file));
- }
- base::FilePath local_path;
- if (current_working_directory) {
- // We're outside of the message loop here, and this is a test.
- base::ThreadRestrictions::ScopedAllowIO allow_io;
- if (net::FileURLToFilePath(test_url, &local_path))
- *current_working_directory = local_path.DirName();
- else
- base::GetCurrentDirectory(current_working_directory);
- }
- return test_url;
-}
-
-bool GetNextTest(const base::CommandLine::StringVector& args,
- size_t* position,
- std::string* test) {
- if (*position >= args.size())
- return false;
- if (args[*position] == FILE_PATH_LITERAL("-"))
- return !!std::getline(std::cin, *test, '\n');
-#if defined(OS_WIN)
- *test = base::WideToUTF8(args[(*position)++]);
-#else
- *test = args[(*position)++];
-#endif
- return true;
-}
-
-bool RunOneTest(const std::string& test_string,
+bool RunOneTest(const test_runner::TestInfo& test_info,
bool* ran_at_least_once,
const scoped_ptr<content::BrowserMainRunner>& main_runner) {
- if (test_string.empty())
- return true;
- if (test_string == "QUIT")
- return false;
-
- bool enable_pixel_dumps;
- std::string pixel_hash;
- base::FilePath cwd;
- GURL test_url =
- GetURLForLayoutTest(test_string, &cwd, &enable_pixel_dumps, &pixel_hash);
if (!content::BlinkTestController::Get()->PrepareForLayoutTest(
- test_url, cwd, enable_pixel_dumps, pixel_hash)) {
+ test_info.url, test_info.current_working_directory,
+ test_info.enable_pixel_dumping, test_info.expected_pixel_hash)) {
return false;
}
@@ -158,17 +74,16 @@ int RunTests(const scoped_ptr<content::BrowserMainRunner>& main_runner) {
base::GetTempDir(&temp_path);
test_controller.SetTempPath(temp_path);
}
- std::string test_string;
- base::CommandLine::StringVector args =
- base::CommandLine::ForCurrentProcess()->GetArgs();
- size_t command_line_position = 0;
- bool ran_at_least_once = false;
std::cout << "#READY\n";
std::cout.flush();
- while (GetNextTest(args, &command_line_position, &test_string)) {
- if (!RunOneTest(test_string, &ran_at_least_once, main_runner))
+ base::CommandLine::StringVector args =
+ base::CommandLine::ForCurrentProcess()->GetArgs();
+ test_runner::TestInfoExtractor test_extractor(args);
+ bool ran_at_least_once = false;
+ while (auto test_info = test_extractor.GetNextTest()) {
Ryan Sleevi 2015/09/10 17:48:04 More auto danger here
sadrul 2015/09/10 18:09:09 Done.
+ if (!RunOneTest(*test_info, &ran_at_least_once, main_runner))
break;
}
if (!ran_at_least_once) {

Powered by Google App Engine
This is Rietveld 408576698