| 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/gdata/drive_test_util.h" | 5 #include "chrome/browser/chromeos/gdata/drive_test_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | |
| 8 #include "base/json/json_file_value_serializer.h" | 7 #include "base/json/json_file_value_serializer.h" |
| 9 #include "base/message_loop.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/threading/sequenced_worker_pool.h" | |
| 12 #include "chrome/browser/chromeos/gdata/drive.pb.h" | 8 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 13 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" | 9 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" |
| 14 #include "chrome/browser/chromeos/gdata/drive_file_system.h" | 10 #include "chrome/browser/chromeos/gdata/drive_file_system.h" |
| 15 #include "chrome/common/chrome_paths.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 12 |
| 19 namespace gdata { | 13 namespace gdata { |
| 20 namespace test_util { | 14 namespace test_util { |
| 21 | 15 |
| 22 // This class is used to monitor if any task is posted to a message loop. | |
| 23 class TaskObserver : public MessageLoop::TaskObserver { | |
| 24 public: | |
| 25 TaskObserver() : posted_(false) {} | |
| 26 virtual ~TaskObserver() {} | |
| 27 | |
| 28 // MessageLoop::TaskObserver overrides. | |
| 29 virtual void WillProcessTask(base::TimeTicks time_posted) {} | |
| 30 virtual void DidProcessTask(base::TimeTicks time_posted) { | |
| 31 posted_ = true; | |
| 32 } | |
| 33 | |
| 34 // Returns true if any task was posted. | |
| 35 bool posted() const { return posted_; } | |
| 36 | |
| 37 private: | |
| 38 bool posted_; | |
| 39 DISALLOW_COPY_AND_ASSIGN(TaskObserver); | |
| 40 }; | |
| 41 | |
| 42 void RunBlockingPoolTask() { | |
| 43 while (true) { | |
| 44 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | |
| 45 | |
| 46 TaskObserver task_observer; | |
| 47 MessageLoop::current()->AddTaskObserver(&task_observer); | |
| 48 MessageLoop::current()->RunAllPending(); | |
| 49 MessageLoop::current()->RemoveTaskObserver(&task_observer); | |
| 50 if (!task_observer.posted()) | |
| 51 break; | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 DriveCacheEntry ToCacheEntry(int cache_state) { | 16 DriveCacheEntry ToCacheEntry(int cache_state) { |
| 56 DriveCacheEntry cache_entry; | 17 DriveCacheEntry cache_entry; |
| 57 cache_entry.set_is_present(cache_state & TEST_CACHE_STATE_PRESENT); | 18 cache_entry.set_is_present(cache_state & TEST_CACHE_STATE_PRESENT); |
| 58 cache_entry.set_is_pinned(cache_state & TEST_CACHE_STATE_PINNED); | 19 cache_entry.set_is_pinned(cache_state & TEST_CACHE_STATE_PINNED); |
| 59 cache_entry.set_is_dirty(cache_state & TEST_CACHE_STATE_DIRTY); | 20 cache_entry.set_is_dirty(cache_state & TEST_CACHE_STATE_DIRTY); |
| 60 cache_entry.set_is_mounted(cache_state & TEST_CACHE_STATE_MOUNTED); | 21 cache_entry.set_is_mounted(cache_state & TEST_CACHE_STATE_MOUNTED); |
| 61 cache_entry.set_is_persistent(cache_state & TEST_CACHE_STATE_PERSISTENT); | 22 cache_entry.set_is_persistent(cache_state & TEST_CACHE_STATE_PERSISTENT); |
| 62 return cache_entry; | 23 return cache_entry; |
| 63 } | 24 } |
| 64 | 25 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 } | 90 } |
| 130 | 91 |
| 131 void CopyResultsFromGetEntryInfoPairCallback( | 92 void CopyResultsFromGetEntryInfoPairCallback( |
| 132 scoped_ptr<EntryInfoPairResult>* out_result, | 93 scoped_ptr<EntryInfoPairResult>* out_result, |
| 133 scoped_ptr<EntryInfoPairResult> result) { | 94 scoped_ptr<EntryInfoPairResult> result) { |
| 134 DCHECK(out_result); | 95 DCHECK(out_result); |
| 135 | 96 |
| 136 *out_result = result.Pass(); | 97 *out_result = result.Pass(); |
| 137 } | 98 } |
| 138 | 99 |
| 139 FilePath GetTestFilePath(const std::string& relative_path) { | |
| 140 FilePath path; | |
| 141 std::string error; | |
| 142 PathService::Get(chrome::DIR_TEST_DATA, &path); | |
| 143 path = path.AppendASCII("chromeos") | |
| 144 .Append(FilePath::FromUTF8Unsafe(relative_path)); | |
| 145 EXPECT_TRUE(file_util::PathExists(path)) << | |
| 146 "Couldn't find " << path.value(); | |
| 147 return path; | |
| 148 } | |
| 149 | |
| 150 scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) { | |
| 151 FilePath path = GetTestFilePath(relative_path); | |
| 152 | |
| 153 std::string error; | |
| 154 JSONFileValueSerializer serializer(path); | |
| 155 scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error)); | |
| 156 EXPECT_TRUE(value.get()) << | |
| 157 "Parse error " << path.value() << ": " << error; | |
| 158 return value.Pass(); | |
| 159 } | |
| 160 | |
| 161 void LoadChangeFeed(const std::string& relative_path, | 100 void LoadChangeFeed(const std::string& relative_path, |
| 162 DriveFileSystem* file_system, | 101 DriveFileSystem* file_system, |
| 163 int64 start_changestamp, | 102 int64 start_changestamp, |
| 164 int64 root_feed_changestamp) { | 103 int64 root_feed_changestamp) { |
| 165 std::string error; | 104 std::string error; |
| 166 scoped_ptr<Value> document = test_util::LoadJSONFile(relative_path); | 105 scoped_ptr<Value> document = test_util::LoadJSONFile(relative_path); |
| 167 ASSERT_TRUE(document.get()); | 106 ASSERT_TRUE(document.get()); |
| 168 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); | 107 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); |
| 169 scoped_ptr<DocumentFeed> document_feed( | 108 scoped_ptr<DocumentFeed> document_feed( |
| 170 DocumentFeed::ExtractAndParse(*document)); | 109 DocumentFeed::ExtractAndParse(*document)); |
| 171 ASSERT_TRUE(document_feed.get()); | 110 ASSERT_TRUE(document_feed.get()); |
| 172 ScopedVector<DocumentFeed> feed_list; | 111 ScopedVector<DocumentFeed> feed_list; |
| 173 feed_list.push_back(document_feed.release()); | 112 feed_list.push_back(document_feed.release()); |
| 174 | 113 |
| 175 GURL unused; | 114 GURL unused; |
| 176 DriveFileError file_error = file_system->UpdateFromFeedForTesting( | 115 DriveFileError file_error = file_system->UpdateFromFeedForTesting( |
| 177 feed_list, | 116 feed_list, |
| 178 start_changestamp, | 117 start_changestamp, |
| 179 root_feed_changestamp); | 118 root_feed_changestamp); |
| 180 ASSERT_EQ(DRIVE_FILE_OK, file_error); | 119 ASSERT_EQ(DRIVE_FILE_OK, file_error); |
| 181 } | 120 } |
| 182 | 121 |
| 183 } // namespace test_util | 122 } // namespace test_util |
| 184 } // namespace gdata | 123 } // namespace gdata |
| OLD | NEW |