OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/sessions/session_types.h" | 10 #include "chrome/browser/sessions/session_types.h" |
11 #include "chrome/browser/sync/glue/session_model_associator.h" | 11 #include "chrome/browser/sync/glue/session_model_associator.h" |
12 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
13 #include "content/common/page_transition_types.h" | 13 #include "content/common/page_transition_types.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using browser_sync::SessionModelAssociator; | 16 using browser_sync::SessionModelAssociator; |
17 using browser_sync::SyncedSessionTracker; | 17 using browser_sync::SyncedSessionTracker; |
| 18 |
18 namespace browser_sync { | 19 namespace browser_sync { |
19 | 20 |
20 typedef testing::Test SessionModelAssociatorTest; | 21 typedef testing::Test SessionModelAssociatorTest; |
21 | 22 |
22 TEST_F(SessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { | 23 TEST_F(SessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { |
23 SessionWindow win; | 24 SessionWindow win; |
24 ASSERT_TRUE(SessionModelAssociator::SessionWindowHasNoTabsToSync(win)); | 25 ASSERT_TRUE(SessionModelAssociator::SessionWindowHasNoTabsToSync(win)); |
25 scoped_ptr<SessionTab> tab(new SessionTab()); | 26 scoped_ptr<SessionTab> tab(new SessionTab()); |
26 win.tabs.push_back(tab.release()); | 27 win.tabs.push_back(tab.release()); |
27 ASSERT_TRUE(SessionModelAssociator::SessionWindowHasNoTabsToSync(win)); | 28 ASSERT_TRUE(SessionModelAssociator::SessionWindowHasNoTabsToSync(win)); |
(...skipping 16 matching lines...) Expand all Loading... |
44 ASSERT_FALSE(SessionModelAssociator::IsValidSessionTab(tab)); | 45 ASSERT_FALSE(SessionModelAssociator::IsValidSessionTab(tab)); |
45 TabNavigation nav2(0, GURL("about:bubba"), | 46 TabNavigation nav2(0, GURL("about:bubba"), |
46 GURL("about:referrer"), | 47 GURL("about:referrer"), |
47 string16(ASCIIToUTF16("title")), | 48 string16(ASCIIToUTF16("title")), |
48 std::string("state"), 0U); | 49 std::string("state"), 0U); |
49 tab.navigations.push_back(nav2); | 50 tab.navigations.push_back(nav2); |
50 // Once there's another navigation, the tab is valid. | 51 // Once there's another navigation, the tab is valid. |
51 ASSERT_TRUE(SessionModelAssociator::IsValidSessionTab(tab)); | 52 ASSERT_TRUE(SessionModelAssociator::IsValidSessionTab(tab)); |
52 } | 53 } |
53 | 54 |
| 55 TEST_F(SessionModelAssociatorTest, PopulateSessionHeader) { |
| 56 sync_pb::SessionHeader header_s; |
| 57 header_s.set_client_name("Client 1"); |
| 58 header_s.set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); |
| 59 |
| 60 SyncedSession session; |
| 61 SessionModelAssociator::PopulateSessionHeaderFromSpecifics( |
| 62 header_s, &session); |
| 63 ASSERT_EQ("Client 1", session.session_name); |
| 64 ASSERT_EQ(SyncedSession::TYPE_WIN, session.device_type); |
| 65 } |
| 66 |
54 TEST_F(SessionModelAssociatorTest, PopulateSessionWindow) { | 67 TEST_F(SessionModelAssociatorTest, PopulateSessionWindow) { |
55 sync_pb::SessionWindow window_s; | 68 sync_pb::SessionWindow window_s; |
56 window_s.add_tab(0); | 69 window_s.add_tab(0); |
57 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); | 70 window_s.set_browser_type(sync_pb::SessionWindow_BrowserType_TYPE_TABBED); |
58 window_s.set_selected_tab_index(1); | 71 window_s.set_selected_tab_index(1); |
59 | 72 |
60 std::string tag = "tag"; | 73 std::string tag = "tag"; |
61 SyncedSessionTracker tracker; | 74 SyncedSessionTracker tracker; |
62 SyncedSession* session = tracker.GetSession(tag); | 75 SyncedSession* session = tracker.GetSession(tag); |
63 SessionWindow* win = new SessionWindow(); | 76 SessionWindow* win = new SessionWindow(); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // The sessions don't have valid windows, lookup should not succeed. | 164 // The sessions don't have valid windows, lookup should not succeed. |
152 std::vector<const SyncedSession*> sessions; | 165 std::vector<const SyncedSession*> sessions; |
153 ASSERT_FALSE(tracker.LookupAllForeignSessions(&sessions)); | 166 ASSERT_FALSE(tracker.LookupAllForeignSessions(&sessions)); |
154 | 167 |
155 tracker.clear(); | 168 tracker.clear(); |
156 ASSERT_EQ(0U, tracker.num_synced_tabs(tag1)); | 169 ASSERT_EQ(0U, tracker.num_synced_tabs(tag1)); |
157 ASSERT_EQ(0U, tracker.num_synced_tabs(tag2)); | 170 ASSERT_EQ(0U, tracker.num_synced_tabs(tag2)); |
158 ASSERT_EQ(0U, tracker.num_synced_sessions()); | 171 ASSERT_EQ(0U, tracker.num_synced_sessions()); |
159 } | 172 } |
160 | 173 |
| 174 #if defined(OS_WIN) |
| 175 // The test is somewhat silly, and just verifies that we return a computer name. |
| 176 TEST(SessionModelAssociatorTest, TestGetComputerName) { |
| 177 std::string computer_name = SessionModelAssociator::GetComputerName(); |
| 178 EXPECT_TRUE(!computer_name.empty()); |
| 179 } |
| 180 #endif |
| 181 |
| 182 #if defined(OS_MACOSX) |
| 183 // The test is somewhat silly, and just verifies that we return a hardware |
| 184 // model name. |
| 185 TEST_F(SessionModelAssociatorTest, GetHardwareModelName) { |
| 186 std::string hardware_model = SessionModelAssociator::GetHardwareModelName(); |
| 187 EXPECT_TRUE(!hardware_model.empty()); |
| 188 } |
| 189 #endif |
| 190 |
| 191 |
161 } // namespace browser_sync | 192 } // namespace browser_sync |
162 | |
OLD | NEW |