OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync_sessions/synced_session_tracker.h" | 5 #include "components/sync_sessions/synced_session_tracker.h" |
6 | 6 |
7 #include "base/rand_util.h" | 7 #include "base/rand_util.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" | 10 #include "components/sessions/core/serialized_navigation_entry_test_helper.h" |
11 #include "components/sync_sessions/fake_sync_sessions_client.h" | 11 #include "components/sync_sessions/fake_sync_sessions_client.h" |
| 12 #include "components/sync_sessions/synced_tab_delegate.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 namespace sync_sessions { | 15 namespace sync_sessions { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 const char kValidUrl[] = "http://www.example.com"; | 19 const char kValidUrl[] = "http://www.example.com"; |
19 const char kInvalidUrl[] = "invalid.url"; | 20 const char kInvalidUrl[] = "invalid.url"; |
20 const char kTag[] = "tag"; | 21 const char kTag[] = "tag"; |
21 const char kTag2[] = "tag2"; | 22 const char kTag2[] = "tag2"; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 GetTracker()->PutWindowInSession(kTag2, 2); | 118 GetTracker()->PutWindowInSession(kTag2, 2); |
118 ASSERT_TRUE(GetTracker()->LookupSessionWindows(kTag, &windows)); | 119 ASSERT_TRUE(GetTracker()->LookupSessionWindows(kTag, &windows)); |
119 ASSERT_EQ(2U, windows.size()); // Only windows from kTag session. | 120 ASSERT_EQ(2U, windows.size()); // Only windows from kTag session. |
120 ASSERT_NE((sessions::SessionWindow*)nullptr, windows[0]); | 121 ASSERT_NE((sessions::SessionWindow*)nullptr, windows[0]); |
121 ASSERT_NE((sessions::SessionWindow*)nullptr, windows[1]); | 122 ASSERT_NE((sessions::SessionWindow*)nullptr, windows[1]); |
122 ASSERT_NE(windows[1], windows[0]); | 123 ASSERT_NE(windows[1], windows[0]); |
123 } | 124 } |
124 | 125 |
125 TEST_F(SyncedSessionTrackerTest, LookupSessionTab) { | 126 TEST_F(SyncedSessionTrackerTest, LookupSessionTab) { |
126 const sessions::SessionTab* tab; | 127 const sessions::SessionTab* tab; |
127 ASSERT_FALSE( | 128 ASSERT_FALSE(GetTracker()->LookupSessionTab(kTag, kInvalidTabID, &tab)); |
128 GetTracker()->LookupSessionTab(kTag, TabNodePool::kInvalidTabID, &tab)); | |
129 ASSERT_FALSE(GetTracker()->LookupSessionTab(kTag, 5, &tab)); | 129 ASSERT_FALSE(GetTracker()->LookupSessionTab(kTag, 5, &tab)); |
130 GetTracker()->GetSession(kTag); | 130 GetTracker()->GetSession(kTag); |
131 GetTracker()->PutWindowInSession(kTag, 0); | 131 GetTracker()->PutWindowInSession(kTag, 0); |
132 GetTracker()->PutTabInWindow(kTag, 0, 5); | 132 GetTracker()->PutTabInWindow(kTag, 0, 5); |
133 ASSERT_TRUE(GetTracker()->LookupSessionTab(kTag, 5, &tab)); | 133 ASSERT_TRUE(GetTracker()->LookupSessionTab(kTag, 5, &tab)); |
134 ASSERT_NE((sessions::SessionTab*)nullptr, tab); | 134 ASSERT_NE((sessions::SessionTab*)nullptr, tab); |
135 } | 135 } |
136 | 136 |
137 TEST_F(SyncedSessionTrackerTest, Complex) { | 137 TEST_F(SyncedSessionTrackerTest, Complex) { |
138 std::vector<sessions::SessionTab *> tabs1, tabs2; | 138 std::vector<sessions::SessionTab *> tabs1, tabs2; |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 // GetSession as well as GetTab. | 554 // GetSession as well as GetTab. |
555 SyncedSession* session = GetTracker()->GetSession(kTag); | 555 SyncedSession* session = GetTracker()->GetSession(kTag); |
556 ASSERT_EQ(GetTracker()->GetTab(kTag, kTab2), | 556 ASSERT_EQ(GetTracker()->GetTab(kTag, kTab2), |
557 session->windows[kWindow1]->tabs[0].get()); | 557 session->windows[kWindow1]->tabs[0].get()); |
558 ASSERT_EQ(session->tab_node_ids.size(), | 558 ASSERT_EQ(session->tab_node_ids.size(), |
559 session->tab_node_ids.count(kTabNode)); | 559 session->tab_node_ids.count(kTabNode)); |
560 ASSERT_EQ(1U, GetTabNodePool()->Capacity()); | 560 ASSERT_EQ(1U, GetTabNodePool()->Capacity()); |
561 } | 561 } |
562 | 562 |
563 } // namespace sync_sessions | 563 } // namespace sync_sessions |
OLD | NEW |