Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(632)

Side by Side Diff: chrome/browser/chromeos/drive/file_system/remove_operation_unittest.cc

Issue 380993002: Upstream RunBlockingPoolTask(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/remove_operation.h"
6 6
7 #include "chrome/browser/chromeos/drive/file_change.h" 7 #include "chrome/browser/chromeos/drive/file_change.h"
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
9 #include "chrome/browser/chromeos/drive/file_system_util.h" 9 #include "chrome/browser/chromeos/drive/file_system_util.h"
10 #include "content/public/test/test_utils.h"
10 #include "google_apis/drive/test_util.h" 11 #include "google_apis/drive/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace drive { 14 namespace drive {
14 namespace file_system { 15 namespace file_system {
15 16
16 typedef OperationTestBase RemoveOperationTest; 17 typedef OperationTestBase RemoveOperationTest;
17 18
18 TEST_F(RemoveOperationTest, RemoveFile) { 19 TEST_F(RemoveOperationTest, RemoveFile) {
19 RemoveOperation operation(blocking_task_runner(), observer(), metadata(), 20 RemoveOperation operation(blocking_task_runner(), observer(), metadata(),
20 cache()); 21 cache());
21 22
22 base::FilePath nonexisting_file( 23 base::FilePath nonexisting_file(
23 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); 24 FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
24 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 25 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
25 base::FilePath file_in_subdir( 26 base::FilePath file_in_subdir(
26 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); 27 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
27 28
28 // Remove a file in root. 29 // Remove a file in root.
29 ResourceEntry entry; 30 ResourceEntry entry;
30 FileError error = FILE_ERROR_FAILED; 31 FileError error = FILE_ERROR_FAILED;
31 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry)); 32 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_root, &entry));
32 operation.Remove(file_in_root, 33 operation.Remove(file_in_root,
33 false, // is_recursive 34 false, // is_recursive
34 google_apis::test_util::CreateCopyResultCallback(&error)); 35 google_apis::test_util::CreateCopyResultCallback(&error));
35 test_util::RunBlockingPoolTask(); 36 content::RunAllBlockingPoolTasksUntilIdle();
36 EXPECT_EQ(FILE_ERROR_OK, error); 37 EXPECT_EQ(FILE_ERROR_OK, error);
37 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry)); 38 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntry(file_in_root, &entry));
38 39
39 const std::string id_file_in_root = entry.local_id(); 40 const std::string id_file_in_root = entry.local_id();
40 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntryById(id_file_in_root, &entry)); 41 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntryById(id_file_in_root, &entry));
41 EXPECT_EQ(util::kDriveTrashDirLocalId, entry.parent_local_id()); 42 EXPECT_EQ(util::kDriveTrashDirLocalId, entry.parent_local_id());
42 43
43 // Remove a file in subdirectory. 44 // Remove a file in subdirectory.
44 error = FILE_ERROR_FAILED; 45 error = FILE_ERROR_FAILED;
45 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry)); 46 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(file_in_subdir, &entry));
46 const std::string resource_id = entry.resource_id(); 47 const std::string resource_id = entry.resource_id();
47 48
48 operation.Remove(file_in_subdir, 49 operation.Remove(file_in_subdir,
49 false, // is_recursive 50 false, // is_recursive
50 google_apis::test_util::CreateCopyResultCallback(&error)); 51 google_apis::test_util::CreateCopyResultCallback(&error));
51 test_util::RunBlockingPoolTask(); 52 content::RunAllBlockingPoolTasksUntilIdle();
52 EXPECT_EQ(FILE_ERROR_OK, error); 53 EXPECT_EQ(FILE_ERROR_OK, error);
53 EXPECT_EQ(FILE_ERROR_NOT_FOUND, 54 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
54 GetLocalResourceEntry(file_in_subdir, &entry)); 55 GetLocalResourceEntry(file_in_subdir, &entry));
55 56
56 const std::string id_file_in_subdir = entry.local_id(); 57 const std::string id_file_in_subdir = entry.local_id();
57 EXPECT_EQ(FILE_ERROR_OK, 58 EXPECT_EQ(FILE_ERROR_OK,
58 GetLocalResourceEntryById(id_file_in_subdir, &entry)); 59 GetLocalResourceEntryById(id_file_in_subdir, &entry));
59 EXPECT_EQ(util::kDriveTrashDirLocalId, entry.parent_local_id()); 60 EXPECT_EQ(util::kDriveTrashDirLocalId, entry.parent_local_id());
60 61
61 // Try removing non-existing file. 62 // Try removing non-existing file.
62 error = FILE_ERROR_FAILED; 63 error = FILE_ERROR_FAILED;
63 ASSERT_EQ(FILE_ERROR_NOT_FOUND, 64 ASSERT_EQ(FILE_ERROR_NOT_FOUND,
64 GetLocalResourceEntry(nonexisting_file, &entry)); 65 GetLocalResourceEntry(nonexisting_file, &entry));
65 operation.Remove(nonexisting_file, 66 operation.Remove(nonexisting_file,
66 false, // is_recursive 67 false, // is_recursive
67 google_apis::test_util::CreateCopyResultCallback(&error)); 68 google_apis::test_util::CreateCopyResultCallback(&error));
68 test_util::RunBlockingPoolTask(); 69 content::RunAllBlockingPoolTasksUntilIdle();
69 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 70 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
70 71
71 // Verify observer notifications. 72 // Verify observer notifications.
72 EXPECT_EQ(2U, observer()->get_changed_files().size()); 73 EXPECT_EQ(2U, observer()->get_changed_files().size());
73 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root)); 74 EXPECT_TRUE(observer()->get_changed_files().count(file_in_root));
74 EXPECT_TRUE(observer()->get_changed_files().count(file_in_subdir)); 75 EXPECT_TRUE(observer()->get_changed_files().count(file_in_subdir));
75 76
76 EXPECT_EQ(2U, observer()->updated_local_ids().size()); 77 EXPECT_EQ(2U, observer()->updated_local_ids().size());
77 EXPECT_TRUE(observer()->updated_local_ids().count(id_file_in_root)); 78 EXPECT_TRUE(observer()->updated_local_ids().count(id_file_in_root));
78 EXPECT_TRUE(observer()->updated_local_ids().count(id_file_in_subdir)); 79 EXPECT_TRUE(observer()->updated_local_ids().count(id_file_in_subdir));
79 } 80 }
80 81
81 TEST_F(RemoveOperationTest, RemoveDirectory) { 82 TEST_F(RemoveOperationTest, RemoveDirectory) {
82 RemoveOperation operation(blocking_task_runner(), observer(), metadata(), 83 RemoveOperation operation(blocking_task_runner(), observer(), metadata(),
83 cache()); 84 cache());
84 85
85 base::FilePath empty_dir(FILE_PATH_LITERAL( 86 base::FilePath empty_dir(FILE_PATH_LITERAL(
86 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder")); 87 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder"));
87 base::FilePath non_empty_dir(FILE_PATH_LITERAL( 88 base::FilePath non_empty_dir(FILE_PATH_LITERAL(
88 "drive/root/Directory 1")); 89 "drive/root/Directory 1"));
89 base::FilePath file_in_non_empty_dir(FILE_PATH_LITERAL( 90 base::FilePath file_in_non_empty_dir(FILE_PATH_LITERAL(
90 "drive/root/Directory 1/SubDirectory File 1.txt")); 91 "drive/root/Directory 1/SubDirectory File 1.txt"));
91 92
92 // Empty directory can be removed even with is_recursive = false. 93 // Empty directory can be removed even with is_recursive = false.
93 FileError error = FILE_ERROR_FAILED; 94 FileError error = FILE_ERROR_FAILED;
94 ResourceEntry entry; 95 ResourceEntry entry;
95 operation.Remove(empty_dir, 96 operation.Remove(empty_dir,
96 false, // is_recursive 97 false, // is_recursive
97 google_apis::test_util::CreateCopyResultCallback(&error)); 98 google_apis::test_util::CreateCopyResultCallback(&error));
98 test_util::RunBlockingPoolTask(); 99 content::RunAllBlockingPoolTasksUntilIdle();
99 EXPECT_EQ(FILE_ERROR_OK, error); 100 EXPECT_EQ(FILE_ERROR_OK, error);
100 EXPECT_EQ(FILE_ERROR_NOT_FOUND, 101 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
101 GetLocalResourceEntry(empty_dir, &entry)); 102 GetLocalResourceEntry(empty_dir, &entry));
102 103
103 // Non-empty directory, cannot. 104 // Non-empty directory, cannot.
104 error = FILE_ERROR_FAILED; 105 error = FILE_ERROR_FAILED;
105 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(non_empty_dir, &entry)); 106 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(non_empty_dir, &entry));
106 operation.Remove(non_empty_dir, 107 operation.Remove(non_empty_dir,
107 false, // is_recursive 108 false, // is_recursive
108 google_apis::test_util::CreateCopyResultCallback(&error)); 109 google_apis::test_util::CreateCopyResultCallback(&error));
109 test_util::RunBlockingPoolTask(); 110 content::RunAllBlockingPoolTasksUntilIdle();
110 EXPECT_EQ(FILE_ERROR_NOT_EMPTY, error); 111 EXPECT_EQ(FILE_ERROR_NOT_EMPTY, error);
111 EXPECT_EQ(FILE_ERROR_OK, 112 EXPECT_EQ(FILE_ERROR_OK,
112 GetLocalResourceEntry(non_empty_dir, &entry)); 113 GetLocalResourceEntry(non_empty_dir, &entry));
113 114
114 // With is_recursive = true, it can be deleted, however. Descendant entries 115 // With is_recursive = true, it can be deleted, however. Descendant entries
115 // are removed together. 116 // are removed together.
116 error = FILE_ERROR_FAILED; 117 error = FILE_ERROR_FAILED;
117 ASSERT_EQ(FILE_ERROR_OK, 118 ASSERT_EQ(FILE_ERROR_OK,
118 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); 119 GetLocalResourceEntry(file_in_non_empty_dir, &entry));
119 operation.Remove(non_empty_dir, 120 operation.Remove(non_empty_dir,
120 true, // is_recursive 121 true, // is_recursive
121 google_apis::test_util::CreateCopyResultCallback(&error)); 122 google_apis::test_util::CreateCopyResultCallback(&error));
122 test_util::RunBlockingPoolTask(); 123 content::RunAllBlockingPoolTasksUntilIdle();
123 EXPECT_EQ(FILE_ERROR_OK, error); 124 EXPECT_EQ(FILE_ERROR_OK, error);
124 EXPECT_EQ(FILE_ERROR_NOT_FOUND, 125 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
125 GetLocalResourceEntry(non_empty_dir, &entry)); 126 GetLocalResourceEntry(non_empty_dir, &entry));
126 EXPECT_EQ(FILE_ERROR_NOT_FOUND, 127 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
127 GetLocalResourceEntry(file_in_non_empty_dir, &entry)); 128 GetLocalResourceEntry(file_in_non_empty_dir, &entry));
128 } 129 }
129 130
130 } // namespace file_system 131 } // namespace file_system
131 } // namespace drive 132 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698