Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / sync / remove_performer_unittest.cc
blob085f70b4aa59dc030aabebb20fac2843c41f5beb
1 // Copyright 2013 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 "chrome/browser/chromeos/drive/sync/remove_performer.h"
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "chrome/browser/drive/fake_drive_service.h"
9 #include "google_apis/drive/gdata_wapi_parser.h"
10 #include "google_apis/drive/test_util.h"
12 namespace drive {
13 namespace internal {
15 typedef file_system::OperationTestBase RemovePerformerTest;
17 TEST_F(RemovePerformerTest, RemoveFile) {
18 RemovePerformer performer(blocking_task_runner(), observer(), scheduler(),
19 metadata());
21 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
22 base::FilePath file_in_subdir(
23 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
25 // Remove a file in root.
26 ResourceEntry entry;
27 FileError error = FILE_ERROR_FAILED;
28 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry));
29 performer.Remove(entry.local_id(),
30 google_apis::test_util::CreateCopyResultCallback(&error));
31 test_util::RunBlockingPoolTask();
32 EXPECT_EQ(FILE_ERROR_OK, error);
34 // Remove a file in subdirectory.
35 error = FILE_ERROR_FAILED;
36 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry));
37 const std::string resource_id = entry.resource_id();
39 performer.Remove(entry.local_id(),
40 google_apis::test_util::CreateCopyResultCallback(&error));
41 test_util::RunBlockingPoolTask();
42 EXPECT_EQ(FILE_ERROR_OK, error);
44 // Verify the file is indeed removed in the server.
45 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
46 scoped_ptr<google_apis::ResourceEntry> gdata_entry;
47 fake_service()->GetResourceEntry(
48 resource_id,
49 google_apis::test_util::CreateCopyResultCallback(&gdata_error,
50 &gdata_entry));
51 test_util::RunBlockingPoolTask();
52 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
53 EXPECT_TRUE(gdata_entry->deleted());
55 // Try removing non-existing file.
56 error = FILE_ERROR_FAILED;
57 performer.Remove("non-existing-id",
58 google_apis::test_util::CreateCopyResultCallback(&error));
59 test_util::RunBlockingPoolTask();
60 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
63 TEST_F(RemovePerformerTest, RemoveShared) {
64 RemovePerformer performer(blocking_task_runner(), observer(), scheduler(),
65 metadata());
67 const base::FilePath kPathInMyDrive(FILE_PATH_LITERAL(
68 "drive/root/shared.txt"));
69 const base::FilePath kPathInOther(FILE_PATH_LITERAL(
70 "drive/other/shared.txt"));
72 // Prepare a shared file to the root folder.
73 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
74 scoped_ptr<google_apis::ResourceEntry> gdata_entry;
75 fake_service()->AddNewFile(
76 "text/plain",
77 "dummy content",
78 fake_service()->GetRootResourceId(),
79 kPathInMyDrive.BaseName().AsUTF8Unsafe(),
80 true, // shared_with_me,
81 google_apis::test_util::CreateCopyResultCallback(&gdata_error,
82 &gdata_entry));
83 test_util::RunBlockingPoolTask();
84 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
85 CheckForUpdates();
87 // Remove it. Locally, the file should be moved to drive/other.
88 ResourceEntry entry;
89 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInMyDrive, &entry));
90 FileError error = FILE_ERROR_FAILED;
91 performer.Remove(entry.local_id(),
92 google_apis::test_util::CreateCopyResultCallback(&error));
93 test_util::RunBlockingPoolTask();
94 EXPECT_EQ(FILE_ERROR_OK, error);
95 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
96 GetLocalResourceEntry(kPathInMyDrive, &entry));
97 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPathInOther, &entry));
99 // Remotely, the entry should have lost its parent.
100 gdata_error = google_apis::GDATA_OTHER_ERROR;
101 const std::string resource_id = gdata_entry->resource_id();
102 fake_service()->GetResourceEntry(
103 resource_id,
104 google_apis::test_util::CreateCopyResultCallback(&gdata_error,
105 &gdata_entry));
106 test_util::RunBlockingPoolTask();
107 ASSERT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
108 EXPECT_FALSE(gdata_entry->deleted()); // It's not deleted.
109 EXPECT_FALSE(gdata_entry->GetLinkByType(google_apis::Link::LINK_PARENT));
112 } // namespace internal
113 } // namespace drive