Commit 2d57f5d0 authored by cbentzel@chromium.org's avatar cbentzel@chromium.org

Added WARN_UNUSED_RESULT to ScopedTempDir methods.

BUG=NONE
TEST=all targets build, tests pass.

Review URL: http://codereview.chromium.org/6042009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71322 0039d316-1c4b-4281-b951-d872f2087c98
parent 7a0c14d1
......@@ -28,17 +28,17 @@ class ScopedTempDir {
// Creates a unique directory in TempPath, and takes ownership of it.
// See file_util::CreateNewTemporaryDirectory.
bool CreateUniqueTempDir();
bool CreateUniqueTempDir() WARN_UNUSED_RESULT;
// Creates a unique directory under a given path, and takes ownership of it.
bool CreateUniqueTempDirUnderPath(const FilePath& path);
bool CreateUniqueTempDirUnderPath(const FilePath& path) WARN_UNUSED_RESULT;
// Takes ownership of directory at |path|, creating it if necessary.
// Don't call multiple times unless Take() has been called first.
bool Set(const FilePath& path);
bool Set(const FilePath& path) WARN_UNUSED_RESULT;
// Deletes the temporary directory wrapped by this object.
bool Delete();
bool Delete() WARN_UNUSED_RESULT;
// Caller takes ownership of the temporary directory so it won't be destroyed
// when this object goes out of scope.
......
......@@ -23,7 +23,7 @@ TEST(ScopedTempDir, FullPath) {
{
ScopedTempDir dir;
dir.Set(test_path);
EXPECT_TRUE(dir.Set(test_path));
// Now the dir doesn't exist, so ensure that it gets created.
EXPECT_TRUE(file_util::DirectoryExists(test_path));
// When we call Release(), it shouldn't get destroyed when leaving scope.
......@@ -36,7 +36,7 @@ TEST(ScopedTempDir, FullPath) {
// Clean up.
{
ScopedTempDir dir;
dir.Set(test_path);
EXPECT_TRUE(dir.Set(test_path));
}
EXPECT_FALSE(file_util::DirectoryExists(test_path));
}
......@@ -83,7 +83,7 @@ TEST(ScopedTempDir, MultipleInvocations) {
EXPECT_TRUE(dir.CreateUniqueTempDir());
EXPECT_FALSE(dir.CreateUniqueTempDir());
ScopedTempDir other_dir;
other_dir.Set(dir.Take());
EXPECT_TRUE(other_dir.Set(dir.Take()));
EXPECT_TRUE(dir.CreateUniqueTempDir());
EXPECT_FALSE(dir.CreateUniqueTempDir());
EXPECT_FALSE(other_dir.CreateUniqueTempDir());
......
......@@ -110,7 +110,7 @@ TEST(ExtensionFromWebApp, Basic) {
ASSERT_TRUE(extension.get());
ScopedTempDir extension_dir;
extension_dir.Set(extension->path());
EXPECT_TRUE(extension_dir.Set(extension->path()));
EXPECT_TRUE(extension->is_app());
EXPECT_TRUE(extension->is_hosted_app());
......@@ -153,7 +153,7 @@ TEST(ExtensionFromWebApp, Minimal) {
ASSERT_TRUE(extension.get());
ScopedTempDir extension_dir;
extension_dir.Set(extension->path());
EXPECT_TRUE(extension_dir.Set(extension->path()));
EXPECT_TRUE(extension->is_app());
EXPECT_TRUE(extension->is_hosted_app());
......
......@@ -20,6 +20,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WebSocket) {
PathService::Get(chrome::DIR_TEST_DATA, &websocket_root_dir);
websocket_root_dir = websocket_root_dir.AppendASCII("layout_tests")
.AppendASCII("LayoutTests");
ui_test_utils::TestWebSocketServer server(websocket_root_dir);
ui_test_utils::TestWebSocketServer server;
ASSERT_TRUE(server.Start(websocket_root_dir));
ASSERT_TRUE(RunExtensionTest("websocket")) << message_;
}
......@@ -100,16 +100,18 @@ class SandboxedExtensionUnpackerTest : public testing::Test {
// Hack since SandboxedExtensionUnpacker gets its background thread id from
// the Start call, but we don't call it here.
sandboxed_unpacker_->thread_identifier_ = BrowserThread::FILE;
PrepareUnpackerEnv();
EXPECT_TRUE(PrepareUnpackerEnv());
}
void PrepareUnpackerEnv() {
bool PrepareUnpackerEnv() {
sandboxed_unpacker_->extension_root_ =
install_dir_.AppendASCII(extension_filenames::kTempExtensionName);
sandboxed_unpacker_->temp_dir_.Set(install_dir_);
if (!sandboxed_unpacker_->temp_dir_.Set(install_dir_))
return false;
sandboxed_unpacker_->public_key_ =
"ocnapchkplbmjmpfehjocmjnipfmogkh";
return true;
}
void OnUnpackSucceeded() {
......
......@@ -951,7 +951,8 @@ bool ProcessSingleton::Create() {
// We've already locked things, so we can't have lost the startup race,
// but something doesn't like us.
LOG(ERROR) << "Failed to create symlinks.";
socket_dir_.Delete();
if (!socket_dir_.Delete())
LOG(ERROR) << "Encountered a problem when deleting socket directory.";
return false;
}
......
......@@ -25,8 +25,7 @@ class ProcessSingletonMacTest : public PlatformTest {
// Put the lock in a temporary directory. Doesn't need to be a
// full profile to test this code.
temp_dir_.CreateUniqueTempDir();
ASSERT_TRUE(temp_dir_.IsValid());
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
lock_path_ = temp_dir_.path().Append(chrome::kSingletonLockFilename);
}
......
......@@ -136,7 +136,7 @@ class ProcessSingletonTest : public UITest {
// We use a manual reset so that all threads wake up at once when signaled
// and thus we must manually reset it for each attempt.
: threads_waker_(true /* manual */, false /* signaled */) {
temp_profile_dir_.CreateUniqueTempDir();
EXPECT_TRUE(temp_profile_dir_.CreateUniqueTempDir());
}
void SetUp() {
......
......@@ -198,7 +198,8 @@ void ServiceUtilityProcessHost::Client::MetafileAvailable(
// The metafile was created in a temp folder which needs to get deleted after
// we have processed it.
ScopedTempDir scratch_metafile_dir;
scratch_metafile_dir.Set(metafile_path.DirName());
if (!scratch_metafile_dir.Set(metafile_path.DirName()))
LOG(WARNING) << "Unable to set scratch metafile directory";
#if defined(OS_WIN)
printing::NativeMetafile metafile;
if (!metafile.CreateFromFile(metafile_path)) {
......
......@@ -1575,8 +1575,10 @@ class AutomationProxySnapshotTest : public UITest {
protected:
AutomationProxySnapshotTest() {
dom_automation_enabled_ = true;
snapshot_dir_.CreateUniqueTempDir();
snapshot_path_ = snapshot_dir_.path().AppendASCII("snapshot.png");
if (!snapshot_dir_.CreateUniqueTempDir())
ADD_FAILURE() << "Unable to create temporary directory";
else
snapshot_path_ = snapshot_dir_.path().AppendASCII("snapshot.png");
}
// Asserts that the given png file can be read and decoded into the given
......
......@@ -161,7 +161,8 @@ void ProxyLauncher::CloseBrowserAndServer(ShutdownType shutdown_type) {
void ProxyLauncher::LaunchBrowser(const LaunchState& state) {
if (state.clear_profile || !temp_profile_dir_.IsValid()) {
temp_profile_dir_.Delete();
if (temp_profile_dir_.IsValid())
ASSERT_TRUE(temp_profile_dir_.Delete());
ASSERT_TRUE(temp_profile_dir_.CreateUniqueTempDir());
ASSERT_TRUE(test_launcher_utils::OverrideUserDataDir(user_data_dir()));
......
......@@ -799,17 +799,30 @@ void AppendToPythonPath(const FilePath& dir) {
} // anonymous namespace
TestWebSocketServer::TestWebSocketServer(const FilePath& root_directory) {
TestWebSocketServer::TestWebSocketServer() : started_(false) {
}
bool TestWebSocketServer::Start(const FilePath& root_directory) {
if (started_)
return true;
scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
cmd_line->AppendSwitchASCII("server", "start");
cmd_line->AppendSwitch("chromium");
cmd_line->AppendSwitch("register_cygwin");
cmd_line->AppendSwitchPath("root", root_directory);
temp_dir_.CreateUniqueTempDir();
if (!temp_dir_.CreateUniqueTempDir()) {
LOG(ERROR) << "Unable to create a temporary directory.";
return false;
}
websocket_pid_file_ = temp_dir_.path().AppendASCII("websocket.pid");
cmd_line->AppendSwitchPath("pidfile", websocket_pid_file_);
SetPythonPath();
base::LaunchApp(*cmd_line.get(), true, false, NULL);
if (!base::LaunchApp(*cmd_line.get(), true, false, NULL)) {
LOG(ERROR) << "Unable to launch websocket server.";
return false;
}
started_ = true;
return true;
}
CommandLine* TestWebSocketServer::CreatePythonCommandLine() {
......@@ -846,6 +859,8 @@ CommandLine* TestWebSocketServer::CreateWebSocketServerCommandLine() {
}
TestWebSocketServer::~TestWebSocketServer() {
if (!started_)
return;
scoped_ptr<CommandLine> cmd_line(CreateWebSocketServerCommandLine());
cmd_line->AppendSwitchASCII("server", "stop");
cmd_line->AppendSwitch("chromium");
......
......@@ -321,12 +321,15 @@ class TimedMessageLoopRunner {
// server.
class TestWebSocketServer {
public:
// Creates and starts a python websocket server with |root_directory|.
explicit TestWebSocketServer(const FilePath& root_directory);
TestWebSocketServer();
// Destroys and stops the server.
// Stops the python websocket server if it was already started.
~TestWebSocketServer();
// Starts the python websocket server using |root_directory|. Returns whether
// the server was successfully started.
bool Start(const FilePath& root_directory);
private:
// Sets up PYTHONPATH to run websocket_server.py.
void SetPythonPath();
......@@ -337,6 +340,9 @@ class TestWebSocketServer {
// Creates a CommandLine for invoking the python websocker server.
CommandLine* CreateWebSocketServerCommandLine();
// Has the server been started?
bool started_;
// A Scoped temporary directory for holding the python pid file.
ScopedTempDir temp_dir_;
......
......@@ -468,7 +468,8 @@ TEST_F(WorkerTest, WorkerWebSocketLayoutTests) {
FilePath websocket_root_dir(temp_test_dir_);
websocket_root_dir = websocket_root_dir.AppendASCII("LayoutTests");
ui_test_utils::TestWebSocketServer websocket_server(websocket_root_dir);
ui_test_utils::TestWebSocketServer websocket_server;
ASSERT_TRUE(websocket_server.Start(websocket_root_dir));
StartHttpServer(new_http_root_dir_);
for (size_t i = 0; i < arraysize(kLayoutTestFiles); ++i)
......
......@@ -27,8 +27,7 @@ class FileSystemOperationTest : public testing::Test {
public:
FileSystemOperationTest()
: status_(kFileOperationStatusNotSet) {
base_.CreateUniqueTempDir();
EXPECT_TRUE(base_.IsValid());
EXPECT_TRUE(base_.CreateUniqueTempDir());
}
FileSystemOperation* operation();
......
......@@ -165,8 +165,7 @@ class FileSystemPathManagerTest : public testing::Test {
void SetUp() {
data_dir_.reset(new ScopedTempDir);
data_dir_->CreateUniqueTempDir();
ASSERT_TRUE(data_dir_->IsValid());
ASSERT_TRUE(data_dir_->CreateUniqueTempDir());
root_path_callback_status_ = false;
root_path_.clear();
file_system_name_.clear();
......
......@@ -28,7 +28,7 @@ SimpleDatabaseSystem* SimpleDatabaseSystem::GetInstance() {
SimpleDatabaseSystem::SimpleDatabaseSystem()
: waiting_for_dbs_to_close_(false) {
temp_dir_.CreateUniqueTempDir();
CHECK(temp_dir_.CreateUniqueTempDir());
db_tracker_ = new DatabaseTracker(temp_dir_.path(), false);
db_tracker_->AddObserver(this);
DCHECK(!instance_);
......
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