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

Side by Side Diff: chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm

Issue 11316127: Alternate NTP: Limit width of tab titles in recent tabs menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years 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 "base/memory/scoped_nsobject.h" 5 #include "base/memory/scoped_nsobject.h"
6 #include "base/sys_string_conversions.h"
6 #include "chrome/app/chrome_command_ids.h" 7 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/sync/glue/session_model_associator.h" 8 #include "chrome/browser/sync/glue/session_model_associator.h"
8 #include "chrome/browser/sync/profile_sync_service_factory.h" 9 #include "chrome/browser/sync/profile_sync_service_factory.h"
9 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" 10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
10 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" 11 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
11 #include "chrome/browser/ui/cocoa/run_loop_testing.h" 12 #include "chrome/browser/ui/cocoa/run_loop_testing.h"
12 #import "chrome/browser/ui/cocoa/view_resizer_pong.h" 13 #import "chrome/browser/ui/cocoa/view_resizer_pong.h"
13 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h" 14 #import "chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.h"
14 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" 15 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h"
15 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" 16 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 [button setTag:IDC_ZOOM_PLUS]; 69 [button setTag:IDC_ZOOM_PLUS];
69 70
70 // Set fake model to test dispatching. 71 // Set fake model to test dispatching.
71 EXPECT_CALL(*fake_model_, ExecuteCommand(IDC_ZOOM_PLUS)); 72 EXPECT_CALL(*fake_model_, ExecuteCommand(IDC_ZOOM_PLUS));
72 [controller() setModel:fake_model_.get()]; 73 [controller() setModel:fake_model_.get()];
73 74
74 [controller() dispatchWrenchMenuCommand:button.get()]; 75 [controller() dispatchWrenchMenuCommand:button.get()];
75 chrome::testing::NSRunLoopRunAllPending(); 76 chrome::testing::NSRunLoopRunAllPending();
76 } 77 }
77 78
78 TEST_F(WrenchMenuControllerTest, RecentTabs) { 79 TEST_F(WrenchMenuControllerTest, RecentTabsFavIcon) {
79 ProfileSyncService* sync_service = 80 ProfileSyncService* sync_service =
80 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile()); 81 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
81 browser_sync::SessionModelAssociator associator_(sync_service, true); 82 browser_sync::SessionModelAssociator associator_(sync_service, true);
82 associator_.SetCurrentMachineTagForTesting("WrenchMenuControllerTest"); 83 associator_.SetCurrentMachineTagForTesting("WrenchMenuControllerTest");
83 84
84 RecentTabsBuilderTestHelper recent_tabs_builder; 85 RecentTabsBuilderTestHelper recent_tabs_builder;
85 recent_tabs_builder.AddSession(); 86 recent_tabs_builder.AddSession();
86 recent_tabs_builder.AddWindow(0); 87 recent_tabs_builder.AddWindow(0);
87 recent_tabs_builder.AddTab(0, 0); 88 recent_tabs_builder.AddTab(0, 0);
88 recent_tabs_builder.RegisterRecentTabs(&associator_); 89 recent_tabs_builder.RegisterRecentTabs(&associator_);
(...skipping 19 matching lines...) Expand all
108 recent_tabs_sub_menu_model.SetIcon(3, icon); 109 recent_tabs_sub_menu_model.SetIcon(3, icon);
109 EXPECT_NSNE(icon.ToNSImage(), [[recent_tabs_menu itemAtIndex:3] image]); 110 EXPECT_NSNE(icon.ToNSImage(), [[recent_tabs_menu itemAtIndex:3] image]);
110 recent_tabs_sub_menu_model.GetMenuModelDelegate()->OnIconChanged(3); 111 recent_tabs_sub_menu_model.GetMenuModelDelegate()->OnIconChanged(3);
111 EXPECT_TRUE([[recent_tabs_menu itemAtIndex:3] image]); 112 EXPECT_TRUE([[recent_tabs_menu itemAtIndex:3] image]);
112 EXPECT_NSEQ(icon.ToNSImage(), [[recent_tabs_menu itemAtIndex:3] image]); 113 EXPECT_NSEQ(icon.ToNSImage(), [[recent_tabs_menu itemAtIndex:3] image]);
113 114
114 controller_.reset(); 115 controller_.reset();
115 fake_model_.reset(); 116 fake_model_.reset();
116 } 117 }
117 118
119 TEST_F(WrenchMenuControllerTest, RecentTabsElideTitle) {
120 ProfileSyncService* sync_service =
121 ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile());
122 browser_sync::SessionModelAssociator associator_(sync_service, true);
123 associator_.SetCurrentMachineTagForTesting("WrenchMenuControllerTest");
124
125 // Add 1 session with 1 window and 2 tabs.
126 RecentTabsBuilderTestHelper recent_tabs_builder;
127 recent_tabs_builder.AddSession();
128 recent_tabs_builder.AddWindow(0);
129 string16 tab1_short_title = ASCIIToUTF16("Short");
130 recent_tabs_builder.AddTabWithInfo(0, 0, base::Time::Now(), tab1_short_title);
131 string16 tab2_long_title = ASCIIToUTF16("Very very very very very very "
132 "very very very very very very long");
133 recent_tabs_builder.AddTabWithInfo(0, 0,
134 base::Time::Now() - base::TimeDelta::FromMinutes(10), tab2_long_title);
135 recent_tabs_builder.RegisterRecentTabs(&associator_);
136
137 RecentTabsSubMenuModel recent_tabs_sub_menu_model(
138 NULL, browser(), &associator_);
139 fake_model_->AddSubMenuWithStringId(
140 IDC_RECENT_TABS_MENU, IDS_RECENT_TABS_MENU,
141 &recent_tabs_sub_menu_model);
142
143 [controller() setModel:fake_model_.get()];
144 NSMenu* menu = [controller() menu];
145 [controller() updateRecentTabsSubmenu];
146
147 NSString* title = l10n_util::GetNSStringWithFixup(IDS_RECENT_TABS_MENU);
148 NSMenu* recent_tabs_menu = [[menu itemWithTitle:title] submenu];
149 EXPECT_TRUE(recent_tabs_menu);
150 EXPECT_EQ(5, [recent_tabs_menu numberOfItems]);
151
152 // Index 0: restore tabs menu item.
153 NSString* restore_tab_label = l10n_util::FixUpWindowsStyleLabel(
154 recent_tabs_sub_menu_model.GetLabelAt(0));
155 EXPECT_NSEQ(restore_tab_label, [[recent_tabs_menu itemAtIndex:0] title]);
156
157 // Item 1: separator.
158 EXPECT_TRUE([[recent_tabs_menu itemAtIndex:1] isSeparatorItem]);
159
160 // Item 2: window title.
161 EXPECT_NSEQ(
162 base::SysUTF16ToNSString(recent_tabs_sub_menu_model.GetLabelAt(2)),
163 [[recent_tabs_menu itemAtIndex:2] title]);
164
165 // Item 3: short tab title.
166 EXPECT_NSEQ(base::SysUTF16ToNSString(tab1_short_title),
167 [[recent_tabs_menu itemAtIndex:3] title]);
168
169 // Item 4: long tab title.
170 NSString* tab2_actual_title = [[recent_tabs_menu itemAtIndex:4] title];
171 NSUInteger title_length = [tab2_actual_title length];
172 EXPECT_GT(tab2_long_title.size(), title_length);
173 NSString* actual_substring =
174 [tab2_actual_title substringToIndex:title_length - 1];
175 NSString* expected_substring = [base::SysUTF16ToNSString(tab2_long_title)
176 substringToIndex:title_length - 1];
177 EXPECT_NSEQ(expected_substring, actual_substring);
178
179 controller_.reset();
180 fake_model_.reset();
181 }
182
118 } // namespace 183 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698