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

Side by Side Diff: chrome/browser/extensions/api/sync_file_system/sync_file_system_apitest.cc

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years 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 unified diff | Download patch
OLDNEW
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"
21 #include "extensions/browser/extension_function.h" 22 #include "extensions/browser/extension_function.h"
22 #include "storage/browser/fileapi/file_system_url.h" 23 #include "storage/browser/fileapi/file_system_url.h"
23 #include "storage/browser/quota/quota_manager.h" 24 #include "storage/browser/quota/quota_manager.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using ::testing::_; 28 using ::testing::_;
28 using ::testing::Eq; 29 using ::testing::Eq;
29 using ::testing::Ne; 30 using ::testing::Ne;
30 using ::testing::Property; 31 using ::testing::Property;
31 using ::testing::Return; 32 using ::testing::Return;
32 using storage::FileSystemURL; 33 using storage::FileSystemURL;
33 using sync_file_system::MockRemoteFileSyncService; 34 using sync_file_system::MockRemoteFileSyncService;
34 using sync_file_system::RemoteFileSyncService; 35 using sync_file_system::RemoteFileSyncService;
35 using sync_file_system::SyncFileSystemServiceFactory; 36 using sync_file_system::SyncFileSystemServiceFactory;
36 37
37 namespace { 38 namespace {
38 39
39 class SyncFileSystemApiTest : public ExtensionApiTest { 40 class SyncFileSystemApiTest : public ExtensionApiTest {
40 public: 41 public:
41 SyncFileSystemApiTest() 42 SyncFileSystemApiTest()
42 : mock_remote_service_(NULL), 43 : 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
53 // TODO(calvinlo): Update test code after default quota is made const 49 // TODO(calvinlo): Update test code after default quota is made const
54 // (http://crbug.com/155488). 50 // (http://crbug.com/155488).
55 real_default_quota_ = 51 real_default_quota_ =
56 storage::QuotaManager::kSyncableStorageDefaultHostQuota; 52 storage::QuotaManager::kSyncableStorageDefaultHostQuota;
57 storage::QuotaManager::kSyncableStorageDefaultHostQuota = 123456; 53 storage::QuotaManager::kSyncableStorageDefaultHostQuota = 123456;
58 } 54 }
59 55
60 void TearDownInProcessBrowserTestFixture() override { 56 void TearDownInProcessBrowserTestFixture() override {
61 storage::QuotaManager::kMinimumPreserveForSystem =
62 real_minimum_preserved_space_;
63 storage::QuotaManager::kSyncableStorageDefaultHostQuota = 57 storage::QuotaManager::kSyncableStorageDefaultHostQuota =
64 real_default_quota_; 58 real_default_quota_;
65 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); 59 ExtensionApiTest::TearDownInProcessBrowserTestFixture();
66 } 60 }
67 61
68 void SetUpOnMainThread() override { 62 void SetUpOnMainThread() override {
69 // Must happen after the browser process is created because instantiating 63 // Must happen after the browser process is created because instantiating
70 // the factory will instantiate ExtensionSystemFactory which depends on 64 // the factory will instantiate ExtensionSystemFactory which depends on
71 // ExtensionsBrowserClient setup in BrowserProcessImpl. 65 // ExtensionsBrowserClient setup in BrowserProcessImpl.
72 mock_remote_service_ = new ::testing::NiceMock<MockRemoteFileSyncService>; 66 mock_remote_service_ = new ::testing::NiceMock<MockRemoteFileSyncService>;
73 SyncFileSystemServiceFactory::GetInstance()->set_mock_remote_file_service( 67 SyncFileSystemServiceFactory::GetInstance()->set_mock_remote_file_service(
74 std::unique_ptr<RemoteFileSyncService>(mock_remote_service_)); 68 std::unique_ptr<RemoteFileSyncService>(mock_remote_service_));
75 ExtensionApiTest::SetUpOnMainThread(); 69 ExtensionApiTest::SetUpOnMainThread();
70
71 content::BrowserContext* context = browser()->profile();
Devlin 2016/11/23 17:04:13 optional nit: There's a profile() accessor we coul
michaeln 2016/12/06 00:35:54 Done.
72 const int kMeg = 1024 * 1024;
73 storage::QuotaSettings settings;
74 settings.pool_size = 25 * kMeg;
75 settings.per_host_quota = 5 * kMeg;
76 settings.must_remain_available = 0;
77 settings.refresh_interval = base::TimeDelta::Max();
78 content::BrowserContext::GetDefaultStoragePartition(context)
79 ->GetQuotaManager()
80 ->SetQuotaSettings(settings);
Devlin 2016/11/23 17:04:13 Having a comment explaining at a high level what t
michaeln 2016/12/06 00:35:54 Done.
76 } 81 }
77 82
78 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service() { 83 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service() {
79 return mock_remote_service_; 84 return mock_remote_service_;
80 } 85 }
81 86
82 private: 87 private:
83 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service_; 88 ::testing::NiceMock<MockRemoteFileSyncService>* mock_remote_service_;
84 int64_t real_minimum_preserved_space_;
85 int64_t real_default_quota_; 89 int64_t real_default_quota_;
86 }; 90 };
87 91
88 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) { 92 ACTION_P(NotifyOkStateAndCallback, mock_remote_service) {
89 mock_remote_service->NotifyRemoteServiceStateUpdated( 93 mock_remote_service->NotifyRemoteServiceStateUpdated(
90 sync_file_system::REMOTE_SERVICE_OK, "Test event description."); 94 sync_file_system::REMOTE_SERVICE_OK, "Test event description.");
91 base::ThreadTaskRunnerHandle::Get()->PostTask( 95 base::ThreadTaskRunnerHandle::Get()->PostTask(
92 FROM_HERE, base::Bind(arg1, sync_file_system::SYNC_STATUS_OK)); 96 FROM_HERE, base::Bind(arg1, sync_file_system::SYNC_STATUS_OK));
93 } 97 }
94 98
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/conflict_resolution_policy")) 210 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/conflict_resolution_policy"))
207 << message_; 211 << message_;
208 } 212 }
209 213
210 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetServiceStatus) { 214 IN_PROC_BROWSER_TEST_F(SyncFileSystemApiTest, GetServiceStatus) {
211 mock_remote_service()->SetServiceState( 215 mock_remote_service()->SetServiceState(
212 sync_file_system::REMOTE_SERVICE_AUTHENTICATION_REQUIRED); 216 sync_file_system::REMOTE_SERVICE_AUTHENTICATION_REQUIRED);
213 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_service_status")) 217 ASSERT_TRUE(RunPlatformAppTest("sync_file_system/get_service_status"))
214 << message_; 218 << message_;
215 } 219 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698