From 035213a6e5c49f37dcc7966b02efc2b6f14d2c84 Mon Sep 17 00:00:00 2001 From: "earthdok@chromium.org" <earthdok@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> Date: Fri, 1 Nov 2013 12:28:58 +0000 Subject: Fix memory leaks in ChromeNotifierDelegateBrowserTest.*. BUG=314040 R=dewittj@chromium.org Review URL: https://codereview.chromium.org/55763003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232340 0039d316-1c4b-4281-b951-d872f2087c98 --- .../chrome_notifier_delegate_browsertest.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'chrome/browser/notifications') diff --git a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc index 50e7ebd..0dd6e60 100644 --- a/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc +++ b/chrome/browser/notifications/sync_notifier/chrome_notifier_delegate_browsertest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/memory/scoped_vector.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/notifications/sync_notifier/chrome_notifier_delegate.h" #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" @@ -47,7 +48,11 @@ class StubChromeNotifierService : public notifier::ChromeNotifierService { read_state); // Set enough fields in sync_data, including specifics, for our tests // to pass. - return new notifier::SyncedNotification(sync_data); + notifier::SyncedNotification* notification = + new notifier::SyncedNotification(sync_data); + // Retain ownership to avoid memory leaks in tests. + owned_notifications_.push_back(notification); + return notification; } // For testing, just return our test notification no matter what key the @@ -62,6 +67,7 @@ class StubChromeNotifierService : public notifier::ChromeNotifierService { private: std::string read_id_; + ScopedVector<notifier::SyncedNotification> owned_notifications_; }; class ChromeNotifierDelegateBrowserTest : public InProcessBrowserTest {}; @@ -78,8 +84,8 @@ class ChromeNotifierDelegateBrowserTest : public InProcessBrowserTest {}; IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest, MAYBE_ClickTest) { std::string id(kTestNotificationId); StubChromeNotifierService notifier; - notifier::ChromeNotifierDelegate* delegate = - new notifier::ChromeNotifierDelegate(id, ¬ifier); + scoped_refptr<notifier::ChromeNotifierDelegate> delegate( + new notifier::ChromeNotifierDelegate(id, ¬ifier)); // Set up an observer to wait for the navigation content::WindowedNotificationObserver observer( @@ -111,8 +117,8 @@ IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest, MAYBE_ButtonClickTest) { std::string id(kTestNotificationId); StubChromeNotifierService notifier; - notifier::ChromeNotifierDelegate* delegate = - new notifier::ChromeNotifierDelegate(id, ¬ifier); + scoped_refptr<notifier::ChromeNotifierDelegate> delegate( + new notifier::ChromeNotifierDelegate(id, ¬ifier)); // Set up an observer to wait for the navigation content::WindowedNotificationObserver observer( @@ -145,8 +151,8 @@ IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest, IN_PROC_BROWSER_TEST_F(ChromeNotifierDelegateBrowserTest, CloseTest) { std::string id(kTestNotificationId); StubChromeNotifierService notifier; - notifier::ChromeNotifierDelegate* delegate = - new notifier::ChromeNotifierDelegate(id, ¬ifier); + scoped_refptr<notifier::ChromeNotifierDelegate> delegate( + new notifier::ChromeNotifierDelegate(id, ¬ifier)); delegate->Close(false); ASSERT_EQ("", notifier.read_id()); -- cgit v1.1