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

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

Issue 1159623009: content: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test build fix. 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"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/sequenced_task_runner_helpers.h" 9 #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_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 22 loop_.task_runner()->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->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 40 message_loop->task_runner()->PostTask(FROM_HERE,
41 base::MessageLoop::QuitClosure());
41 } 42 }
42 43
43 class DeletedOnFile 44 class DeletedOnFile
44 : public base::RefCountedThreadSafe< 45 : public base::RefCountedThreadSafe<
45 DeletedOnFile, BrowserThread::DeleteOnFileThread> { 46 DeletedOnFile, BrowserThread::DeleteOnFileThread> {
46 public: 47 public:
47 explicit DeletedOnFile(base::MessageLoop* message_loop) 48 explicit DeletedOnFile(base::MessageLoop* message_loop)
48 : message_loop_(message_loop) {} 49 : message_loop_(message_loop) {}
49 50
50 private: 51 private:
51 friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>; 52 friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>;
52 friend class base::DeleteHelper<DeletedOnFile>; 53 friend class base::DeleteHelper<DeletedOnFile>;
53 54
54 ~DeletedOnFile() { 55 ~DeletedOnFile() {
55 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 56 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
56 message_loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); 57 message_loop_->task_runner()->PostTask(FROM_HERE,
58 base::MessageLoop::QuitClosure());
57 } 59 }
58 60
59 base::MessageLoop* message_loop_; 61 base::MessageLoop* message_loop_;
60 }; 62 };
61 63
62 private: 64 private:
63 scoped_ptr<BrowserThreadImpl> ui_thread_; 65 scoped_ptr<BrowserThreadImpl> ui_thread_;
64 scoped_ptr<BrowserThreadImpl> file_thread_; 66 scoped_ptr<BrowserThreadImpl> file_thread_;
65 // It's kind of ugly to make this mutable - solely so we can post the Quit 67 // It's kind of ugly to make this mutable - solely so we can post the Quit
66 // Task from Release(). This should be fixed. 68 // Task from Release(). This should be fixed.
(...skipping 14 matching lines...) Expand all
81 } 83 }
82 84
83 TEST_F(BrowserThreadTest, ReleasedOnCorrectThread) { 85 TEST_F(BrowserThreadTest, ReleasedOnCorrectThread) {
84 { 86 {
85 scoped_refptr<DeletedOnFile> test( 87 scoped_refptr<DeletedOnFile> test(
86 new DeletedOnFile(base::MessageLoop::current())); 88 new DeletedOnFile(base::MessageLoop::current()));
87 } 89 }
88 base::MessageLoop::current()->Run(); 90 base::MessageLoop::current()->Run();
89 } 91 }
90 92
91 TEST_F(BrowserThreadTest, PostTaskViaMessageLoopProxy) { 93 TEST_F(BrowserThreadTest, PostTaskViaTaskRunner) {
92 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 94 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
93 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE); 95 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
94 message_loop_proxy->PostTask( 96 task_runner->PostTask(
95 FROM_HERE, base::Bind(&BasicFunction, base::MessageLoop::current())); 97 FROM_HERE, base::Bind(&BasicFunction, base::MessageLoop::current()));
96 base::MessageLoop::current()->Run(); 98 base::MessageLoop::current()->Run();
97 } 99 }
98 100
99 TEST_F(BrowserThreadTest, ReleaseViaMessageLoopProxy) { 101 TEST_F(BrowserThreadTest, ReleaseViaTaskRunner) {
100 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = 102 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); 103 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
102 message_loop_proxy->ReleaseSoon(FROM_HERE, this); 104 task_runner->ReleaseSoon(FROM_HERE, this);
103 base::MessageLoop::current()->Run(); 105 base::MessageLoop::current()->Run();
104 } 106 }
105 107
106 TEST_F(BrowserThreadTest, PostTaskAndReply) { 108 TEST_F(BrowserThreadTest, PostTaskAndReply) {
107 // Most of the heavy testing for PostTaskAndReply() is done inside the 109 // Most of the heavy testing for PostTaskAndReply() is done inside the
108 // MessageLoopProxy test. This just makes sure we get piped through at all. 110 // task runner test. This just makes sure we get piped through at all.
109 ASSERT_TRUE(BrowserThread::PostTaskAndReply( 111 ASSERT_TRUE(BrowserThread::PostTaskAndReply(
110 BrowserThread::FILE, 112 BrowserThread::FILE,
111 FROM_HERE, 113 FROM_HERE,
112 base::Bind(&base::DoNothing), 114 base::Bind(&base::DoNothing),
113 base::Bind(&base::MessageLoop::Quit, 115 base::Bind(&base::MessageLoop::Quit,
114 base::Unretained(base::MessageLoop::current()->current())))); 116 base::Unretained(base::MessageLoop::current()->current()))));
115 base::MessageLoop::current()->Run(); 117 base::MessageLoop::current()->Run();
116 } 118 }
117 119
118 } // namespace content 120 } // 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