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/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/fake_drive_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/json/json_string_value_serializer.h" |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
11 #include "base/md5.h" | 12 #include "base/md5.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
15 #include "base/strings/string_tokenizer.h" | 16 #include "base/strings/string_tokenizer.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
209 | 210 |
210 // Load JSON data, which must be a dictionary. | 211 // Load JSON data, which must be a dictionary. |
211 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); | 212 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); |
212 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); | 213 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
213 app_info_value_.reset( | 214 app_info_value_.reset( |
214 static_cast<base::DictionaryValue*>(value.release())); | 215 static_cast<base::DictionaryValue*>(value.release())); |
215 return app_info_value_; | 216 return app_info_value_; |
216 } | 217 } |
217 | 218 |
| 219 void FakeDriveService::AddApp(const std::string& app_id, |
| 220 const std::string& app_name, |
| 221 const std::string& product_id, |
| 222 const std::string& create_url) { |
| 223 if (app_json_template_.empty()) { |
| 224 base::FilePath path = |
| 225 test_util::GetTestFilePath("drive/applist_app_template.json"); |
| 226 CHECK(base::ReadFileToString(path, &app_json_template_)); |
| 227 } |
| 228 |
| 229 std::string app_json = app_json_template_; |
| 230 ReplaceSubstringsAfterOffset(&app_json, 0, "$AppId", app_id); |
| 231 ReplaceSubstringsAfterOffset(&app_json, 0, "$AppName", app_name); |
| 232 ReplaceSubstringsAfterOffset(&app_json, 0, "$ProductId", product_id); |
| 233 ReplaceSubstringsAfterOffset(&app_json, 0, "$CreateUrl", create_url); |
| 234 |
| 235 JSONStringValueSerializer json(app_json); |
| 236 std::string error_message; |
| 237 scoped_ptr<base::Value> value(json.Deserialize(NULL, &error_message)); |
| 238 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
| 239 |
| 240 base::ListValue* item_list; |
| 241 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
| 242 item_list->Append(value.release()); |
| 243 } |
| 244 |
| 245 void FakeDriveService::RemoveAppByProductId(const std::string& product_id) { |
| 246 base::ListValue* item_list; |
| 247 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
| 248 for (size_t i = 0; i < item_list->GetSize(); ++i) { |
| 249 base::DictionaryValue* item; |
| 250 CHECK(item_list->GetDictionary(i, &item)); |
| 251 const char kKeyProductId[] = "productId"; |
| 252 std::string item_product_id; |
| 253 if (item->GetStringWithoutPathExpansion(kKeyProductId, &item_product_id) && |
| 254 product_id == item_product_id) { |
| 255 item_list->Remove(i, NULL); |
| 256 return; |
| 257 } |
| 258 } |
| 259 } |
| 260 |
| 261 bool FakeDriveService::HasApp(const std::string& app_id) const { |
| 262 base::ListValue* item_list; |
| 263 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
| 264 for (size_t i = 0; i < item_list->GetSize(); ++i) { |
| 265 base::DictionaryValue* item; |
| 266 CHECK(item_list->GetDictionary(i, &item)); |
| 267 const char kKeyId[] = "id"; |
| 268 std::string item_id; |
| 269 if (item->GetStringWithoutPathExpansion(kKeyId, &item_id) && |
| 270 item_id == app_id) { |
| 271 return true; |
| 272 } |
| 273 } |
| 274 |
| 275 return false; |
| 276 } |
| 277 |
218 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { | 278 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { |
219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
220 | 280 |
221 about_resource_->set_quota_bytes_used(used); | 281 about_resource_->set_quota_bytes_used(used); |
222 about_resource_->set_quota_bytes_total(total); | 282 about_resource_->set_quota_bytes_total(total); |
223 } | 283 } |
224 | 284 |
225 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { | 285 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { |
226 return GURL("https://fake_server/" + net::EscapePath(resource_id)); | 286 return GURL("https://fake_server/" + net::EscapePath(resource_id)); |
227 } | 287 } |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 google_apis::drive::PermissionRole role, | 1568 google_apis::drive::PermissionRole role, |
1509 const google_apis::EntryActionCallback& callback) { | 1569 const google_apis::EntryActionCallback& callback) { |
1510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1570 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1511 DCHECK(!callback.is_null()); | 1571 DCHECK(!callback.is_null()); |
1512 | 1572 |
1513 NOTREACHED(); | 1573 NOTREACHED(); |
1514 return CancelCallback(); | 1574 return CancelCallback(); |
1515 } | 1575 } |
1516 | 1576 |
1517 } // namespace drive | 1577 } // namespace drive |
OLD | NEW |