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

Side by Side Diff: chrome/browser/chromeos/file_manager/file_watcher_unittest.cc

Issue 2965903002: Revert of file_manager: Migrate FILE thread to TaskScheduler (Closed)
Patch Set: Created 3 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
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_watcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_manager/file_watcher.h" 5 #include "chrome/browser/chromeos/file_manager/file_watcher.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/task_scheduler/task_scheduler.h"
12 #include "content/public/test/test_browser_thread_bundle.h" 11 #include "content/public/test/test_browser_thread_bundle.h"
13 #include "google_apis/drive/test_util.h" 12 #include "google_apis/drive/test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 namespace file_manager { 15 namespace file_manager {
17 namespace { 16 namespace {
18 17
19 using google_apis::test_util::CreateQuitCallback; 18 using google_apis::test_util::CreateQuitCallback;
20 using google_apis::test_util::CreateCopyResultCallback; 19 using google_apis::test_util::CreateCopyResultCallback;
21 20
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Start watching changes in the temporary directory. 122 // Start watching changes in the temporary directory.
124 base::FilePath changed_path; 123 base::FilePath changed_path;
125 bool watcher_created = false; 124 bool watcher_created = false;
126 bool on_change_error = false; 125 bool on_change_error = false;
127 base::RunLoop run_loop; 126 base::RunLoop run_loop;
128 file_watcher->WatchLocalFile( 127 file_watcher->WatchLocalFile(
129 temp_dir.GetPath(), 128 temp_dir.GetPath(),
130 CreateQuitCallback( 129 CreateQuitCallback(
131 &run_loop, CreateCopyResultCallback(&changed_path, &on_change_error)), 130 &run_loop, CreateCopyResultCallback(&changed_path, &on_change_error)),
132 CreateCopyResultCallback(&watcher_created)); 131 CreateCopyResultCallback(&watcher_created));
133 // Flush the task scheduler and spin the message loop and so the 132 // Spin the message loop so the base::FilePathWatcher is created.
134 // base::FilePathWatcher is created.
135 base::TaskScheduler::GetInstance()->FlushForTesting();
136 base::RunLoop().RunUntilIdle(); 133 base::RunLoop().RunUntilIdle();
137 ASSERT_TRUE(watcher_created); 134 ASSERT_TRUE(watcher_created);
138 135
139 // Create a temporary file in the temporary directory. The file watcher 136 // Create a temporary file in the temporary directory. The file watcher
140 // should detect the change in the directory. 137 // should detect the change in the directory.
141 base::FilePath temp_file_path; 138 base::FilePath temp_file_path;
142 ASSERT_TRUE( 139 ASSERT_TRUE(
143 base::CreateTemporaryFileInDir(temp_dir.GetPath(), &temp_file_path)); 140 base::CreateTemporaryFileInDir(temp_dir.GetPath(), &temp_file_path));
144 // Wait until the directory change is notified. 141 // Wait until the directory change is notified.
145 run_loop.Run(); 142 run_loop.Run();
146 ASSERT_FALSE(on_change_error); 143 ASSERT_FALSE(on_change_error);
147 ASSERT_EQ(temp_dir.GetPath().value(), changed_path.value()); 144 ASSERT_EQ(temp_dir.GetPath().value(), changed_path.value());
148 145
149 // This is ugly, but FileWatcher should be deleted explicitly here, and 146 // This is ugly, but FileWatcher should be deleted explicitly here, and
150 // flush the task scheduler, so the base::FilePathWatcher is deleted. 147 // spin the message loop so the base::FilePathWatcher is deleted.
151 // Otherwise, base::FilePathWatcher may detect a change when the temporary 148 // Otherwise, base::FilePathWatcher may detect a change when the temporary
152 // directory is deleted, which may result in crash. 149 // directory is deleted, which may result in crash.
153 file_watcher.reset(); 150 file_watcher.reset();
154 base::TaskScheduler::GetInstance()->FlushForTesting(); 151 base::RunLoop().RunUntilIdle();
155 } 152 }
156 153
157 } // namespace 154 } // namespace
158 } // namespace file_manager. 155 } // namespace file_manager.
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/file_manager/file_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698