| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "apps/saved_files_service.h" | 7 #include "apps/saved_files_service.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/test/values_test_util.h" | 10 #include "base/test/values_test_util.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 std::string GenerateId(int i) { | 30 std::string GenerateId(int i) { |
| 31 return base::IntToString(i) + ":filename.ext"; | 31 return base::IntToString(i) + ":filename.ext"; |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 class SavedFilesServiceUnitTest : public testing::Test { | 36 class SavedFilesServiceUnitTest : public testing::Test { |
| 37 protected: | 37 protected: |
| 38 virtual void SetUp() OVERRIDE { | 38 virtual void SetUp() override { |
| 39 testing::Test::SetUp(); | 39 testing::Test::SetUp(); |
| 40 extension_ = env_.MakeExtension(*base::test::ParseJson( | 40 extension_ = env_.MakeExtension(*base::test::ParseJson( |
| 41 "{" | 41 "{" |
| 42 " \"app\": {" | 42 " \"app\": {" |
| 43 " \"background\": {" | 43 " \"background\": {" |
| 44 " \"scripts\": [\"background.js\"]" | 44 " \"scripts\": [\"background.js\"]" |
| 45 " }" | 45 " }" |
| 46 " }," | 46 " }," |
| 47 " \"permissions\": [" | 47 " \"permissions\": [" |
| 48 " {\"fileSystem\": [\"retainEntries\"]}" | 48 " {\"fileSystem\": [\"retainEntries\"]}" |
| 49 " ]" | 49 " ]" |
| 50 "}")); | 50 "}")); |
| 51 service_ = SavedFilesService::Get(env_.profile()); | 51 service_ = SavedFilesService::Get(env_.profile()); |
| 52 path_ = base::FilePath(FILE_PATH_LITERAL("filename.ext")); | 52 path_ = base::FilePath(FILE_PATH_LITERAL("filename.ext")); |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void TearDown() OVERRIDE { | 55 virtual void TearDown() override { |
| 56 SavedFilesService::ClearMaxSequenceNumberForTest(); | 56 SavedFilesService::ClearMaxSequenceNumberForTest(); |
| 57 SavedFilesService::ClearLruSizeForTest(); | 57 SavedFilesService::ClearLruSizeForTest(); |
| 58 testing::Test::TearDown(); | 58 testing::Test::TearDown(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Check that a registered file entry has the correct value. | 61 // Check that a registered file entry has the correct value. |
| 62 void CheckEntrySequenceNumber(int id, int sequence_number) { | 62 void CheckEntrySequenceNumber(int id, int sequence_number) { |
| 63 std::string id_string = GenerateId(id); | 63 std::string id_string = GenerateId(id); |
| 64 SCOPED_TRACE(id_string); | 64 SCOPED_TRACE(id_string); |
| 65 EXPECT_TRUE(service_->IsRegistered(extension_->id(), id_string)); | 65 EXPECT_TRUE(service_->IsRegistered(extension_->id(), id_string)); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 TRACE_CALL(CheckEntrySequenceNumber(3, 6)); | 226 TRACE_CALL(CheckEntrySequenceNumber(3, 6)); |
| 227 | 227 |
| 228 // This should push the sequence number to the limit of 8, and trigger a | 228 // This should push the sequence number to the limit of 8, and trigger a |
| 229 // sequence number compaction. Expect that the sequence numbers are | 229 // sequence number compaction. Expect that the sequence numbers are |
| 230 // contiguous from 1 to 4. | 230 // contiguous from 1 to 4. |
| 231 service_->EnqueueFileEntry(extension_->id(), GenerateId(3)); | 231 service_->EnqueueFileEntry(extension_->id(), GenerateId(3)); |
| 232 TRACE_CALL(CheckRangeEnqueuedInOrder(0, 4)); | 232 TRACE_CALL(CheckRangeEnqueuedInOrder(0, 4)); |
| 233 service_->Clear(extension_->id()); | 233 service_->Clear(extension_->id()); |
| 234 TRACE_CALL(CheckRangeEnqueuedInOrder(0, 4)); | 234 TRACE_CALL(CheckRangeEnqueuedInOrder(0, 4)); |
| 235 } | 235 } |
| OLD | NEW |