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

Side by Side Diff: chrome/browser/memory/tab_manager_observer_browsertest.cc

Issue 2245203002: Clean up defensive TabManager handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 4 years, 4 months 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
« no previous file with comments | « chrome/browser/memory/tab_manager_browsertest.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2016 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/memory/tab_manager.h" 7 #include "chrome/browser/memory/tab_manager.h"
8 #include "chrome/browser/memory/tab_manager_observer.h" 8 #include "chrome/browser/memory/tab_manager_observer.h"
9 #include "chrome/browser/memory/tab_manager_web_contents_data.h" 9 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 int nb_events_; 76 int nb_events_;
77 WebContents* contents_; 77 WebContents* contents_;
78 bool is_discarded_; 78 bool is_discarded_;
79 bool is_auto_discardable_; 79 bool is_auto_discardable_;
80 80
81 DISALLOW_COPY_AND_ASSIGN(MockTabManagerObserver); 81 DISALLOW_COPY_AND_ASSIGN(MockTabManagerObserver);
82 }; 82 };
83 83
84 IN_PROC_BROWSER_TEST_F(TabManagerObserverTest, OnDiscardStateChange) { 84 IN_PROC_BROWSER_TEST_F(TabManagerObserverTest, OnDiscardStateChange) {
85 TabManager* tab_manager = g_browser_process->GetTabManager(); 85 TabManager* tab_manager = g_browser_process->GetTabManager();
86 ASSERT_TRUE(tab_manager);
87 auto* tsm = browser()->tab_strip_model(); 86 auto* tsm = browser()->tab_strip_model();
88 set_tab_strip_model(tsm); 87 set_tab_strip_model(tsm);
89 88
90 // Open two tabs. 89 // Open two tabs.
91 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 90 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
92 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false); 91 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false);
93 int index_1 = GetIndex(browser()->OpenURL(open1)); 92 int index_1 = GetIndex(browser()->OpenURL(open1));
94 93
95 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(), 94 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
96 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false); 95 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 138
140 // After removing the observer from the TabManager's list, it shouldn't 139 // After removing the observer from the TabManager's list, it shouldn't
141 // receive events anymore. 140 // receive events anymore.
142 tab_manager->RemoveObserver(&tabmanager_observer); 141 tab_manager->RemoveObserver(&tabmanager_observer);
143 EXPECT_TRUE(tab_manager->DiscardTabById(ContentsId(GetContents(index_1)))); 142 EXPECT_TRUE(tab_manager->DiscardTabById(ContentsId(GetContents(index_1))));
144 EXPECT_EQ(4, tabmanager_observer.nb_events()); 143 EXPECT_EQ(4, tabmanager_observer.nb_events());
145 } 144 }
146 145
147 IN_PROC_BROWSER_TEST_F(TabManagerObserverTest, OnAutoDiscardableStateChange) { 146 IN_PROC_BROWSER_TEST_F(TabManagerObserverTest, OnAutoDiscardableStateChange) {
148 TabManager* tab_manager = g_browser_process->GetTabManager(); 147 TabManager* tab_manager = g_browser_process->GetTabManager();
149 ASSERT_TRUE(tab_manager);
150 auto tsm = browser()->tab_strip_model(); 148 auto tsm = browser()->tab_strip_model();
151 set_tab_strip_model(tsm); 149 set_tab_strip_model(tsm);
152 150
153 // Open two tabs. 151 // Open two tabs.
154 OpenURLParams open(GURL(chrome::kChromeUIAboutURL), content::Referrer(), 152 OpenURLParams open(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
155 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false); 153 NEW_BACKGROUND_TAB, ui::PAGE_TRANSITION_TYPED, false);
156 WebContents* contents = browser()->OpenURL(open); 154 WebContents* contents = browser()->OpenURL(open);
157 155
158 // Subscribe observer to TabManager's observer list. 156 // Subscribe observer to TabManager's observer list.
159 MockTabManagerObserver observer; 157 MockTabManagerObserver observer;
(...skipping 19 matching lines...) Expand all
179 // Change it back and we should have another event. 177 // Change it back and we should have another event.
180 tab_manager->SetTabAutoDiscardableState(contents, true); 178 tab_manager->SetTabAutoDiscardableState(contents, true);
181 EXPECT_EQ(2, observer.nb_events()); 179 EXPECT_EQ(2, observer.nb_events());
182 EXPECT_TRUE(observer.is_auto_discardable()); 180 EXPECT_TRUE(observer.is_auto_discardable());
183 EXPECT_EQ(ContentsId(contents), ContentsId(observer.content())); 181 EXPECT_EQ(ContentsId(contents), ContentsId(observer.content()));
184 } 182 }
185 183
186 } // namespace memory 184 } // namespace memory
187 185
188 #endif // OS_WIN || OS_MAXOSX || OS_LINUX 186 #endif // OS_WIN || OS_MAXOSX || OS_LINUX
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager_browsertest.cc ('k') | chrome/browser/ui/browser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698