summaryrefslogtreecommitdiffstats
path: root/chrome/browser/drive/test_util.cc
blob: 2f15d5e0e36d84d120815f4c639b02a0dc5a223d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/drive/test_util.h"

#include "base/run_loop.h"
#include "chrome/browser/drive/drive_api_util.h"
#include "chrome/browser/drive/fake_drive_service.h"
#include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/test_util.h"

using google_apis::FileResource;
using google_apis::GDATA_OTHER_ERROR;
using google_apis::GDataErrorCode;
using google_apis::HTTP_CREATED;

namespace drive {
namespace test_util {

bool SetUpTestEntries(FakeDriveService* drive_service) {
  GDataErrorCode error = GDATA_OTHER_ERROR;
  scoped_ptr<FileResource> entry;

  drive_service->AddNewFileWithResourceId(
      "2_file_resource_id",
      "audio/mpeg",
      "This is some test content.",
      drive_service->GetRootResourceId(),
      "File 1.txt",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "slash_file_resource_id",
      "audio/mpeg",
      "This is some test content.",
      drive_service->GetRootResourceId(),
      "Slash / in file 1.txt",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "3_file_resource_id",
      "audio/mpeg",
      "This is some test content.",
      drive_service->GetRootResourceId(),
      "Duplicate Name.txt",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "4_file_resource_id",
      "audio/mpeg",
      "This is some test content.",
      drive_service->GetRootResourceId(),
      "Duplicate Name.txt",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "5_document_resource_id",
      util::kGoogleDocumentMimeType,
      std::string(),
      drive_service->GetRootResourceId(),
      "Document 1 excludeDir-test",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "1_folder_resource_id",
      util::kDriveFolderMimeType,
      std::string(),
      drive_service->GetRootResourceId(),
      "Directory 1",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "subdirectory_file_1_id",
      "audio/mpeg",
      "This is some test content.",
      "1_folder_resource_id",
      "SubDirectory File 1.txt",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "subdirectory_unowned_file_1_id",
      "audio/mpeg",
      "This is some test content.",
      "1_folder_resource_id",
      "Shared to The Account Owner.txt",
      true,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewDirectoryWithResourceId(
      "sub_dir_folder_resource_id",
      "1_folder_resource_id",
      "Sub Directory Folder",
      DriveServiceInterface::AddNewDirectoryOptions(),
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewDirectoryWithResourceId(
      "sub_sub_directory_folder_id",
      "sub_dir_folder_resource_id",
      "Sub Sub Directory Folder",
      DriveServiceInterface::AddNewDirectoryOptions(),
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewDirectoryWithResourceId(
      "slash_dir_folder_resource_id",
      drive_service->GetRootResourceId(),
      "Slash / in directory",
      DriveServiceInterface::AddNewDirectoryOptions(),
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "slash_subdir_file",
      "audio/mpeg",
      "This is some test content.",
      "slash_dir_folder_resource_id",
      "Slash SubDir File.txt",
      false,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewDirectoryWithResourceId(
      "sub_dir_folder_2_self_link",
      drive_service->GetRootResourceId(),
      "Directory 2 excludeDir-test",
      DriveServiceInterface::AddNewDirectoryOptions(),
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "1_orphanfile_resource_id",
      "text/plain",
      "This is some test content.",
      std::string(),
      "Orphan File 1.txt",
      true,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  drive_service->AddNewFileWithResourceId(
      "orphan_doc_1",
      util::kGoogleDocumentMimeType,
      std::string(),
      std::string(),
      "Orphan Document",
      true,  // shared_with_me
      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  base::RunLoop().RunUntilIdle();
  if (error != HTTP_CREATED)
    return false;

  return true;
}

}  // namespace test_util
}  // namespace drive