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 "components/drive/service/test_util.h"
7 #include "base/run_loop.h"
8 #include "components/drive/drive_api_util.h"
9 #include "components/drive/service/fake_drive_service.h"
10 #include "google_apis/drive/drive_api_parser.h"
11 #include "google_apis/drive/test_util.h"
13 using google_apis::FileResource
;
14 using google_apis::DRIVE_OTHER_ERROR
;
15 using google_apis::DriveApiErrorCode
;
16 using google_apis::HTTP_CREATED
;
21 bool SetUpTestEntries(FakeDriveService
* drive_service
) {
22 DriveApiErrorCode error
= DRIVE_OTHER_ERROR
;
23 scoped_ptr
<FileResource
> entry
;
25 drive_service
->AddNewFileWithResourceId(
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 "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(
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(
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 "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 "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 "subdirectory_file_1_id",
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
)
109 drive_service
->AddNewFileWithResourceId(
110 "subdirectory_unowned_file_1_id",
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
)
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
)
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
)
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
)
145 drive_service
->AddNewFileWithResourceId(
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
)
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
)
165 drive_service
->AddNewFileWithResourceId(
166 "1_orphanfile_resource_id",
168 "This is some test content.",
171 true, // shared_with_me
172 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
173 base::RunLoop().RunUntilIdle();
174 if (error
!= HTTP_CREATED
)
177 drive_service
->AddNewFileWithResourceId(
179 util::kGoogleDocumentMimeType
,
183 true, // shared_with_me
184 google_apis::test_util::CreateCopyResultCallback(&error
, &entry
));
185 base::RunLoop().RunUntilIdle();
186 if (error
!= HTTP_CREATED
)
192 } // namespace test_util