test_util.cc 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. #include "components/drive/service/test_util.h"
  5. #include <memory>
  6. #include <string>
  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/common/test_util.h"
  11. #include "google_apis/drive/drive_api_parser.h"
  12. using google_apis::ApiErrorCode;
  13. using google_apis::FileResource;
  14. using google_apis::HTTP_CREATED;
  15. using google_apis::OTHER_ERROR;
  16. namespace drive {
  17. namespace test_util {
  18. bool SetUpTestEntries(FakeDriveService* drive_service) {
  19. return SetUpTestEntries(drive_service, drive_service->GetRootResourceId());
  20. }
  21. bool SetUpTeamDriveTestEntries(FakeDriveService* drive_service,
  22. const std::string& team_drive_id,
  23. const std::string& team_drive_name) {
  24. drive_service->AddTeamDrive(team_drive_id, team_drive_name);
  25. return SetUpTestEntries(drive_service, team_drive_id);
  26. }
  27. bool SetUpTestEntries(FakeDriveService* drive_service,
  28. const std::string& parent_resource_id) {
  29. ApiErrorCode error = OTHER_ERROR;
  30. std::unique_ptr<FileResource> entry;
  31. drive_service->AddNewFileWithResourceId(
  32. "2_file_resource_id", "audio/mpeg", "This is some test content.",
  33. parent_resource_id, "File 1.txt",
  34. false, // shared_with_me
  35. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  36. base::RunLoop().RunUntilIdle();
  37. if (error != HTTP_CREATED)
  38. return false;
  39. drive_service->AddNewFileWithResourceId(
  40. "slash_file_resource_id", "audio/mpeg", "This is some test content.",
  41. parent_resource_id, "Slash / in file 1.txt",
  42. false, // shared_with_me
  43. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  44. base::RunLoop().RunUntilIdle();
  45. if (error != HTTP_CREATED)
  46. return false;
  47. drive_service->AddNewFileWithResourceId(
  48. "3_file_resource_id", "audio/mpeg", "This is some test content.",
  49. parent_resource_id, "Duplicate Name.txt",
  50. false, // shared_with_me
  51. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  52. base::RunLoop().RunUntilIdle();
  53. if (error != HTTP_CREATED)
  54. return false;
  55. drive_service->AddNewFileWithResourceId(
  56. "4_file_resource_id", "audio/mpeg", "This is some test content.",
  57. parent_resource_id, "Duplicate Name.txt",
  58. false, // shared_with_me
  59. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  60. base::RunLoop().RunUntilIdle();
  61. if (error != HTTP_CREATED)
  62. return false;
  63. drive_service->AddNewFileWithResourceId(
  64. "5_document_resource_id", util::kGoogleDocumentMimeType, std::string(),
  65. parent_resource_id, "Document 1 excludeDir-test",
  66. false, // shared_with_me
  67. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  68. base::RunLoop().RunUntilIdle();
  69. if (error != HTTP_CREATED)
  70. return false;
  71. drive_service->AddNewFileWithResourceId(
  72. "1_folder_resource_id", util::kDriveFolderMimeType, std::string(),
  73. parent_resource_id, "Directory 1",
  74. false, // shared_with_me
  75. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  76. base::RunLoop().RunUntilIdle();
  77. if (error != HTTP_CREATED)
  78. return false;
  79. drive_service->AddNewFileWithResourceId(
  80. "subdirectory_file_1_id", "audio/mpeg", "This is some test content.",
  81. "1_folder_resource_id", "SubDirectory File 1.txt",
  82. false, // shared_with_me
  83. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  84. base::RunLoop().RunUntilIdle();
  85. if (error != HTTP_CREATED)
  86. return false;
  87. drive_service->AddNewFileWithResourceId(
  88. "subdirectory_unowned_file_1_id", "audio/mpeg",
  89. "This is some test content.", "1_folder_resource_id",
  90. "Shared to The Account Owner.txt",
  91. true, // shared_with_me
  92. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  93. base::RunLoop().RunUntilIdle();
  94. if (error != HTTP_CREATED)
  95. return false;
  96. drive_service->AddNewDirectoryWithResourceId(
  97. "sub_dir_folder_resource_id", "1_folder_resource_id",
  98. "Sub Directory Folder", AddNewDirectoryOptions(),
  99. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  100. base::RunLoop().RunUntilIdle();
  101. if (error != HTTP_CREATED)
  102. return false;
  103. drive_service->AddNewDirectoryWithResourceId(
  104. "sub_sub_directory_folder_id", "sub_dir_folder_resource_id",
  105. "Sub Sub Directory Folder", AddNewDirectoryOptions(),
  106. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  107. base::RunLoop().RunUntilIdle();
  108. if (error != HTTP_CREATED)
  109. return false;
  110. drive_service->AddNewDirectoryWithResourceId(
  111. "slash_dir_folder_resource_id", parent_resource_id,
  112. "Slash / in directory", AddNewDirectoryOptions(),
  113. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  114. base::RunLoop().RunUntilIdle();
  115. if (error != HTTP_CREATED)
  116. return false;
  117. drive_service->AddNewFileWithResourceId(
  118. "slash_subdir_file", "audio/mpeg", "This is some test content.",
  119. "slash_dir_folder_resource_id", "Slash SubDir File.txt",
  120. false, // shared_with_me
  121. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  122. base::RunLoop().RunUntilIdle();
  123. if (error != HTTP_CREATED)
  124. return false;
  125. drive_service->AddNewDirectoryWithResourceId(
  126. "sub_dir_folder_2_self_link", parent_resource_id,
  127. "Directory 2 excludeDir-test", AddNewDirectoryOptions(),
  128. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  129. base::RunLoop().RunUntilIdle();
  130. if (error != HTTP_CREATED)
  131. return false;
  132. drive_service->AddNewFileWithResourceId(
  133. "1_orphanfile_resource_id", "text/plain", "This is some test content.",
  134. std::string(), "Orphan File 1.txt",
  135. true, // shared_with_me
  136. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  137. base::RunLoop().RunUntilIdle();
  138. if (error != HTTP_CREATED)
  139. return false;
  140. drive_service->AddNewFileWithResourceId(
  141. "orphan_doc_1", util::kGoogleDocumentMimeType, std::string(),
  142. std::string(), "Orphan Document",
  143. true, // shared_with_me
  144. google_apis::test_util::CreateCopyResultCallback(&error, &entry));
  145. base::RunLoop().RunUntilIdle();
  146. if (error != HTTP_CREATED)
  147. return false;
  148. return true;
  149. }
  150. } // namespace test_util
  151. } // namespace drive