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

Side by Side Diff: chrome/browser/ui/toolbar/recent_tabs_sub_menu_model_unittest.cc

Issue 23530070: backup for dynamic recent tabs submenu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: new RecentTabsMenuModelDelegate w/ new intf Created 7 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
6 6
7 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
8 #include "chrome/browser/sessions/session_types.h" 8 #include "chrome/browser/sessions/session_types.h"
9 #include "chrome/browser/sessions/persistent_tab_restore_service.h" 9 #include "chrome/browser/sessions/persistent_tab_restore_service.h"
10 #include "chrome/browser/sessions/tab_restore_service_factory.h" 10 #include "chrome/browser/sessions/tab_restore_service_factory.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 Profile::FromBrowserContext(browser_context), NULL);; 70 Profile::FromBrowserContext(browser_context), NULL);;
71 } 71 }
72 private: 72 private:
73 TestingProfile testing_profile_; 73 TestingProfile testing_profile_;
74 testing::NiceMock<ProfileSyncServiceMock> sync_service_; 74 testing::NiceMock<ProfileSyncServiceMock> sync_service_;
75 75
76 protected: 76 protected:
77 browser_sync::SessionModelAssociator associator_; 77 browser_sync::SessionModelAssociator associator_;
78 }; 78 };
79 79
80 // Test disabled "Reopen closed tab" with no foreign tabs. 80 // Test disabled "Recently closed" header with no foreign tabs.
81 TEST_F(RecentTabsSubMenuModelTest, NoTabs) { 81 TEST_F(RecentTabsSubMenuModelTest, NoTabs) {
82 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 82 TestRecentTabsSubMenuModel model(NULL, browser(), NULL);
83 83
84 // Expected menu: 84 // Expected menu:
85 // Menu index Menu items 85 // Menu index Menu items
86 // -------------------------------------- 86 // ---------------------------------------------
87 // 0 Reopen closed tab 87 // 0 Recently closed header (disabled)
88 // 1 <separator> 88 // 1 <separator>
89 // 2 No tabs from other Devices 89 // 2 No tabs from other Devices
90 90
91 int num_items = model.GetItemCount(); 91 int num_items = model.GetItemCount();
92 EXPECT_EQ(3, num_items); 92 EXPECT_EQ(3, num_items);
93 EXPECT_FALSE(model.IsEnabledAt(0)); 93 EXPECT_FALSE(model.IsEnabledAt(0));
94 EXPECT_FALSE(model.IsEnabledAt(2)); 94 EXPECT_FALSE(model.IsEnabledAt(2));
95 EXPECT_EQ(0, model.enable_count_); 95 EXPECT_EQ(0, model.enable_count_);
96 } 96 }
97 97
98 // Test enabled "Reopen closed tab" with no foreign tabs. 98 // Test enabled "Recently closed" header with no foreign tabs.
99 TEST_F(RecentTabsSubMenuModelTest, ReopenClosedTab) { 99 TEST_F(RecentTabsSubMenuModelTest, ReopenClosedTab) {
100 TabRestoreServiceFactory::GetInstance()->SetTestingFactory( 100 TabRestoreServiceFactory::GetInstance()->SetTestingFactory(
101 browser()->profile(), RecentTabsSubMenuModelTest::GetTabRestoreService); 101 browser()->profile(), RecentTabsSubMenuModelTest::GetTabRestoreService);
102 102
103 // Add a tab and close it. 103 // Add a tab and close it.
104 GURL url1("http://foo/1"); 104 GURL url1("http://foo/1");
105 AddTab(browser(), url1); 105 AddTab(browser(), url1);
106 browser()->tab_strip_model()->CloseWebContentsAt( 106 browser()->tab_strip_model()->CloseWebContentsAt(
107 0, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB); 107 0, TabStripModel::CLOSE_CREATE_HISTORICAL_TAB);
108 108
109 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 109 TestRecentTabsSubMenuModel model(NULL, browser(), NULL);
110 // Expected menu: 110 // Expected menu:
111 // Menu index Menu items 111 // Menu index Menu items
112 // -------------------------------------- 112 // --------------------------------------
113 // 0 Recently Closed Header 113 // 0 Recently closed header
114 // 1 Single entry to restore 114 // 1 Single entry to restore
115 // 2 <separator> 115 // 2 <separator>
116 // 3 No tabs from other Devices 116 // 3 No tabs from other Devices
117 int num_items = model.GetItemCount(); 117 int num_items = model.GetItemCount();
118 EXPECT_EQ(4, num_items); 118 EXPECT_EQ(4, num_items);
119 EXPECT_FALSE(model.IsEnabledAt(0)); 119 EXPECT_FALSE(model.IsEnabledAt(0));
120 EXPECT_TRUE(model.IsEnabledAt(1)); 120 EXPECT_TRUE(model.IsEnabledAt(1));
121 model.ActivatedAt(1); 121 model.ActivatedAt(1);
122 EXPECT_FALSE(model.IsEnabledAt(3)); 122 EXPECT_FALSE(model.IsEnabledAt(3));
123 EXPECT_EQ(1, model.enable_count_); 123 EXPECT_EQ(1, model.enable_count_);
124 EXPECT_EQ(1, model.execute_count_); 124 EXPECT_EQ(1, model.execute_count_);
125 } 125 }
126 126
127 // Test enabled "Reopen closed tab" with multiple sessions, multiple windows, 127 // Test disabled "Recently closed" header with multiple sessions, multiple
128 // and multiple enabled tabs from other devices. 128 // windows, and multiple enabled tabs from other devices.
129 TEST_F(RecentTabsSubMenuModelTest, OtherDevices) { 129 TEST_F(RecentTabsSubMenuModelTest, OtherDevices) {
130 // Tabs are populated in decreasing timestamp. 130 // Tabs are populated in decreasing timestamp.
131 base::Time timestamp = base::Time::Now(); 131 base::Time timestamp = base::Time::Now();
132 const base::TimeDelta time_delta = base::TimeDelta::FromMinutes(10); 132 const base::TimeDelta time_delta = base::TimeDelta::FromMinutes(10);
133 133
134 RecentTabsBuilderTestHelper recent_tabs_builder; 134 RecentTabsBuilderTestHelper recent_tabs_builder;
135 135
136 // Create 1st session : 1 window, 3 tabs 136 // Create 1st session : 1 window, 3 tabs
137 recent_tabs_builder.AddSession(); 137 recent_tabs_builder.AddSession();
138 recent_tabs_builder.AddWindow(0); 138 recent_tabs_builder.AddWindow(0);
(...skipping 12 matching lines...) Expand all
151 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, string16()); 151 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, string16());
152 timestamp -= time_delta; 152 timestamp -= time_delta;
153 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, string16()); 153 recent_tabs_builder.AddTabWithInfo(1, 1, timestamp, string16());
154 154
155 recent_tabs_builder.RegisterRecentTabs(&associator_); 155 recent_tabs_builder.RegisterRecentTabs(&associator_);
156 156
157 // Verify that data is populated correctly in RecentTabsSubMenuModel. 157 // Verify that data is populated correctly in RecentTabsSubMenuModel.
158 // Expected menu: 158 // Expected menu:
159 // - first inserted tab is most recent and hence is top 159 // - first inserted tab is most recent and hence is top
160 // Menu index Menu items 160 // Menu index Menu items
161 // -------------------------------------- 161 // -----------------------------------------------------
162 // 0 Reopen closed tab 162 // 0 Recently closed header (disabled)
163 // 1 <separator> 163 // 1 <separator>
164 // 2 <section header for 1st session> 164 // 2 <section header for 1st session>
165 // 3-5 <3 tabs of the only window of session 0> 165 // 3-5 <3 tabs of the only window of session 0>
166 // 6 <separator> 166 // 6 <separator>
167 // 7 <section header for 2nd session> 167 // 7 <section header for 2nd session>
168 // 8 <the only tab of window 0 of session 1> 168 // 8 <the only tab of window 0 of session 1>
169 // 9-10 <2 tabs of window 1 of session 2> 169 // 9-10 <2 tabs of window 1 of session 2>
170 // 11 <separator> 170 // 11 <separator>
171 // 12 More... 171 // 12 More...
172 172
(...skipping 26 matching lines...) Expand all
199 recent_tabs_builder.AddSession(); 199 recent_tabs_builder.AddSession();
200 recent_tabs_builder.AddWindow(s); 200 recent_tabs_builder.AddWindow(s);
201 recent_tabs_builder.AddTab(s, 0); 201 recent_tabs_builder.AddTab(s, 0);
202 } 202 }
203 recent_tabs_builder.RegisterRecentTabs(&associator_); 203 recent_tabs_builder.RegisterRecentTabs(&associator_);
204 204
205 // Verify that data is populated correctly in RecentTabsSubMenuModel. 205 // Verify that data is populated correctly in RecentTabsSubMenuModel.
206 // Expected menu: 206 // Expected menu:
207 // - max sessions is 3, so only 3 most-recent sessions will show. 207 // - max sessions is 3, so only 3 most-recent sessions will show.
208 // Menu index Menu items 208 // Menu index Menu items
209 // -------------------------------------- 209 // ----------------------------------------------------------
210 // 0 Reopen closed tab 210 // 0 Recently closed header (disabled)
211 // 1 <separator> 211 // 1 <separator>
212 // 2 <section header for 1st session> 212 // 2 <section header for 1st session>
213 // 3 <the only tab of the only window of session 3> 213 // 3 <the only tab of the only window of session 3>
214 // 4 <separator> 214 // 4 <separator>
215 // 5 <section header for 2nd session> 215 // 5 <section header for 2nd session>
216 // 6 <the only tab of the only window of session 2> 216 // 6 <the only tab of the only window of session 2>
217 // 7 <separator> 217 // 7 <separator>
218 // 8 <section header for 3rd session> 218 // 8 <section header for 3rd session>
219 // 9 <the only tab of the only window of session 1> 219 // 9 <the only tab of the only window of session 1>
220 // 10 <separator> 220 // 10 <separator>
(...skipping 19 matching lines...) Expand all
240 for (int t = 0; t < 5; ++t) 240 for (int t = 0; t < 5; ++t)
241 recent_tabs_builder.AddTab(0, w); 241 recent_tabs_builder.AddTab(0, w);
242 } 242 }
243 recent_tabs_builder.RegisterRecentTabs(&associator_); 243 recent_tabs_builder.RegisterRecentTabs(&associator_);
244 244
245 // Verify that data is populated correctly in RecentTabsSubMenuModel. 245 // Verify that data is populated correctly in RecentTabsSubMenuModel.
246 // Expected menu: 246 // Expected menu:
247 // - max tabs per session is 4, so only 4 most-recent tabs will show, 247 // - max tabs per session is 4, so only 4 most-recent tabs will show,
248 // independent of which window they came from. 248 // independent of which window they came from.
249 // Menu index Menu items 249 // Menu index Menu items
250 // -------------------------------------- 250 // ---------------------------------------------
251 // 0 Reopen closed tab 251 // 0 Recently closed header (disabled)
252 // 1 <separator> 252 // 1 <separator>
253 // 2 <section header for session> 253 // 2 <section header for session>
254 // 3-6 <4 most-recent tabs of session> 254 // 3-6 <4 most-recent tabs of session>
255 // 7 <separator> 255 // 7 <separator>
256 // 8 More... 256 // 8 More...
257 257
258 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_); 258 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_);
259 int num_items = model.GetItemCount(); 259 int num_items = model.GetItemCount();
260 EXPECT_EQ(9, num_items); 260 EXPECT_EQ(9, num_items);
261 261
262 std::vector<string16> tab_titles = 262 std::vector<string16> tab_titles =
263 recent_tabs_builder.GetTabTitlesSortedByRecency(); 263 recent_tabs_builder.GetTabTitlesSortedByRecency();
264 for (int i = 0; i < 4; ++i) 264 for (int i = 0; i < 4; ++i)
265 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3)); 265 EXPECT_EQ(tab_titles[i], model.GetLabelAt(i + 3));
266 } 266 }
267 267
268 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) { 268 TEST_F(RecentTabsSubMenuModelTest, MaxWidth) {
269 // Create 1 session with 1 window and 1 tab. 269 // Create 1 session with 1 window and 1 tab.
270 RecentTabsBuilderTestHelper recent_tabs_builder; 270 RecentTabsBuilderTestHelper recent_tabs_builder;
271 recent_tabs_builder.AddSession(); 271 recent_tabs_builder.AddSession();
272 recent_tabs_builder.AddWindow(0); 272 recent_tabs_builder.AddWindow(0);
273 recent_tabs_builder.AddTab(0, 0); 273 recent_tabs_builder.AddTab(0, 0);
274 recent_tabs_builder.RegisterRecentTabs(&associator_); 274 recent_tabs_builder.RegisterRecentTabs(&associator_);
275 275
276 // Menu index Menu items 276 // Menu index Menu items
277 // -------------------------------------- 277 // ----------------------------------------------------------
278 // 0 Reopen closed tab 278 // 0 Recently closed header (disabled)
279 // 1 <separator> 279 // 1 <separator>
280 // 2 <section header for 1st session> 280 // 2 <section header for 1st session>
281 // 3 <the only tab of the only window of session 1> 281 // 3 <the only tab of the only window of session 1>
282 // 4 <separator> 282 // 4 <separator>
283 // 5 More... 283 // 5 More...
284 284
285 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_); 285 TestRecentTabsSubMenuModel model(NULL, browser(), &associator_);
286 EXPECT_EQ(6, model.GetItemCount()); 286 EXPECT_EQ(6, model.GetItemCount());
287 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); 287 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0));
288 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); 288 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1));
289 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2)); 289 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(2));
290 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3)); 290 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(3));
291 } 291 }
292 292
293 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) { 293 TEST_F(RecentTabsSubMenuModelTest, MaxWidthNoDevices) {
294 // Expected menu: 294 // Expected menu:
295 // Menu index Menu items 295 // Menu index Menu items
296 // -------------------------------------- 296 // --------------------------------------------
297 // 0 Reopen closed tab 297 // 0 Recently closed heaer (disabled)
298 // 1 <separator> 298 // 1 <separator>
299 // 2 No tabs from other Devices 299 // 2 No tabs from other Devices
300 300
301 TestRecentTabsSubMenuModel model(NULL, browser(), NULL); 301 TestRecentTabsSubMenuModel model(NULL, browser(), NULL);
302 EXPECT_EQ(3, model.GetItemCount()); 302 EXPECT_EQ(3, model.GetItemCount());
303 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0)); 303 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(0));
304 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1)); 304 EXPECT_NE(-1, model.GetMaxWidthForItemAtIndex(1));
305 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2)); 305 EXPECT_EQ(-1, model.GetMaxWidthForItemAtIndex(2));
306 } 306 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.cc ('k') | chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698