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.
5 #include "chrome/browser/drive/test_util.h"
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/gdata_wapi_parser.h"
11 #include "google_apis/drive/test_util.h"
13 using google_apis::GDATA_OTHER_ERROR;
14 using google_apis::GDataErrorCode;
15 using google_apis::HTTP_CREATED;
16 using google_apis::ResourceEntry;
21 bool SetUpTestEntries(FakeDriveService* drive_service) {
22 GDataErrorCode error = GDATA_OTHER_ERROR;
23 scoped_ptr<ResourceEntry> entry;
25 drive_service->AddNewFileWithResourceId(
26 "file:2_file_resource_id",
28 "This is some test content.",
29 drive_service->GetRootResourceId(),
31 false, // shared_with_me
32 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
33 base::RunLoop().RunUntilIdle();
34 if (error != HTTP_CREATED)
37 drive_service->AddNewFileWithResourceId(
38 "file:slash_file_resource_id",
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)
49 drive_service->AddNewFileWithResourceId(
50 "file:3_file_resource_id",
52 "This is some test content.",
53 drive_service->GetRootResourceId(),
55 false, // shared_with_me
56 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
57 base::RunLoop().RunUntilIdle();
58 if (error != HTTP_CREATED)
61 drive_service->AddNewFileWithResourceId(
62 "file:4_file_resource_id",
64 "This is some test content.",
65 drive_service->GetRootResourceId(),
67 false, // shared_with_me
68 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
69 base::RunLoop().RunUntilIdle();
70 if (error != HTTP_CREATED)
73 drive_service->AddNewFileWithResourceId(
74 "document:5_document_resource_id",
75 util::kGoogleDocumentMimeType,
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)
85 drive_service->AddNewFileWithResourceId(
86 "folder:1_folder_resource_id",
87 util::kDriveFolderMimeType,
89 drive_service->GetRootResourceId(),
91 false, // shared_with_me
92 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
93 base::RunLoop().RunUntilIdle();
94 if (error != HTTP_CREATED)
97 drive_service->AddNewFileWithResourceId(
98 "file:subdirectory_file_1_id",
100 "This is some test content.",
101 "folder: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)
109 drive_service->AddNewFileWithResourceId(
110 "file:subdirectory_unowned_file_1_id",
112 "This is some test content.",
113 "folder: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)
121 drive_service->AddNewDirectoryWithResourceId(
122 "folder:sub_dir_folder_resource_id",
123 "folder:1_folder_resource_id",
124 "Sub Directory Folder",
125 DriveServiceInterface::AddNewDirectoryOptions(),
126 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
127 base::RunLoop().RunUntilIdle();
128 if (error != HTTP_CREATED)
131 drive_service->AddNewDirectoryWithResourceId(
132 "folder:sub_sub_directory_folder_id",
133 "folder:sub_dir_folder_resource_id",
134 "Sub Sub Directory Folder",
135 DriveServiceInterface::AddNewDirectoryOptions(),
136 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
137 base::RunLoop().RunUntilIdle();
138 if (error != HTTP_CREATED)
141 drive_service->AddNewDirectoryWithResourceId(
142 "folder:slash_dir_folder_resource_id",
143 drive_service->GetRootResourceId(),
144 "Slash / in directory",
145 DriveServiceInterface::AddNewDirectoryOptions(),
146 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
147 base::RunLoop().RunUntilIdle();
148 if (error != HTTP_CREATED)
151 drive_service->AddNewFileWithResourceId(
152 "file:slash_subdir_file",
154 "This is some test content.",
155 "folder:slash_dir_folder_resource_id",
156 "Slash SubDir File.txt",
157 false, // shared_with_me
158 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
159 base::RunLoop().RunUntilIdle();
160 if (error != HTTP_CREATED)
163 drive_service->AddNewDirectoryWithResourceId(
164 "folder:sub_dir_folder_2_self_link",
165 drive_service->GetRootResourceId(),
166 "Directory 2 excludeDir-test",
167 DriveServiceInterface::AddNewDirectoryOptions(),
168 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
169 base::RunLoop().RunUntilIdle();
170 if (error != HTTP_CREATED)
173 drive_service->AddNewFileWithResourceId(
174 "file:1_orphanfile_resource_id",
176 "This is some test content.",
179 true, // shared_with_me
180 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
181 base::RunLoop().RunUntilIdle();
182 if (error != HTTP_CREATED)
185 drive_service->AddNewFileWithResourceId(
186 "document:orphan_doc_1",
187 util::kGoogleDocumentMimeType,
191 true, // shared_with_me
192 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
193 base::RunLoop().RunUntilIdle();
194 if (error != HTTP_CREATED)
200 } // namespace test_util