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 "chrome/browser/sessions/session_types.h" | 9 #include "chrome/browser/sessions/session_types.h" |
10 #include "chrome/browser/sync/glue/session_model_associator.h" | 10 #include "chrome/browser/sync/glue/session_model_associator.h" |
11 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
12 #include "content/common/page_transition_types.h" | 12 #include "content/public/common/page_transition_types.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace browser_sync { | 15 namespace browser_sync { |
16 | 16 |
17 typedef testing::Test SessionModelAssociatorTest; | 17 typedef testing::Test SessionModelAssociatorTest; |
18 | 18 |
19 TEST_F(SessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { | 19 TEST_F(SessionModelAssociatorTest, SessionWindowHasNoTabsToSync) { |
20 SessionWindow win; | 20 SessionWindow win; |
21 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); | 21 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); |
22 scoped_ptr<SessionTab> tab(new SessionTab()); | 22 scoped_ptr<SessionTab> tab(new SessionTab()); |
23 win.tabs.push_back(tab.release()); | 23 win.tabs.push_back(tab.release()); |
24 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); | 24 ASSERT_TRUE(SessionWindowHasNoTabsToSync(win)); |
25 TabNavigation nav(0, GURL("about:bubba"), GURL("about:referrer"), | 25 TabNavigation nav(0, GURL("about:bubba"), GURL("about:referrer"), |
26 string16(ASCIIToUTF16("title")), | 26 string16(ASCIIToUTF16("title")), |
27 std::string("state"), 0U); | 27 std::string("state"), content::PageTransitionFromInt(0)); |
28 win.tabs[0]->navigations.push_back(nav); | 28 win.tabs[0]->navigations.push_back(nav); |
29 ASSERT_FALSE(SessionWindowHasNoTabsToSync(win)); | 29 ASSERT_FALSE(SessionWindowHasNoTabsToSync(win)); |
30 } | 30 } |
31 | 31 |
32 TEST_F(SessionModelAssociatorTest, IsValidSessionTab) { | 32 TEST_F(SessionModelAssociatorTest, IsValidSessionTab) { |
33 SessionTab tab; | 33 SessionTab tab; |
34 ASSERT_FALSE(IsValidSessionTab(tab)); | 34 ASSERT_FALSE(IsValidSessionTab(tab)); |
35 TabNavigation nav(0, GURL(chrome::kChromeUINewTabURL), | 35 TabNavigation nav(0, GURL(chrome::kChromeUINewTabURL), |
36 GURL("about:referrer"), | 36 GURL("about:referrer"), |
37 string16(ASCIIToUTF16("title")), | 37 string16(ASCIIToUTF16("title")), |
38 std::string("state"), 0U); | 38 std::string("state"), content::PageTransitionFromInt(0)); |
39 tab.navigations.push_back(nav); | 39 tab.navigations.push_back(nav); |
40 // NewTab does not count as valid if it's the only navigation. | 40 // NewTab does not count as valid if it's the only navigation. |
41 ASSERT_FALSE(IsValidSessionTab(tab)); | 41 ASSERT_FALSE(IsValidSessionTab(tab)); |
42 TabNavigation nav2(0, GURL("about:bubba"), | 42 TabNavigation nav2(0, GURL("about:bubba"), |
43 GURL("about:referrer"), | 43 GURL("about:referrer"), |
44 string16(ASCIIToUTF16("title")), | 44 string16(ASCIIToUTF16("title")), |
45 std::string("state"), 0U); | 45 std::string("state"), content::PageTransitionFromInt(0)); |
46 tab.navigations.push_back(nav2); | 46 tab.navigations.push_back(nav2); |
47 // Once there's another navigation, the tab is valid. | 47 // Once there's another navigation, the tab is valid. |
48 ASSERT_TRUE(IsValidSessionTab(tab)); | 48 ASSERT_TRUE(IsValidSessionTab(tab)); |
49 } | 49 } |
50 | 50 |
51 TEST_F(SessionModelAssociatorTest, IsValidSessionTabIgnoresFragmentForNtp) { | 51 TEST_F(SessionModelAssociatorTest, IsValidSessionTabIgnoresFragmentForNtp) { |
52 SessionTab tab; | 52 SessionTab tab; |
53 ASSERT_FALSE(IsValidSessionTab(tab)); | 53 ASSERT_FALSE(IsValidSessionTab(tab)); |
54 TabNavigation nav(0, GURL(std::string(chrome::kChromeUINewTabURL) + | 54 TabNavigation nav(0, GURL(std::string(chrome::kChromeUINewTabURL) + |
55 "#bookmarks"), | 55 "#bookmarks"), |
56 GURL("about:referrer"), | 56 GURL("about:referrer"), |
57 string16(ASCIIToUTF16("title")), | 57 string16(ASCIIToUTF16("title")), |
58 std::string("state"), 0U); | 58 std::string("state"), content::PageTransitionFromInt(0)); |
59 tab.navigations.push_back(nav); | 59 tab.navigations.push_back(nav); |
60 // NewTab does not count as valid if it's the only navigation. | 60 // NewTab does not count as valid if it's the only navigation. |
61 ASSERT_FALSE(IsValidSessionTab(tab)); | 61 ASSERT_FALSE(IsValidSessionTab(tab)); |
62 } | 62 } |
63 | 63 |
64 TEST_F(SessionModelAssociatorTest, PopulateSessionHeader) { | 64 TEST_F(SessionModelAssociatorTest, PopulateSessionHeader) { |
65 sync_pb::SessionHeader header_s; | 65 sync_pb::SessionHeader header_s; |
66 header_s.set_client_name("Client 1"); | 66 header_s.set_client_name("Client 1"); |
67 header_s.set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); | 67 header_s.set_device_type(sync_pb::SessionHeader_DeviceType_TYPE_WIN); |
68 | 68 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 SessionModelAssociator::PopulateSessionTabFromSpecifics( | 111 SessionModelAssociator::PopulateSessionTabFromSpecifics( |
112 tab_s, base::Time(), &tab); | 112 tab_s, base::Time(), &tab); |
113 ASSERT_EQ(5, tab.tab_id.id()); | 113 ASSERT_EQ(5, tab.tab_id.id()); |
114 ASSERT_EQ(13, tab.tab_visual_index); | 114 ASSERT_EQ(13, tab.tab_visual_index); |
115 ASSERT_EQ(3, tab.current_navigation_index); | 115 ASSERT_EQ(3, tab.current_navigation_index); |
116 ASSERT_TRUE(tab.pinned); | 116 ASSERT_TRUE(tab.pinned); |
117 ASSERT_EQ("app_id", tab.extension_app_id); | 117 ASSERT_EQ("app_id", tab.extension_app_id); |
118 ASSERT_EQ(12, tab.navigations[0].index()); | 118 ASSERT_EQ(12, tab.navigations[0].index()); |
119 ASSERT_EQ(GURL("referrer"), tab.navigations[0].referrer()); | 119 ASSERT_EQ(GURL("referrer"), tab.navigations[0].referrer()); |
120 ASSERT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[0].title()); | 120 ASSERT_EQ(string16(ASCIIToUTF16("title")), tab.navigations[0].title()); |
121 ASSERT_EQ(PageTransition::TYPED, tab.navigations[0].transition()); | 121 ASSERT_EQ(content::PAGE_TRANSITION_TYPED, tab.navigations[0].transition()); |
122 ASSERT_EQ(GURL("http://foo/1"), tab.navigations[0].virtual_url()); | 122 ASSERT_EQ(GURL("http://foo/1"), tab.navigations[0].virtual_url()); |
123 } | 123 } |
124 | 124 |
125 #if defined(OS_WIN) | 125 #if defined(OS_WIN) |
126 // The test is somewhat silly, and just verifies that we return a computer name. | 126 // The test is somewhat silly, and just verifies that we return a computer name. |
127 TEST(SessionModelAssociatorTest, TestGetComputerName) { | 127 TEST(SessionModelAssociatorTest, TestGetComputerName) { |
128 std::string computer_name = SessionModelAssociator::GetComputerName(); | 128 std::string computer_name = SessionModelAssociator::GetComputerName(); |
129 EXPECT_TRUE(!computer_name.empty()); | 129 EXPECT_TRUE(!computer_name.empty()); |
130 } | 130 } |
131 #endif | 131 #endif |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 ASSERT_FALSE(pool.empty()); | 181 ASSERT_FALSE(pool.empty()); |
182 ASSERT_TRUE(pool.full()); | 182 ASSERT_TRUE(pool.full()); |
183 ASSERT_EQ(2U, pool.capacity()); | 183 ASSERT_EQ(2U, pool.capacity()); |
184 pool.clear(); | 184 pool.clear(); |
185 ASSERT_TRUE(pool.empty()); | 185 ASSERT_TRUE(pool.empty()); |
186 ASSERT_TRUE(pool.full()); | 186 ASSERT_TRUE(pool.full()); |
187 ASSERT_EQ(0U, pool.capacity()); | 187 ASSERT_EQ(0U, pool.capacity()); |
188 } | 188 } |
189 | 189 |
190 } // namespace browser_sync | 190 } // namespace browser_sync |
OLD | NEW |