Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / components / drive / service / test_util.cc
blob42c54f15224a447693c99efaab1854c48fabf927
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;
18 namespace drive {
19 namespace test_util {
21 bool SetUpTestEntries(FakeDriveService* drive_service) {
22 DriveApiErrorCode error = DRIVE_OTHER_ERROR;
23 scoped_ptr<FileResource> entry;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
189 return true;
192 } // namespace test_util
193 } // namespace drive