| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/pepper/quota_reservation.h" | 5 #include "content/browser/renderer_host/pepper/quota_reservation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/location.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | |
| 15 #include "base/thread_task_runner_handle.h" | |
| 16 #include "storage/browser/fileapi/quota/quota_reservation.h" | 14 #include "storage/browser/fileapi/quota/quota_reservation.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 16 |
| 19 using storage::QuotaReservationManager; | 17 using storage::QuotaReservationManager; |
| 20 | 18 |
| 21 namespace content { | 19 namespace content { |
| 22 | 20 |
| 23 namespace { | 21 namespace { |
| 24 | 22 |
| 25 const char kOrigin[] = "http://example.com"; | 23 const char kOrigin[] = "http://example.com"; |
| 26 const storage::FileSystemType kType = storage::kFileSystemTypeTemporary; | 24 const storage::FileSystemType kType = storage::kFileSystemTypeTemporary; |
| 27 | 25 |
| 28 const base::FilePath::StringType file1_name = FILE_PATH_LITERAL("file1"); | 26 const base::FilePath::StringType file1_name = FILE_PATH_LITERAL("file1"); |
| 29 const base::FilePath::StringType file2_name = FILE_PATH_LITERAL("file2"); | 27 const base::FilePath::StringType file2_name = FILE_PATH_LITERAL("file2"); |
| 30 const base::FilePath::StringType file3_name = FILE_PATH_LITERAL("file3"); | 28 const base::FilePath::StringType file3_name = FILE_PATH_LITERAL("file3"); |
| 31 const int kFile1ID = 1; | 29 const int kFile1ID = 1; |
| 32 const int kFile2ID = 2; | 30 const int kFile2ID = 2; |
| 33 const int kFile3ID = 3; | 31 const int kFile3ID = 3; |
| 34 | 32 |
| 35 class FakeBackend : public QuotaReservationManager::QuotaBackend { | 33 class FakeBackend : public QuotaReservationManager::QuotaBackend { |
| 36 public: | 34 public: |
| 37 FakeBackend() {} | 35 FakeBackend() {} |
| 38 ~FakeBackend() override {} | 36 ~FakeBackend() override {} |
| 39 | 37 |
| 40 void ReserveQuota( | 38 void ReserveQuota( |
| 41 const GURL& origin, | 39 const GURL& origin, |
| 42 storage::FileSystemType type, | 40 storage::FileSystemType type, |
| 43 int64 delta, | 41 int64 delta, |
| 44 const QuotaReservationManager::ReserveQuotaCallback& callback) override { | 42 const QuotaReservationManager::ReserveQuotaCallback& callback) override { |
| 45 base::ThreadTaskRunnerHandle::Get()->PostTask( | 43 base::MessageLoopProxy::current()->PostTask( |
| 46 FROM_HERE, | 44 FROM_HERE, |
| 47 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK, delta)); | 45 base::Bind(base::IgnoreResult(callback), base::File::FILE_OK, delta)); |
| 48 } | 46 } |
| 49 | 47 |
| 50 void ReleaseReservedQuota(const GURL& origin, | 48 void ReleaseReservedQuota(const GURL& origin, |
| 51 storage::FileSystemType type, | 49 storage::FileSystemType type, |
| 52 int64 size) override {} | 50 int64 size) override {} |
| 53 | 51 |
| 54 void CommitQuotaUsage(const GURL& origin, | 52 void CommitQuotaUsage(const GURL& origin, |
| 55 storage::FileSystemType type, | 53 storage::FileSystemType type, |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 EXPECT_EQ(amount, reserved_quota); | 235 EXPECT_EQ(amount, reserved_quota); |
| 238 EXPECT_EQ(2U, file_growths.size()); | 236 EXPECT_EQ(2U, file_growths.size()); |
| 239 EXPECT_EQ(file1_size, file_growths[kFile1ID].max_written_offset); | 237 EXPECT_EQ(file1_size, file_growths[kFile1ID].max_written_offset); |
| 240 EXPECT_EQ(file3_size, file_growths[kFile3ID].max_written_offset); | 238 EXPECT_EQ(file3_size, file_growths[kFile3ID].max_written_offset); |
| 241 | 239 |
| 242 test->CloseFile(kFile1ID, ppapi::FileGrowth(file1_size, 0)); | 240 test->CloseFile(kFile1ID, ppapi::FileGrowth(file1_size, 0)); |
| 243 test->CloseFile(kFile3ID, ppapi::FileGrowth(file3_size, 0)); | 241 test->CloseFile(kFile3ID, ppapi::FileGrowth(file3_size, 0)); |
| 244 } | 242 } |
| 245 | 243 |
| 246 } // namespace content | 244 } // namespace content |
| OLD | NEW |