This source file includes following definitions.
- real_default_quota_
- SetUpInProcessBrowserTestFixture
- TearDownInProcessBrowserTestFixture
- SetUpOnMainThread
- mock_remote_service
- ACTION_P
- ACTION_P2
- ACTION_P5
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "base/bind.h"
#include "base/command_line.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/browser/sync_file_system/drive_backend_v1/drive_file_sync_service.h"
#include "chrome/browser/sync_file_system/file_status_observer.h"
#include "chrome/browser/sync_file_system/local_change_processor.h"
#include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
#include "chrome/browser/sync_file_system/sync_file_system_service.h"
#include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
#include "chrome/browser/sync_file_system/sync_status_code.h"
#include "chrome/browser/sync_file_system/syncable_file_system_util.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/test/base/test_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/browser/fileapi/file_system_url.h"
#include "webkit/browser/quota/quota_manager.h"
using ::testing::_;
using ::testing::Eq;
using ::testing::Ne;
using ::testing::Property;
using ::testing::Return;
using fileapi::FileSystemURL;
using sync_file_system::MockRemoteFileSyncService;
using sync_file_system::RemoteFileSyncService;
using sync_file_system::SyncFileSystemServiceFactory;
namespace {
class SyncFileSystemApiTest : public ExtensionApiTest {
public:
SyncFileSystemApiTest()
: mock_remote_service_(NULL),
real_minimum_preserved_space_(0),
real_default_quota_(0) {}
virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
ExtensionApiTest::SetUpInProcessBrowserTestFixture();
real_minimum_preserved_space_ =
quota::QuotaManager::kMinimumPreserveForSystem;
quota::QuotaManager::kMinimumPreserveForSystem = 0;
real_default_quota_ = quota::QuotaManager::kSyncableStorageDefaultHostQuota;
quota::QuotaManager::kSyncableStorageDefaultHostQuota = 123456;
}
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
quota::QuotaManager::kMinimumPreserveForSystem =
real_minimum_preserved_space_;
quota::QuotaManager::kSyncableStorageDefaultHostQuota = real_default_quota_;
ExtensionApiTest::TearDownInProcessBrowserTestFixture();
}
virtual void SetUpOnMainThread() OVERRIDE {
mock_remote_service_ = new ::testing::NiceMock<MockRemoteFileSyncService>;
SyncFileSystemServiceFactory::GetInstance()->set_mock_remote_file_service(
scoped_ptr<RemoteFileSyncService>(mock_remote_service_));
ExtensionApiTest::SetUpOnMainThread();
}
::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service() {
return mock_remote_service_;
}
private:
::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service_;
int64 real_minimum_preserved_space_;
int64 real_default_quota_;
};
ACTION_P(NotifyOkStateAndCallback, mock_remote_service) {
mock_remote_service->NotifyRemoteServiceStateUpdated(
sync_file_system::REMOTE_SERVICE_OK, "Test event description.");
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(arg1, sync_file_system::SYNC_STATUS_OK));
}
ACTION_P2(UpdateRemoteChangeQueue, origin, mock_remote_service) {
*origin = arg0;
mock_remote_service->NotifyRemoteChangeQueueUpdated(1);
}
ACTION_P5(ReturnWithFakeFileAddedStatus,
origin,
mock_remote_service,
sync_direction,
sync_file_status,
sync_action_taken) {
FileSystemURL mock_url = sync_file_system::CreateSyncableFileSystemURL(
*origin,
base::FilePath(FILE_PATH_LITERAL("foo.txt")));
mock_remote_service->NotifyRemoteChangeQueueUpdated(0);
base::MessageLoopProxy::current()->PostTask(
FROM_HERE, base::Bind(arg0,
sync_file_system::SYNC_STATUS_OK,
mock_url));
mock_remote_service->NotifyFileStatusChanged(
mock_url, sync_direction, sync_file_status, sync_action_taken);
}
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetFileStatus) {
EXPECT_CALL(*mock_remote_service(), IsConflicting(_)).WillOnce(Return(true));
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_file_status"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetFileStatuses) {
base::FilePath conflicting = base::FilePath::FromUTF8Unsafe("Conflicting");
EXPECT_CALL(*mock_remote_service(),
IsConflicting(Property(&FileSystemURL::path, Eq(conflicting))))
.WillOnce(Return(true));
EXPECT_CALL(*mock_remote_service(),
IsConflicting(Property(&FileSystemURL::path, Ne(conflicting))))
.WillRepeatedly(Return(false));
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_file_statuses"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) {
ASSERT_TRUE(RunExtensionTest("sync_file_system/get_usage_and_quota"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileStatusChanged) {
GURL origin;
EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _))
.WillOnce(UpdateRemoteChangeQueue(&origin, mock_remote_service()));
EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_))
.WillOnce(ReturnWithFakeFileAddedStatus(
&origin,
mock_remote_service(),
sync_file_system::SYNC_FILE_STATUS_SYNCED,
sync_file_system::SYNC_ACTION_ADDED,
sync_file_system::SYNC_DIRECTION_REMOTE_TO_LOCAL));
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_file_status_changed"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileStatusChangedDeleted) {
GURL origin;
EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _))
.WillOnce(UpdateRemoteChangeQueue(&origin, mock_remote_service()));
EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_))
.WillOnce(ReturnWithFakeFileAddedStatus(
&origin,
mock_remote_service(),
sync_file_system::SYNC_FILE_STATUS_SYNCED,
sync_file_system::SYNC_ACTION_DELETED,
sync_file_system::SYNC_DIRECTION_REMOTE_TO_LOCAL));
ASSERT_TRUE(RunPlatformAppTest(
"sync_file_system/on_file_status_changed_deleted"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnServiceStatusChanged) {
EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _))
.WillOnce(NotifyOkStateAndCallback(mock_remote_service()));
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_service_status_changed"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, RequestFileSystem) {
EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _)).Times(1);
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/request_file_system"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, WriteFileThenGetUsage) {
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/write_file_then_get_usage"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, ConflictResolutionPolicy) {
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/conflict_resolution_policy"))
<< message_;
}
IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetServiceStatus) {
mock_remote_service()->SetServiceState(
sync_file_system::REMOTE_SERVICE_AUTHENTICATION_REQUIRED);
ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_service_status"))
<< message_;
}