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

Unified Diff: chrome/browser/google_apis/fake_drive_service_unittest.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
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/google_apis/fake_drive_service_unittest.cc
diff --git a/chrome/browser/google_apis/fake_drive_service_unittest.cc b/chrome/browser/google_apis/fake_drive_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c205c62dff65d494a69fd0b28c18e87af6e11b63
--- /dev/null
+++ b/chrome/browser/google_apis/fake_drive_service_unittest.cc
@@ -0,0 +1,148 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/google_apis/fake_drive_service.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"
+#include "content/public/test/test_browser_thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace google_apis {
+
+class FakeDriveServiceTest : public testing::Test {
+ protected:
+ FakeDriveServiceTest()
+ : ui_thread_(content::BrowserThread::UI, &message_loop_) {
+ }
+
+ // Returns true if the resource identified by |resource_id| exists.
+ bool Exists(const std::string& resource_id) {
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceEntry> resource_entry;
+ fake_service_.GetResourceEntry(
+ resource_id,
+ base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
+ &error,
+ &resource_entry));
+ message_loop_.RunUntilIdle();
+ return error == HTTP_SUCCESS;
+ }
+
+ MessageLoopForUI message_loop_;
+ content::TestBrowserThread ui_thread_;
+ FakeDriveService fake_service_;
+};
+
+TEST_F(FakeDriveServiceTest, GetResourceList) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceList> resource_list;
+ fake_service_.GetResourceList(
+ GURL(),
+ 0, // start_changestamp
+ "", // search_query
+ false, // shared_with_me
+ "", // directory_resource_id
+ base::Bind(&test_util::CopyResultsFromGetResourceListCallback,
+ &error,
+ &resource_list));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ ASSERT_TRUE(resource_list);
+ // Do some sanity check.
+ EXPECT_EQ(12U, resource_list->entries().size());
+}
+
+TEST_F(FakeDriveServiceTest, GetAccountMetadata) {
+ ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
+ "gdata/account_metadata.json"));
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<AccountMetadataFeed> account_metadata;
+ fake_service_.GetAccountMetadata(
+ base::Bind(&test_util::CopyResultsFromGetAccountMetadataCallback,
+ &error,
+ &account_metadata));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+
+ ASSERT_TRUE(account_metadata);
+ // Do some sanity check.
+ EXPECT_EQ(2U, account_metadata->installed_apps().size());
+}
+
+TEST_F(FakeDriveServiceTest, GetResourceEntry_ExistingFile) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ const std::string kResourceId = "file:2_file_resource_id";
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceEntry> resource_entry;
+ fake_service_.GetResourceEntry(
+ kResourceId,
+ base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
+ &error,
+ &resource_entry));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ ASSERT_TRUE(resource_entry);
+ // Do some sanity check.
+ EXPECT_EQ(kResourceId, resource_entry->resource_id());
+}
+
+TEST_F(FakeDriveServiceTest, GetResourceEntry_NonexistingFile) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ const std::string kResourceId = "file:nonexisting_resource_id";
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ scoped_ptr<ResourceEntry> resource_entry;
+ fake_service_.GetResourceEntry(
+ kResourceId,
+ base::Bind(&test_util::CopyResultsFromGetResourceEntryCallback,
+ &error,
+ &resource_entry));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_NOT_FOUND, error);
+ ASSERT_FALSE(resource_entry);
+}
+
+TEST_F(FakeDriveServiceTest, DeleteResource_ExistingFile) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ // Resource "file:2_file_resource_id" should now exist.
+ ASSERT_TRUE(Exists("file:2_file_resource_id"));
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ fake_service_.DeleteResource(
+ GURL("https://file1_link_self/file:2_file_resource_id"),
+ base::Bind(&test_util::CopyResultsFromEntryActionCallback,
+ &error));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_SUCCESS, error);
+ // Resource "file:2_file_resource_id" should be gone now.
+ EXPECT_FALSE(Exists("file:2_file_resource_id"));
+}
+
+TEST_F(FakeDriveServiceTest, DeleteResource_NonexistingFile) {
+ ASSERT_TRUE(fake_service_.LoadResourceListForWapi("gdata/root_feed.json"));
+
+ GDataErrorCode error = GDATA_OTHER_ERROR;
+ fake_service_.DeleteResource(
+ GURL("https://file1_link_self/file:nonexisting_resource_id"),
+ base::Bind(&test_util::CopyResultsFromEntryActionCallback,
+ &error));
+ message_loop_.RunUntilIdle();
+
+ EXPECT_EQ(HTTP_NOT_FOUND, error);
+}
+
+} // namespace google_apis
« no previous file with comments | « chrome/browser/google_apis/fake_drive_service.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698