Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2216)

Unified Diff: chrome/browser/google_apis/fake_drive_service.cc

Issue 11787038: google_apis: Implement some functions in FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Exclude the test on Android Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/google_apis/fake_drive_service.cc
diff --git a/chrome/browser/google_apis/fake_drive_service.cc b/chrome/browser/google_apis/fake_drive_service.cc
index c349337f0be0f4cbb71f423ca8f16cef794c120c..c4f7064249d36965023995f746319e9071019213 100644
--- a/chrome/browser/google_apis/fake_drive_service.cc
+++ b/chrome/browser/google_apis/fake_drive_service.cc
@@ -5,6 +5,9 @@
#include "chrome/browser/google_apis/fake_drive_service.h"
#include "base/logging.h"
+#include "base/message_loop.h"
+#include "chrome/browser/google_apis/gdata_wapi_parser.h"
+#include "chrome/browser/google_apis/test_util.h"
#include "content/public/browser/browser_thread.h"
using content::BrowserThread;
@@ -19,6 +22,32 @@ FakeDriveService::~FakeDriveService() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
+bool FakeDriveService::LoadResourceListForWapi(
+ const std::string& relative_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ scoped_ptr<Value> raw_value = test_util::LoadJSONFile(relative_path);
+ base::DictionaryValue* as_dict = NULL;
+ base::Value* feed = NULL;
+ base::DictionaryValue* feed_as_dict = NULL;
+
+ // Extract the "feed" from the raw value and take the ownership.
+ // Note that Remove() transfers the ownership to |feed|.
+ if (raw_value->GetAsDictionary(&as_dict) &&
+ as_dict->Remove("feed", &feed) &&
+ feed->GetAsDictionary(&feed_as_dict)) {
+ resource_list_value_.reset(feed_as_dict);
+ }
+
+ return resource_list_value_;
+}
+
+bool FakeDriveService::LoadAccountMetadataForWapi(
+ const std::string& relative_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ account_metadata_value_ = test_util::LoadJSONFile(relative_path);
+ return account_metadata_value_;
+}
+
void FakeDriveService::Initialize(Profile* profile) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
@@ -68,6 +97,14 @@ void FakeDriveService::GetResourceList(
const GetResourceListCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+
+ scoped_ptr<ResourceList> resource_list =
+ ResourceList::CreateFrom(*resource_list_value_);
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ HTTP_SUCCESS,
+ base::Passed(&resource_list)));
}
void FakeDriveService::GetResourceEntry(
@@ -75,12 +112,48 @@ void FakeDriveService::GetResourceEntry(
const GetResourceEntryCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+
+ base::DictionaryValue* resource_list_dict = NULL;
+ base::ListValue* entries = NULL;
+ // Go through entries and return the one that matches |resource_id|.
+ if (resource_list_value_->GetAsDictionary(&resource_list_dict) &&
+ resource_list_dict->GetList("entry", &entries)) {
+ for (size_t i = 0; i < entries->GetSize(); ++i) {
+ base::DictionaryValue* entry = NULL;
+ base::DictionaryValue* resource_id_dict = NULL;
+ std::string current_resource_id;
+ if (entries->GetDictionary(i, &entry) &&
+ entry->GetDictionary("gd$resourceId", &resource_id_dict) &&
+ resource_id_dict->GetString("$t", &current_resource_id) &&
+ resource_id == current_resource_id) {
+ scoped_ptr<ResourceEntry> resource_entry =
+ ResourceEntry::CreateFrom(*entry);
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, HTTP_SUCCESS, base::Passed(&resource_entry)));
+ return;
+ }
+ }
+ }
+
+ scoped_ptr<ResourceEntry> null;
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback, HTTP_NOT_FOUND, base::Passed(&null)));
}
void FakeDriveService::GetAccountMetadata(
const GetAccountMetadataCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+
+ scoped_ptr<AccountMetadataFeed> account_metadata =
+ AccountMetadataFeed::CreateFrom(*account_metadata_value_);
+ MessageLoop::current()->PostTask(
+ FROM_HERE,
+ base::Bind(callback,
+ HTTP_SUCCESS,
+ base::Passed(&account_metadata)));
}
void FakeDriveService::GetApplicationInfo(
@@ -94,6 +167,38 @@ void FakeDriveService::DeleteResource(
const EntryActionCallback& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null());
+
+ base::DictionaryValue* resource_list_dict = NULL;
+ base::ListValue* entries = NULL;
+ // Go through entries and remove the one that matches |edit_url|.
+ if (resource_list_value_->GetAsDictionary(&resource_list_dict) &&
+ resource_list_dict->GetList("entry", &entries)) {
+ for (size_t i = 0; i < entries->GetSize(); ++i) {
+ base::DictionaryValue* entry = NULL;
+ base::ListValue* links = NULL;
+ if (entries->GetDictionary(i, &entry) &&
+ entry->GetList("link", &links)) {
+ for (size_t j = 0; j < links->GetSize(); ++j) {
+ base::DictionaryValue* link = NULL;
+ std::string rel;
+ std::string href;
+ if (links->GetDictionary(j, &link) &&
+ link->GetString("rel", &rel) &&
+ link->GetString("href", &href) &&
+ rel == "edit" &&
+ GURL(href) == edit_url) {
+ entries->Remove(i, NULL);
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, HTTP_SUCCESS));
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ MessageLoop::current()->PostTask(
+ FROM_HERE, base::Bind(callback, HTTP_NOT_FOUND));
}
void FakeDriveService::DownloadHostedDocument(
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.h ('k') | chrome/browser/google_apis/fake_drive_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698