Commit e1cf85a2 authored by jam@chromium.org's avatar jam@chromium.org

Make content_browsertests support restarts across a test.

BUG=90448
Review URL: https://chromiumcodereview.appspot.com/10855231

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152174 0039d316-1c4b-4281-b951-d872f2087c98
parent 53b98655
......@@ -10,7 +10,6 @@
#include "base/logging.h"
#include "base/memory/linked_ptr.h"
#include "base/run_loop.h"
#include "base/scoped_temp_dir.h"
#include "base/test/test_file_util.h"
#include "chrome/app/chrome_main_delegate.h"
#include "chrome/common/chrome_switches.h"
......@@ -78,7 +77,7 @@ class ChromeTestLauncherDelegate : public test_launcher::TestLauncherDelegate {
}
virtual bool AdjustChildProcessCommandLine(
CommandLine* command_line) OVERRIDE {
CommandLine* command_line, const FilePath& temp_data_dir) OVERRIDE {
CommandLine new_command_line(command_line->GetProgram());
CommandLine::SwitchMap switches = command_line->GetSwitches();
......@@ -90,20 +89,7 @@ class ChromeTestLauncherDelegate : public test_launcher::TestLauncherDelegate {
new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
}
// Clean up previous temp dir.
// We Take() the directory and delete it ourselves so that the next
// CreateUniqueTempDir will succeed even if deleting the directory fails.
if (!temp_dir_.path().empty() &&
!file_util::DieFileDie(temp_dir_.Take(), true)) {
LOG(ERROR) << "Error deleting previous temp profile directory";
}
// Create a new user data dir and pass it to the child.
if (!temp_dir_.CreateUniqueTempDir() || !temp_dir_.IsValid()) {
LOG(ERROR) << "Error creating temp profile directory";
return false;
}
new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_dir_.path());
new_command_line.AppendSwitchPath(switches::kUserDataDir, temp_data_dir);
// file:// access for ChromeOS.
new_command_line.AppendSwitch(switches::kAllowFileAccess);
......@@ -133,8 +119,6 @@ class ChromeTestLauncherDelegate : public test_launcher::TestLauncherDelegate {
}
private:
ScopedTempDir temp_dir_;
#if !defined(USE_AURA) && defined(TOOLKIT_VIEWS)
std::stack<linked_ptr<views::AcceleratorHandler> > handlers_;
#endif
......
......@@ -61,6 +61,10 @@ const char kPreTestPrefix[] = "PRE_";
// add a new binary that must be compiled on all builds.
const char kManualTestPrefix[] = "MANUAL_";
// Tests with this suffix are expected to crash, so it won't count as a failure.
// A test that uses this must have a PRE_ prefix.
const char kCrashTestSuffix[] = "_CRASH";
TestLauncherDelegate* g_launcher_delegate;
}
......@@ -331,8 +335,10 @@ int RunTestInternal(const testing::TestCase* test_case,
if (cur_test_name == pre_test_name) {
int exit_code = RunTestInternal(test_case, pre_test_name, command_line,
default_timeout, was_timeout);
if (exit_code != 0)
if (exit_code != 0 &&
!EndsWith(pre_test_name, kCrashTestSuffix, true)) {
return exit_code;
}
}
}
}
......@@ -440,8 +446,17 @@ int RunTest(TestLauncherDelegate* launcher_delegate,
// failure status back to the parent.
new_cmd_line.AppendSwitch(base::TestSuite::kStrictFailureHandling);
if (!launcher_delegate->AdjustChildProcessCommandLine(&new_cmd_line))
ScopedTempDir temp_dir;
// Create a new data dir and pass it to the child.
if (!temp_dir.CreateUniqueTempDir() || !temp_dir.IsValid()) {
LOG(ERROR) << "Error creating temp data directory";
return -1;
}
if (!launcher_delegate->AdjustChildProcessCommandLine(&new_cmd_line,
temp_dir.path())) {
return -1;
}
return RunTestInternal(
test_case, test_name, &new_cmd_line, default_timeout, was_timeout);
......
......@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
class CommandLine;
class FilePath;
namespace base {
class RunLoop;
......@@ -38,7 +39,8 @@ class TestLauncherDelegate {
virtual std::string GetEmptyTestName() = 0;
virtual bool Run(int argc, char** argv, int* return_code) = 0;
virtual int RunTestSuite(int argc, char** argv) = 0;
virtual bool AdjustChildProcessCommandLine(CommandLine* command_line) = 0;
virtual bool AdjustChildProcessCommandLine(CommandLine* command_line,
const FilePath& temp_data_dir) = 0;
virtual void PreRunMessageLoop(base::RunLoop* run_loop) {}
virtual void PostRunMessageLoop() {}
......
......@@ -41,12 +41,15 @@ ShellBrowserContext::~ShellBrowserContext() {
void ShellBrowserContext::InitWhileIOAllowed() {
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kContentBrowserTest) ||
cmd_line->HasSwitch(switches::kDumpRenderTree)) {
if (cmd_line->HasSwitch(switches::kDumpRenderTree)) {
CHECK(testing_path_.CreateUniqueTempDir());
path_ = testing_path_.path();
return;
}
if (cmd_line->HasSwitch(switches::kContentShellDataPath)) {
path_ = cmd_line->GetSwitchValuePath(switches::kContentShellDataPath);
return;
}
#if defined(OS_WIN)
CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &path_));
path_ = path_.Append(std::wstring(L"content_shell"));
......
......@@ -12,6 +12,9 @@ const char kCheckLayoutTestSysDeps[] = "check-layout-test-sys-deps";
// Tells Content Shell that it's running as a content_browsertest.
const char kContentBrowserTest[] = "browser-test";
// Makes Content Shell use the given path for its data directory.
const char kContentShellDataPath[] = "data-path";
// Request pages to be dumped as text once they finished loading.
const char kDumpRenderTree[] = "dump-render-tree";
......
......@@ -11,6 +11,7 @@ namespace switches {
extern const char kCheckLayoutTestSysDeps[];
extern const char kContentBrowserTest[];
extern const char kContentShellDataPath[];
extern const char kDumpRenderTree[];
extern const char kNoTimeout[];
......
......@@ -8,7 +8,6 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/scoped_temp_dir.h"
#include "base/test/test_suite.h"
#include "content/public/app/content_main.h"
#include "content/public/common/content_switches.h"
......@@ -16,6 +15,7 @@
#include "content/shell/shell_content_browser_client.h"
#include "content/shell/shell_content_client.h"
#include "content/shell/shell_main_delegate.h"
#include "content/shell/shell_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#if defined(OS_WIN)
......@@ -121,7 +121,9 @@ class ContentTestLauncherDelegate : public test_launcher::TestLauncherDelegate {
}
virtual bool AdjustChildProcessCommandLine(
CommandLine* command_line) OVERRIDE {
CommandLine* command_line, const FilePath& temp_data_dir) OVERRIDE {
command_line->AppendSwitchPath(switches::kContentShellDataPath,
temp_data_dir);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment