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

Unified Diff: chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc

Issue 16097003: drive: Stop using FilePathWatcher from FileManagerBrowserTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 7 years, 7 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
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc
diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc
index 570e6f3c71b0b646663778365ebe5380d4c325ca..13313e128d1666274f99cbdf867912f642ea9de7 100644
--- a/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_browsertest.cc
@@ -14,12 +14,9 @@
#include "base/callback.h"
#include "base/file_util.h"
#include "base/files/file_path.h"
-#include "base/files/file_path_watcher.h"
-#include "base/run_loop.h"
#include "base/time.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h"
-#include "chrome/browser/chromeos/drive/file_system_observer.h"
#include "chrome/browser/chromeos/extensions/file_manager/drive_test_util.h"
#include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_apitest.h"
@@ -36,9 +33,6 @@
namespace {
-const char kKeyboardTestFileName[] = "world.ogv";
-const char kKeyboardTestFileCopyName[] = "world (1).ogv";
-
// Test suffixes appended to the Javascript tests' names.
const char kDownloadsVolume[] = "Downloads";
const char kDriveVolume[] = "Drive";
@@ -66,7 +60,7 @@ TestEntryInfo kTestEntrySetCommon[] = {
{ FILE, "text.txt", "hello.txt", "text/plain", NONE, "4 Sep 1998 12:34:56" },
{ FILE, "image.png", "My Desktop Background.png", "text/plain", NONE,
"18 Jan 2038 01:02:03" },
- { FILE, "video.ogv", kKeyboardTestFileName, "text/plain", NONE,
+ { FILE, "video.ogv", "world.ogv", "text/plain", NONE,
"4 July 2012 10:35:00" },
{ DIRECTORY, "", "photos", NULL, NONE, "1 Jan 1980 23:59:59" },
{ DIRECTORY, "", ".warez", NULL, NONE, "26 Oct 1985 13:39" }
@@ -79,115 +73,6 @@ TestEntryInfo kTestEntrySetDriveOnly[] = {
SHARED, "20 Mar 2013 22:40:00" }
};
-// Monitors changes to a single file until the supplied condition callback
-// returns true. Usage:
-// TestFilePathWatcher watcher(path_to_file, MyConditionCallback);
-// watcher.StartAndWaitUntilReady();
-// ... trigger filesystem modification ...
-// watcher.RunMessageLoopUntilConditionSatisfied();
-class TestFilePathWatcher {
- public:
- typedef base::Callback<bool(const base::FilePath& file_path)>
- ConditionCallback;
-
- // Stores the supplied |path| and |condition| for later use (no side effects).
- TestFilePathWatcher(const base::FilePath& path,
- const ConditionCallback& condition);
-
- // Waits (running a message pump) until the callback returns true or
- // FilePathWatcher reports an error. Return true on success.
- bool RunMessageLoopUntilConditionSatisfied();
-
- private:
- // Starts the FilePathWatcher to watch the target file. Also check if the
- // condition is already met.
- void StartWatching();
-
- // FilePathWatcher callback (on the FILE thread). Posts Done() to the UI
- // thread when the condition is satisfied or there is an error.
- void FilePathWatcherCallback(const base::FilePath& path, bool error);
-
- const base::FilePath path_;
- ConditionCallback condition_;
- scoped_ptr<base::FilePathWatcher> watcher_;
- base::RunLoop run_loop_;
- base::Closure quit_closure_;
- bool failed_;
-};
-
-TestFilePathWatcher::TestFilePathWatcher(const base::FilePath& path,
- const ConditionCallback& condition)
- : path_(path),
- condition_(condition),
- quit_closure_(run_loop_.QuitClosure()),
- failed_(false) {
-}
-
-void TestFilePathWatcher::StartWatching() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
-
- watcher_.reset(new base::FilePathWatcher);
- failed_ = !watcher_->Watch(
- path_, false /*recursive*/,
- base::Bind(&TestFilePathWatcher::FilePathWatcherCallback,
- base::Unretained(this)));
-
- // If failed to start the watcher, then quit the message loop immediately.
- // Also, if the condition was already met before FilePathWatcher was launched,
- // FilePathWatcher won't be able to detect a change, so check the condition
- // here.
- if (failed_ || condition_.Run(path_)) {
- watcher_.reset();
- content::BrowserThread::PostTask(content::BrowserThread::UI,
- FROM_HERE,
- quit_closure_);
- return;
- }
-}
-
-void TestFilePathWatcher::FilePathWatcherCallback(const base::FilePath& path,
- bool failed) {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
- DCHECK_EQ(path_.value(), path.value());
-
- if (failed || condition_.Run(path)) {
- failed_ = failed;
- watcher_.reset();
- content::BrowserThread::PostTask(content::BrowserThread::UI,
- FROM_HERE,
- quit_closure_);
- }
-}
-
-bool TestFilePathWatcher::RunMessageLoopUntilConditionSatisfied() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- content::BrowserThread::PostTask(
- content::BrowserThread::FILE,
- FROM_HERE,
- base::Bind(&TestFilePathWatcher::StartWatching,
- base::Unretained(this)));
-
- // Wait until the condition is met.
- run_loop_.Run();
- return !failed_;
-}
-
-// Returns true if a file with the given size is present at |path|.
-bool FilePresentWithSize(const int64 file_size,
- const base::FilePath& path) {
- int64 copy_size = 0;
- // If the file doesn't exist yet this will fail and we'll keep waiting.
- if (!file_util::GetFileSize(path, &copy_size))
- return false;
- return (copy_size == file_size);
-}
-
-// Returns true if a file is not present at |path|.
-bool FileNotPresent(const base::FilePath& path) {
- return !file_util::PathExists(path);
-};
-
// The base class of volumes for test.
// Sub-classes of this class are used by test cases and provide operations such
// as creating files for each type of test volume.
@@ -198,22 +83,8 @@ class TestVolume {
// Creates an entry with given information.
virtual void CreateEntry(const TestEntryInfo& entry) = 0;
- // Returns the path of the root directory.
- virtual base::FilePath GetRootPath() const = 0;
-
- // Returns true if |file_path| exists.
- virtual bool PathExists(const base::FilePath& file_path) const = 0;
-
// Returns the name of volume such as "Downloads" or "Drive".
virtual std::string GetName() const = 0;
-
- // Waits until a file with the given size is present at |path|. Returns
- // true on success.
- virtual bool WaitUntilFilePresentWithSize(const base::FilePath& file_path,
- int64 file_size) = 0;
-
- // Waits until a file is not present at |path|. Returns true on success.
- virtual bool WaitUntilFileNotPresent(const base::FilePath& file_path) = 0;
};
// The local volume class for test.
@@ -225,12 +96,6 @@ class LocalTestVolume : public TestVolume {
: mount_name_(mount_name) {
}
- LocalTestVolume(const std::string& mount_name,
- const base::FilePath& local_path)
- : mount_name_(mount_name),
- local_path_(local_path) {
- }
-
// Adds this volume to the file system as a local volume. Returns true on
// success.
bool Mount(Profile* profile) {
@@ -298,28 +163,6 @@ class LocalTestVolume : public TestVolume {
return mount_name_;
}
- virtual base::FilePath GetRootPath() const OVERRIDE {
- return local_path_;
- }
-
- virtual bool PathExists(const base::FilePath& file_path) const OVERRIDE {
- return file_util::PathExists(file_path);
- }
-
- virtual bool WaitUntilFilePresentWithSize(
- const base::FilePath& file_path,
- int64 file_size) OVERRIDE {
- TestFilePathWatcher watcher(file_path, base::Bind(FilePresentWithSize,
- file_size));
- return watcher.RunMessageLoopUntilConditionSatisfied();
- }
-
- virtual bool WaitUntilFileNotPresent(
- const base::FilePath& file_path) OVERRIDE {
- TestFilePathWatcher watcher(file_path, base::Bind(FileNotPresent));
- return watcher.RunMessageLoopUntilConditionSatisfied();
- }
-
private:
std::string mount_name_;
base::FilePath local_path_;
@@ -329,12 +172,10 @@ class LocalTestVolume : public TestVolume {
// The drive volume class for test.
// This class provides the operations for a test volume that simulates Google
// drive.
-class DriveTestVolume : public TestVolume,
- public drive::FileSystemObserver {
+class DriveTestVolume : public TestVolume {
public:
DriveTestVolume() : fake_drive_service_(NULL),
- integration_service_(NULL),
- waiting_for_directory_change_(false) {
+ integration_service_(NULL) {
}
// Send request to add this volume to the file system as Google drive.
@@ -439,53 +280,6 @@ class DriveTestVolume : public TestVolume,
CheckForUpdates();
}
- virtual base::FilePath GetRootPath() const OVERRIDE {
- return base::FilePath(drive::util::kDriveMyDriveRootPath);
- }
-
- virtual bool PathExists(const base::FilePath& file_path) const OVERRIDE {
- DCHECK(integration_service_);
- DCHECK(integration_service_->file_system());
-
- drive::FileError error = drive::FILE_ERROR_FAILED;
- scoped_ptr<drive::ResourceEntry> entry_proto;
- integration_service_->file_system()->GetResourceEntryByPath(
- file_path,
- google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
- google_apis::test_util::RunBlockingPoolTask();
-
- return error == drive::FILE_ERROR_OK;
- }
-
- virtual bool WaitUntilFilePresentWithSize(
- const base::FilePath& file_path,
- int64 file_size) OVERRIDE {
- while (true) {
- if (FileIsPresentWithSize(file_path, file_size))
- return true;
- WaitUntilDirectoryChanged();
- }
- NOTREACHED();
- return false;
- }
-
- virtual bool WaitUntilFileNotPresent(
- const base::FilePath& file_path) OVERRIDE {
- while (true) {
- if (FileIsNotPresent(file_path))
- return true;
- WaitUntilDirectoryChanged();
- }
- NOTREACHED();
- return false;
- }
-
- virtual void OnDirectoryChanged(
- const base::FilePath& directory_path) OVERRIDE {
- if (waiting_for_directory_change_)
- MessageLoop::current()->Quit();
- }
-
// Notifies FileSystem that the contents in FakeDriveService are
// changed, hence the new contents should be fetched.
void CheckForUpdates() {
@@ -494,47 +288,6 @@ class DriveTestVolume : public TestVolume,
}
}
- // Waits until a notification for a directory change is received.
- void WaitUntilDirectoryChanged() {
- waiting_for_directory_change_ = true;
- MessageLoop::current()->Run();
- waiting_for_directory_change_ = false;
- }
-
- // Returns true if a file of the size |file_size| is present at |file_path|.
- bool FileIsPresentWithSize(
- const base::FilePath& file_path,
- int64 file_size) {
- DCHECK(integration_service_);
- DCHECK(integration_service_->file_system());
-
- drive::FileError error = drive::FILE_ERROR_FAILED;
- scoped_ptr<drive::ResourceEntry> entry_proto;
- integration_service_->file_system()->GetResourceEntryByPath(
- file_path,
- google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
- google_apis::test_util::RunBlockingPoolTask();
-
- return (error == drive::FILE_ERROR_OK &&
- entry_proto->file_info().size() == file_size);
- }
-
- // Returns true if a file is not present at |file_path|.
- bool FileIsNotPresent(
- const base::FilePath& file_path) {
- DCHECK(integration_service_);
- DCHECK(integration_service_->file_system());
-
- drive::FileError error = drive::FILE_ERROR_FAILED;
- scoped_ptr<drive::ResourceEntry> entry_proto;
- integration_service_->file_system()->GetResourceEntryByPath(
- file_path,
- google_apis::test_util::CreateCopyResultCallback(&error, &entry_proto));
- google_apis::test_util::RunBlockingPoolTask();
-
- return error == drive::FILE_ERROR_NOT_FOUND;
- }
-
drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) {
fake_drive_service_ = new google_apis::FakeDriveService;
@@ -548,7 +301,6 @@ class DriveTestVolume : public TestVolume,
fake_drive_service_,
test_cache_root_.path(),
NULL);
- integration_service_->file_system()->AddObserver(this);
return integration_service_;
}
@@ -556,7 +308,6 @@ class DriveTestVolume : public TestVolume,
base::ScopedTempDir test_cache_root_;
google_apis::FakeDriveService* fake_drive_service_;
drive::DriveIntegrationService* integration_service_;
- bool waiting_for_directory_change_;
};
// The base test class. Used by FileManagerBrowserLocalTest,
@@ -639,44 +390,6 @@ void FileManagerBrowserTestBase::DoTestFileDisplay(TestVolume* volume) {
ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
-void FileManagerBrowserTestBase::DoTestGalleryOpen(TestVolume* volume) {
- ResultCatcher catcher;
- StartTest("galleryOpen" + volume->GetName());
- ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
-}
-
-void FileManagerBrowserTestBase::DoTestKeyboardCopy(TestVolume* volume) {
- base::FilePath copy_path =
- volume->GetRootPath().AppendASCII(kKeyboardTestFileCopyName);
- ASSERT_FALSE(volume->PathExists(copy_path));
-
- ResultCatcher catcher;
- ASSERT_NO_FATAL_FAILURE(StartTest("keyboardCopy" + volume->GetName()));
-
- const int64 kKeyboardTestFileSize = 59943;
-
- ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
- ASSERT_TRUE(volume->WaitUntilFilePresentWithSize(
- copy_path, kKeyboardTestFileSize));
-
- // Check that it was a copy, not a move.
- base::FilePath source_path =
- volume->GetRootPath().AppendASCII(kKeyboardTestFileName);
- ASSERT_TRUE(volume->PathExists(source_path));
-}
-
-void FileManagerBrowserTestBase::DoTestKeyboardDelete(TestVolume* volume) {
- base::FilePath delete_path =
- volume->GetRootPath().AppendASCII(kKeyboardTestFileName);
- ASSERT_TRUE(volume->PathExists(delete_path));
-
- ResultCatcher catcher;
- ASSERT_NO_FATAL_FAILURE(StartTest("keyboardDelete" + volume->GetName()));
-
- ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
- ASSERT_TRUE(volume->WaitUntilFileNotPresent(delete_path));
-}
-
// A class to test local volumes.
class FileManagerBrowserLocalTest : public FileManagerBrowserTestBase {
public:
@@ -773,19 +486,29 @@ IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestFileDisplay) {
}
IN_PROC_BROWSER_TEST_P(FileManagerBrowserLocalTest, TestGalleryOpen) {
- DoTestGalleryOpen(&volume_);
+ ResultCatcher catcher;
+ ASSERT_NO_FATAL_FAILURE(StartTest("galleryOpenDownloads"));
+ ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
-IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestGalleryOpen) {
- DoTestGalleryOpen(&volume_);
+// Disabled temporarily since fails on Linux Chromium OS ASAN Tests (2).
+// TODO(mtomasz): crbug.com/243611.
+IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, DISABLED_TestGalleryOpen) {
+ ResultCatcher catcher;
+ ASSERT_NO_FATAL_FAILURE(StartTest("galleryOpenDrive"));
+ ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestKeyboardCopy) {
- DoTestKeyboardCopy(&volume_);
+ ResultCatcher catcher;
+ ASSERT_NO_FATAL_FAILURE(StartTest("keyboardCopyDrive"));
+ ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestKeyboardDelete) {
- DoTestKeyboardDelete(&volume_);
+ ResultCatcher catcher;
+ ASSERT_NO_FATAL_FAILURE(StartTest("keyboardDeleteDrive"));
+ ASSERT_TRUE(catcher.GetNextResult()) << catcher.message();
}
IN_PROC_BROWSER_TEST_P(FileManagerBrowserDriveTest, TestOpenRecent) {
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698