summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/tab_contents/test_tab_contents.cc29
-rw-r--r--chrome/browser/tab_contents/test_tab_contents.h10
2 files changed, 39 insertions, 0 deletions
diff --git a/chrome/browser/tab_contents/test_tab_contents.cc b/chrome/browser/tab_contents/test_tab_contents.cc
index bd5eac4..84bde21 100644
--- a/chrome/browser/tab_contents/test_tab_contents.cc
+++ b/chrome/browser/tab_contents/test_tab_contents.cc
@@ -6,10 +6,39 @@
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/test/test_render_view_host.h"
+#include "chrome/common/notification_service.h"
TestTabContents::TestTabContents(Profile* profile, SiteInstance* instance)
: TabContents(profile, instance, MSG_ROUTING_NONE, NULL),
transition_cross_site(false) {
+ // Listen for infobar events so we can call InfoBarClosed() on the infobar
+ // delegates and give them an opportunity to delete themselves. (Since we
+ // have no InfobarContainer in TestTabContents, InfoBarClosed() is not called
+ // most likely leading to the infobar delegates being leaked.)
+ Source<TabContents> source(this);
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
+ source);
+ registrar_.Add(this, NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
+ source);
+}
+
+void TestTabContents::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ // TabContents does not handle TAB_CONTENTS_INFOBAR_* so we don't pass it
+ // these notifications.
+ switch (type.value) {
+ case NotificationType::TAB_CONTENTS_INFOBAR_REMOVED:
+ Details<InfoBarDelegate>(details).ptr()->InfoBarClosed();
+ break;
+ case NotificationType::TAB_CONTENTS_INFOBAR_REPLACED:
+ Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details).ptr()->
+ first->InfoBarClosed();
+ break;
+ default:
+ TabContents::Observe(type, source, details);
+ break;
+ }
}
TestRenderViewHost* TestTabContents::pending_rvh() {
diff --git a/chrome/browser/tab_contents/test_tab_contents.h b/chrome/browser/tab_contents/test_tab_contents.h
index 9ed1258..aebae87 100644
--- a/chrome/browser/tab_contents/test_tab_contents.h
+++ b/chrome/browser/tab_contents/test_tab_contents.h
@@ -7,6 +7,7 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/notification_registrar.h"
class RenderViewHostFactory;
class TestRenderViewHost;
@@ -29,6 +30,13 @@ class TestTabContents : public TabContents {
// alternatives without using command-line switches.
bool ShouldTransitionCrossSite() { return transition_cross_site; }
+ // Overrides TabContents::Observe. We are listening to infobar related
+ // notifications so we can call InfoBarClosed() on the infobar delegates to
+ // prevent them from leaking.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
// Promote DidNavigate to public.
void TestDidNavigate(RenderViewHost* render_view_host,
const ViewHostMsg_FrameNavigate_Params& params) {
@@ -50,6 +58,8 @@ class TestTabContents : public TabContents {
// Set by individual tests.
bool transition_cross_site;
+
+ NotificationRegistrar registrar_;
};
#endif // CHROME_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_