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
13using google_apis::FileResource;
14using google_apis::GDATA_OTHER_ERROR;
15using google_apis::GDataErrorCode;
16using google_apis::HTTP_CREATED;
17
18namespace drive {
19namespace test_util {
20
21bool SetUpTestEntries(FakeDriveService* drive_service) {
22  GDataErrorCode error = GDATA_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",
123      "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)
129    return false;
130
131  drive_service->AddNewDirectoryWithResourceId(
132      "sub_sub_directory_folder_id",
133      "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)
139    return false;
140
141  drive_service->AddNewDirectoryWithResourceId(
142      "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)
149    return false;
150
151  drive_service->AddNewFileWithResourceId(
152      "slash_subdir_file",
153      "audio/mpeg",
154      "This is some test content.",
155      "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)
161    return false;
162
163  drive_service->AddNewDirectoryWithResourceId(
164      "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)
171    return false;
172
173  drive_service->AddNewFileWithResourceId(
174      "1_orphanfile_resource_id",
175      "text/plain",
176      "This is some test content.",
177      std::string(),
178      "Orphan File 1.txt",
179      true,  // shared_with_me
180      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
181  base::RunLoop().RunUntilIdle();
182  if (error != HTTP_CREATED)
183    return false;
184
185  drive_service->AddNewFileWithResourceId(
186      "orphan_doc_1",
187      util::kGoogleDocumentMimeType,
188      std::string(),
189      std::string(),
190      "Orphan Document",
191      true,  // shared_with_me
192      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
193  base::RunLoop().RunUntilIdle();
194  if (error != HTTP_CREATED)
195    return false;
196
197  return true;
198}
199
200}  // namespace test_util
201}  // namespace drive
202