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

Side by Side Diff: chrome/browser/drive/fake_drive_service_unittest.cc

Issue 18506002: drive/syncFS: Switch to ID based download URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 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/drive/fake_drive_service.h" 5 #include "chrome/browser/drive/fake_drive_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 855
856 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { 856 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
857 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 857 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
858 "gdata/root_feed.json")); 858 "gdata/root_feed.json"));
859 859
860 base::ScopedTempDir temp_dir; 860 base::ScopedTempDir temp_dir;
861 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 861 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
862 862
863 std::vector<test_util::ProgressInfo> download_progress_values; 863 std::vector<test_util::ProgressInfo> download_progress_values;
864 864
865 const GURL kContentUrl("https://file_content_url/");
866 const base::FilePath kOutputFilePath = 865 const base::FilePath kOutputFilePath =
867 temp_dir.path().AppendASCII("whatever.txt"); 866 temp_dir.path().AppendASCII("whatever.txt");
868 GDataErrorCode error = GDATA_OTHER_ERROR; 867 GDataErrorCode error = GDATA_OTHER_ERROR;
869 base::FilePath output_file_path; 868 base::FilePath output_file_path;
870 test_util::TestGetContentCallback get_content_callback; 869 test_util::TestGetContentCallback get_content_callback;
871 fake_service_.DownloadFile( 870 fake_service_.DownloadFile(
872 kOutputFilePath, 871 kOutputFilePath,
873 kContentUrl, 872 "file:2_file_resource_id",
874 test_util::CreateCopyResultCallback(&error, &output_file_path), 873 test_util::CreateCopyResultCallback(&error, &output_file_path),
875 get_content_callback.callback(), 874 get_content_callback.callback(),
876 base::Bind(&test_util::AppendProgressCallbackResult, 875 base::Bind(&test_util::AppendProgressCallbackResult,
877 &download_progress_values)); 876 &download_progress_values));
878 base::RunLoop().RunUntilIdle(); 877 base::RunLoop().RunUntilIdle();
879 878
880 EXPECT_EQ(HTTP_SUCCESS, error); 879 EXPECT_EQ(HTTP_SUCCESS, error);
881 EXPECT_EQ(output_file_path, kOutputFilePath); 880 EXPECT_EQ(output_file_path, kOutputFilePath);
882 std::string content; 881 std::string content;
883 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content)); 882 ASSERT_TRUE(file_util::ReadFileToString(output_file_path, &content));
884 // The content is "x"s of the file size specified in root_feed.json. 883 // The content is "x"s of the file size specified in root_feed.json.
885 EXPECT_EQ("This is some test content.", content); 884 EXPECT_EQ("This is some test content.", content);
886 ASSERT_TRUE(!download_progress_values.empty()); 885 ASSERT_TRUE(!download_progress_values.empty());
887 EXPECT_TRUE(base::STLIsSorted(download_progress_values)); 886 EXPECT_TRUE(base::STLIsSorted(download_progress_values));
888 EXPECT_LE(0, download_progress_values.front().first); 887 EXPECT_LE(0, download_progress_values.front().first);
889 EXPECT_GE(26, download_progress_values.back().first); 888 EXPECT_GE(26, download_progress_values.back().first);
890 EXPECT_EQ(content, get_content_callback.GetConcatenatedData()); 889 EXPECT_EQ(content, get_content_callback.GetConcatenatedData());
891 } 890 }
892 891
893 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) { 892 TEST_F(FakeDriveServiceTest, DownloadFile_NonexistingFile) {
894 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 893 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
895 "gdata/root_feed.json")); 894 "gdata/root_feed.json"));
896 895
897 base::ScopedTempDir temp_dir; 896 base::ScopedTempDir temp_dir;
898 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 897 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
899 898
900 const GURL kContentUrl("https://non_existing_content_url/");
901 const base::FilePath kOutputFilePath = 899 const base::FilePath kOutputFilePath =
902 temp_dir.path().AppendASCII("whatever.txt"); 900 temp_dir.path().AppendASCII("whatever.txt");
903 GDataErrorCode error = GDATA_OTHER_ERROR; 901 GDataErrorCode error = GDATA_OTHER_ERROR;
904 base::FilePath output_file_path; 902 base::FilePath output_file_path;
905 fake_service_.DownloadFile( 903 fake_service_.DownloadFile(
906 kOutputFilePath, 904 kOutputFilePath,
907 kContentUrl, 905 "file:non_existent_file_resource_id",
908 test_util::CreateCopyResultCallback(&error, &output_file_path), 906 test_util::CreateCopyResultCallback(&error, &output_file_path),
909 GetContentCallback(), 907 GetContentCallback(),
910 ProgressCallback()); 908 ProgressCallback());
911 base::RunLoop().RunUntilIdle(); 909 base::RunLoop().RunUntilIdle();
912 910
913 EXPECT_EQ(HTTP_NOT_FOUND, error); 911 EXPECT_EQ(HTTP_NOT_FOUND, error);
914 } 912 }
915 913
916 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) { 914 TEST_F(FakeDriveServiceTest, DownloadFile_Offline) {
917 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 915 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
918 "gdata/root_feed.json")); 916 "gdata/root_feed.json"));
919 fake_service_.set_offline(true); 917 fake_service_.set_offline(true);
920 918
921 base::ScopedTempDir temp_dir; 919 base::ScopedTempDir temp_dir;
922 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 920 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
923 921
924 const GURL kContentUrl("https://file_content_url/");
925 const base::FilePath kOutputFilePath = 922 const base::FilePath kOutputFilePath =
926 temp_dir.path().AppendASCII("whatever.txt"); 923 temp_dir.path().AppendASCII("whatever.txt");
927 GDataErrorCode error = GDATA_OTHER_ERROR; 924 GDataErrorCode error = GDATA_OTHER_ERROR;
928 base::FilePath output_file_path; 925 base::FilePath output_file_path;
929 fake_service_.DownloadFile( 926 fake_service_.DownloadFile(
930 kOutputFilePath, 927 kOutputFilePath,
931 kContentUrl, 928 "file:2_file_resource_id",
932 test_util::CreateCopyResultCallback(&error, &output_file_path), 929 test_util::CreateCopyResultCallback(&error, &output_file_path),
933 GetContentCallback(), 930 GetContentCallback(),
934 ProgressCallback()); 931 ProgressCallback());
935 base::RunLoop().RunUntilIdle(); 932 base::RunLoop().RunUntilIdle();
936 933
937 EXPECT_EQ(GDATA_NO_CONNECTION, error); 934 EXPECT_EQ(GDATA_NO_CONNECTION, error);
938 } 935 }
939 936
940 TEST_F(FakeDriveServiceTest, CopyResource) { 937 TEST_F(FakeDriveServiceTest, CopyResource) {
941 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 938 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2163 test_util::CreateCopyResultCallback(&error, &resource_entry)); 2160 test_util::CreateCopyResultCallback(&error, &resource_entry));
2164 base::RunLoop().RunUntilIdle(); 2161 base::RunLoop().RunUntilIdle();
2165 2162
2166 EXPECT_EQ(GDATA_NO_CONNECTION, error); 2163 EXPECT_EQ(GDATA_NO_CONNECTION, error);
2167 EXPECT_FALSE(resource_entry); 2164 EXPECT_FALSE(resource_entry);
2168 } 2165 }
2169 2166
2170 } // namespace 2167 } // namespace
2171 2168
2172 } // namespace drive 2169 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698