Index: extensions/browser/content_hash_fetcher_unittest.cc |
diff --git a/extensions/browser/content_hash_fetcher_unittest.cc b/extensions/browser/content_hash_fetcher_unittest.cc |
index e54b4d66f7b8be0cb6e32f25e6fa4100da187bd8..7342070556575c0fc09a9c68dd4dbe26deb4497a 100644 |
--- a/extensions/browser/content_hash_fetcher_unittest.cc |
+++ b/extensions/browser/content_hash_fetcher_unittest.cc |
@@ -280,4 +280,85 @@ TEST_F(ContentHashFetcherTest, MAYBE_MissingVerifiedContentsAndCorrupt) { |
base::PathExists(file_util::GetVerifiedContentsPath(extension->path()))); |
} |
+class Job : public base::RefCountedThreadSafe<Job> { |
+ public: |
+ using JobCallback = base::Callback<void(bool)>; |
+ explicit Job(const JobCallback& callback) : job_callback_(callback) { |
+ bool got_id = |
+ content::BrowserThread::GetCurrentThreadIdentifier(&creation_thread_); |
+ DCHECK(got_id); |
+ } |
+ |
+ void Start() { |
+ content::BrowserThread::PostBlockingPoolSequencedTask( |
+ "Job", FROM_HERE, base::Bind(&Job::Task1OnBlockingPool, this)); |
+ } |
+ |
+ void Task1OnBlockingPool() { |
+ printf("Task1OnBlockingPool BEG\n"); |
+ |
+ content::BrowserThread::PostTask( |
+ creation_thread_, FROM_HERE, |
+ base::Bind(&Job::Task2OnCreationThread, this)); |
+ printf("Task1OnBlockingPool END\n"); |
+ post_task_finished_ = true; |
+ } |
+ |
+ void Task2OnCreationThread() { |
+ printf("Task2OnCreationThread\n"); |
+ job_callback_.Run(true); |
+ } |
+ |
+ bool post_task_finished() { return post_task_finished_; } |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<Job>; |
+ ~Job() {} |
+ |
+ bool post_task_finished_ = false; |
+ JobCallback job_callback_; |
+ content::BrowserThread::ID creation_thread_; |
+ DISALLOW_COPY_AND_ASSIGN(Job); |
+}; |
+ |
+class JobWaiter { |
+ public: |
+ JobWaiter() : weak_factory_(this) {} |
+ |
+ Job::JobCallback CreateCallback() { |
+ return base::Bind(&JobWaiter::Callback, weak_factory_.GetWeakPtr()); |
+ } |
+ |
+ void WaitForCallback() { |
+ if (seen_) { |
+ ADD_FAILURE() << "Already seen_"; |
+ return; |
+ } |
+ base::RunLoop run_loop; |
+ run_loop_quit_ = run_loop.QuitClosure(); |
+ run_loop.Run(); |
+ } |
+ |
+ private: |
+ void Callback(bool unused) { |
+ printf("JobWaiter::Callback\n"); |
+ seen_ = true; |
+ if (run_loop_quit_) |
+ base::ResetAndReturn(&run_loop_quit_).Run(); |
+ } |
+ |
+ bool seen_ = false; |
+ base::Closure run_loop_quit_; |
+ base::WeakPtrFactory<JobWaiter> weak_factory_; |
+ DISALLOW_COPY_AND_ASSIGN(JobWaiter); |
+}; |
+ |
+TEST_F(ContentHashFetcherTest, TestCase) { |
+ JobWaiter waiter; |
+ scoped_refptr<Job> job(new Job(waiter.CreateCallback())); |
+ job->Start(); |
+ waiter.WaitForCallback(); |
+ { ASSERT_TRUE(job->post_task_finished()); } |
+} |
+ |
} // namespace extensions |