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 "chrome/browser/chromeos/drive/drive_cache.h" | 5 #include "chrome/browser/chromeos/drive/drive_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 virtual void SetUp() OVERRIDE { | 104 virtual void SetUp() OVERRIDE { |
105 profile_.reset(new TestingProfile); | 105 profile_.reset(new TestingProfile); |
106 | 106 |
107 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 107 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
108 | 108 |
109 scoped_refptr<base::SequencedWorkerPool> pool = | 109 scoped_refptr<base::SequencedWorkerPool> pool = |
110 content::BrowserThread::GetBlockingPool(); | 110 content::BrowserThread::GetBlockingPool(); |
111 blocking_task_runner_ = | 111 blocking_task_runner_ = |
112 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); | 112 pool->GetSequencedTaskRunner(pool->GetSequenceToken()); |
113 cache_ = new DriveCache( | 113 cache_.reset(new DriveCache(DriveCache::GetCacheRootPath(profile_.get()), |
114 DriveCache::GetCacheRootPath(profile_.get()), | 114 blocking_task_runner_, |
115 blocking_task_runner_, | 115 fake_free_disk_space_getter_.get())); |
116 fake_free_disk_space_getter_.get()); | |
117 | 116 |
118 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); | 117 mock_cache_observer_.reset(new StrictMock<MockDriveCacheObserver>); |
119 cache_->AddObserver(mock_cache_observer_.get()); | 118 cache_->AddObserver(mock_cache_observer_.get()); |
120 | 119 |
121 bool initialization_success = false; | 120 bool initialization_success = false; |
122 cache_->RequestInitialize( | 121 cache_->RequestInitialize( |
123 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, | 122 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, |
124 &initialization_success)); | 123 &initialization_success)); |
125 google_apis::test_util::RunBlockingPoolTask(); | 124 google_apis::test_util::RunBlockingPoolTask(); |
126 ASSERT_TRUE(initialization_success); | 125 ASSERT_TRUE(initialization_success); |
127 } | 126 } |
128 | 127 |
129 virtual void TearDown() OVERRIDE { | 128 virtual void TearDown() OVERRIDE { |
130 test_util::DeleteDriveCache(cache_); | 129 cache_.reset(); |
131 profile_.reset(NULL); | 130 profile_.reset(NULL); |
132 } | 131 } |
133 | 132 |
134 void PrepareTestCacheResources() { | 133 void PrepareTestCacheResources() { |
135 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | 134 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); |
136 | 135 |
137 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cache_resources); ++i) { | 136 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cache_resources); ++i) { |
138 const struct TestCacheResource& resource = test_cache_resources[i]; | 137 const struct TestCacheResource& resource = test_cache_resources[i]; |
139 // Copy file from data dir to cache. | 138 // Copy file from data dir to cache. |
140 if (!std::string(resource.source_file).empty()) { | 139 if (!std::string(resource.source_file).empty()) { |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 } | 635 } |
637 return num_files_found; | 636 return num_files_found; |
638 } | 637 } |
639 | 638 |
640 MessageLoopForUI message_loop_; | 639 MessageLoopForUI message_loop_; |
641 // The order of the test threads is important, do not change the order. | 640 // The order of the test threads is important, do not change the order. |
642 // See also content/browser/browser_thread_imple.cc. | 641 // See also content/browser/browser_thread_imple.cc. |
643 content::TestBrowserThread ui_thread_; | 642 content::TestBrowserThread ui_thread_; |
644 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 643 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
645 scoped_ptr<TestingProfile> profile_; | 644 scoped_ptr<TestingProfile> profile_; |
646 DriveCache* cache_; | 645 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache_; |
647 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; | 646 scoped_ptr<FakeFreeDiskSpaceGetter> fake_free_disk_space_getter_; |
648 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; | 647 scoped_ptr<StrictMock<MockDriveCacheObserver> > mock_cache_observer_; |
649 | 648 |
650 DriveFileError expected_error_; | 649 DriveFileError expected_error_; |
651 int expected_cache_state_; | 650 int expected_cache_state_; |
652 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; | 651 DriveCache::CacheSubDirectoryType expected_sub_dir_type_; |
653 bool expected_success_; | 652 bool expected_success_; |
654 bool expect_outgoing_symlink_; | 653 bool expect_outgoing_symlink_; |
655 std::string expected_file_extension_; | 654 std::string expected_file_extension_; |
656 int root_feed_changestamp_; | 655 int root_feed_changestamp_; |
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 // Don't use TEST_F, as we don't want SetUp() and TearDown() for this test. | 1336 // Don't use TEST_F, as we don't want SetUp() and TearDown() for this test. |
1338 TEST(DriveCacheExtraTest, InitializationFailure) { | 1337 TEST(DriveCacheExtraTest, InitializationFailure) { |
1339 MessageLoopForUI message_loop; | 1338 MessageLoopForUI message_loop; |
1340 content::TestBrowserThread ui_thread(content::BrowserThread::UI, | 1339 content::TestBrowserThread ui_thread(content::BrowserThread::UI, |
1341 &message_loop); | 1340 &message_loop); |
1342 | 1341 |
1343 scoped_refptr<base::SequencedWorkerPool> pool = | 1342 scoped_refptr<base::SequencedWorkerPool> pool = |
1344 content::BrowserThread::GetBlockingPool(); | 1343 content::BrowserThread::GetBlockingPool(); |
1345 | 1344 |
1346 // Set the cache root to a non existent path, so the initialization fails. | 1345 // Set the cache root to a non existent path, so the initialization fails. |
1347 DriveCache* cache = new DriveCache( | 1346 scoped_ptr<DriveCache, test_util::DestroyHelperForTests> cache(new DriveCache( |
1348 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"), | 1347 base::FilePath::FromUTF8Unsafe("/somewhere/nonexistent/blah/blah"), |
1349 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), | 1348 pool->GetSequencedTaskRunner(pool->GetSequenceToken()), |
1350 NULL /* free_disk_space_getter */); | 1349 NULL /* free_disk_space_getter */)); |
1351 | 1350 |
1352 bool success = false; | 1351 bool success = false; |
1353 cache->RequestInitialize( | 1352 cache->RequestInitialize( |
1354 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &success)); | 1353 base::Bind(&test_util::CopyResultFromInitializeCacheCallback, &success)); |
1355 google_apis::test_util::RunBlockingPoolTask(); | 1354 google_apis::test_util::RunBlockingPoolTask(); |
1356 EXPECT_FALSE(success); | 1355 EXPECT_FALSE(success); |
1357 | |
1358 test_util::DeleteDriveCache(cache); | |
1359 } | 1356 } |
1360 | 1357 |
1361 } // namespace drive | 1358 } // namespace drive |
OLD | NEW |