| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/test/test_browser_thread.h" | 10 #include "content/test/test_browser_thread.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/platform_test.h" | 12 #include "testing/platform_test.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class BrowserThreadTest : public testing::Test { | 16 class BrowserThreadTest : public testing::Test { |
| 17 public: | 17 public: |
| 18 void Release() const { | 18 void Release() const { |
| 19 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 19 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 20 loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); | 20 loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 21 } | 21 } |
| 22 | 22 |
| 23 protected: | 23 protected: |
| 24 virtual void SetUp() { | 24 virtual void SetUp() { |
| 25 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI)); | 25 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI)); |
| 26 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE)); | 26 file_thread_.reset(new BrowserThreadImpl(BrowserThread::FILE)); |
| 27 ui_thread_->Start(); | 27 ui_thread_->Start(); |
| 28 file_thread_->Start(); | 28 file_thread_->Start(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 virtual void TearDown() { | 31 virtual void TearDown() { |
| 32 ui_thread_->Stop(); | 32 ui_thread_->Stop(); |
| 33 file_thread_->Stop(); | 33 file_thread_->Stop(); |
| 34 } | 34 } |
| 35 | 35 |
| 36 static void BasicFunction(MessageLoop* message_loop) { | 36 static void BasicFunction(MessageLoop* message_loop) { |
| 37 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 37 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 38 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 38 message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 static void DoNothing() { | 41 static void DoNothing() { |
| 42 } | 42 } |
| 43 | 43 |
| 44 class DummyTask : public Task { | 44 class DummyTask : public Task { |
| 45 public: | 45 public: |
| 46 explicit DummyTask(bool* deleted) : deleted_(deleted) { } | 46 explicit DummyTask(bool* deleted) : deleted_(deleted) { } |
| 47 ~DummyTask() { | 47 ~DummyTask() { |
| 48 *deleted_ = true; | 48 *deleted_ = true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void Run() { | 51 void Run() { |
| 52 CHECK(false); | 52 CHECK(false); |
| 53 } | 53 } |
| 54 | 54 |
| 55 private: | 55 private: |
| 56 bool* deleted_; | 56 bool* deleted_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 class DeletedOnFile | 59 class DeletedOnFile |
| 60 : public base::RefCountedThreadSafe< | 60 : public base::RefCountedThreadSafe< |
| 61 DeletedOnFile, BrowserThread::DeleteOnFileThread> { | 61 DeletedOnFile, BrowserThread::DeleteOnFileThread> { |
| 62 public: | 62 public: |
| 63 explicit DeletedOnFile(MessageLoop* message_loop) | 63 explicit DeletedOnFile(MessageLoop* message_loop) |
| 64 : message_loop_(message_loop) { } | 64 : message_loop_(message_loop) { } |
| 65 | 65 |
| 66 ~DeletedOnFile() { | 66 ~DeletedOnFile() { |
| 67 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 67 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 68 message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 68 message_loop_->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 69 } | 69 } |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 MessageLoop* message_loop_; | 72 MessageLoop* message_loop_; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class NeverDeleted | 75 class NeverDeleted |
| 76 : public base::RefCountedThreadSafe< | 76 : public base::RefCountedThreadSafe< |
| 77 NeverDeleted, BrowserThread::DeleteOnWebKitThread> { | 77 NeverDeleted, BrowserThread::DeleteOnWebKitThread> { |
| 78 public: | 78 public: |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 bool deleted = false; | 180 bool deleted = false; |
| 181 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = | 181 scoped_refptr<base::MessageLoopProxy> message_loop_proxy = |
| 182 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 182 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 183 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); | 183 bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted)); |
| 184 EXPECT_FALSE(ret); | 184 EXPECT_FALSE(ret); |
| 185 EXPECT_TRUE(deleted); | 185 EXPECT_TRUE(deleted); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } | 188 } |
| OLD | NEW |