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

Side by Side Diff: chrome/browser/chromeos/drive/sync/entry_revert_performer_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/sync/entry_revert_performer.h" 5 #include "chrome/browser/chromeos/drive/sync/entry_revert_performer.h"
6 6
7 #include "base/task_runner_util.h" 7 #include "base/task_runner_util.h"
8 #include "chrome/browser/chromeos/drive/file_change.h" 8 #include "chrome/browser/chromeos/drive/file_change.h"
9 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" 9 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
10 #include "chrome/browser/chromeos/drive/file_system_util.h" 10 #include "chrome/browser/chromeos/drive/file_system_util.h"
11 #include "chrome/browser/chromeos/drive/job_scheduler.h" 11 #include "chrome/browser/chromeos/drive/job_scheduler.h"
12 #include "chrome/browser/chromeos/drive/resource_metadata.h" 12 #include "chrome/browser/chromeos/drive/resource_metadata.h"
13 #include "chrome/browser/drive/fake_drive_service.h" 13 #include "chrome/browser/drive/fake_drive_service.h"
14 #include "content/public/test/test_utils.h"
14 #include "google_apis/drive/test_util.h" 15 #include "google_apis/drive/test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace drive { 18 namespace drive {
18 namespace internal { 19 namespace internal {
19 20
20 class EntryRevertPerformerTest : public file_system::OperationTestBase { 21 class EntryRevertPerformerTest : public file_system::OperationTestBase {
21 protected: 22 protected:
22 virtual void SetUp() OVERRIDE { 23 virtual void SetUp() OVERRIDE {
23 OperationTestBase::SetUp(); 24 OperationTestBase::SetUp();
(...skipping 20 matching lines...) Expand all
44 updated_entry.set_title("Updated" + src_entry.title()); 45 updated_entry.set_title("Updated" + src_entry.title());
45 updated_entry.set_metadata_edit_state(ResourceEntry::DIRTY); 46 updated_entry.set_metadata_edit_state(ResourceEntry::DIRTY);
46 47
47 FileError error = FILE_ERROR_FAILED; 48 FileError error = FILE_ERROR_FAILED;
48 base::PostTaskAndReplyWithResult( 49 base::PostTaskAndReplyWithResult(
49 blocking_task_runner(), 50 blocking_task_runner(),
50 FROM_HERE, 51 FROM_HERE,
51 base::Bind(&ResourceMetadata::RefreshEntry, 52 base::Bind(&ResourceMetadata::RefreshEntry,
52 base::Unretained(metadata()), updated_entry), 53 base::Unretained(metadata()), updated_entry),
53 google_apis::test_util::CreateCopyResultCallback(&error)); 54 google_apis::test_util::CreateCopyResultCallback(&error));
54 test_util::RunBlockingPoolTask(); 55 content::RunAllBlockingPoolTasksUntilIdle();
55 EXPECT_EQ(FILE_ERROR_OK, error); 56 EXPECT_EQ(FILE_ERROR_OK, error);
56 57
57 // Revert local change. 58 // Revert local change.
58 error = FILE_ERROR_FAILED; 59 error = FILE_ERROR_FAILED;
59 performer_->RevertEntry( 60 performer_->RevertEntry(
60 src_entry.local_id(), 61 src_entry.local_id(),
61 ClientContext(USER_INITIATED), 62 ClientContext(USER_INITIATED),
62 google_apis::test_util::CreateCopyResultCallback(&error)); 63 google_apis::test_util::CreateCopyResultCallback(&error));
63 test_util::RunBlockingPoolTask(); 64 content::RunAllBlockingPoolTasksUntilIdle();
64 EXPECT_EQ(FILE_ERROR_OK, error); 65 EXPECT_EQ(FILE_ERROR_OK, error);
65 66
66 // Verify local change is reverted. 67 // Verify local change is reverted.
67 ResourceEntry result_entry; 68 ResourceEntry result_entry;
68 EXPECT_EQ(FILE_ERROR_OK, 69 EXPECT_EQ(FILE_ERROR_OK,
69 GetLocalResourceEntryById(src_entry.local_id(), &result_entry)); 70 GetLocalResourceEntryById(src_entry.local_id(), &result_entry));
70 EXPECT_EQ(src_entry.title(), result_entry.title()); 71 EXPECT_EQ(src_entry.title(), result_entry.title());
71 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state()); 72 EXPECT_EQ(ResourceEntry::CLEAN, result_entry.metadata_edit_state());
72 73
73 EXPECT_EQ(2U, observer()->get_changed_files().size()); 74 EXPECT_EQ(2U, observer()->get_changed_files().size());
(...skipping 13 matching lines...) Expand all
87 entry.set_parent_local_id(my_drive.local_id()); 88 entry.set_parent_local_id(my_drive.local_id());
88 89
89 FileError error = FILE_ERROR_FAILED; 90 FileError error = FILE_ERROR_FAILED;
90 std::string local_id; 91 std::string local_id;
91 base::PostTaskAndReplyWithResult( 92 base::PostTaskAndReplyWithResult(
92 blocking_task_runner(), 93 blocking_task_runner(),
93 FROM_HERE, 94 FROM_HERE,
94 base::Bind(&ResourceMetadata::AddEntry, 95 base::Bind(&ResourceMetadata::AddEntry,
95 base::Unretained(metadata()), entry, &local_id), 96 base::Unretained(metadata()), entry, &local_id),
96 google_apis::test_util::CreateCopyResultCallback(&error)); 97 google_apis::test_util::CreateCopyResultCallback(&error));
97 test_util::RunBlockingPoolTask(); 98 content::RunAllBlockingPoolTasksUntilIdle();
98 EXPECT_EQ(FILE_ERROR_OK, error); 99 EXPECT_EQ(FILE_ERROR_OK, error);
99 100
100 // Revert local change. The added entry should be removed. 101 // Revert local change. The added entry should be removed.
101 error = FILE_ERROR_FAILED; 102 error = FILE_ERROR_FAILED;
102 performer_->RevertEntry( 103 performer_->RevertEntry(
103 local_id, 104 local_id,
104 ClientContext(USER_INITIATED), 105 ClientContext(USER_INITIATED),
105 google_apis::test_util::CreateCopyResultCallback(&error)); 106 google_apis::test_util::CreateCopyResultCallback(&error));
106 test_util::RunBlockingPoolTask(); 107 content::RunAllBlockingPoolTasksUntilIdle();
107 EXPECT_EQ(FILE_ERROR_OK, error); 108 EXPECT_EQ(FILE_ERROR_OK, error);
108 109
109 // Verify the entry was deleted locally. 110 // Verify the entry was deleted locally.
110 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry)); 111 EXPECT_EQ(FILE_ERROR_NOT_FOUND, GetLocalResourceEntryById(local_id, &entry));
111 112
112 EXPECT_EQ(1U, observer()->get_changed_files().size()); 113 EXPECT_EQ(1U, observer()->get_changed_files().size());
113 EXPECT_TRUE(observer()->get_changed_files().CountDirectory( 114 EXPECT_TRUE(observer()->get_changed_files().CountDirectory(
114 util::GetDriveMyDriveRootPath())); 115 util::GetDriveMyDriveRootPath()));
115 } 116 }
116 117
117 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) { 118 TEST_F(EntryRevertPerformerTest, RevertEntry_TrashedOnServer) {
118 base::FilePath path( 119 base::FilePath path(
119 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); 120 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
120 121
121 ResourceEntry entry; 122 ResourceEntry entry;
122 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry)); 123 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(path, &entry));
123 124
124 // Trash the entry on the server. 125 // Trash the entry on the server.
125 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; 126 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
126 fake_service()->TrashResource( 127 fake_service()->TrashResource(
127 entry.resource_id(), 128 entry.resource_id(),
128 google_apis::test_util::CreateCopyResultCallback(&gdata_error)); 129 google_apis::test_util::CreateCopyResultCallback(&gdata_error));
129 test_util::RunBlockingPoolTask(); 130 content::RunAllBlockingPoolTasksUntilIdle();
130 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error); 131 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
131 132
132 // Revert local change. The entry should be removed. 133 // Revert local change. The entry should be removed.
133 FileError error = FILE_ERROR_FAILED; 134 FileError error = FILE_ERROR_FAILED;
134 performer_->RevertEntry( 135 performer_->RevertEntry(
135 entry.local_id(), 136 entry.local_id(),
136 ClientContext(USER_INITIATED), 137 ClientContext(USER_INITIATED),
137 google_apis::test_util::CreateCopyResultCallback(&error)); 138 google_apis::test_util::CreateCopyResultCallback(&error));
138 test_util::RunBlockingPoolTask(); 139 content::RunAllBlockingPoolTasksUntilIdle();
139 EXPECT_EQ(FILE_ERROR_OK, error); 140 EXPECT_EQ(FILE_ERROR_OK, error);
140 141
141 // Verify the entry was deleted locally. 142 // Verify the entry was deleted locally.
142 EXPECT_EQ(FILE_ERROR_NOT_FOUND, 143 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
143 GetLocalResourceEntryById(entry.local_id(), &entry)); 144 GetLocalResourceEntryById(entry.local_id(), &entry));
144 145
145 EXPECT_EQ(1U, observer()->get_changed_files().size()); 146 EXPECT_EQ(1U, observer()->get_changed_files().size());
146 EXPECT_TRUE(observer()->get_changed_files().count(path)); 147 EXPECT_TRUE(observer()->get_changed_files().count(path));
147 } 148 }
148 149
149 } // namespace internal 150 } // namespace internal
150 } // namespace drive 151 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698