| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/drive/test_util.h" | |
| 6 | |
| 7 #include "base/run_loop.h" | |
| 8 #include "chrome/browser/drive/drive_api_util.h" | |
| 9 #include "chrome/browser/drive/fake_drive_service.h" | |
| 10 #include "google_apis/drive/drive_api_parser.h" | |
| 11 #include "google_apis/drive/test_util.h" | |
| 12 | |
| 13 using google_apis::FileResource; | |
| 14 using google_apis::DRIVE_OTHER_ERROR; | |
| 15 using google_apis::DriveApiErrorCode; | |
| 16 using google_apis::HTTP_CREATED; | |
| 17 | |
| 18 namespace drive { | |
| 19 namespace test_util { | |
| 20 | |
| 21 bool SetUpTestEntries(FakeDriveService* drive_service) { | |
| 22 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | |
| 23 scoped_ptr<FileResource> entry; | |
| 24 | |
| 25 drive_service->AddNewFileWithResourceId( | |
| 26 "2_file_resource_id", | |
| 27 "audio/mpeg", | |
| 28 "This is some test content.", | |
| 29 drive_service->GetRootResourceId(), | |
| 30 "File 1.txt", | |
| 31 false, // shared_with_me | |
| 32 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 33 base::RunLoop().RunUntilIdle(); | |
| 34 if (error != HTTP_CREATED) | |
| 35 return false; | |
| 36 | |
| 37 drive_service->AddNewFileWithResourceId( | |
| 38 "slash_file_resource_id", | |
| 39 "audio/mpeg", | |
| 40 "This is some test content.", | |
| 41 drive_service->GetRootResourceId(), | |
| 42 "Slash / in file 1.txt", | |
| 43 false, // shared_with_me | |
| 44 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 45 base::RunLoop().RunUntilIdle(); | |
| 46 if (error != HTTP_CREATED) | |
| 47 return false; | |
| 48 | |
| 49 drive_service->AddNewFileWithResourceId( | |
| 50 "3_file_resource_id", | |
| 51 "audio/mpeg", | |
| 52 "This is some test content.", | |
| 53 drive_service->GetRootResourceId(), | |
| 54 "Duplicate Name.txt", | |
| 55 false, // shared_with_me | |
| 56 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 57 base::RunLoop().RunUntilIdle(); | |
| 58 if (error != HTTP_CREATED) | |
| 59 return false; | |
| 60 | |
| 61 drive_service->AddNewFileWithResourceId( | |
| 62 "4_file_resource_id", | |
| 63 "audio/mpeg", | |
| 64 "This is some test content.", | |
| 65 drive_service->GetRootResourceId(), | |
| 66 "Duplicate Name.txt", | |
| 67 false, // shared_with_me | |
| 68 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 69 base::RunLoop().RunUntilIdle(); | |
| 70 if (error != HTTP_CREATED) | |
| 71 return false; | |
| 72 | |
| 73 drive_service->AddNewFileWithResourceId( | |
| 74 "5_document_resource_id", | |
| 75 util::kGoogleDocumentMimeType, | |
| 76 std::string(), | |
| 77 drive_service->GetRootResourceId(), | |
| 78 "Document 1 excludeDir-test", | |
| 79 false, // shared_with_me | |
| 80 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 81 base::RunLoop().RunUntilIdle(); | |
| 82 if (error != HTTP_CREATED) | |
| 83 return false; | |
| 84 | |
| 85 drive_service->AddNewFileWithResourceId( | |
| 86 "1_folder_resource_id", | |
| 87 util::kDriveFolderMimeType, | |
| 88 std::string(), | |
| 89 drive_service->GetRootResourceId(), | |
| 90 "Directory 1", | |
| 91 false, // shared_with_me | |
| 92 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 93 base::RunLoop().RunUntilIdle(); | |
| 94 if (error != HTTP_CREATED) | |
| 95 return false; | |
| 96 | |
| 97 drive_service->AddNewFileWithResourceId( | |
| 98 "subdirectory_file_1_id", | |
| 99 "audio/mpeg", | |
| 100 "This is some test content.", | |
| 101 "1_folder_resource_id", | |
| 102 "SubDirectory File 1.txt", | |
| 103 false, // shared_with_me | |
| 104 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 105 base::RunLoop().RunUntilIdle(); | |
| 106 if (error != HTTP_CREATED) | |
| 107 return false; | |
| 108 | |
| 109 drive_service->AddNewFileWithResourceId( | |
| 110 "subdirectory_unowned_file_1_id", | |
| 111 "audio/mpeg", | |
| 112 "This is some test content.", | |
| 113 "1_folder_resource_id", | |
| 114 "Shared to The Account Owner.txt", | |
| 115 true, // shared_with_me | |
| 116 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 117 base::RunLoop().RunUntilIdle(); | |
| 118 if (error != HTTP_CREATED) | |
| 119 return false; | |
| 120 | |
| 121 drive_service->AddNewDirectoryWithResourceId( | |
| 122 "sub_dir_folder_resource_id", "1_folder_resource_id", | |
| 123 "Sub Directory Folder", AddNewDirectoryOptions(), | |
| 124 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 125 base::RunLoop().RunUntilIdle(); | |
| 126 if (error != HTTP_CREATED) | |
| 127 return false; | |
| 128 | |
| 129 drive_service->AddNewDirectoryWithResourceId( | |
| 130 "sub_sub_directory_folder_id", "sub_dir_folder_resource_id", | |
| 131 "Sub Sub Directory Folder", AddNewDirectoryOptions(), | |
| 132 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 133 base::RunLoop().RunUntilIdle(); | |
| 134 if (error != HTTP_CREATED) | |
| 135 return false; | |
| 136 | |
| 137 drive_service->AddNewDirectoryWithResourceId( | |
| 138 "slash_dir_folder_resource_id", drive_service->GetRootResourceId(), | |
| 139 "Slash / in directory", AddNewDirectoryOptions(), | |
| 140 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 141 base::RunLoop().RunUntilIdle(); | |
| 142 if (error != HTTP_CREATED) | |
| 143 return false; | |
| 144 | |
| 145 drive_service->AddNewFileWithResourceId( | |
| 146 "slash_subdir_file", | |
| 147 "audio/mpeg", | |
| 148 "This is some test content.", | |
| 149 "slash_dir_folder_resource_id", | |
| 150 "Slash SubDir File.txt", | |
| 151 false, // shared_with_me | |
| 152 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 153 base::RunLoop().RunUntilIdle(); | |
| 154 if (error != HTTP_CREATED) | |
| 155 return false; | |
| 156 | |
| 157 drive_service->AddNewDirectoryWithResourceId( | |
| 158 "sub_dir_folder_2_self_link", drive_service->GetRootResourceId(), | |
| 159 "Directory 2 excludeDir-test", AddNewDirectoryOptions(), | |
| 160 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 161 base::RunLoop().RunUntilIdle(); | |
| 162 if (error != HTTP_CREATED) | |
| 163 return false; | |
| 164 | |
| 165 drive_service->AddNewFileWithResourceId( | |
| 166 "1_orphanfile_resource_id", | |
| 167 "text/plain", | |
| 168 "This is some test content.", | |
| 169 std::string(), | |
| 170 "Orphan File 1.txt", | |
| 171 true, // shared_with_me | |
| 172 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 173 base::RunLoop().RunUntilIdle(); | |
| 174 if (error != HTTP_CREATED) | |
| 175 return false; | |
| 176 | |
| 177 drive_service->AddNewFileWithResourceId( | |
| 178 "orphan_doc_1", | |
| 179 util::kGoogleDocumentMimeType, | |
| 180 std::string(), | |
| 181 std::string(), | |
| 182 "Orphan Document", | |
| 183 true, // shared_with_me | |
| 184 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | |
| 185 base::RunLoop().RunUntilIdle(); | |
| 186 if (error != HTTP_CREATED) | |
| 187 return false; | |
| 188 | |
| 189 return true; | |
| 190 } | |
| 191 | |
| 192 } // namespace test_util | |
| 193 } // namespace drive | |
| OLD | NEW |