Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / sync_file_system / sync_file_system_apitest.cc
blob2aad3242f091c81f6d39f68fb1479754c6893c92
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/bind.h"
6 #include "base/command_line.h"
7 #include "base/run_loop.h"
8 #include "base/thread_task_runner_handle.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/sync_file_system/file_status_observer.h"
11 #include "chrome/browser/sync_file_system/local_change_processor.h"
12 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
13 #include "chrome/browser/sync_file_system/sync_file_system_service.h"
14 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
15 #include "chrome/browser/sync_file_system/sync_status_code.h"
16 #include "chrome/browser/sync_file_system/syncable_file_system_util.h"
17 #include "chrome/common/chrome_version_info.h"
18 #include "chrome/test/base/test_switches.h"
19 #include "storage/browser/fileapi/file_system_url.h"
20 #include "storage/browser/quota/quota_manager.h"
21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
24 using ::testing::_;
25 using ::testing::Eq;
26 using ::testing::Ne;
27 using ::testing::Property;
28 using ::testing::Return;
29 using storage::FileSystemURL;
30 using sync_file_system::MockRemoteFileSyncService;
31 using sync_file_system::RemoteFileSyncService;
32 using sync_file_system::SyncFileSystemServiceFactory;
34 namespace {
36 class SyncFileSystemApiTest : public ExtensionApiTest {
37 public:
38 SyncFileSystemApiTest()
39 : mock_remote_service_(NULL),
40 real_minimum_preserved_space_(0),
41 real_default_quota_(0) {}
43 void SetUpInProcessBrowserTestFixture() override {
44 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
46 real_minimum_preserved_space_ =
47 storage::QuotaManager::kMinimumPreserveForSystem;
48 storage::QuotaManager::kMinimumPreserveForSystem = 0;
50 // TODO(calvinlo): Update test code after default quota is made const
51 // (http://crbug.com/155488).
52 real_default_quota_ =
53 storage::QuotaManager::kSyncableStorageDefaultHostQuota;
54 storage::QuotaManager::kSyncableStorageDefaultHostQuota = 123456;
57 void TearDownInProcessBrowserTestFixture() override {
58 storage::QuotaManager::kMinimumPreserveForSystem =
59 real_minimum_preserved_space_;
60 storage::QuotaManager::kSyncableStorageDefaultHostQuota =
61 real_default_quota_;
62 ExtensionApiTest::TearDownInProcessBrowserTestFixture();
65 void SetUpOnMainThread() override {
66 // Must happen after the browser process is created because instantiating
67 // the factory will instantiate ExtensionSystemFactory which depends on
68 // ExtensionsBrowserClient setup in BrowserProcessImpl.
69 mock_remote_service_ = new ::testing::NiceMock<MockRemoteFileSyncService>;
70 SyncFileSystemServiceFactory::GetInstance()->set_mock_remote_file_service(
71 scoped_ptr<RemoteFileSyncService>(mock_remote_service_));
72 ExtensionApiTest::SetUpOnMainThread();
75 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service() {
76 return mock_remote_service_;
79 private:
80 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service_;
81 int64 real_minimum_preserved_space_;
82 int64 real_default_quota_;
85 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) {
86 mock_remote_service->NotifyRemoteServiceStateUpdated(
87 sync_file_system::REMOTE_SERVICE_OK, "Test event description.");
88 base::ThreadTaskRunnerHandle::Get()->PostTask(
89 FROM_HERE, base::Bind(arg1, sync_file_system::SYNC_STATUS_OK));
92 ACTION_P2(UpdateRemoteChangeQueue, origin, mock_remote_service) {
93 *origin = arg0;
94 mock_remote_service->NotifyRemoteChangeQueueUpdated(1);
97 ACTION_P6(ReturnWithFakeFileAddedStatus,
98 origin,
99 mock_remote_service,
100 file_type,
101 sync_file_status,
102 sync_action_taken,
103 sync_direction) {
104 FileSystemURL mock_url = sync_file_system::CreateSyncableFileSystemURL(
105 *origin,
106 base::FilePath(FILE_PATH_LITERAL("foo.txt")));
107 mock_remote_service->NotifyRemoteChangeQueueUpdated(0);
108 base::ThreadTaskRunnerHandle::Get()->PostTask(
109 FROM_HERE, base::Bind(arg0,
110 sync_file_system::SYNC_STATUS_OK,
111 mock_url));
112 mock_remote_service->NotifyFileStatusChanged(
113 mock_url,
114 file_type,
115 sync_file_status,
116 sync_action_taken,
117 sync_direction);
120 } // namespace
122 // Flaky on Win, OS X, and Linux: http://crbug.com/417330.
123 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, DISABLED_GetFileStatus) {
124 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_file_status"))
125 << message_;
128 // http://crbug.com/417330
129 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, DISABLED_GetFileStatuses) {
130 // Mocking to return IsConflicting() == true only for the path "Conflicting".
131 base::FilePath conflicting = base::FilePath::FromUTF8Unsafe("Conflicting");
132 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_file_statuses"))
133 << message_;
136 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetUsageAndQuota) {
137 ASSERT_TRUE(RunExtensionTest("sync_file_system/get_usage_and_quota"))
138 << message_;
141 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileStatusChanged) {
142 // Mock a pending remote change to be synced.
143 GURL origin;
144 EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _))
145 .WillOnce(UpdateRemoteChangeQueue(&origin, mock_remote_service()));
146 EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_))
147 .WillOnce(ReturnWithFakeFileAddedStatus(
148 &origin,
149 mock_remote_service(),
150 sync_file_system::SYNC_FILE_TYPE_FILE,
151 sync_file_system::SYNC_FILE_STATUS_SYNCED,
152 sync_file_system::SYNC_ACTION_ADDED,
153 sync_file_system::SYNC_DIRECTION_REMOTE_TO_LOCAL));
154 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_file_status_changed"))
155 << message_;
158 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnFileStatusChangedDeleted) {
159 // Mock a pending remote change to be synced.
160 GURL origin;
161 EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _))
162 .WillOnce(UpdateRemoteChangeQueue(&origin, mock_remote_service()));
163 EXPECT_CALL(*mock_remote_service(), ProcessRemoteChange(_))
164 .WillOnce(ReturnWithFakeFileAddedStatus(
165 &origin,
166 mock_remote_service(),
167 sync_file_system::SYNC_FILE_TYPE_FILE,
168 sync_file_system::SYNC_FILE_STATUS_SYNCED,
169 sync_file_system::SYNC_ACTION_DELETED,
170 sync_file_system::SYNC_DIRECTION_REMOTE_TO_LOCAL));
171 ASSERT_TRUE(RunPlatformAppTest(
172 "sync_file_system/on_file_status_changed_deleted"))
173 << message_;
176 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, OnServiceStatusChanged) {
177 EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _))
178 .WillOnce(NotifyOkStateAndCallback(mock_remote_service()));
179 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/on_service_status_changed"))
180 << message_;
183 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, RequestFileSystem) {
184 EXPECT_CALL(*mock_remote_service(), RegisterOrigin(_, _)).Times(1);
185 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/request_file_system"))
186 << message_;
189 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, WriteFileThenGetUsage) {
190 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/write_file_then_get_usage"))
191 << message_;
194 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, ConflictResolutionPolicy) {
195 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/conflict_resolution_policy"))
196 << message_;
199 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetServiceStatus) {
200 mock_remote_service()->SetServiceState(
201 sync_file_system::REMOTE_SERVICE_AUTHENTICATION_REQUIRED);
202 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_service_status"))
203 << message_;