| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/chromeos/drive/search_metadata.h" | 5 #include "chrome/browser/chromeos/drive/search_metadata.h" |
| 6 | 6 |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop/message_loop_proxy.h" | 8 #include "base/message_loop/message_loop_proxy.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 class SearchMetadataTest : public testing::Test { | 64 class SearchMetadataTest : public testing::Test { |
| 65 protected: | 65 protected: |
| 66 virtual void SetUp() OVERRIDE { | 66 virtual void SetUp() OVERRIDE { |
| 67 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 67 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 68 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 68 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
| 69 | 69 |
| 70 metadata_storage_.reset(new ResourceMetadataStorage( |
| 71 temp_dir_.path(), base::MessageLoopProxy::current())); |
| 72 ASSERT_TRUE(metadata_storage_->Initialize()); |
| 73 |
| 70 cache_.reset(new internal::FileCache(temp_dir_.path(), | 74 cache_.reset(new internal::FileCache(temp_dir_.path(), |
| 71 temp_dir_.path(), | 75 temp_dir_.path(), |
| 72 base::MessageLoopProxy::current(), | 76 base::MessageLoopProxy::current(), |
| 73 fake_free_disk_space_getter_.get())); | 77 fake_free_disk_space_getter_.get())); |
| 74 ASSERT_TRUE(cache_->Initialize()); | 78 ASSERT_TRUE(cache_->Initialize()); |
| 75 | 79 |
| 76 resource_metadata_.reset( | 80 resource_metadata_.reset( |
| 77 new ResourceMetadata(temp_dir_.path(), | 81 new ResourceMetadata(metadata_storage_.get(), |
| 78 base::MessageLoopProxy::current())); | 82 base::MessageLoopProxy::current())); |
| 79 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize()); | 83 ASSERT_EQ(FILE_ERROR_OK, resource_metadata_->Initialize()); |
| 80 | 84 |
| 81 AddEntriesToMetadata(); | 85 AddEntriesToMetadata(); |
| 82 } | 86 } |
| 83 | 87 |
| 84 void AddEntriesToMetadata() { | 88 void AddEntriesToMetadata() { |
| 85 ResourceEntry entry; | 89 ResourceEntry entry; |
| 86 | 90 |
| 87 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetDirectoryEntry( | 91 EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(GetDirectoryEntry( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 entry.set_resource_id(resource_id); | 185 entry.set_resource_id(resource_id); |
| 182 entry.set_parent_resource_id(parent_resource_id); | 186 entry.set_parent_resource_id(parent_resource_id); |
| 183 entry.mutable_file_info()->set_last_accessed(last_accessed); | 187 entry.mutable_file_info()->set_last_accessed(last_accessed); |
| 184 entry.mutable_file_info()->set_is_directory(true); | 188 entry.mutable_file_info()->set_is_directory(true); |
| 185 return entry; | 189 return entry; |
| 186 } | 190 } |
| 187 | 191 |
| 188 content::TestBrowserThreadBundle thread_bundle_; | 192 content::TestBrowserThreadBundle thread_bundle_; |
| 189 base::ScopedTempDir temp_dir_; | 193 base::ScopedTempDir temp_dir_; |
| 190 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; | 194 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; |
| 195 scoped_ptr<ResourceMetadataStorage, |
| 196 test_util::DestroyHelperForTests> metadata_storage_; |
| 191 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> | 197 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> |
| 192 resource_metadata_; | 198 resource_metadata_; |
| 193 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 199 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
| 194 }; | 200 }; |
| 195 | 201 |
| 196 TEST_F(SearchMetadataTest, SearchMetadata_ZeroMatches) { | 202 TEST_F(SearchMetadataTest, SearchMetadata_ZeroMatches) { |
| 197 FileError error = FILE_ERROR_FAILED; | 203 FileError error = FILE_ERROR_FAILED; |
| 198 scoped_ptr<MetadataSearchResultVector> result; | 204 scoped_ptr<MetadataSearchResultVector> result; |
| 199 | 205 |
| 200 SearchMetadata(base::MessageLoopProxy::current(), | 206 SearchMetadata(base::MessageLoopProxy::current(), |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 } | 587 } |
| 582 | 588 |
| 583 TEST(SearchMetadataSimpleTest, FindAndHighlight_MoreMetaChars) { | 589 TEST(SearchMetadataSimpleTest, FindAndHighlight_MoreMetaChars) { |
| 584 std::string highlighted_text; | 590 std::string highlighted_text; |
| 585 EXPECT_TRUE(FindAndHighlight("a&b&c&d", "b&c", &highlighted_text)); | 591 EXPECT_TRUE(FindAndHighlight("a&b&c&d", "b&c", &highlighted_text)); |
| 586 EXPECT_EQ("a&<b>b&c</b>&d", highlighted_text); | 592 EXPECT_EQ("a&<b>b&c</b>&d", highlighted_text); |
| 587 } | 593 } |
| 588 | 594 |
| 589 } // namespace internal | 595 } // namespace internal |
| 590 } // namespace drive | 596 } // namespace drive |
| OLD | NEW |