| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/sync/model/attachments/attachment_id.h" | 13 #include "components/sync/model/attachments/attachment_id.h" |
| 14 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" | 14 #include "components/sync/model/attachments/attachment_service_proxy_for_test.h" |
| 15 #include "components/sync/protocol/session_specifics.pb.h" | 15 #include "components/sync/protocol/session_specifics.pb.h" |
| 16 #include "components/sync_sessions/open_tabs_ui_delegate.h" | 16 #include "components/sync_sessions/open_tabs_ui_delegate.h" |
| 17 #include "components/sync_sessions/sessions_sync_manager.h" | 17 #include "components/sync_sessions/sessions_sync_manager.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 const char kBaseSessionTag[] = "session_tag"; | 22 const char kBaseSessionTag[] = "session_tag"; |
| 23 const char kBaseSessionName[] = "session_name"; | 23 const char kBaseSessionName[] = "session_name"; |
| 24 const char kBaseTabUrl[] = "http://foo/?"; | 24 const char kBaseTabUrl[] = "http://foo/?"; |
| 25 const char kTabTitleFormat[] = "session=%d;window=%d;tab=%d"; | 25 const char kTabTitleFormat[] = "session=%d;window=%d;tab=%d"; |
| 26 const uint64_t kMaxMinutesRange = 1000; |
| 26 | 27 |
| 27 struct TitleTimestampPair { | 28 struct TitleTimestampPair { |
| 28 base::string16 title; | 29 base::string16 title; |
| 29 base::Time timestamp; | 30 base::Time timestamp; |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 bool SortTabTimesByRecency(const TitleTimestampPair& t1, | 33 bool SortTabTimesByRecency(const TitleTimestampPair& t1, |
| 33 const TitleTimestampPair& t2) { | 34 const TitleTimestampPair& t2) { |
| 34 return t1.timestamp > t2.timestamp; | 35 return t1.timestamp > t2.timestamp; |
| 35 } | 36 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return sessions_[session_index].windows.size(); | 129 return sessions_[session_index].windows.size(); |
| 129 } | 130 } |
| 130 | 131 |
| 131 SessionID::id_type RecentTabsBuilderTestHelper::GetWindowID(int session_index, | 132 SessionID::id_type RecentTabsBuilderTestHelper::GetWindowID(int session_index, |
| 132 int window_index) { | 133 int window_index) { |
| 133 return sessions_[session_index].windows[window_index].id; | 134 return sessions_[session_index].windows[window_index].id; |
| 134 } | 135 } |
| 135 | 136 |
| 136 void RecentTabsBuilderTestHelper::AddTab(int session_index, int window_index) { | 137 void RecentTabsBuilderTestHelper::AddTab(int session_index, int window_index) { |
| 137 base::Time timestamp = | 138 base::Time timestamp = |
| 138 start_time_ + base::TimeDelta::FromMinutes(base::RandUint64()); | 139 start_time_ + |
| 140 base::TimeDelta::FromMinutes(base::RandGenerator(kMaxMinutesRange)); |
| 139 AddTabWithInfo(session_index, window_index, timestamp, base::string16()); | 141 AddTabWithInfo(session_index, window_index, timestamp, base::string16()); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void RecentTabsBuilderTestHelper::AddTabWithInfo(int session_index, | 144 void RecentTabsBuilderTestHelper::AddTabWithInfo(int session_index, |
| 143 int window_index, | 145 int window_index, |
| 144 base::Time timestamp, | 146 base::Time timestamp, |
| 145 const base::string16& title) { | 147 const base::string16& title) { |
| 146 TabInfo tab_info; | 148 TabInfo tab_info; |
| 147 tab_info.id = CreateUniqueID(); | 149 tab_info.id = CreateUniqueID(); |
| 148 tab_info.timestamp = timestamp; | 150 tab_info.timestamp = timestamp; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 tab->set_current_navigation_index(0); | 301 tab->set_current_navigation_index(0); |
| 300 tab->set_pinned(true); | 302 tab->set_pinned(true); |
| 301 tab->set_extension_app_id("app_id"); | 303 tab->set_extension_app_id("app_id"); |
| 302 sync_pb::TabNavigation* navigation = tab->add_navigation(); | 304 sync_pb::TabNavigation* navigation = tab->add_navigation(); |
| 303 navigation->set_virtual_url(ToTabUrl(session_id, window_id, tab_id)); | 305 navigation->set_virtual_url(ToTabUrl(session_id, window_id, tab_id)); |
| 304 navigation->set_referrer("referrer"); | 306 navigation->set_referrer("referrer"); |
| 305 navigation->set_title(base::UTF16ToUTF8(GetTabTitle( | 307 navigation->set_title(base::UTF16ToUTF8(GetTabTitle( |
| 306 session_index, window_index, tab_index))); | 308 session_index, window_index, tab_index))); |
| 307 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); | 309 navigation->set_page_transition(sync_pb::SyncEnums_PageTransition_TYPED); |
| 308 } | 310 } |
| OLD | NEW |