Commit 0df38665 authored by iseki's avatar iseki Committed by Commit bot

Modify test case to support streaming operation in sandbox file system.

BUG=360088
TEST=content_unittests passed

Review URL: https://codereview.chromium.org/522543002

Cr-Commit-Position: refs/heads/master@{#293327}
parent bb2bb40a
......@@ -50,11 +50,10 @@ void AssertFileErrorEq(const tracked_objects::Location& from_here,
ASSERT_EQ(expected, actual) << from_here.ToString();
}
void AssertFileErrorEqWithClosure(
const tracked_objects::Location& from_here,
base::File::Error expected,
base::Closure closure,
base::File::Error actual) {
void AssertFileErrorEqWithClosure(const tracked_objects::Location& from_here,
base::File::Error expected,
base::Closure closure,
base::File::Error actual) {
ASSERT_EQ(expected, actual) << from_here.ToString();
closure.Run();
}
......@@ -286,7 +285,7 @@ class FileSystemOperationImplTest
}
private:
base::MessageLoop message_loop_;
base::MessageLoopForIO message_loop_;
scoped_refptr<QuotaManager> quota_manager_;
scoped_refptr<QuotaManagerProxy> quota_manager_proxy_;
......@@ -614,8 +613,8 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcFileAndOverwrite) {
EXPECT_EQ(base::File::FILE_OK, status());
EXPECT_TRUE(FileExists("dest"));
EXPECT_EQ(2, quota_manager_proxy()->notify_storage_accessed_count());
EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count());
EXPECT_TRUE(change_observer()->HasNoChange());
}
......@@ -651,8 +650,8 @@ TEST_F(FileSystemOperationImplTest, TestCopySuccessSrcDirAndOverwrite) {
EXPECT_FALSE(DirectoryExists("dest/src"));
EXPECT_GE(quota_manager_proxy()->notify_storage_accessed_count(), 3);
EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count());
EXPECT_EQ(1, change_observer()->get_and_reset_remove_directory_count());
EXPECT_TRUE(change_observer()->HasNoChange());
}
......@@ -1266,12 +1265,19 @@ TEST_F(FileSystemOperationImplTest,
EXPECT_EQ(all_file_size, GetDataSizeOnDisk());
EXPECT_EQ(expected_usage, usage);
// Copy src to dest1.
operation_runner()->Copy(
src, dest1, FileSystemOperation::OPTION_NONE,
FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
base::RunLoop().RunUntilIdle();
{
base::RunLoop run_loop;
// Copy src to dest1.
operation_runner()->Copy(src,
dest1,
FileSystemOperation::OPTION_NONE,
FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&AssertFileErrorEqWithClosure,
FROM_HERE,
base::File::FILE_OK,
run_loop.QuitClosure()));
run_loop.Run();
}
expected_usage += all_file_size + child_path_cost + grandchild_path_cost;
EXPECT_TRUE(DirectoryExists("src/dir"));
......@@ -1282,12 +1288,19 @@ TEST_F(FileSystemOperationImplTest,
EXPECT_EQ(2 * all_file_size, GetDataSizeOnDisk());
EXPECT_EQ(expected_usage, GetUsage());
// Copy src/dir to dest2.
operation_runner()->Copy(
child_dir, dest2, FileSystemOperation::OPTION_NONE,
FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&AssertFileErrorEq, FROM_HERE, base::File::FILE_OK));
base::RunLoop().RunUntilIdle();
{
base::RunLoop run_loop;
// Copy src/dir to dest2.
operation_runner()->Copy(child_dir,
dest2,
FileSystemOperation::OPTION_NONE,
FileSystemOperationRunner::CopyProgressCallback(),
base::Bind(&AssertFileErrorEqWithClosure,
FROM_HERE,
base::File::FILE_OK,
run_loop.QuitClosure()));
run_loop.Run();
}
expected_usage += grandchild_file_size + grandchild_path_cost;
usage = GetUsage();
......
......@@ -796,7 +796,7 @@ class ObfuscatedFileUtilTest : public testing::Test {
protected:
base::ScopedTempDir data_dir_;
base::MessageLoop message_loop_;
base::MessageLoopForIO message_loop_;
scoped_refptr<MockSpecialStoragePolicy> storage_policy_;
scoped_refptr<storage::QuotaManager> quota_manager_;
scoped_refptr<FileSystemContext> file_system_context_;
......
......@@ -10,6 +10,7 @@
#include "net/base/net_errors.h"
#include "webkit/browser/blob/file_stream_reader.h"
#include "webkit/browser/fileapi/copy_or_move_file_validator.h"
#include "webkit/browser/fileapi/file_observers.h"
#include "webkit/browser/fileapi/file_stream_writer.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_operation_runner.h"
......@@ -366,6 +367,7 @@ class StreamCopyOrMoveImpl
public:
StreamCopyOrMoveImpl(
FileSystemOperationRunner* operation_runner,
FileSystemContext* file_system_context,
CopyOrMoveOperationDelegate::OperationType operation_type,
const FileSystemURL& src_url,
const FileSystemURL& dest_url,
......@@ -375,6 +377,7 @@ class StreamCopyOrMoveImpl
const FileSystemOperation::CopyFileProgressCallback&
file_progress_callback)
: operation_runner_(operation_runner),
file_system_context_(file_system_context),
operation_type_(operation_type),
src_url_(src_url),
dest_url_(dest_url),
......@@ -403,6 +406,27 @@ class StreamCopyOrMoveImpl
}
private:
void NotifyOnStartUpdate(const FileSystemURL& url) {
if (file_system_context_->GetUpdateObservers(url.type())) {
file_system_context_->GetUpdateObservers(url.type())
->Notify(&FileUpdateObserver::OnStartUpdate, MakeTuple(url));
}
}
void NotifyOnModifyFile(const FileSystemURL& url) {
if (file_system_context_->GetChangeObservers(url.type())) {
file_system_context_->GetChangeObservers(url.type())
->Notify(&FileChangeObserver::OnModifyFile, MakeTuple(url));
}
}
void NotifyOnEndUpdate(const FileSystemURL& url) {
if (file_system_context_->GetUpdateObservers(url.type())) {
file_system_context_->GetUpdateObservers(url.type())
->Notify(&FileUpdateObserver::OnEndUpdate, MakeTuple(url));
}
}
void RunAfterGetMetadataForSource(
const CopyOrMoveOperationDelegate::StatusCallback& callback,
base::File::Error error,
......@@ -437,6 +461,10 @@ class StreamCopyOrMoveImpl
base::File::Error error) {
if (cancel_requested_)
error = base::File::FILE_ERROR_ABORT;
// This conversion is to return the consistent status code with
// FileSystemFileUtil::Copy.
if (error == base::File::FILE_ERROR_NOT_A_FILE)
error = base::File::FILE_ERROR_INVALID_OPERATION;
if (error != base::File::FILE_OK &&
error != base::File::FILE_ERROR_EXISTS) {
......@@ -473,6 +501,7 @@ class StreamCopyOrMoveImpl
const bool need_flush = dest_url_.mount_option().copy_sync_option() ==
storage::COPY_SYNC_OPTION_SYNC;
NotifyOnStartUpdate(dest_url_);
DCHECK(!copy_helper_);
copy_helper_.reset(
new CopyOrMoveOperationDelegate::StreamCopyHelper(
......@@ -491,6 +520,8 @@ class StreamCopyOrMoveImpl
const CopyOrMoveOperationDelegate::StatusCallback& callback,
const base::Time& last_modified,
base::File::Error error) {
NotifyOnModifyFile(dest_url_);
NotifyOnEndUpdate(dest_url_);
if (cancel_requested_)
error = base::File::FILE_ERROR_ABORT;
......@@ -544,6 +575,7 @@ class StreamCopyOrMoveImpl
}
FileSystemOperationRunner* operation_runner_;
scoped_refptr<FileSystemContext> file_system_context_;
CopyOrMoveOperationDelegate::OperationType operation_type_;
FileSystemURL src_url_;
FileSystemURL dest_url_;
......@@ -791,10 +823,17 @@ void CopyOrMoveOperationDelegate::ProcessFile(
file_system_context()->CreateFileStreamWriter(dest_url, 0);
if (reader && writer) {
impl = new StreamCopyOrMoveImpl(
operation_runner(), operation_type_, src_url, dest_url, option_,
reader.Pass(), writer.Pass(),
operation_runner(),
file_system_context(),
operation_type_,
src_url,
dest_url,
option_,
reader.Pass(),
writer.Pass(),
base::Bind(&CopyOrMoveOperationDelegate::OnCopyFileProgress,
weak_factory_.GetWeakPtr(), src_url));
weak_factory_.GetWeakPtr(),
src_url));
}
}
......
......@@ -298,6 +298,14 @@ const UpdateObserverList* FileSystemContext::GetUpdateObservers(
return NULL;
}
const ChangeObserverList* FileSystemContext::GetChangeObservers(
FileSystemType type) const {
FileSystemBackend* backend = GetFileSystemBackend(type);
if (backend->GetQuotaUtil())
return backend->GetQuotaUtil()->GetChangeObservers(type);
return NULL;
}
const AccessObserverList* FileSystemContext::GetAccessObservers(
FileSystemType type) const {
FileSystemBackend* backend = GetFileSystemBackend(type);
......
......@@ -176,6 +176,7 @@ class STORAGE_EXPORT FileSystemContext
// Returns observers for the given filesystem type.
const UpdateObserverList* GetUpdateObservers(FileSystemType type) const;
const ChangeObserverList* GetChangeObservers(FileSystemType type) const;
const AccessObserverList* GetAccessObservers(FileSystemType type) const;
// Returns all registered filesystem types.
......
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