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

Side by Side Diff: chrome/browser/tabs/tab_strip_model_unittest.cc

Issue 2821011: Removes phantom tabs. (Closed)
Patch Set: Created 10 years, 6 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
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_util.h" 9 #include "base/string_util.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (i > 0) 142 if (i > 0)
143 actual += " "; 143 actual += " ";
144 144
145 actual += IntToString(GetID(model.GetTabContentsAt(i))); 145 actual += IntToString(GetID(model.GetTabContentsAt(i)));
146 146
147 if (model.IsAppTab(i)) 147 if (model.IsAppTab(i))
148 actual += "a"; 148 actual += "a";
149 149
150 if (model.IsTabPinned(i)) 150 if (model.IsTabPinned(i))
151 actual += "p"; 151 actual += "p";
152
153 if (model.IsPhantomTab(i))
154 actual += "h";
155 } 152 }
156 return actual; 153 return actual;
157 } 154 }
158 155
159 std::string GetIndicesClosedByCommandAsString( 156 std::string GetIndicesClosedByCommandAsString(
160 const TabStripModel& model, 157 const TabStripModel& model,
161 int index, 158 int index,
162 TabStripModel::ContextMenuCommand id) const { 159 TabStripModel::ContextMenuCommand id) const {
163 std::vector<int> indices = model.GetIndicesClosedByCommand(index, id); 160 std::vector<int> indices = model.GetIndicesClosedByCommand(index, id);
164 std::string result; 161 std::string result;
(...skipping 29 matching lines...) Expand all
194 } 191 }
195 192
196 enum TabStripModelObserverAction { 193 enum TabStripModelObserverAction {
197 INSERT, 194 INSERT,
198 CLOSE, 195 CLOSE,
199 DETACH, 196 DETACH,
200 SELECT, 197 SELECT,
201 MOVE, 198 MOVE,
202 CHANGE, 199 CHANGE,
203 PINNED, 200 PINNED,
204 REPLACED
205 }; 201 };
206 202
207 struct State { 203 struct State {
208 State(TabContents* a_dst_contents, 204 State(TabContents* a_dst_contents,
209 int a_dst_index, 205 int a_dst_index,
210 TabStripModelObserverAction a_action) 206 TabStripModelObserverAction a_action)
211 : src_contents(NULL), 207 : src_contents(NULL),
212 dst_contents(a_dst_contents), 208 dst_contents(a_dst_contents),
213 src_index(-1), 209 src_index(-1),
214 dst_index(a_dst_index), 210 dst_index(a_dst_index),
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 virtual void TabClosingAt(TabContents* contents, int index) { 277 virtual void TabClosingAt(TabContents* contents, int index) {
282 states_.push_back(new State(contents, index, CLOSE)); 278 states_.push_back(new State(contents, index, CLOSE));
283 } 279 }
284 virtual void TabDetachedAt(TabContents* contents, int index) { 280 virtual void TabDetachedAt(TabContents* contents, int index) {
285 states_.push_back(new State(contents, index, DETACH)); 281 states_.push_back(new State(contents, index, DETACH));
286 } 282 }
287 virtual void TabChangedAt(TabContents* contents, int index, 283 virtual void TabChangedAt(TabContents* contents, int index,
288 TabChangeType change_type) { 284 TabChangeType change_type) {
289 states_.push_back(new State(contents, index, CHANGE)); 285 states_.push_back(new State(contents, index, CHANGE));
290 } 286 }
291 virtual void TabReplacedAt(TabContents* old_contents,
292 TabContents* new_contents, int index) {
293 State* s = new State(new_contents, index, REPLACED);
294 s ->src_contents = old_contents;
295 states_.push_back(s);
296 }
297 virtual void TabPinnedStateChanged(TabContents* contents, int index) { 287 virtual void TabPinnedStateChanged(TabContents* contents, int index) {
298 states_.push_back(new State(contents, index, PINNED)); 288 states_.push_back(new State(contents, index, PINNED));
299 } 289 }
300 virtual void TabStripEmpty() { 290 virtual void TabStripEmpty() {
301 empty_ = true; 291 empty_ = true;
302 } 292 }
303 293
304 void ClearStates() { 294 void ClearStates() {
305 STLDeleteContainerPointers(states_.begin(), states_.end()); 295 STLDeleteContainerPointers(states_.begin(), states_.end());
306 states_.clear(); 296 states_.clear();
(...skipping 1453 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 1750
1761 ASSERT_EQ(1, observer.GetStateCount()); 1751 ASSERT_EQ(1, observer.GetStateCount());
1762 State state(contents4, 2, MockTabStripModelObserver::INSERT); 1752 State state(contents4, 2, MockTabStripModelObserver::INSERT);
1763 EXPECT_TRUE(observer.StateEquals(0, state)); 1753 EXPECT_TRUE(observer.StateEquals(0, state));
1764 1754
1765 EXPECT_EQ("1p 3p 4 2", GetPinnedState(tabstrip)); 1755 EXPECT_EQ("1p 3p 4 2", GetPinnedState(tabstrip));
1766 } 1756 }
1767 1757
1768 tabstrip.CloseAllTabs(); 1758 tabstrip.CloseAllTabs();
1769 } 1759 }
1770
1771 // Tests various permutations of making a tab phantom.
1772 TEST_F(TabStripModelTest, Phantom) {
1773 TabStripDummyDelegate delegate(NULL);
1774 TabStripModel tabstrip(&delegate, profile());
1775 MockTabStripModelObserver observer;
1776 tabstrip.AddObserver(&observer);
1777
1778 EXPECT_TRUE(tabstrip.empty());
1779
1780 typedef MockTabStripModelObserver::State State;
1781
1782 TabContents* contents1 = CreateTabContents();
1783 TabContents* contents2 = CreateTabContents();
1784 TabContents* contents3 = CreateTabContents();
1785
1786 SetID(contents1, 1);
1787 SetID(contents2, 2);
1788 SetID(contents3, 3);
1789
1790 // Note! The ordering of these tests is important, each subsequent test
1791 // builds on the state established in the previous. This is important if you
1792 // ever insert tests rather than append.
1793
1794 // Initial state, three tabs, first selected.
1795 tabstrip.AppendTabContents(contents1, true);
1796 tabstrip.AppendTabContents(contents2, false);
1797 tabstrip.AppendTabContents(contents3, false);
1798
1799 observer.ClearStates();
1800
1801 // Pin the first tab, and make it phantom.
1802 {
1803 tabstrip.SetTabPinned(0, true);
1804
1805 observer.ClearStates();
1806
1807 tabstrip.CloseTabContentsAt(0, TabStripModel::CLOSE_NONE);
1808
1809 // The tabcontents should have changed.
1810 TabContents* old_contents1 = contents1;
1811 TabContents* new_contents1 = tabstrip.GetTabContentsAt(0);
1812 ASSERT_TRUE(new_contents1 != contents1);
1813 contents1 = new_contents1;
1814 SetID(contents1, 1);
1815
1816 // Verify the state.
1817 EXPECT_EQ("1ph 2 3", GetPinnedState(tabstrip));
1818
1819 // We should have gotten notification of the following:
1820 // . tab closing.
1821 // . selection changed.
1822 // . tab replaced.
1823 ASSERT_EQ(3, observer.GetStateCount());
1824 State state(old_contents1, 0, MockTabStripModelObserver::CLOSE);
1825 EXPECT_TRUE(observer.StateEquals(0, state));
1826 state = State(contents1, 0, MockTabStripModelObserver::REPLACED);
1827 state.src_contents = old_contents1;
1828 EXPECT_TRUE(observer.StateEquals(1, state));
1829 state = State(contents2, 1, MockTabStripModelObserver::SELECT);
1830 state.src_contents = contents1;
1831 state.user_gesture = true;
1832 EXPECT_TRUE(observer.StateEquals(2, state));
1833
1834 observer.ClearStates();
1835 }
1836
1837 {
1838 tabstrip.SetTabPinned(1, true);
1839 observer.ClearStates();
1840
1841 // Close the second tab, which should make it phantom.
1842 tabstrip.CloseTabContentsAt(1, TabStripModel::CLOSE_NONE);
1843
1844 // The tabcontents should have changed.
1845 TabContents* new_contents2 = tabstrip.GetTabContentsAt(1);
1846 ASSERT_TRUE(new_contents2 != contents2);
1847 contents2 = new_contents2;
1848 SetID(contents2, 2);
1849
1850 EXPECT_EQ("1ph 2ph 3", GetPinnedState(tabstrip));
1851
1852 EXPECT_EQ(2, tabstrip.selected_index());
1853
1854 contents2 = tabstrip.GetTabContentsAt(1);
1855
1856 observer.ClearStates();
1857 }
1858
1859 {
1860 tabstrip.SetTabPinned(2, true);
1861 observer.ClearStates();
1862
1863 // Close the last tab, we should get a tabstrip empty notification.
1864 tabstrip.CloseTabContentsAt(2, TabStripModel::CLOSE_NONE);
1865
1866 // The tabcontents should have changed.
1867 TabContents* old_contents3 = contents3;
1868 TabContents* new_contents3 = tabstrip.GetTabContentsAt(2);
1869 ASSERT_TRUE(new_contents3 != contents3);
1870 contents3 = new_contents3;
1871 SetID(contents3, 3);
1872
1873 EXPECT_EQ("1ph 2ph 3ph", GetPinnedState(tabstrip));
1874
1875 // We should have gotten notification of the following:
1876 // . tab closing.
1877 // . tab replaced.
1878 // . tabstrip empty.
1879 ASSERT_EQ(2, observer.GetStateCount());
1880 State state(old_contents3, 2, MockTabStripModelObserver::CLOSE);
1881 EXPECT_TRUE(observer.StateEquals(0, state));
1882 state = State(contents3, 2, MockTabStripModelObserver::REPLACED);
1883 state.src_contents = old_contents3;
1884 EXPECT_TRUE(observer.StateEquals(1, state));
1885 EXPECT_TRUE(observer.empty());
1886
1887 observer.ClearStates();
1888 }
1889
1890 // Clean up the phantom tabs.
1891 tabstrip.CloseAllTabs();
1892 }
OLDNEW
« no previous file with comments | « chrome/browser/tabs/tab_strip_model_order_controller.cc ('k') | chrome/browser/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698