summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/gdata
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 16:06:04 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 16:06:04 +0000
commit6258b86e1d35c31818cf8fafb71c574622fa009b (patch)
tree458f151998cba77b8dfbdd7ef431e04337b42cb0 /chrome/browser/chromeos/gdata
parent7a3a69a2c0f5acb6c16f104399aecc0e85474f28 (diff)
downloadchromium_src-6258b86e1d35c31818cf8fafb71c574622fa009b.zip
chromium_src-6258b86e1d35c31818cf8fafb71c574622fa009b.tar.gz
chromium_src-6258b86e1d35c31818cf8fafb71c574622fa009b.tar.bz2
drive: Change LoadJSONFile() to return a scoped_ptr.
This makes the ownership of the returned object clearer. BUG=148730 TEST=unit_tests Review URL: https://codereview.chromium.org/10907208 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156557 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/gdata')
-rw-r--r--chrome/browser/chromeos/gdata/document_entry_conversion_unittest.cc16
-rw-r--r--chrome/browser/chromeos/gdata/drive_api_parser_unittest.cc9
-rw-r--r--chrome/browser/chromeos/gdata/drive_file_system_unittest.cc50
-rw-r--r--chrome/browser/chromeos/gdata/drive_test_util.cc10
-rw-r--r--chrome/browser/chromeos/gdata/drive_test_util.h4
-rw-r--r--chrome/browser/chromeos/gdata/drive_webapps_registry_unittest.cc6
-rw-r--r--chrome/browser/chromeos/gdata/gdata_wapi_parser_unittest.cc7
-rw-r--r--chrome/browser/chromeos/gdata/mock_drive_service.cc12
8 files changed, 57 insertions, 57 deletions
diff --git a/chrome/browser/chromeos/gdata/document_entry_conversion_unittest.cc b/chrome/browser/chromeos/gdata/document_entry_conversion_unittest.cc
index c96c0b0..d363308 100644
--- a/chrome/browser/chromeos/gdata/document_entry_conversion_unittest.cc
+++ b/chrome/browser/chromeos/gdata/document_entry_conversion_unittest.cc
@@ -15,8 +15,8 @@
namespace gdata {
TEST(DocumentEntryConversionTest, ConvertDocumentEntryToDriveEntryProto_File) {
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/file_entry.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/file_entry.json");
ASSERT_TRUE(value.get());
scoped_ptr<DocumentEntry> document_entry(
@@ -74,8 +74,8 @@ TEST(DocumentEntryConversionTest, ConvertDocumentEntryToDriveEntryProto_File) {
TEST(DocumentEntryConversionTest,
ConvertDocumentEntryToDriveEntryProto_HostedDocument) {
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/hosted_document_entry.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/hosted_document_entry.json");
ASSERT_TRUE(value.get());
scoped_ptr<DocumentEntry> document_entry(
@@ -142,8 +142,8 @@ TEST(DocumentEntryConversionTest,
TEST(DocumentEntryConversionTest,
ConvertDocumentEntryToDriveEntryProto_Directory) {
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/directory_entry.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/directory_entry.json");
ASSERT_TRUE(value.get());
scoped_ptr<DocumentEntry> document_entry(
@@ -205,8 +205,8 @@ TEST(DocumentEntryConversionTest,
TEST(DocumentEntryConversionTest,
ConvertDocumentEntryToDriveEntryProto_DeletedHostedDocument) {
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/deleted_hosted_document_entry.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/deleted_hosted_document_entry.json");
ASSERT_TRUE(value.get());
scoped_ptr<DocumentEntry> document_entry(
diff --git a/chrome/browser/chromeos/gdata/drive_api_parser_unittest.cc b/chrome/browser/chromeos/gdata/drive_api_parser_unittest.cc
index 4f7d06a..ffc007c 100644
--- a/chrome/browser/chromeos/gdata/drive_api_parser_unittest.cc
+++ b/chrome/browser/chromeos/gdata/drive_api_parser_unittest.cc
@@ -26,7 +26,7 @@ namespace gdata {
// Test about resource parsing.
TEST(DriveAPIParserTest, AboutResourceParser) {
std::string error;
- scoped_ptr<Value> document(test_util::LoadJSONFile("drive/about.json"));
+ scoped_ptr<Value> document = test_util::LoadJSONFile("drive/about.json");
ASSERT_TRUE(document.get());
ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
@@ -42,7 +42,7 @@ TEST(DriveAPIParserTest, AboutResourceParser) {
// Test app list parsing.
TEST(DriveAPIParserTest, AppListParser) {
std::string error;
- scoped_ptr<Value> document(test_util::LoadJSONFile("drive/applist.json"));
+ scoped_ptr<Value> document = test_util::LoadJSONFile("drive/applist.json");
ASSERT_TRUE(document.get());
ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
@@ -123,7 +123,7 @@ TEST(DriveAPIParserTest, AppListParser) {
// Test file list parsing.
TEST(DriveAPIParserTest, FileListParser) {
std::string error;
- scoped_ptr<Value> document(test_util::LoadJSONFile("drive/filelist.json"));
+ scoped_ptr<Value> document = test_util::LoadJSONFile("drive/filelist.json");
ASSERT_TRUE(document.get());
ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
@@ -227,7 +227,8 @@ TEST(DriveAPIParserTest, FileListParser) {
// Test change list parsing.
TEST(DriveAPIParserTest, ChangeListParser) {
std::string error;
- scoped_ptr<Value> document(test_util::LoadJSONFile("drive/changelist.json"));
+ scoped_ptr<Value> document =
+ test_util::LoadJSONFile("drive/changelist.json");
ASSERT_TRUE(document.get());
ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
diff --git a/chrome/browser/chromeos/gdata/drive_file_system_unittest.cc b/chrome/browser/chromeos/gdata/drive_file_system_unittest.cc
index 8d4bdf8..f0b9f20 100644
--- a/chrome/browser/chromeos/gdata/drive_file_system_unittest.cc
+++ b/chrome/browser/chromeos/gdata/drive_file_system_unittest.cc
@@ -106,8 +106,8 @@ ACTION_P4(MockUploadExistingFile,
// Action used to set mock expectations for
// DriveUploaderInterface::UploadNewFile().
ACTION(MockUploadNewFile) {
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/uploaded_file.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/uploaded_file.json");
scoped_ptr<DocumentEntry> document_entry(
DocumentEntry::ExtractAndParse(*value));
@@ -238,7 +238,7 @@ class DriveFileSystemTest : public testing::Test {
void AddDirectoryFromFile(const FilePath& directory_path,
const std::string& filename) {
- scoped_ptr<Value> atom(test_util::LoadJSONFile(filename));
+ scoped_ptr<Value> atom = test_util::LoadJSONFile(filename);
ASSERT_TRUE(atom.get());
ASSERT_TRUE(atom->GetType() == Value::TYPE_DICTIONARY);
@@ -1175,7 +1175,7 @@ TEST_F(DriveFileSystemTest, CachedFeadLoadingThenServerFeedLoading) {
// SaveTestFileSystem and "account_metadata.json" have the same changestamp,
// so no request for new feeds (i.e., call to GetDocuments) should happen.
mock_drive_service_->set_account_metadata(
- test_util::LoadJSONFile("gdata/account_metadata.json"));
+ test_util::LoadJSONFile("gdata/account_metadata.json").release());
EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
EXPECT_CALL(*mock_drive_service_, GetDocuments(_, _, _, _, _)).Times(0);
@@ -1187,7 +1187,7 @@ TEST_F(DriveFileSystemTest, CachedFeadLoadingThenServerFeedLoading) {
// it should change its state to FROM_SERVER, which admits periodic refresh.
// To test it, call CheckForUpdates and verify it does try to check updates.
mock_drive_service_->set_account_metadata(
- test_util::LoadJSONFile("gdata/account_metadata.json"));
+ test_util::LoadJSONFile("gdata/account_metadata.json").release());
EXPECT_CALL(*mock_drive_service_, GetAccountMetadata(_)).Times(1);
EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1);
@@ -1220,8 +1220,8 @@ TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt"));
EXPECT_FALSE(EntryExists(remote_dest_file_path));
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
scoped_ptr<DocumentEntry> document_entry(
DocumentEntry::ExtractAndParse(*value));
@@ -1266,8 +1266,8 @@ TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) {
// We'll copy a hosted document using CopyDocument.
// ".gdoc" suffix should be stripped when copying.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/uploaded_document.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/uploaded_document.json");
EXPECT_CALL(*mock_drive_service_,
CopyDocument(kResourceId,
FILE_PATH_LITERAL("Document 1"),
@@ -1320,8 +1320,8 @@ TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is obtained with the mock DriveService.
@@ -1938,8 +1938,8 @@ TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is obtained with the mock DriveService.
@@ -1979,8 +1979,8 @@ TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is not obtained with the mock DriveService, because of no space.
@@ -2034,8 +2034,8 @@ TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is obtained with the mock DriveService, because of we freed up the
@@ -2087,8 +2087,8 @@ TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is obtained with the mock DriveService.
@@ -2193,8 +2193,8 @@ TEST_F(DriveFileSystemTest, GetFileByResourceId) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is obtained with the mock DriveService, because it's not stored in
@@ -2337,8 +2337,8 @@ TEST_F(DriveFileSystemTest, UpdateFileByResourceId_PersistentFile) {
// DriveUploaderInterface::UploadExistingFile().
// TODO(satorux): This should be cleaned up. crbug.com/134240.
DocumentEntry* document_entry = NULL;
- scoped_ptr<base::Value> value(
- test_util::LoadJSONFile("gdata/root_feed.json"));
+ scoped_ptr<base::Value> value =
+ test_util::LoadJSONFile("gdata/root_feed.json");
ASSERT_TRUE(value.get());
base::DictionaryValue* as_dict = NULL;
base::ListValue* entry_list = NULL;
@@ -2551,8 +2551,8 @@ TEST_F(DriveFileSystemTest, OpenAndCloseFile) {
// Before Download starts metadata from server will be fetched.
// We will read content url from the result.
- scoped_ptr<base::Value> document(
- test_util::LoadJSONFile("gdata/document_to_download.json"));
+ scoped_ptr<base::Value> document =
+ test_util::LoadJSONFile("gdata/document_to_download.json");
SetExpectationsForGetDocumentEntry(&document, "file:2_file_resource_id");
// The file is obtained with the mock DriveService.
diff --git a/chrome/browser/chromeos/gdata/drive_test_util.cc b/chrome/browser/chromeos/gdata/drive_test_util.cc
index f10fcc2..25010f5 100644
--- a/chrome/browser/chromeos/gdata/drive_test_util.cc
+++ b/chrome/browser/chromeos/gdata/drive_test_util.cc
@@ -147,15 +147,15 @@ FilePath GetTestFilePath(const std::string& relative_path) {
return path;
}
-base::Value* LoadJSONFile(const std::string& relative_path) {
+scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path) {
FilePath path = GetTestFilePath(relative_path);
std::string error;
JSONFileValueSerializer serializer(path);
- base::Value* value = serializer.Deserialize(NULL, &error);
- EXPECT_TRUE(value) <<
+ scoped_ptr<base::Value> value(serializer.Deserialize(NULL, &error));
+ EXPECT_TRUE(value.get()) <<
"Parse error " << path.value() << ": " << error;
- return value;
+ return value.Pass();
}
void LoadChangeFeed(const std::string& relative_path,
@@ -163,7 +163,7 @@ void LoadChangeFeed(const std::string& relative_path,
int64 start_changestamp,
int64 root_feed_changestamp) {
std::string error;
- scoped_ptr<Value> document(test_util::LoadJSONFile(relative_path));
+ scoped_ptr<Value> document = test_util::LoadJSONFile(relative_path);
ASSERT_TRUE(document.get());
ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY);
scoped_ptr<DocumentFeed> document_feed(
diff --git a/chrome/browser/chromeos/gdata/drive_test_util.h b/chrome/browser/chromeos/gdata/drive_test_util.h
index d4cdac6..7b3807c 100644
--- a/chrome/browser/chromeos/gdata/drive_test_util.h
+++ b/chrome/browser/chromeos/gdata/drive_test_util.h
@@ -105,9 +105,7 @@ FilePath GetTestFilePath(const std::string& relative_path);
// Loads a test JSON file as a base::Value, from a test file stored under
// chrome/test/data/chromeos.
-//
-// The caller should delete the returned object.
-base::Value* LoadJSONFile(const std::string& relative_path);
+scoped_ptr<base::Value> LoadJSONFile(const std::string& relative_path);
// Loads a test json file as root ("/drive") element from a test file stored
// under chrome/test/data/chromeos.
diff --git a/chrome/browser/chromeos/gdata/drive_webapps_registry_unittest.cc b/chrome/browser/chromeos/gdata/drive_webapps_registry_unittest.cc
index 068a316..f756af7 100644
--- a/chrome/browser/chromeos/gdata/drive_webapps_registry_unittest.cc
+++ b/chrome/browser/chromeos/gdata/drive_webapps_registry_unittest.cc
@@ -75,8 +75,8 @@ class DriveWebAppsRegistryTest : public testing::Test {
};
TEST_F(DriveWebAppsRegistryTest, LoadAndFindWebApps) {
- scoped_ptr<Value> document(
- test_util::LoadJSONFile("gdata/account_metadata.json"));
+ scoped_ptr<Value> document =
+ test_util::LoadJSONFile("gdata/account_metadata.json");
ASSERT_TRUE(document.get());
ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY);
DictionaryValue* entry_value;
@@ -124,7 +124,7 @@ TEST_F(DriveWebAppsRegistryTest, LoadAndFindWebApps) {
}
TEST_F(DriveWebAppsRegistryTest, LoadAndFindDriveWebApps) {
- scoped_ptr<Value> document(test_util::LoadJSONFile("drive/applist.json"));
+ scoped_ptr<Value> document = test_util::LoadJSONFile("drive/applist.json");
ASSERT_TRUE(document.get());
ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY);
diff --git a/chrome/browser/chromeos/gdata/gdata_wapi_parser_unittest.cc b/chrome/browser/chromeos/gdata/gdata_wapi_parser_unittest.cc
index 07babb4..2abded2 100644
--- a/chrome/browser/chromeos/gdata/gdata_wapi_parser_unittest.cc
+++ b/chrome/browser/chromeos/gdata/gdata_wapi_parser_unittest.cc
@@ -56,7 +56,8 @@ class GDataWAPIParserTest : public testing::Test {
// Test document feed parsing.
TEST_F(GDataWAPIParserTest, DocumentFeedJsonParser) {
std::string error;
- scoped_ptr<Value> document(test_util::LoadJSONFile("gdata/basic_feed.json"));
+ scoped_ptr<Value> document =
+ test_util::LoadJSONFile("gdata/basic_feed.json");
ASSERT_TRUE(document.get());
ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
scoped_ptr<DocumentFeed> feed(DocumentFeed::ExtractAndParse(*document));
@@ -266,8 +267,8 @@ TEST_F(GDataWAPIParserTest, DocumentEntryXmlParser) {
}
TEST_F(GDataWAPIParserTest, AccountMetadataFeedParser) {
- scoped_ptr<Value> document(
- test_util::LoadJSONFile("gdata/account_metadata.json"));
+ scoped_ptr<Value> document =
+ test_util::LoadJSONFile("gdata/account_metadata.json");
ASSERT_TRUE(document.get());
ASSERT_EQ(Value::TYPE_DICTIONARY, document->GetType());
DictionaryValue* entry_value = NULL;
diff --git a/chrome/browser/chromeos/gdata/mock_drive_service.cc b/chrome/browser/chromeos/gdata/mock_drive_service.cc
index bec8814..69bac42 100644
--- a/chrome/browser/chromeos/gdata/mock_drive_service.cc
+++ b/chrome/browser/chromeos/gdata/mock_drive_service.cc
@@ -49,18 +49,18 @@ MockDriveService::MockDriveService() {
.WillByDefault(Invoke(this, &MockDriveService::DownloadFileStub));
// Fill in the default values for mock feeds.
- account_metadata_.reset(
- test_util::LoadJSONFile("gdata/account_metadata.json"));
- feed_data_.reset(test_util::LoadJSONFile("gdata/basic_feed.json"));
- directory_data_.reset(
- test_util::LoadJSONFile("gdata/new_folder_entry.json"));
+ account_metadata_ =
+ test_util::LoadJSONFile("gdata/account_metadata.json");
+ feed_data_ = test_util::LoadJSONFile("gdata/basic_feed.json");
+ directory_data_ =
+ test_util::LoadJSONFile("gdata/new_folder_entry.json");
}
MockDriveService::~MockDriveService() {}
void MockDriveService::set_search_result(
const std::string& search_result_feed) {
- search_result_.reset(test_util::LoadJSONFile(search_result_feed));
+ search_result_ = test_util::LoadJSONFile(search_result_feed);
}
void MockDriveService::AuthenticateStub(