OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
12 #include "chrome/browser/extensions/extension_apitest.h" | 12 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/sync_file_system/file_status_observer.h" | 13 #include "chrome/browser/sync_file_system/file_status_observer.h" |
14 #include "chrome/browser/sync_file_system/local_change_processor.h" | 14 #include "chrome/browser/sync_file_system/local_change_processor.h" |
15 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" | 15 #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" |
16 #include "chrome/browser/sync_file_system/sync_file_system_service.h" | 16 #include "chrome/browser/sync_file_system/sync_file_system_service.h" |
17 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" | 17 #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" |
18 #include "chrome/browser/sync_file_system/sync_status_code.h" | 18 #include "chrome/browser/sync_file_system/sync_status_code.h" |
19 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" | 19 #include "chrome/browser/sync_file_system/syncable_file_system_util.h" |
20 #include "chrome/test/base/test_switches.h" | 20 #include "chrome/test/base/test_switches.h" |
21 #include "content/public/browser/storage_partition.h" | |
22 #include "extensions/browser/extension_function.h" | 21 #include "extensions/browser/extension_function.h" |
23 #include "storage/browser/fileapi/file_system_url.h" | 22 #include "storage/browser/fileapi/file_system_url.h" |
24 #include "storage/browser/quota/quota_manager.h" | 23 #include "storage/browser/quota/quota_manager.h" |
25 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
27 | 26 |
28 using ::testing::_; | 27 using ::testing::_; |
29 using ::testing::Eq; | 28 using ::testing::Eq; |
30 using ::testing::Ne; | 29 using ::testing::Ne; |
31 using ::testing::Property; | 30 using ::testing::Property; |
32 using ::testing::Return; | 31 using ::testing::Return; |
33 using storage::FileSystemURL; | 32 using storage::FileSystemURL; |
34 using sync_file_system::MockRemoteFileSyncService; | 33 using sync_file_system::MockRemoteFileSyncService; |
35 using sync_file_system::RemoteFileSyncService; | 34 using sync_file_system::RemoteFileSyncService; |
36 using sync_file_system::SyncFileSystemServiceFactory; | 35 using sync_file_system::SyncFileSystemServiceFactory; |
37 | 36 |
38 namespace { | 37 namespace { |
39 | 38 |
40 class SyncFileSystemApiTest : public ExtensionApiTest { | 39 class SyncFileSystemApiTest : public ExtensionApiTest { |
41 public: | 40 public: |
42 SyncFileSystemApiTest() | 41 SyncFileSystemApiTest() |
43 : mock_remote_service_(NULL), | 42 : mock_remote_service_(NULL), |
| 43 real_minimum_preserved_space_(0), |
44 real_default_quota_(0) {} | 44 real_default_quota_(0) {} |
45 | 45 |
46 void SetUpInProcessBrowserTestFixture() override { | 46 void SetUpInProcessBrowserTestFixture() override { |
47 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 47 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
48 | 48 |
| 49 real_minimum_preserved_space_ = |
| 50 storage::QuotaManager::kMinimumPreserveForSystem; |
| 51 storage::QuotaManager::kMinimumPreserveForSystem = 0; |
| 52 |
49 // TODO(calvinlo): Update test code after default quota is made const | 53 // TODO(calvinlo): Update test code after default quota is made const |
50 // (http://crbug.com/155488). | 54 // (http://crbug.com/155488). |
51 real_default_quota_ = | 55 real_default_quota_ = |
52 storage::QuotaManager::kSyncableStorageDefaultHostQuota; | 56 storage::QuotaManager::kSyncableStorageDefaultHostQuota; |
53 storage::QuotaManager::kSyncableStorageDefaultHostQuota = 123456; | 57 storage::QuotaManager::kSyncableStorageDefaultHostQuota = 123456; |
54 } | 58 } |
55 | 59 |
56 void TearDownInProcessBrowserTestFixture() override { | 60 void TearDownInProcessBrowserTestFixture() override { |
| 61 storage::QuotaManager::kMinimumPreserveForSystem = |
| 62 real_minimum_preserved_space_; |
57 storage::QuotaManager::kSyncableStorageDefaultHostQuota = | 63 storage::QuotaManager::kSyncableStorageDefaultHostQuota = |
58 real_default_quota_; | 64 real_default_quota_; |
59 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); | 65 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); |
60 } | 66 } |
61 | 67 |
62 void SetUpOnMainThread() override { | 68 void SetUpOnMainThread() override { |
63 // Must happen after the browser process is created because instantiating | 69 // Must happen after the browser process is created because instantiating |
64 // the factory will instantiate ExtensionSystemFactory which depends on | 70 // the factory will instantiate ExtensionSystemFactory which depends on |
65 // ExtensionsBrowserClient setup in BrowserProcessImpl. | 71 // ExtensionsBrowserClient setup in BrowserProcessImpl. |
66 mock_remote_service_ = new ::testing::NiceMock<MockRemoteFileSyncService>; | 72 mock_remote_service_ = new ::testing::NiceMock<MockRemoteFileSyncService>; |
67 SyncFileSystemServiceFactory::GetInstance()->set_mock_remote_file_service( | 73 SyncFileSystemServiceFactory::GetInstance()->set_mock_remote_file_service( |
68 std::unique_ptr<RemoteFileSyncService>(mock_remote_service_)); | 74 std::unique_ptr<RemoteFileSyncService>(mock_remote_service_)); |
69 ExtensionApiTest::SetUpOnMainThread(); | 75 ExtensionApiTest::SetUpOnMainThread(); |
70 } | 76 } |
71 | 77 |
72 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service() { | 78 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service() { |
73 return mock_remote_service_; | 79 return mock_remote_service_; |
74 } | 80 } |
75 | 81 |
76 private: | 82 private: |
77 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service_; | 83 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service_; |
| 84 int64_t real_minimum_preserved_space_; |
78 int64_t real_default_quota_; | 85 int64_t real_default_quota_; |
79 }; | 86 }; |
80 | 87 |
81 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { | 88 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { |
82 mock_remote_service->NotifyRemoteServiceStateUpdated( | 89 mock_remote_service->NotifyRemoteServiceStateUpdated( |
83 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); | 90 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); |
84 base::ThreadTaskRunnerHandle::Get()->PostTask( | 91 base::ThreadTaskRunnerHandle::Get()->PostTask( |
85 FROM_HERE, base::Bind(arg1, sync_file_system::SYNC_STATUS_OK)); | 92 FROM_HERE, base::Bind(arg1, sync_file_system::SYNC_STATUS_OK)); |
86 } | 93 } |
87 | 94 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/conflict_resolution_policy")) | 206 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/conflict_resolution_policy")) |
200 << message_; | 207 << message_; |
201 } | 208 } |
202 | 209 |
203 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetServiceStatus) { | 210 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetServiceStatus) { |
204 mock_remote_service()->SetServiceState( | 211 mock_remote_service()->SetServiceState( |
205 sync_file_system::REMOTE_SERVICE_AUTHENTICATION_REQUIRED); | 212 sync_file_system::REMOTE_SERVICE_AUTHENTICATION_REQUIRED); |
206 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_service_status")) | 213 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_service_status")) |
207 << message_; | 214 << message_; |
208 } | 215 } |
OLD | NEW |