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