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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 193 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
193 | 194 |
194 // Load JSON data, which must be a dictionary. | 195 // Load JSON data, which must be a dictionary. |
195 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); | 196 scoped_ptr<base::Value> value = test_util::LoadJSONFile(relative_path); |
196 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); | 197 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
197 app_info_value_.reset( | 198 app_info_value_.reset( |
198 static_cast<base::DictionaryValue*>(value.release())); | 199 static_cast<base::DictionaryValue*>(value.release())); |
199 return app_info_value_; | 200 return app_info_value_; |
200 } | 201 } |
201 | 202 |
| 203 void FakeDriveService::AddApp(const std::string& app_id, |
| 204 const std::string& app_name, |
| 205 const std::string& product_id, |
| 206 const std::string& create_url) { |
| 207 if (app_json_template_.empty()) { |
| 208 base::FilePath path = |
| 209 test_util::GetTestFilePath("drive/applist_app_template.json"); |
| 210 CHECK(base::ReadFileToString(path, &app_json_template_)); |
| 211 } |
| 212 |
| 213 std::string app_json = app_json_template_; |
| 214 ReplaceSubstringsAfterOffset(&app_json, 0, "$AppId", app_id); |
| 215 ReplaceSubstringsAfterOffset(&app_json, 0, "$AppName", app_name); |
| 216 ReplaceSubstringsAfterOffset(&app_json, 0, "$ProductId", product_id); |
| 217 ReplaceSubstringsAfterOffset(&app_json, 0, "$CreateUrl", create_url); |
| 218 |
| 219 JSONStringValueSerializer json(app_json); |
| 220 std::string error_message; |
| 221 scoped_ptr<base::Value> value(json.Deserialize(NULL, &error_message)); |
| 222 CHECK_EQ(base::Value::TYPE_DICTIONARY, value->GetType()); |
| 223 |
| 224 base::ListValue* item_list; |
| 225 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
| 226 item_list->Append(value.release()); |
| 227 } |
| 228 |
| 229 void FakeDriveService::RemoveAppByProductId(const std::string& product_id) { |
| 230 base::ListValue* item_list; |
| 231 CHECK(app_info_value_->GetListWithoutPathExpansion("items", &item_list)); |
| 232 for (size_t i = 0; i < item_list->GetSize(); ++i) { |
| 233 base::DictionaryValue* item; |
| 234 CHECK(item_list->GetDictionary(i, &item)); |
| 235 const char kKeyProductId[] = "productId"; |
| 236 std::string item_product_id; |
| 237 if (item->GetStringWithoutPathExpansion(kKeyProductId, &item_product_id) && |
| 238 product_id == item_product_id) { |
| 239 item_list->Remove(i, NULL); |
| 240 return; |
| 241 } |
| 242 } |
| 243 } |
| 244 |
| 245 bool FakeDriveService::HasApp(const std::string& app_id) const { |
| 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 kKeyId[] = "id"; |
| 252 std::string item_id; |
| 253 if (item->GetStringWithoutPathExpansion(kKeyId, &item_id) && |
| 254 item_id == app_id) { |
| 255 return true; |
| 256 } |
| 257 } |
| 258 |
| 259 return false; |
| 260 } |
| 261 |
202 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { | 262 void FakeDriveService::SetQuotaValue(int64 used, int64 total) { |
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
204 | 264 |
205 about_resource_->set_quota_bytes_used(used); | 265 about_resource_->set_quota_bytes_used(used); |
206 about_resource_->set_quota_bytes_total(total); | 266 about_resource_->set_quota_bytes_total(total); |
207 } | 267 } |
208 | 268 |
209 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { | 269 GURL FakeDriveService::GetFakeLinkUrl(const std::string& resource_id) { |
210 return GURL("https://fake_server/" + net::EscapePath(resource_id)); | 270 return GURL("https://fake_server/" + net::EscapePath(resource_id)); |
211 } | 271 } |
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1502 google_apis::drive::PermissionRole role, | 1562 google_apis::drive::PermissionRole role, |
1503 const google_apis::EntryActionCallback& callback) { | 1563 const google_apis::EntryActionCallback& callback) { |
1504 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1505 DCHECK(!callback.is_null()); | 1565 DCHECK(!callback.is_null()); |
1506 | 1566 |
1507 NOTREACHED(); | 1567 NOTREACHED(); |
1508 return CancelCallback(); | 1568 return CancelCallback(); |
1509 } | 1569 } |
1510 | 1570 |
1511 } // namespace drive | 1571 } // namespace drive |
OLD | NEW |