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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/system_monitor.h" 5 #include "app/system_monitor.h"
6 #include "base/file_path.h" 6 #include "base/file_path.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/notification_registrar.h" 29 #include "chrome/common/notification_registrar.h"
30 #include "chrome/common/notification_service.h" 30 #include "chrome/common/notification_service.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/property_bag.h" 32 #include "chrome/common/property_bag.h"
33 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
34 #include "chrome/test/testing_profile.h" 34 #include "chrome/test/testing_profile.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 using testing::_; 37 using testing::_;
38 38
39 namespace {
40
41 // Class used to delete a TabContents when another TabContents is destroyed.
42 class DeleteTabContentsOnDestroyedObserver : public NotificationObserver {
43 public:
44 DeleteTabContentsOnDestroyedObserver(TabContents* source,
45 TabContents* tab_to_delete)
46 : source_(source),
47 tab_to_delete_(tab_to_delete) {
48 registrar_.Add(this,
49 NotificationType::TAB_CONTENTS_DESTROYED,
50 Source<TabContents>(source));
51 }
52
53 virtual void Observe(NotificationType type,
54 const NotificationSource& source,
55 const NotificationDetails& details) {
56 TabContents* tab_to_delete = tab_to_delete_;
57 tab_to_delete_ = NULL;
58 delete tab_to_delete;
59 }
60
61 private:
62 TabContents* source_;
63 TabContents* tab_to_delete_;
64 NotificationRegistrar registrar_;
65
66 DISALLOW_COPY_AND_ASSIGN(DeleteTabContentsOnDestroyedObserver);
67 };
68
69 } // namespace
70
39 class TabStripDummyDelegate : public TabStripModelDelegate { 71 class TabStripDummyDelegate : public TabStripModelDelegate {
40 public: 72 public:
41 explicit TabStripDummyDelegate(TabContents* dummy) 73 explicit TabStripDummyDelegate(TabContents* dummy)
42 : dummy_contents_(dummy), can_close_(true), run_unload_(false) {} 74 : dummy_contents_(dummy), can_close_(true), run_unload_(false) {}
43 virtual ~TabStripDummyDelegate() {} 75 virtual ~TabStripDummyDelegate() {}
44 76
45 void set_can_close(bool value) { can_close_ = value; } 77 void set_can_close(bool value) { can_close_ = value; }
46 void set_run_unload_listener(bool value) { run_unload_ = value; } 78 void set_run_unload_listener(bool value) { run_unload_ = value; }
47 79
48 // Overridden from TabStripModelDelegate: 80 // Overridden from TabStripModelDelegate:
(...skipping 1779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 strip.ReplaceTabContentsAt(1, new_contents); 1860 strip.ReplaceTabContentsAt(1, new_contents);
1829 1861
1830 ASSERT_EQ(1, tabstrip_observer.GetStateCount()); 1862 ASSERT_EQ(1, tabstrip_observer.GetStateCount());
1831 1863
1832 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED); 1864 state = State(new_contents, 1, MockTabStripModelObserver::REPLACED);
1833 state.src_contents = third_contents; 1865 state.src_contents = third_contents;
1834 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state)); 1866 EXPECT_TRUE(tabstrip_observer.StateEquals(0, state));
1835 1867
1836 strip.CloseAllTabs(); 1868 strip.CloseAllTabs();
1837 } 1869 }
1870
1871 // Makes sure TabStripModel handles the case of deleting a tab while removing
1872 // another tab.
1873 TEST_F(TabStripModelTest, DeleteFromDestroy) {
1874 TabStripDummyDelegate delegate(NULL);
1875 TabStripModel strip(&delegate, profile());
1876 TabContents* contents1 = CreateTabContents();
1877 TabContents* contents2 = CreateTabContents();
1878 strip.AppendTabContents(contents1, true);
1879 strip.AppendTabContents(contents2, true);
1880 // DeleteTabContentsOnDestroyedObserver deletes contents1 when contents2 sends
1881 // out notification that it is being destroyed.
1882 DeleteTabContentsOnDestroyedObserver observer(contents2, contents1);
1883 strip.CloseAllTabs();
1884 }
OLDNEW
« 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