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

Side by Side Diff: content/browser/browser_thread_unittest.cc

Issue 1170623003: Revert "content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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 | « content/browser/browser_thread_impl.cc ('k') | content/browser/byte_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/location.h"
8 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/sequenced_task_runner_helpers.h" 10 #include "base/sequenced_task_runner_helpers.h"
10 #include "base/single_thread_task_runner.h"
11 #include "content/browser/browser_thread_impl.h" 11 #include "content/browser/browser_thread_impl.h"
12 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 class BrowserThreadTest : public testing::Test { 18 class BrowserThreadTest : public testing::Test {
19 public: 19 public:
20 void Release() const { 20 void Release() const {
21 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 21 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
22 loop_.task_runner()->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 22 loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
23 } 23 }
24 24
25 protected: 25 protected:
26 void SetUp() override { 26 void SetUp() override {
27 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI)); 27 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI));
28 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE)); 28 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE));
29 ui_thread_->Start(); 29 ui_thread_->Start();
30 file_thread_->Start(); 30 file_thread_->Start();
31 } 31 }
32 32
33 void TearDown() override { 33 void TearDown() override {
34 ui_thread_->Stop(); 34 ui_thread_->Stop();
35 file_thread_->Stop(); 35 file_thread_->Stop();
36 } 36 }
37 37
38 static void BasicFunction(base::MessageLoop* message_loop) { 38 static void BasicFunction(base::MessageLoop* message_loop) {
39 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 39 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
40 message_loop->task_runner()->PostTask(FROM_HERE, 40 message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
41 base::MessageLoop::QuitClosure());
42 } 41 }
43 42
44 class DeletedOnFile 43 class DeletedOnFile
45 : public base::RefCountedThreadSafe< 44 : public base::RefCountedThreadSafe<
46 DeletedOnFile, BrowserThread::DeleteOnFileThread> { 45 DeletedOnFile, BrowserThread::DeleteOnFileThread> {
47 public: 46 public:
48 explicit DeletedOnFile(base::MessageLoop* message_loop) 47 explicit DeletedOnFile(base::MessageLoop* message_loop)
49 : message_loop_(message_loop) {} 48 : message_loop_(message_loop) {}
50 49
51 private: 50 private:
52 friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>; 51 friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>;
53 friend class base::DeleteHelper<DeletedOnFile>; 52 friend class base::DeleteHelper<DeletedOnFile>;
54 53
55 ~DeletedOnFile() { 54 ~DeletedOnFile() {
56 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 55 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
57 message_loop_->task_runner()->PostTask(FROM_HERE, 56 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
58 base::MessageLoop::QuitClosure());
59 } 57 }
60 58
61 base::MessageLoop* message_loop_; 59 base::MessageLoop* message_loop_;
62 }; 60 };
63 61
64 private: 62 private:
65 scoped_ptr<BrowserThreadImpl> ui_thread_; 63 scoped_ptr<BrowserThreadImpl> ui_thread_;
66 scoped_ptr<BrowserThreadImpl> file_thread_; 64 scoped_ptr<BrowserThreadImpl> file_thread_;
67 // It's kind of ugly to make this mutable - solely so we can post the Quit 65 // It's kind of ugly to make this mutable - solely so we can post the Quit
68 // Task from Release(). This should be fixed. 66 // Task from Release(). This should be fixed.
(...skipping 14 matching lines...) Expand all
83 } 81 }
84 82
85 TEST_F(BrowserThreadTest, ReleasedOnCorrectThread) { 83 TEST_F(BrowserThreadTest, ReleasedOnCorrectThread) {
86 { 84 {
87 scoped_refptr<DeletedOnFile> test( 85 scoped_refptr<DeletedOnFile> test(
88 new DeletedOnFile(base::MessageLoop::current())); 86 new DeletedOnFile(base::MessageLoop::current()));
89 } 87 }
90 base::MessageLoop::current()->Run(); 88 base::MessageLoop::current()->Run();
91 } 89 }
92 90
93 TEST_F(BrowserThreadTest, PostTaskViaTaskRunner) { 91 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxy) {
94 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 92 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 93 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
96 task_runner->PostTask( 94 message_loop_proxy->PostTask(
97 FROM_HERE, base::Bind(&BasicFunction, base::MessageLoop::current())); 95 FROM_HERE, base::Bind(&BasicFunction, base::MessageLoop::current()));
98 base::MessageLoop::current()->Run(); 96 base::MessageLoop::current()->Run();
99 } 97 }
100 98
101 TEST_F(BrowserThreadTest, ReleaseViaTaskRunner) { 99 TEST_F(BrowserThreadTest, ReleaseViaMessageLoopProxy) {
102 scoped_refptr<base::SingleThreadTaskRunner> task_runner = 100 scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
103 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); 101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
104 task_runner->ReleaseSoon(FROM_HERE, this); 102 message_loop_proxy->ReleaseSoon(FROM_HERE, this);
105 base::MessageLoop::current()->Run(); 103 base::MessageLoop::current()->Run();
106 } 104 }
107 105
108 TEST_F(BrowserThreadTest, PostTaskAndReply) { 106 TEST_F(BrowserThreadTest, PostTaskAndReply) {
109 // Most of the heavy testing for PostTaskAndReply() is done inside the 107 // Most of the heavy testing for PostTaskAndReply() is done inside the
110 // task runner test. This just makes sure we get piped through at all. 108 // MessageLoopProxy test. This just makes sure we get piped through at all.
111 ASSERT_TRUE(BrowserThread::PostTaskAndReply( 109 ASSERT_TRUE(BrowserThread::PostTaskAndReply(
112 BrowserThread::FILE, 110 BrowserThread::FILE,
113 FROM_HERE, 111 FROM_HERE,
114 base::Bind(&base::DoNothing), 112 base::Bind(&base::DoNothing),
115 base::Bind(&base::MessageLoop::Quit, 113 base::Bind(&base::MessageLoop::Quit,
116 base::Unretained(base::MessageLoop::current()->current())))); 114 base::Unretained(base::MessageLoop::current()->current()))));
117 base::MessageLoop::current()->Run(); 115 base::MessageLoop::current()->Run();
118 } 116 }
119 117
120 } // namespace content 118 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browser_thread_impl.cc ('k') | content/browser/byte_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698