| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync/glue/session_sync_test_helper.h" | 5 #include "components/sync_sessions/session_sync_test_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/sync/protocol/session_specifics.pb.h" | 10 #include "components/sync/protocol/session_specifics.pb.h" |
| 11 #include "components/sync/protocol/sync_enums.pb.h" | 11 #include "components/sync/protocol/sync_enums.pb.h" |
| 12 #include "components/sync_sessions/synced_session.h" | 12 #include "components/sync_sessions/synced_session.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 | 15 namespace sync_sessions { |
| 16 namespace browser_sync { | |
| 17 | 16 |
| 18 static const char* kClientName = "name"; | 17 static const char* kClientName = "name"; |
| 19 static const char* kAppId = "app_id"; | 18 static const char* kAppId = "app_id"; |
| 20 static const char* kVirtualUrl = "http://foo/1"; | 19 static const char* kVirtualUrl = "http://foo/1"; |
| 21 static const char* kReferrer = "referrer"; | 20 static const char* kReferrer = "referrer"; |
| 22 static const char* kTitle = "title"; | 21 static const char* kTitle = "title"; |
| 23 | 22 |
| 24 // static | 23 // static |
| 25 void SessionSyncTestHelper::BuildSessionSpecifics( | 24 void SessionSyncTestHelper::BuildSessionSpecifics( |
| 26 const std::string& tag, | 25 const std::string& tag, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 for (std::vector<int>::const_iterator iter = tab_list.begin(); | 43 for (std::vector<int>::const_iterator iter = tab_list.begin(); |
| 45 iter != tab_list.end(); ++iter) { | 44 iter != tab_list.end(); ++iter) { |
| 46 window->add_tab(*iter); | 45 window->add_tab(*iter); |
| 47 } | 46 } |
| 48 } | 47 } |
| 49 | 48 |
| 50 // static | 49 // static |
| 51 void SessionSyncTestHelper::VerifySyncedSession( | 50 void SessionSyncTestHelper::VerifySyncedSession( |
| 52 const std::string& tag, | 51 const std::string& tag, |
| 53 const std::vector<std::vector<SessionID::id_type>>& windows, | 52 const std::vector<std::vector<SessionID::id_type>>& windows, |
| 54 const sync_driver::SyncedSession& session) { | 53 const SyncedSession& session) { |
| 55 ASSERT_EQ(tag, session.session_tag); | 54 ASSERT_EQ(tag, session.session_tag); |
| 56 ASSERT_EQ(sync_driver::SyncedSession::TYPE_LINUX, session.device_type); | 55 ASSERT_EQ(SyncedSession::TYPE_LINUX, session.device_type); |
| 57 ASSERT_EQ(kClientName, session.session_name); | 56 ASSERT_EQ(kClientName, session.session_name); |
| 58 ASSERT_EQ(windows.size(), session.windows.size()); | 57 ASSERT_EQ(windows.size(), session.windows.size()); |
| 59 | 58 |
| 60 // We assume the window id's are in increasing order. | 59 // We assume the window id's are in increasing order. |
| 61 int i = 0; | 60 int i = 0; |
| 62 for (std::vector<std::vector<int> >::const_iterator win_iter = | 61 for (std::vector<std::vector<int>>::const_iterator win_iter = windows.begin(); |
| 63 windows.begin(); | |
| 64 win_iter != windows.end(); ++win_iter, ++i) { | 62 win_iter != windows.end(); ++win_iter, ++i) { |
| 65 sessions::SessionWindow* win_ptr; | 63 sessions::SessionWindow* win_ptr; |
| 66 sync_driver::SyncedSession::SyncedWindowMap::const_iterator map_iter = | 64 SyncedSession::SyncedWindowMap::const_iterator map_iter = |
| 67 session.windows.find(i); | 65 session.windows.find(i); |
| 68 if (map_iter != session.windows.end()) | 66 if (map_iter != session.windows.end()) |
| 69 win_ptr = map_iter->second; | 67 win_ptr = map_iter->second; |
| 70 else | 68 else |
| 71 FAIL(); | 69 FAIL(); |
| 72 ASSERT_EQ(win_iter->size(), win_ptr->tabs.size()); | 70 ASSERT_EQ(win_iter->size(), win_ptr->tabs.size()); |
| 73 ASSERT_EQ(0, win_ptr->selected_tab_index); | 71 ASSERT_EQ(0, win_ptr->selected_tab_index); |
| 74 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, win_ptr->type); | 72 ASSERT_EQ(sessions::SessionWindow::TYPE_TABBED, win_ptr->type); |
| 75 int j = 0; | 73 int j = 0; |
| 76 for (std::vector<int>::const_iterator tab_iter = (*win_iter).begin(); | 74 for (std::vector<int>::const_iterator tab_iter = (*win_iter).begin(); |
| 77 tab_iter != (*win_iter).end(); ++tab_iter, ++j) { | 75 tab_iter != (*win_iter).end(); ++tab_iter, ++j) { |
| 78 sessions::SessionTab* tab = win_ptr->tabs[j]; | 76 sessions::SessionTab* tab = win_ptr->tabs[j]; |
| 79 ASSERT_EQ(*tab_iter, tab->tab_id.id()); | 77 ASSERT_EQ(*tab_iter, tab->tab_id.id()); |
| 80 ASSERT_EQ(1U, tab->navigations.size()); | 78 ASSERT_EQ(1U, tab->navigations.size()); |
| 81 ASSERT_EQ(1, tab->tab_visual_index); | 79 ASSERT_EQ(1, tab->tab_visual_index); |
| 82 ASSERT_EQ(0, tab->current_navigation_index); | 80 ASSERT_EQ(0, tab->current_navigation_index); |
| 83 ASSERT_TRUE(tab->pinned); | 81 ASSERT_TRUE(tab->pinned); |
| 84 ASSERT_EQ(kAppId, tab->extension_app_id); | 82 ASSERT_EQ(kAppId, tab->extension_app_id); |
| 85 ASSERT_EQ(1U, tab->navigations.size()); | 83 ASSERT_EQ(1U, tab->navigations.size()); |
| 86 ASSERT_EQ(tab->navigations[0].virtual_url(), GURL(kVirtualUrl)); | 84 ASSERT_EQ(tab->navigations[0].virtual_url(), GURL(kVirtualUrl)); |
| 87 ASSERT_EQ(tab->navigations[0].referrer_url(), GURL(kReferrer)); | 85 ASSERT_EQ(tab->navigations[0].referrer_url(), GURL(kReferrer)); |
| 88 ASSERT_EQ(tab->navigations[0].title(), | 86 ASSERT_EQ(tab->navigations[0].title(), base::ASCIIToUTF16(kTitle)); |
| 89 base::ASCIIToUTF16(kTitle)); | |
| 90 ASSERT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 87 ASSERT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
| 91 tab->navigations[0].transition_type(), ui::PAGE_TRANSITION_TYPED)); | 88 tab->navigations[0].transition_type(), ui::PAGE_TRANSITION_TYPED)); |
| 92 } | 89 } |
| 93 } | 90 } |
| 94 } | 91 } |
| 95 | 92 |
| 96 void SessionSyncTestHelper::BuildTabSpecifics( | 93 void SessionSyncTestHelper::BuildTabSpecifics( |
| 97 const std::string& tag, | 94 const std::string& tag, |
| 98 int window_id, | 95 int window_id, |
| 99 int tab_id, | 96 int tab_id, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 tabs1.resize(tab_list.size()); | 134 tabs1.resize(tab_list.size()); |
| 138 for (size_t i = 0; i < tab_list.size(); ++i) { | 135 for (size_t i = 0; i < tab_list.size(); ++i) { |
| 139 BuildTabSpecifics(tag, 0, tab_list[i], &tabs1[i]); | 136 BuildTabSpecifics(tag, 0, tab_list[i], &tabs1[i]); |
| 140 } | 137 } |
| 141 | 138 |
| 142 if (tabs) | 139 if (tabs) |
| 143 tabs->swap(tabs1); | 140 tabs->swap(tabs1); |
| 144 return meta; | 141 return meta; |
| 145 } | 142 } |
| 146 | 143 |
| 147 } // namespace browser_sync | 144 } // namespace sync_sessions |
| OLD | NEW |