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

Unified Diff: chrome/browser/tabs/tab_strip_model_unittest.cc

Issue 4687009: Fixes possible crash in TabStripModel. If during close all a tab was (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/tabs/tab_strip_model_unittest.cc
diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc
index 81847e945144c671738b116f621e54fd966feb82..26ac70d941ebde8642e6e7b65861715769f20de2 100644
--- a/chrome/browser/tabs/tab_strip_model_unittest.cc
+++ b/chrome/browser/tabs/tab_strip_model_unittest.cc
@@ -36,6 +36,38 @@
using testing::_;
+namespace {
+
+// Class used to delete a TabContents when another TabContents is destroyed.
+class DeleteTabContentsOnDestroyedObserver : public NotificationObserver {
+ public:
+ DeleteTabContentsOnDestroyedObserver(TabContents* source,
+ TabContents* tab_to_delete)
+ : source_(source),
+ tab_to_delete_(tab_to_delete) {
+ registrar_.Add(this,
+ NotificationType::TAB_CONTENTS_DESTROYED,
+ Source<TabContents>(source));
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ TabContents* tab_to_delete = tab_to_delete_;
+ tab_to_delete_ = NULL;
+ delete tab_to_delete;
+ }
+
+ private:
+ TabContents* source_;
+ TabContents* tab_to_delete_;
+ NotificationRegistrar registrar_;
+
+ DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver);
+};
+
+} // namespace
+
class TabStripDummyDelegate : public TabStripModelDelegate {
public:
explicit TabStripDummyDelegate(TabContents* dummy)
@@ -1835,3 +1867,18 @@ TEST_F(TabStripModelTest, ReplaceSendsSelected) {
strip.CloseAllTabs();
}
+
+// Makes sure TabStripModel handles the case of deleting a tab while removing
+// another tab.
+TEST_F(TabStripModelTest, DeleteFromDestroy) {
+ TabStripDummyDelegate delegate(NULL);
+ TabStripModel strip(&delegate, profile());
+ TabContents* contents1 = CreateTabContents();
+ TabContents* contents2 = CreateTabContents();
+ strip.AppendTabContents(contents1, true);
+ strip.AppendTabContents(contents2, true);
+ // DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends
+ // out notification that it is being destroyed.
+ DeleteTabContentsOnDestroyedObserver observer(contents2, contents1);
+ strip.CloseAllTabs();
+}
« chrome/browser/tabs/tab_strip_model.cc ('K') | « chrome/browser/tabs/tab_strip_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698