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/gdata_test_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_test_util.h" |
6 | 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/json/json_file_value_serializer.h" |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/path_service.h" |
8 #include "base/threading/sequenced_worker_pool.h" | 11 #include "base/threading/sequenced_worker_pool.h" |
9 #include "chrome/browser/chromeos/gdata/drive.pb.h" | 12 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
| 13 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" |
| 14 #include "chrome/browser/chromeos/gdata/drive_file_system.h" |
| 15 #include "chrome/common/chrome_paths.h" |
10 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
11 | 18 |
12 namespace gdata { | 19 namespace gdata { |
13 namespace test_util { | 20 namespace test_util { |
14 | 21 |
15 // This class is used to monitor if any task is posted to a message loop. | 22 // This class is used to monitor if any task is posted to a message loop. |
16 class TaskObserver : public MessageLoop::TaskObserver { | 23 class TaskObserver : public MessageLoop::TaskObserver { |
17 public: | 24 public: |
18 TaskObserver() : posted_(false) {} | 25 TaskObserver() : posted_(false) {} |
19 virtual ~TaskObserver() {} | 26 virtual ~TaskObserver() {} |
20 | 27 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 } | 129 } |
123 | 130 |
124 void CopyResultsFromGetEntryInfoPairCallback( | 131 void CopyResultsFromGetEntryInfoPairCallback( |
125 scoped_ptr<EntryInfoPairResult>* out_result, | 132 scoped_ptr<EntryInfoPairResult>* out_result, |
126 scoped_ptr<EntryInfoPairResult> result) { | 133 scoped_ptr<EntryInfoPairResult> result) { |
127 DCHECK(out_result); | 134 DCHECK(out_result); |
128 | 135 |
129 *out_result = result.Pass(); | 136 *out_result = result.Pass(); |
130 } | 137 } |
131 | 138 |
| 139 // Returns the absolute path for a test file stored under |
| 140 // chrome/test/data/chromeos/gdata. |
| 141 FilePath GetTestFilePath(const FilePath::StringType& base_name) { |
| 142 FilePath path; |
| 143 std::string error; |
| 144 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 145 path = path.AppendASCII("chromeos") |
| 146 .AppendASCII("gdata") |
| 147 .AppendASCII(base_name.c_str()); |
| 148 EXPECT_TRUE(file_util::PathExists(path)) << |
| 149 "Couldn't find " << path.value(); |
| 150 return path; |
| 151 } |
| 152 |
| 153 base::Value* LoadJSONFile(const std::string& base_name) { |
| 154 FilePath path = GetTestFilePath(base_name); |
| 155 |
| 156 std::string error; |
| 157 JSONFileValueSerializer serializer(path); |
| 158 base::Value* value = serializer.Deserialize(NULL, &error); |
| 159 EXPECT_TRUE(value) << |
| 160 "Parse error " << path.value() << ": " << error; |
| 161 return value; |
| 162 } |
| 163 |
| 164 void LoadChangeFeed(const std::string& filename, |
| 165 DriveFileSystem* file_system, |
| 166 int64 start_changestamp, |
| 167 int64 root_feed_changestamp) { |
| 168 std::string error; |
| 169 scoped_ptr<Value> document(test_util::LoadJSONFile(filename)); |
| 170 ASSERT_TRUE(document.get()); |
| 171 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); |
| 172 scoped_ptr<DocumentFeed> document_feed( |
| 173 DocumentFeed::ExtractAndParse(*document)); |
| 174 ASSERT_TRUE(document_feed.get()); |
| 175 std::vector<DocumentFeed*> feed_list; |
| 176 feed_list.push_back(document_feed.get()); |
| 177 |
| 178 GURL unused; |
| 179 DriveFileError file_error = file_system->UpdateFromFeedForTesting( |
| 180 feed_list, |
| 181 start_changestamp, |
| 182 root_feed_changestamp); |
| 183 ASSERT_EQ(DRIVE_FILE_OK, file_error); |
| 184 } |
| 185 |
132 } // namespace test_util | 186 } // namespace test_util |
133 } // namespace gdata | 187 } // namespace gdata |
OLD | NEW |