Skip to content

Commit

Permalink
[content shell] add support for getting tests from the command line.
Browse files Browse the repository at this point in the history
Related to this, parse a single dash on the command line as argument, instead of a switch with no value and name

BUG=111316
TEST=out/Debug/content_shell --dump-render-tree path/to/test.html works


Review URL: https://chromiumcodereview.appspot.com/11184050

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@162947 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jochen@chromium.org committed Oct 19, 2012
1 parent cd44bd3 commit 21e342f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion base/command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ bool IsSwitch(const CommandLine::StringType& string,
CommandLine::StringType* switch_value) {
switch_string->clear();
switch_value->clear();
if (GetSwitchPrefixLength(string) == 0)
size_t prefix_length = GetSwitchPrefixLength(string);
if (prefix_length == 0 || prefix_length == string.length())
return false;

const size_t equals_position = string.find(kSwitchValueSeparator);
Expand Down
5 changes: 4 additions & 1 deletion base/command_line_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TEST(CommandLineTest, CommandLineConstructor) {
FILE_PATH_LITERAL("--other-switches=--dog=canine --cat=feline"),
FILE_PATH_LITERAL("-spaetzle=Crepe"),
FILE_PATH_LITERAL("-=loosevalue"),
FILE_PATH_LITERAL("-"),
FILE_PATH_LITERAL("FLAN"),
FILE_PATH_LITERAL("a"),
FILE_PATH_LITERAL("--input-translation=45--output-rotation"),
Expand Down Expand Up @@ -75,11 +76,13 @@ TEST(CommandLineTest, CommandLineConstructor) {
EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));

const CommandLine::StringVector& args = cl.GetArgs();
ASSERT_EQ(7U, args.size());
ASSERT_EQ(8U, args.size());

std::vector<CommandLine::StringType>::const_iterator iter = args.begin();
EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter);
++iter;
EXPECT_EQ(FILE_PATH_LITERAL("-"), *iter);
++iter;
EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter);
++iter;
EXPECT_EQ(FILE_PATH_LITERAL("a"), *iter);
Expand Down
32 changes: 24 additions & 8 deletions content/shell/shell_browser_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/sys_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "base/utf_string_conversions.h"
#include "content/public/browser/browser_main_runner.h"
#include "content/shell/shell_switches.h"
#include "content/shell/webkit_test_runner_host.h"
Expand All @@ -21,7 +22,7 @@

namespace {

GURL GetURLForLayoutTest(const char* test_name,
GURL GetURLForLayoutTest(const std::string& test_name,
bool* enable_pixel_dumping,
std::string* expected_pixel_hash) {
// A test name is formated like file:///path/to/test'--pixel-test'pixelhash
Expand Down Expand Up @@ -63,6 +64,21 @@ GURL GetURLForLayoutTest(const char* test_name,
return test_url;
}

bool GetNextTest(const 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 = WideToUTF8(args[(*position)++]);
#else
*test = args[(*position)++];
#endif
return true;
}

} // namespace

// Main routine for running as the Browser process.
Expand All @@ -85,20 +101,20 @@ int ShellBrowserMain(const content::MainFunctionParams& parameters) {

if (layout_test_mode) {
content::WebKitTestController test_controller;
std::string test_string;
CommandLine::StringVector args =
CommandLine::ForCurrentProcess()->GetArgs();
size_t command_line_position = 0;

char test_string[2048];
#if defined(OS_ANDROID)
std::cout << "#READY\n";
std::cout.flush();
#endif

while (fgets(test_string, sizeof(test_string), stdin)) {
char *new_line_position = strchr(test_string, '\n');
if (new_line_position)
*new_line_position = '\0';
if (test_string[0] == '\0')
while (GetNextTest(args, &command_line_position, &test_string)) {
if (test_string.empty())
continue;
if (!strcmp(test_string, "QUIT"))
if (test_string == "QUIT")
break;

bool enable_pixel_dumps;
Expand Down

0 comments on commit 21e342f

Please sign in to comment.