diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 17:56:50 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-23 17:56:50 +0000 |
commit | de9b65ba8c0e9b461fcf3720d694ac5ffd47037c (patch) | |
tree | 342f0d8c6ef55a8f82cc6da5e1bc8eac72b0344b | |
parent | 6f40bf701483e182ddc9b2375d2a4cbfba0e47cf (diff) | |
download | chromium_src-de9b65ba8c0e9b461fcf3720d694ac5ffd47037c.zip chromium_src-de9b65ba8c0e9b461fcf3720d694ac5ffd47037c.tar.gz chromium_src-de9b65ba8c0e9b461fcf3720d694ac5ffd47037c.tar.bz2 |
Have UtilityProcessHostTest wait until the utility process dies before
finishing. This is an attempt to fix a memory leak.
BUG=17387
TEST=no
Review URL: http://codereview.chromium.org/155895
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21409 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/utility_process_host_unittest.cc | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/chrome/browser/utility_process_host_unittest.cc b/chrome/browser/utility_process_host_unittest.cc index 426f8ba..759aab0 100644 --- a/chrome/browser/utility_process_host_unittest.cc +++ b/chrome/browser/utility_process_host_unittest.cc @@ -14,6 +14,8 @@ #include "chrome/browser/renderer_host/resource_dispatcher_host.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" +#include "chrome/common/notification_registrar.h" +#include "chrome/common/notification_service.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -40,7 +42,6 @@ class TestUtilityProcessHostClient : public UtilityProcessHost::Client { virtual void OnUnpackExtensionSucceeded(const DictionaryValue& manifest) { success_ = true; - message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask); } virtual void OnUnpackExtensionFailed(const std::string& error_message) { @@ -90,6 +91,39 @@ class TestUtilityProcessHost : public UtilityProcessHost { private: }; +class ProcessClosedObserver : public NotificationObserver { + public: + ProcessClosedObserver(MessageLoop* message_loop)
+ : message_loop_(message_loop) {
+ registrar_.Add(this, NotificationType::CHILD_PROCESS_HOST_DISCONNECTED,
+ NotificationService::AllSources());
+ } + + void RunUntilClose(int child_pid) { + child_pid_ = child_pid; + observed_ = false; + message_loop_->Run(); + DCHECK(observed_); + } + + private: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::CHILD_PROCESS_HOST_DISCONNECTED); + ChildProcessInfo* info = Details<ChildProcessInfo>(details).ptr(); + if (info->GetProcessId() == child_pid_) { + observed_ = true; + message_loop_->Quit(); + } + } + + MessageLoop* message_loop_; + NotificationRegistrar registrar_; + int child_pid_; + bool observed_; +}; + TEST_F(UtilityProcessHostTest, ExtensionUnpacker) { // Copy the test extension into a temp dir and install from the temp dir. FilePath extension_file; @@ -109,9 +143,10 @@ TEST_F(UtilityProcessHostTest, ExtensionUnpacker) { TestUtilityProcessHost* process_host = new TestUtilityProcessHost(client.get(), &message_loop_, &rdh); // process_host will delete itself when it's done. + ProcessClosedObserver observer(&message_loop_); process_host->StartExtensionUnpacker( temp_extension_dir.AppendASCII("theme.crx")); - message_loop_.Run(); + observer.RunUntilClose(process_host->GetProcessId()); EXPECT_TRUE(client->success()); // Clean up the temp dir. |