diff options
author | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-08 02:12:34 +0000 |
---|---|---|
committer | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-08 02:12:34 +0000 |
commit | ad0b30a4f07ce261cb1cb24903e65bc1945ab270 (patch) | |
tree | ecfcd9721ab62371c0e50efcd94a1be849847c14 /chrome/renderer | |
parent | b1de7e20676534de147ac0c1935d871f95859e19 (diff) | |
download | chromium_src-ad0b30a4f07ce261cb1cb24903e65bc1945ab270.zip chromium_src-ad0b30a4f07ce261cb1cb24903e65bc1945ab270.tar.gz chromium_src-ad0b30a4f07ce261cb1cb24903e65bc1945ab270.tar.bz2 |
Modify renderwidget unittest to make purify happy
- Some posted task was not being processed.
- It needed a mock of RenderProcess.
Review URL: http://codereview.chromium.org/5660
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2988 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/render_widget_unittest.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/chrome/renderer/render_widget_unittest.cc b/chrome/renderer/render_widget_unittest.cc index 790d429..086f8bf 100644 --- a/chrome/renderer/render_widget_unittest.cc +++ b/chrome/renderer/render_widget_unittest.cc @@ -5,9 +5,22 @@ #include "testing/gtest/include/gtest/gtest.h" #include "base/ref_counted.h" +#include "chrome/common/child_process.h" #include "chrome/renderer/render_widget.h" #include "chrome/renderer/render_thread.h" +// This class is a trivial mock of the child process singleton. It is necessary +// so we don't trip DCHECKs in ChildProcess::ReleaseProcess() when destroying +// a render widget instance. +class MockProcess : public ChildProcess { + public: + explicit MockProcess(const std::wstring& channel_name) {} + static void GlobalInit() { + ChildProcessFactory<MockProcess> factory; + ChildProcess::GlobalInit(L"dummy", &factory); + } +}; + // This class is very simple mock of RenderThread. It simulates an IPC channel // which supports only two messages: // ViewHostMsg_CreateWidget : sync message sent by the Widget. @@ -49,6 +62,7 @@ class MockRenderThread : public RenderThreadBase { if (msg->is_reply()) { if (reply_deserializer_) reply_deserializer_->SerializeOutputParameters(*msg); + delete reply_deserializer_; reply_deserializer_ = NULL; } else { if (msg->is_sync()) { @@ -116,14 +130,16 @@ class MockRenderThread : public RenderThreadBase { IPC::MessageReplyDeserializer* reply_deserializer_; }; -TEST(RenderWidgetTest, DISABLED_CreateAndCloseWidget) { +TEST(RenderWidgetTest, CreateAndCloseWidget) { MessageLoop msg_loop; MockRenderThread render_thread; + MockProcess::GlobalInit(); const int32 kRouteId = 5; const int32 kOpenerId = 7; - render_thread.set_routing_id(kRouteId); + + { scoped_refptr<RenderWidget> rw = RenderWidget::Create(kOpenerId, &render_thread); ASSERT_TRUE(rw != NULL); @@ -136,5 +152,14 @@ TEST(RenderWidgetTest, DISABLED_CreateAndCloseWidget) { // Now simulate a close of the Widget. render_thread.SendCloseMessage(); EXPECT_FALSE(render_thread.has_widget()); + + // Run the loop so the release task from the renderwidget executes. + msg_loop.PostTask(FROM_HERE, new MessageLoop::QuitTask()); + msg_loop.Run(); } + // There is a delayed task that the child process posts to terminate the + // message loop so we need to spin the message loop to delete the task. + MockProcess::GlobalCleanup(); + msg_loop.Run(); +} |