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

Side by Side Diff: chrome/renderer/render_thread_unittest.cc

Issue 155944: Switch the first thread in a child process to be the main thread... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 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/waitable_event.h" 5 #include "base/waitable_event.h"
6 #include "chrome/common/render_messages.h" 6 #include "chrome/common/render_messages.h"
7 #include "chrome/renderer/mock_render_process.h" 7 #include "chrome/renderer/mock_render_process.h"
8 #include "chrome/renderer/render_thread.h" 8 #include "chrome/renderer/render_thread.h"
9 #include "ipc/ipc_sync_channel.h" 9 #include "ipc/ipc_sync_channel.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace { 12 namespace {
13 13
14 const char kThreadName[] = "render_thread_unittest"; 14 const char kThreadName[] = "render_thread_unittest";
15 15
16 class RenderThreadTest : public testing::Test { 16 class RenderThreadTest : public testing::Test {
17 public: 17 public:
18 virtual void SetUp() { 18 virtual void SetUp() {
19 // Need a MODE_SERVER to make MODE_CLIENTs (like a RenderThread) happy. 19 // Need a MODE_SERVER to make MODE_CLIENTs (like a RenderThread) happy.
20 channel_ = new IPC::Channel(kThreadName, IPC::Channel::MODE_SERVER, NULL); 20 channel_ = new IPC::Channel(kThreadName, IPC::Channel::MODE_SERVER, NULL);
21 mock_process_.reset(new MockProcess(new RenderThread(kThreadName))); 21 mock_process_.reset(new MockProcess());
22 mock_process_->set_main_thread(new RenderThread(kThreadName));
22 } 23 }
23 24
24 virtual void TearDown() { 25 virtual void TearDown() {
25 message_loop_.RunAllPending(); 26 message_loop_.RunAllPending();
26 mock_process_.reset(); 27 mock_process_.reset();
27 // Need to fully destruct IPC::SyncChannel before the message loop goes 28 // Need to fully destruct IPC::SyncChannel before the message loop goes
28 // away. 29 // away.
29 message_loop_.RunAllPending(); 30 message_loop_.RunAllPending();
30 // Delete the server channel after the RenderThread so that 31 // Delete the server channel after the RenderThread so that
31 // IPC::SyncChannel's OnChannelError doesn't fire on the context and attempt 32 // IPC::SyncChannel's OnChannelError doesn't fire on the context and attempt
32 // to use the listener thread which is now gone. 33 // to use the listener thread which is now gone.
33 delete channel_; 34 delete channel_;
34 } 35 }
35 36
36 protected: 37 protected:
37 MessageLoopForIO message_loop_; 38 MessageLoop message_loop_;
38 scoped_ptr<MockProcess> mock_process_; 39 scoped_ptr<MockProcess> mock_process_;
39 IPC::Channel *channel_; 40 IPC::Channel *channel_;
40 }; 41 };
41 42
42 TEST_F(RenderThreadTest, TestGlobal) { 43 TEST_F(RenderThreadTest, TestGlobal) {
43 // Can't reach the RenderThread object on other threads, since it's not 44 ASSERT_TRUE(RenderThread::current());
44 // thread-safe!
45 ASSERT_FALSE(RenderThread::current());
46 } 45 }
47 46
48 TEST_F(RenderThreadTest, TestVisitedMsg) { 47 TEST_F(RenderThreadTest, TestVisitedMsg) {
49 #if defined(OS_WIN) 48 #if defined(OS_WIN)
50 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(NULL); 49 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(NULL);
51 #elif defined(OS_POSIX) 50 #elif defined(OS_POSIX)
52 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable( 51 IPC::Message* msg = new ViewMsg_VisitedLink_NewTable(
53 base::SharedMemoryHandle(0, false)); 52 base::SharedMemoryHandle(0, false));
54 #endif 53 #endif
55 ASSERT_TRUE(msg); 54 ASSERT_TRUE(msg);
56 // Message goes nowhere, but this confirms Init() has happened. 55 // Message goes nowhere, but this confirms Init() has happened.
57 // Unusually (?), RenderThread() Start()s itself in it's constructor. 56 // Unusually (?), RenderThread() Start()s itself in it's constructor.
58 mock_process_->child_thread()->Send(msg); 57 mock_process_->main_thread()->Send(msg);
59 58
60 // No need to delete msg; per Message::Send() documentation, "The 59 // No need to delete msg; per Message::Send() documentation, "The
61 // implementor takes ownership of the given Message regardless of 60 // implementor takes ownership of the given Message regardless of
62 // whether or not this method succeeds." 61 // whether or not this method succeeds."
63 } 62 }
64 63
65 } // namespace 64 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698