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

Side by Side Diff: chrome/browser/chromeos/drive/drive_file_system_unittest.cc

Issue 11359217: Move scoped_temp_dir from base to base/files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/chromeos/drive/drive_file_system.h" 5 #include "chrome/browser/chromeos/drive/drive_file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
13 #include "base/json/json_file_value_serializer.h" 14 #include "base/json/json_file_value_serializer.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop.h" 16 #include "base/message_loop.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/scoped_temp_dir.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/threading/sequenced_worker_pool.h" 19 #include "base/threading/sequenced_worker_pool.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "chrome/browser/chromeos/drive/drive.pb.h" 21 #include "chrome/browser/chromeos/drive/drive.pb.h"
22 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 22 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
23 #include "chrome/browser/chromeos/drive/drive_test_util.h" 23 #include "chrome/browser/chromeos/drive/drive_test_util.h"
24 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h" 24 #include "chrome/browser/chromeos/drive/drive_webapps_registry.h"
25 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 25 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
26 #include "chrome/browser/chromeos/drive/mock_directory_change_observer.h" 26 #include "chrome/browser/chromeos/drive/mock_directory_change_observer.h"
27 #include "chrome/browser/chromeos/drive/mock_drive_cache_observer.h" 27 #include "chrome/browser/chromeos/drive/mock_drive_cache_observer.h"
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 1269
1270 // We'll add a file to the Drive root directory. 1270 // We'll add a file to the Drive root directory.
1271 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1271 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1272 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1272 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1273 1273
1274 FileOperationCallback callback = 1274 FileOperationCallback callback =
1275 base::Bind(&CallbackHelper::FileOperationCallback, 1275 base::Bind(&CallbackHelper::FileOperationCallback,
1276 callback_helper_.get()); 1276 callback_helper_.get());
1277 1277
1278 // Prepare a local file. 1278 // Prepare a local file.
1279 ScopedTempDir temp_dir; 1279 base::ScopedTempDir temp_dir;
1280 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1280 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1281 const FilePath local_src_file_path = temp_dir.path().Append("local.txt"); 1281 const FilePath local_src_file_path = temp_dir.path().Append("local.txt");
1282 const std::string kContent = "hello"; 1282 const std::string kContent = "hello";
1283 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); 1283 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size());
1284 1284
1285 // Confirm that the remote file does not exist. 1285 // Confirm that the remote file does not exist.
1286 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt")); 1286 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt"));
1287 EXPECT_FALSE(EntryExists(remote_dest_file_path)); 1287 EXPECT_FALSE(EntryExists(remote_dest_file_path));
1288 1288
1289 scoped_ptr<base::Value> value = 1289 scoped_ptr<base::Value> value =
(...skipping 13 matching lines...) Expand all
1303 1303
1304 // Now the remote file should exist. 1304 // Now the remote file should exist.
1305 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 1305 EXPECT_TRUE(EntryExists(remote_dest_file_path));
1306 } 1306 }
1307 1307
1308 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { 1308 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) {
1309 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1309 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1310 1310
1311 // Prepare a local file, which is a json file of a hosted document, which 1311 // Prepare a local file, which is a json file of a hosted document, which
1312 // matches "Document 1" in root_feed.json. 1312 // matches "Document 1" in root_feed.json.
1313 ScopedTempDir temp_dir; 1313 base::ScopedTempDir temp_dir;
1314 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1314 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1315 const FilePath local_src_file_path = temp_dir.path().Append("local.gdoc"); 1315 const FilePath local_src_file_path = temp_dir.path().Append("local.gdoc");
1316 const std::string kEditUrl = 1316 const std::string kEditUrl =
1317 "https://3_document_self_link/document:5_document_resource_id"; 1317 "https://3_document_self_link/document:5_document_resource_id";
1318 const std::string kResourceId = "document:5_document_resource_id"; 1318 const std::string kResourceId = "document:5_document_resource_id";
1319 const std::string kContent = 1319 const std::string kContent =
1320 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}", 1320 base::StringPrintf("{\"url\": \"%s\", \"resource_id\": \"%s\"}",
1321 kEditUrl.c_str(), kResourceId.c_str()); 1321 kEditUrl.c_str(), kResourceId.c_str());
1322 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); 1322 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size());
1323 1323
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 1358 EXPECT_TRUE(EntryExists(remote_dest_file_path));
1359 } 1359 }
1360 1360
1361 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { 1361 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) {
1362 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1362 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1363 1363
1364 FileOperationCallback callback = 1364 FileOperationCallback callback =
1365 base::Bind(&CallbackHelper::FileOperationCallback, 1365 base::Bind(&CallbackHelper::FileOperationCallback,
1366 callback_helper_.get()); 1366 callback_helper_.get());
1367 1367
1368 ScopedTempDir temp_dir; 1368 base::ScopedTempDir temp_dir;
1369 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1369 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1370 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); 1370 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt");
1371 1371
1372 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1372 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1373 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( 1373 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync(
1374 remote_src_file_path); 1374 remote_src_file_path);
1375 FilePath cache_file = GetCachePathForFile( 1375 FilePath cache_file = GetCachePathForFile(
1376 file->resource_id(), 1376 file->resource_id(),
1377 file->file_specific_info().file_md5()); 1377 file->file_specific_info().file_md5());
1378 const int64 file_size = file->file_info().size(); 1378 const int64 file_size = file->file_info().size();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 EXPECT_EQ(remote_src_file_data, local_dest_file_data); 1414 EXPECT_EQ(remote_src_file_data, local_dest_file_data);
1415 } 1415 }
1416 1416
1417 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { 1417 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) {
1418 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1418 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1419 1419
1420 FileOperationCallback callback = 1420 FileOperationCallback callback =
1421 base::Bind(&CallbackHelper::FileOperationCallback, 1421 base::Bind(&CallbackHelper::FileOperationCallback,
1422 callback_helper_.get()); 1422 callback_helper_.get());
1423 1423
1424 ScopedTempDir temp_dir; 1424 base::ScopedTempDir temp_dir;
1425 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1425 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1426 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); 1426 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt");
1427 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); 1427 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc"));
1428 file_system_->TransferFileFromRemoteToLocal( 1428 file_system_->TransferFileFromRemoteToLocal(
1429 remote_src_file_path, local_dest_file_path, callback); 1429 remote_src_file_path, local_dest_file_path, callback);
1430 google_apis::test_util::RunBlockingPoolTask(); 1430 google_apis::test_util::RunBlockingPoolTask();
1431 1431
1432 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1432 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_);
1433 1433
1434 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( 1434 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync(
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 2698
2699 // Try to close the same file twice. 2699 // Try to close the same file twice.
2700 file_system_->CloseFile(kFileInRoot, close_file_callback); 2700 file_system_->CloseFile(kFileInRoot, close_file_callback);
2701 message_loop_.Run(); 2701 message_loop_.Run();
2702 2702
2703 // It must fail. 2703 // It must fail.
2704 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2704 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_);
2705 } 2705 }
2706 2706
2707 } // namespace drive 2707 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698