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

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

Issue 445793003: Add permission check to FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 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
« no previous file with comments | « chrome/browser/drive/fake_drive_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13 matching lines...) Expand all
24 using google_apis::AppList; 24 using google_apis::AppList;
25 using google_apis::ChangeList; 25 using google_apis::ChangeList;
26 using google_apis::ChangeResource; 26 using google_apis::ChangeResource;
27 using google_apis::FileList; 27 using google_apis::FileList;
28 using google_apis::FileResource; 28 using google_apis::FileResource;
29 using google_apis::GDATA_NO_CONNECTION; 29 using google_apis::GDATA_NO_CONNECTION;
30 using google_apis::GDATA_OTHER_ERROR; 30 using google_apis::GDATA_OTHER_ERROR;
31 using google_apis::GDataErrorCode; 31 using google_apis::GDataErrorCode;
32 using google_apis::GetContentCallback; 32 using google_apis::GetContentCallback;
33 using google_apis::HTTP_CREATED; 33 using google_apis::HTTP_CREATED;
34 using google_apis::HTTP_FORBIDDEN;
34 using google_apis::HTTP_NOT_FOUND; 35 using google_apis::HTTP_NOT_FOUND;
35 using google_apis::HTTP_NO_CONTENT; 36 using google_apis::HTTP_NO_CONTENT;
36 using google_apis::HTTP_PRECONDITION; 37 using google_apis::HTTP_PRECONDITION;
37 using google_apis::HTTP_RESUME_INCOMPLETE; 38 using google_apis::HTTP_RESUME_INCOMPLETE;
38 using google_apis::HTTP_SUCCESS; 39 using google_apis::HTTP_SUCCESS;
39 using google_apis::ProgressCallback; 40 using google_apis::ProgressCallback;
40 using google_apis::UploadRangeResponse; 41 using google_apis::UploadRangeResponse;
41 42
42 namespace drive { 43 namespace drive {
43 44
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 895
895 GDataErrorCode error = GDATA_OTHER_ERROR; 896 GDataErrorCode error = GDATA_OTHER_ERROR;
896 fake_service_.DeleteResource("2_file_resource_id", 897 fake_service_.DeleteResource("2_file_resource_id",
897 std::string(), // etag 898 std::string(), // etag
898 test_util::CreateCopyResultCallback(&error)); 899 test_util::CreateCopyResultCallback(&error));
899 base::RunLoop().RunUntilIdle(); 900 base::RunLoop().RunUntilIdle();
900 901
901 EXPECT_EQ(GDATA_NO_CONNECTION, error); 902 EXPECT_EQ(GDATA_NO_CONNECTION, error);
902 } 903 }
903 904
905 TEST_F(FakeDriveServiceTest, DeleteResource_Forbidden) {
906 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
907
908 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission(
909 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER));
910
911 GDataErrorCode error = GDATA_OTHER_ERROR;
912 fake_service_.DeleteResource("2_file_resource_id",
913 std::string(), // etag
914 test_util::CreateCopyResultCallback(&error));
915 base::RunLoop().RunUntilIdle();
916
917 EXPECT_EQ(HTTP_FORBIDDEN, error);
918 }
919
904 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) { 920 TEST_F(FakeDriveServiceTest, TrashResource_ExistingFile) {
905 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 921 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
906 922
907 // Resource "2_file_resource_id" should now exist. 923 // Resource "2_file_resource_id" should now exist.
908 ASSERT_TRUE(Exists("2_file_resource_id")); 924 ASSERT_TRUE(Exists("2_file_resource_id"));
909 925
910 GDataErrorCode error = GDATA_OTHER_ERROR; 926 GDataErrorCode error = GDATA_OTHER_ERROR;
911 fake_service_.TrashResource("2_file_resource_id", 927 fake_service_.TrashResource("2_file_resource_id",
912 test_util::CreateCopyResultCallback(&error)); 928 test_util::CreateCopyResultCallback(&error));
913 base::RunLoop().RunUntilIdle(); 929 base::RunLoop().RunUntilIdle();
(...skipping 26 matching lines...) Expand all
940 fake_service_.set_offline(true); 956 fake_service_.set_offline(true);
941 957
942 GDataErrorCode error = GDATA_OTHER_ERROR; 958 GDataErrorCode error = GDATA_OTHER_ERROR;
943 fake_service_.TrashResource("2_file_resource_id", 959 fake_service_.TrashResource("2_file_resource_id",
944 test_util::CreateCopyResultCallback(&error)); 960 test_util::CreateCopyResultCallback(&error));
945 base::RunLoop().RunUntilIdle(); 961 base::RunLoop().RunUntilIdle();
946 962
947 EXPECT_EQ(GDATA_NO_CONNECTION, error); 963 EXPECT_EQ(GDATA_NO_CONNECTION, error);
948 } 964 }
949 965
966 TEST_F(FakeDriveServiceTest, TrashResource_Forbidden) {
967 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
968
969 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission(
970 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER));
971
972 GDataErrorCode error = GDATA_OTHER_ERROR;
973 fake_service_.TrashResource("2_file_resource_id",
974 test_util::CreateCopyResultCallback(&error));
975 base::RunLoop().RunUntilIdle();
976
977 EXPECT_EQ(HTTP_FORBIDDEN, error);
978 }
979
950 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) { 980 TEST_F(FakeDriveServiceTest, DownloadFile_ExistingFile) {
951 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 981 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
952 982
953 base::ScopedTempDir temp_dir; 983 base::ScopedTempDir temp_dir;
954 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 984 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
955 985
956 std::vector<test_util::ProgressInfo> download_progress_values; 986 std::vector<test_util::ProgressInfo> download_progress_values;
957 987
958 const base::FilePath kOutputFilePath = 988 const base::FilePath kOutputFilePath =
959 temp_dir.path().AppendASCII("whatever.txt"); 989 temp_dir.path().AppendASCII("whatever.txt");
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 "new title", 1251 "new title",
1222 base::Time(), 1252 base::Time(),
1223 base::Time(), 1253 base::Time(),
1224 test_util::CreateCopyResultCallback(&error, &entry)); 1254 test_util::CreateCopyResultCallback(&error, &entry));
1225 base::RunLoop().RunUntilIdle(); 1255 base::RunLoop().RunUntilIdle();
1226 1256
1227 EXPECT_EQ(GDATA_NO_CONNECTION, error); 1257 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1228 EXPECT_FALSE(entry); 1258 EXPECT_FALSE(entry);
1229 } 1259 }
1230 1260
1261 TEST_F(FakeDriveServiceTest, UpdateResource_Forbidden) {
1262 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1263
1264 const std::string kResourceId = "2_file_resource_id";
1265 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission(
1266 kResourceId, google_apis::drive::PERMISSION_ROLE_READER));
1267
1268 GDataErrorCode error = GDATA_OTHER_ERROR;
1269 scoped_ptr<FileResource> entry;
1270 fake_service_.UpdateResource(
1271 kResourceId,
1272 std::string(),
1273 "new title",
1274 base::Time(),
1275 base::Time(),
1276 test_util::CreateCopyResultCallback(&error, &entry));
1277 base::RunLoop().RunUntilIdle();
1278
1279 EXPECT_EQ(HTTP_FORBIDDEN, error);
1280 EXPECT_FALSE(entry);
1281 }
1282
1231 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) { 1283 TEST_F(FakeDriveServiceTest, AddResourceToDirectory_FileInRootDirectory) {
1232 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1284 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1233 1285
1234 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1286 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1235 1287
1236 const std::string kResourceId = "2_file_resource_id"; 1288 const std::string kResourceId = "2_file_resource_id";
1237 const std::string kOldParentResourceId = fake_service_.GetRootResourceId(); 1289 const std::string kOldParentResourceId = fake_service_.GetRootResourceId();
1238 const std::string kNewParentResourceId = "1_folder_resource_id"; 1290 const std::string kNewParentResourceId = "1_folder_resource_id";
1239 1291
1240 // Here's the original parent link. 1292 // Here's the original parent link.
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 13, 1693 13,
1642 "2_file_resource_id", 1694 "2_file_resource_id",
1643 FakeDriveService::InitiateUploadExistingFileOptions(), 1695 FakeDriveService::InitiateUploadExistingFileOptions(),
1644 test_util::CreateCopyResultCallback(&error, &upload_location)); 1696 test_util::CreateCopyResultCallback(&error, &upload_location));
1645 base::RunLoop().RunUntilIdle(); 1697 base::RunLoop().RunUntilIdle();
1646 1698
1647 EXPECT_EQ(GDATA_NO_CONNECTION, error); 1699 EXPECT_EQ(GDATA_NO_CONNECTION, error);
1648 EXPECT_TRUE(upload_location.is_empty()); 1700 EXPECT_TRUE(upload_location.is_empty());
1649 } 1701 }
1650 1702
1703 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_Forbidden) {
1704 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1705
1706 EXPECT_EQ(HTTP_SUCCESS, fake_service_.SetUserPermission(
1707 "2_file_resource_id", google_apis::drive::PERMISSION_ROLE_READER));
1708
1709 GDataErrorCode error = GDATA_OTHER_ERROR;
1710 GURL upload_location;
1711 fake_service_.InitiateUploadExistingFile(
1712 "test/foo",
1713 13,
1714 "2_file_resource_id",
1715 FakeDriveService::InitiateUploadExistingFileOptions(),
1716 test_util::CreateCopyResultCallback(&error, &upload_location));
1717 base::RunLoop().RunUntilIdle();
1718
1719 EXPECT_EQ(HTTP_FORBIDDEN, error);
1720 EXPECT_TRUE(upload_location.is_empty());
1721 }
1722
1651 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) { 1723 TEST_F(FakeDriveServiceTest, InitiateUploadExistingFile_NotFound) {
1652 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_)); 1724 ASSERT_TRUE(test_util::SetUpTestEntries(&fake_service_));
1653 1725
1654 GDataErrorCode error = GDATA_OTHER_ERROR; 1726 GDataErrorCode error = GDATA_OTHER_ERROR;
1655 GURL upload_location; 1727 GURL upload_location;
1656 fake_service_.InitiateUploadExistingFile( 1728 fake_service_.InitiateUploadExistingFile(
1657 "test/foo", 1729 "test/foo",
1658 13, 1730 13,
1659 "non_existent", 1731 "non_existent",
1660 FakeDriveService::InitiateUploadExistingFileOptions(), 1732 FakeDriveService::InitiateUploadExistingFileOptions(),
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
2148 test_util::CreateCopyResultCallback(&error, &entry)); 2220 test_util::CreateCopyResultCallback(&error, &entry));
2149 base::RunLoop().RunUntilIdle(); 2221 base::RunLoop().RunUntilIdle();
2150 2222
2151 EXPECT_EQ(GDATA_NO_CONNECTION, error); 2223 EXPECT_EQ(GDATA_NO_CONNECTION, error);
2152 EXPECT_FALSE(entry); 2224 EXPECT_FALSE(entry);
2153 } 2225 }
2154 2226
2155 } // namespace 2227 } // namespace
2156 2228
2157 } // namespace drive 2229 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/drive/fake_drive_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698