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

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

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 "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h" 5 #include "chrome/browser/ui/toolbar/recent_tabs_builder_test_helper.h"
6 6
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "chrome/browser/sync/glue/session_model_associator.h" 10 #include "chrome/browser/sync/glue/session_model_associator.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 } 49 }
50 50
51 std::string ToTabUrl(SessionID::id_type session_id, 51 std::string ToTabUrl(SessionID::id_type session_id,
52 SessionID::id_type window_id, 52 SessionID::id_type window_id,
53 SessionID::id_type tab_id) { 53 SessionID::id_type tab_id) {
54 return std::string(kBaseTabUrl + ToTabTitle(session_id, window_id, tab_id)); 54 return std::string(kBaseTabUrl + ToTabTitle(session_id, window_id, tab_id));
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 struct RecentTabsBuilderTestHelper::TabInfo {
60 SessionID::id_type id;
sky 2012/11/28 15:41:28 Add constructor to initialize id.
sail 2012/11/30 23:24:53 Done.
61 base::Time timestamp;
62 string16 title;
63 };
64 struct RecentTabsBuilderTestHelper::WindowInfo {
65 WindowInfo() {}
sky 2012/11/28 15:41:28 initialize id.
sail 2012/11/30 23:24:53 Done.
66 ~WindowInfo() {}
67 SessionID::id_type id;
68 std::vector<TabInfo> tabs;
69 };
70 struct RecentTabsBuilderTestHelper::SessionInfo {
71 SessionInfo() {}
sky 2012/11/28 15:41:28 initialize id.
sail 2012/11/30 23:24:53 Done.
72 ~SessionInfo() {}
73 SessionID::id_type id;
74 std::vector<WindowInfo> windows;
75 };
76
59 RecentTabsBuilderTestHelper::RecentTabsBuilderTestHelper() { 77 RecentTabsBuilderTestHelper::RecentTabsBuilderTestHelper() {
60 start_time_ = base::Time::Now(); 78 start_time_ = base::Time::Now();
61 } 79 }
62 80
63 RecentTabsBuilderTestHelper::~RecentTabsBuilderTestHelper() { 81 RecentTabsBuilderTestHelper::~RecentTabsBuilderTestHelper() {
64 } 82 }
65 83
66 void RecentTabsBuilderTestHelper::AddSession() { 84 void RecentTabsBuilderTestHelper::AddSession() {
67 SessionInfo info; 85 SessionInfo info;
68 info.id = CreateUniqueID(); 86 info.id = CreateUniqueID();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 121 }
104 122
105 SessionID::id_type RecentTabsBuilderTestHelper::GetWindowID(int session_index, 123 SessionID::id_type RecentTabsBuilderTestHelper::GetWindowID(int session_index,
106 int window_index) { 124 int window_index) {
107 return sessions_[session_index].windows[window_index].id; 125 return sessions_[session_index].windows[window_index].id;
108 } 126 }
109 127
110 void RecentTabsBuilderTestHelper::AddTab(int session_index, int window_index) { 128 void RecentTabsBuilderTestHelper::AddTab(int session_index, int window_index) {
111 base::Time timestamp = 129 base::Time timestamp =
112 start_time_ + base::TimeDelta::FromMinutes(base::RandUint64()); 130 start_time_ + base::TimeDelta::FromMinutes(base::RandUint64());
113 AddTabWithTimestamp(session_index, window_index, timestamp); 131 AddTabWithInfo(session_index, window_index, timestamp, string16());
114 } 132 }
115 133
116 void RecentTabsBuilderTestHelper::AddTabWithTimestamp(int session_index, 134 void RecentTabsBuilderTestHelper::AddTabWithInfo(int session_index,
117 int window_index, 135 int window_index,
118 base::Time timestamp) { 136 base::Time timestamp,
137 const string16& title) {
119 TabInfo tab_info; 138 TabInfo tab_info;
120 tab_info.id = CreateUniqueID(); 139 tab_info.id = CreateUniqueID();
121 tab_info.timestamp = timestamp; 140 tab_info.timestamp = timestamp;
141 tab_info.title = title;
122 sessions_[session_index].windows[window_index].tabs.push_back(tab_info); 142 sessions_[session_index].windows[window_index].tabs.push_back(tab_info);
123 } 143 }
124 144
125 int RecentTabsBuilderTestHelper::GetTabCount(int session_index, 145 int RecentTabsBuilderTestHelper::GetTabCount(int session_index,
126 int window_index) { 146 int window_index) {
127 return sessions_[session_index].windows[window_index].tabs.size(); 147 return sessions_[session_index].windows[window_index].tabs.size();
128 } 148 }
129 149
130 SessionID::id_type RecentTabsBuilderTestHelper::GetTabID(int session_index, 150 SessionID::id_type RecentTabsBuilderTestHelper::GetTabID(int session_index,
131 int window_index, 151 int window_index,
132 int tab_index) { 152 int tab_index) {
133 return sessions_[session_index].windows[window_index].tabs[tab_index].id; 153 return sessions_[session_index].windows[window_index].tabs[tab_index].id;
134 } 154 }
135 155
136 base::Time RecentTabsBuilderTestHelper::GetTabTimestamp(int session_index, 156 base::Time RecentTabsBuilderTestHelper::GetTabTimestamp(int session_index,
137 int window_index, 157 int window_index,
138 int tab_index) { 158 int tab_index) {
139 return sessions_[session_index].windows[window_index] 159 return sessions_[session_index].windows[window_index]
140 .tabs[tab_index].timestamp; 160 .tabs[tab_index].timestamp;
141 } 161 }
142 162
163 string16 RecentTabsBuilderTestHelper::GetTabTitle(int session_index,
164 int window_index,
165 int tab_index) {
166 string16 title =
167 sessions_[session_index].windows[window_index].tabs[tab_index].title;
168 if (title.empty()) {
169 title = UTF8ToUTF16(ToTabTitle(
170 GetSessionID(session_index),
171 GetWindowID(session_index, window_index),
172 GetTabID(session_index, window_index, tab_index)));
173 }
174 return title;
175 }
176
143 void RecentTabsBuilderTestHelper::RegisterRecentTabs( 177 void RecentTabsBuilderTestHelper::RegisterRecentTabs(
144 browser_sync::SessionModelAssociator* associator) { 178 browser_sync::SessionModelAssociator* associator) {
145 for (int s = 0; s < GetSessionCount(); ++s) { 179 for (int s = 0; s < GetSessionCount(); ++s) {
146 sync_pb::SessionSpecifics meta; 180 sync_pb::SessionSpecifics meta;
147 BuildSessionSpecifics(s, &meta); 181 BuildSessionSpecifics(s, &meta);
148 for (int w = 0; w < GetWindowCount(s); ++w) { 182 for (int w = 0; w < GetWindowCount(s); ++w) {
149 BuildWindowSpecifics(s, w, &meta); 183 BuildWindowSpecifics(s, w, &meta);
150 for (int t = 0; t < GetTabCount(s, w); ++t) { 184 for (int t = 0; t < GetTabCount(s, w); ++t) {
151 sync_pb::SessionSpecifics tab_base; 185 sync_pb::SessionSpecifics tab_base;
152 BuildTabSpecifics(s, w, t, &tab_base); 186 BuildTabSpecifics(s, w, t, &tab_base);
(...skipping 18 matching lines...) Expand all
171 } 205 }
172 } 206 }
173 207
174 std::vector<string16> 208 std::vector<string16>
175 RecentTabsBuilderTestHelper::GetTabTitlesSortedByRecency() { 209 RecentTabsBuilderTestHelper::GetTabTitlesSortedByRecency() {
176 std::vector<TitleTimestampPair> tabs; 210 std::vector<TitleTimestampPair> tabs;
177 for (int s = 0; s < GetSessionCount(); ++s) { 211 for (int s = 0; s < GetSessionCount(); ++s) {
178 for (int w = 0; w < GetWindowCount(s); ++w) { 212 for (int w = 0; w < GetWindowCount(s); ++w) {
179 for (int t = 0; t < GetTabCount(s, w); ++t) { 213 for (int t = 0; t < GetTabCount(s, w); ++t) {
180 TitleTimestampPair pair; 214 TitleTimestampPair pair;
181 pair.title = UTF8ToUTF16(ToTabTitle( 215 pair.title = GetTabTitle(s, w, t);
182 GetSessionID(s), GetWindowID(s, w), GetTabID(s, w, t)));
183 pair.timestamp = GetTabTimestamp(s, w, t); 216 pair.timestamp = GetTabTimestamp(s, w, t);
184 tabs.push_back(pair); 217 tabs.push_back(pair);
185 } 218 }
186 } 219 }
187 } 220 }
188 sort(tabs.begin(), tabs.end(), SortTabTimesByRecency); 221 sort(tabs.begin(), tabs.end(), SortTabTimesByRecency);
189 222
190 std::vector<string16> titles; 223 std::vector<string16> titles;
191 for (size_t i = 0; i < tabs.size(); ++i) 224 for (size_t i = 0; i < tabs.size(); ++i)
192 titles.push_back(tabs[i].title); 225 titles.push_back(tabs[i].title);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 sync_pb::SessionTab* tab = tab_base->mutable_tab(); 263 sync_pb::SessionTab* tab = tab_base->mutable_tab();
231 tab->set_window_id(window_id); 264 tab->set_window_id(window_id);
232 tab->set_tab_id(tab_id); 265 tab->set_tab_id(tab_id);
233 tab->set_tab_visual_index(1); 266 tab->set_tab_visual_index(1);
234 tab->set_current_navigation_index(0); 267 tab->set_current_navigation_index(0);
235 tab->set_pinned(true); 268 tab->set_pinned(true);
236 tab->set_extension_app_id("app_id"); 269 tab->set_extension_app_id("app_id");
237 sync_pb::TabNavigation* navigation = tab->add_navigation(); 270 sync_pb::TabNavigation* navigation = tab->add_navigation();
238 navigation->set_virtual_url(ToTabUrl(session_id, window_id, tab_id)); 271 navigation->set_virtual_url(ToTabUrl(session_id, window_id, tab_id));
239 navigation->set_referrer("referrer"); 272 navigation->set_referrer("referrer");
240 navigation->set_title(ToTabTitle(session_id, window_id, tab_id)); 273 navigation->set_title(UTF16ToUTF8(GetTabTitle(
274 session_index, window_index, tab_index)));
241 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); 275 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED);
242 } 276 }
243
244 RecentTabsBuilderTestHelper::WindowInfo::WindowInfo() {}
245
246 RecentTabsBuilderTestHelper::WindowInfo::~WindowInfo() {}
247
248 RecentTabsBuilderTestHelper::SessionInfo::SessionInfo() {}
249
250 RecentTabsBuilderTestHelper::SessionInfo::~SessionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698