| 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 <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/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "chrome/browser/sessions/session_types.h" | 10 #include "chrome/browser/sessions/session_types.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "sync/protocol/session_specifics.pb.h" | 24 #include "sync/protocol/session_specifics.pb.h" |
| 25 #include "sync/util/time.h" | 25 #include "sync/util/time.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 26 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 28 |
| 29 using content::BrowserThread; | 29 using content::BrowserThread; |
| 30 using sessions::SerializedNavigationEntry; | 30 using sessions::SerializedNavigationEntry; |
| 31 using sessions::SerializedNavigationEntryTestHelper; | 31 using sessions::SerializedNavigationEntryTestHelper; |
| 32 using testing::NiceMock; | 32 using testing::NiceMock; |
| 33 using testing::Return; | 33 using testing::Return; |
| 34 using testing::ReturnRef; |
| 34 using testing::StrictMock; | 35 using testing::StrictMock; |
| 35 using testing::_; | 36 using testing::_; |
| 36 | 37 |
| 37 namespace browser_sync { | 38 namespace browser_sync { |
| 38 | 39 |
| 39 class SyncSessionModelAssociatorTest : public testing::Test { | 40 class SyncSessionModelAssociatorTest : public testing::Test { |
| 40 protected: | 41 protected: |
| 41 SyncSessionModelAssociatorTest() | 42 SyncSessionModelAssociatorTest() |
| 42 : ui_thread_(BrowserThread::UI, &message_loop_), | 43 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 43 sync_service_(&profile_), | 44 sync_service_(&profile_), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ASSERT_EQ(1U, tracker.num_synced_tabs(std::string("tag"))); | 168 ASSERT_EQ(1U, tracker.num_synced_tabs(std::string("tag"))); |
| 168 } | 169 } |
| 169 | 170 |
| 170 namespace { | 171 namespace { |
| 171 | 172 |
| 172 class SyncedTabDelegateMock : public SyncedTabDelegate { | 173 class SyncedTabDelegateMock : public SyncedTabDelegate { |
| 173 public: | 174 public: |
| 174 SyncedTabDelegateMock() {} | 175 SyncedTabDelegateMock() {} |
| 175 virtual ~SyncedTabDelegateMock() {} | 176 virtual ~SyncedTabDelegateMock() {} |
| 176 | 177 |
| 177 MOCK_CONST_METHOD0(GetWindowId, SessionID::id_type()); | 178 MOCK_CONST_METHOD0(GetWindowId, const SessionID&()); |
| 178 MOCK_CONST_METHOD0(GetSessionId, SessionID::id_type()); | 179 MOCK_CONST_METHOD0(GetSessionId, const SessionID&()); |
| 179 MOCK_CONST_METHOD0(IsBeingDestroyed, bool()); | 180 MOCK_CONST_METHOD0(IsBeingDestroyed, bool()); |
| 180 MOCK_CONST_METHOD0(profile, Profile*()); | 181 MOCK_CONST_METHOD0(profile, Profile*()); |
| 181 MOCK_CONST_METHOD0(GetExtensionAppId, std::string()); | 182 MOCK_CONST_METHOD0(GetExtensionAppId, std::string()); |
| 182 MOCK_CONST_METHOD0(GetCurrentEntryIndex, int()); | 183 MOCK_CONST_METHOD0(GetCurrentEntryIndex, int()); |
| 183 MOCK_CONST_METHOD0(GetEntryCount, int()); | 184 MOCK_CONST_METHOD0(GetEntryCount, int()); |
| 184 MOCK_CONST_METHOD0(GetPendingEntryIndex, int()); | 185 MOCK_CONST_METHOD0(GetPendingEntryIndex, int()); |
| 185 MOCK_CONST_METHOD0(GetPendingEntry, content::NavigationEntry*()); | 186 MOCK_CONST_METHOD0(GetPendingEntry, content::NavigationEntry*()); |
| 186 MOCK_CONST_METHOD1(GetEntryAtIndex, content::NavigationEntry*(int i)); | 187 MOCK_CONST_METHOD1(GetEntryAtIndex, content::NavigationEntry*(int i)); |
| 187 MOCK_CONST_METHOD0(GetActiveEntry, content::NavigationEntry*()); | 188 MOCK_CONST_METHOD0(GetActiveEntry, content::NavigationEntry*()); |
| 188 MOCK_CONST_METHOD0(IsPinned, bool()); | 189 MOCK_CONST_METHOD0(IsPinned, bool()); |
| 190 MOCK_CONST_METHOD0(GetSyncSessionId, int64()); |
| 191 MOCK_CONST_METHOD0(IsTabInMemory, bool()); |
| 192 MOCK_METHOD1(SetSyncSessionId, void(const int64)); |
| 193 |
| 189 }; | 194 }; |
| 190 | 195 |
| 191 class SyncRefreshListener : public content::NotificationObserver { | 196 class SyncRefreshListener : public content::NotificationObserver { |
| 192 public: | 197 public: |
| 193 SyncRefreshListener() : notified_of_refresh_(false) { | 198 SyncRefreshListener() : notified_of_refresh_(false) { |
| 194 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 199 registrar_.Add(this, chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
| 195 content::NotificationService::AllSources()); | 200 content::NotificationService::AllSources()); |
| 196 } | 201 } |
| 197 | 202 |
| 198 virtual void Observe(int type, | 203 virtual void Observe(int type, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 219 model_associator_.AttemptSessionsDataRefresh(); | 224 model_associator_.AttemptSessionsDataRefresh(); |
| 220 EXPECT_TRUE(refresh_listener.notified_of_refresh()); | 225 EXPECT_TRUE(refresh_listener.notified_of_refresh()); |
| 221 } | 226 } |
| 222 | 227 |
| 223 // Test that we exclude tabs with only chrome:// and file:// schemed navigations | 228 // Test that we exclude tabs with only chrome:// and file:// schemed navigations |
| 224 // from ShouldSyncTab(..). | 229 // from ShouldSyncTab(..). |
| 225 TEST_F(SyncSessionModelAssociatorTest, ValidTabs) { | 230 TEST_F(SyncSessionModelAssociatorTest, ValidTabs) { |
| 226 NiceMock<SyncedTabDelegateMock> tab_mock; | 231 NiceMock<SyncedTabDelegateMock> tab_mock; |
| 227 | 232 |
| 228 // A null entry shouldn't crash. | 233 // A null entry shouldn't crash. |
| 234 SessionID window_id; |
| 235 ON_CALL(tab_mock, GetWindowId()).WillByDefault(ReturnRef(window_id)); |
| 229 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(0)); | 236 EXPECT_CALL(tab_mock, GetCurrentEntryIndex()).WillRepeatedly(Return(0)); |
| 230 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( | 237 EXPECT_CALL(tab_mock, GetEntryAtIndex(0)).WillRepeatedly( |
| 231 Return((content::NavigationEntry *)NULL)); | 238 Return((content::NavigationEntry *)NULL)); |
| 232 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(1)); | 239 EXPECT_CALL(tab_mock, GetEntryCount()).WillRepeatedly(Return(1)); |
| 233 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); | 240 EXPECT_CALL(tab_mock, GetPendingEntryIndex()).WillRepeatedly(Return(-1)); |
| 234 EXPECT_FALSE(model_associator_.ShouldSyncTab(tab_mock)); | 241 EXPECT_FALSE(model_associator_.ShouldSyncTab(tab_mock)); |
| 235 | 242 |
| 236 // A chrome:// entry isn't valid. | 243 // A chrome:// entry isn't valid. |
| 237 scoped_ptr<content::NavigationEntry> entry( | 244 scoped_ptr<content::NavigationEntry> entry( |
| 238 content::NavigationEntry::Create()); | 245 content::NavigationEntry::Create()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 const base::Time kTime3 = base::Time::FromInternalValue(110); | 314 const base::Time kTime3 = base::Time::FromInternalValue(110); |
| 308 const base::Time kTime4 = base::Time::FromInternalValue(120); | 315 const base::Time kTime4 = base::Time::FromInternalValue(120); |
| 309 const base::Time kTime5 = base::Time::FromInternalValue(130); | 316 const base::Time kTime5 = base::Time::FromInternalValue(130); |
| 310 | 317 |
| 311 // Populate the mock tab delegate with some data and navigation | 318 // Populate the mock tab delegate with some data and navigation |
| 312 // entries and make sure that setting a SessionTab from it preserves | 319 // entries and make sure that setting a SessionTab from it preserves |
| 313 // those entries (and clobbers any existing data). | 320 // those entries (and clobbers any existing data). |
| 314 TEST_F(SyncSessionModelAssociatorTest, SetSessionTabFromDelegate) { | 321 TEST_F(SyncSessionModelAssociatorTest, SetSessionTabFromDelegate) { |
| 315 // Create a tab with three valid entries. | 322 // Create a tab with three valid entries. |
| 316 NiceMock<SyncedTabDelegateMock> tab_mock; | 323 NiceMock<SyncedTabDelegateMock> tab_mock; |
| 317 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(Return(0)); | 324 SessionID window_id; |
| 325 ON_CALL(tab_mock, GetWindowId()).WillByDefault(ReturnRef(window_id)); |
| 326 SessionID tab_id; |
| 327 EXPECT_CALL(tab_mock, GetSessionId()).WillRepeatedly(ReturnRef(tab_id)); |
| 318 scoped_ptr<content::NavigationEntry> entry1( | 328 scoped_ptr<content::NavigationEntry> entry1( |
| 319 content::NavigationEntry::Create()); | 329 content::NavigationEntry::Create()); |
| 320 entry1->SetVirtualURL(GURL("http://www.google.com")); | 330 entry1->SetVirtualURL(GURL("http://www.google.com")); |
| 321 entry1->SetTimestamp(kTime1); | 331 entry1->SetTimestamp(kTime1); |
| 322 scoped_ptr<content::NavigationEntry> entry2( | 332 scoped_ptr<content::NavigationEntry> entry2( |
| 323 content::NavigationEntry::Create()); | 333 content::NavigationEntry::Create()); |
| 324 entry2->SetVirtualURL(GURL("http://www.noodle.com")); | 334 entry2->SetVirtualURL(GURL("http://www.noodle.com")); |
| 325 entry2->SetTimestamp(kTime2); | 335 entry2->SetTimestamp(kTime2); |
| 326 scoped_ptr<content::NavigationEntry> entry3( | 336 scoped_ptr<content::NavigationEntry> entry3( |
| 327 content::NavigationEntry::Create()); | 337 content::NavigationEntry::Create()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 345 session_tab.pinned = true; | 355 session_tab.pinned = true; |
| 346 session_tab.extension_app_id = "app id"; | 356 session_tab.extension_app_id = "app id"; |
| 347 session_tab.user_agent_override = "override"; | 357 session_tab.user_agent_override = "override"; |
| 348 session_tab.timestamp = kTime5; | 358 session_tab.timestamp = kTime5; |
| 349 session_tab.navigations.push_back( | 359 session_tab.navigations.push_back( |
| 350 SerializedNavigationEntryTestHelper::CreateNavigation( | 360 SerializedNavigationEntryTestHelper::CreateNavigation( |
| 351 "http://www.example.com", "Example")); | 361 "http://www.example.com", "Example")); |
| 352 session_tab.session_storage_persistent_id = "persistent id"; | 362 session_tab.session_storage_persistent_id = "persistent id"; |
| 353 SetSessionTabFromDelegate(tab_mock, kTime4, &session_tab); | 363 SetSessionTabFromDelegate(tab_mock, kTime4, &session_tab); |
| 354 | 364 |
| 355 EXPECT_EQ(0, session_tab.window_id.id()); | 365 EXPECT_EQ(window_id.id(), session_tab.window_id.id()); |
| 356 EXPECT_EQ(0, session_tab.tab_id.id()); | 366 EXPECT_EQ(tab_id.id(), session_tab.tab_id.id()); |
| 357 EXPECT_EQ(0, session_tab.tab_visual_index); | 367 EXPECT_EQ(0, session_tab.tab_visual_index); |
| 358 EXPECT_EQ(2, session_tab.current_navigation_index); | 368 EXPECT_EQ(2, session_tab.current_navigation_index); |
| 359 EXPECT_FALSE(session_tab.pinned); | 369 EXPECT_FALSE(session_tab.pinned); |
| 360 EXPECT_TRUE(session_tab.extension_app_id.empty()); | 370 EXPECT_TRUE(session_tab.extension_app_id.empty()); |
| 361 EXPECT_TRUE(session_tab.user_agent_override.empty()); | 371 EXPECT_TRUE(session_tab.user_agent_override.empty()); |
| 362 EXPECT_EQ(kTime4, session_tab.timestamp); | 372 EXPECT_EQ(kTime4, session_tab.timestamp); |
| 363 ASSERT_EQ(3u, session_tab.navigations.size()); | 373 ASSERT_EQ(3u, session_tab.navigations.size()); |
| 364 EXPECT_EQ(entry1->GetVirtualURL(), | 374 EXPECT_EQ(entry1->GetVirtualURL(), |
| 365 session_tab.navigations[0].virtual_url()); | 375 session_tab.navigations[0].virtual_url()); |
| 366 EXPECT_EQ(entry2->GetVirtualURL(), | 376 EXPECT_EQ(entry2->GetVirtualURL(), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 // The new page should be mapped to the old favicon data. | 475 // The new page should be mapped to the old favicon data. |
| 466 EXPECT_TRUE(FaviconEquals(GURL(page_url2), std::string())); | 476 EXPECT_TRUE(FaviconEquals(GURL(page_url2), std::string())); |
| 467 LoadTabFavicon(tab2); | 477 LoadTabFavicon(tab2); |
| 468 EXPECT_TRUE(FaviconEquals(GURL(page_url), favicon)); | 478 EXPECT_TRUE(FaviconEquals(GURL(page_url), favicon)); |
| 469 EXPECT_TRUE(FaviconEquals(GURL(page_url2), favicon)); | 479 EXPECT_TRUE(FaviconEquals(GURL(page_url2), favicon)); |
| 470 } | 480 } |
| 471 | 481 |
| 472 } // namespace | 482 } // namespace |
| 473 | 483 |
| 474 } // namespace browser_sync | 484 } // namespace browser_sync |
| OLD | NEW |