| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/sessions/sessions_sync_manager.h" | 5 #include "chrome/browser/sync/sessions/sessions_sync_manager.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/sessions/session_id.h" | 9 #include "chrome/browser/sessions/session_id.h" |
| 10 #include "chrome/browser/sessions/session_tab_helper.h" | 10 #include "chrome/browser/sessions/session_tab_helper.h" |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 ASSERT_EQ(1U, | 349 ASSERT_EQ(1U, |
| 350 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); | 350 manager()->session_tracker_.num_synced_tabs(std::string("tag"))); |
| 351 } | 351 } |
| 352 | 352 |
| 353 namespace { | 353 namespace { |
| 354 | 354 |
| 355 class SyncedTabDelegateFake : public SyncedTabDelegate { | 355 class SyncedTabDelegateFake : public SyncedTabDelegate { |
| 356 public: | 356 public: |
| 357 SyncedTabDelegateFake() : current_entry_index_(0), | 357 SyncedTabDelegateFake() : current_entry_index_(0), |
| 358 pending_entry_index_(-1), | 358 pending_entry_index_(-1), |
| 359 is_managed_(false), | 359 is_supervised_(false), |
| 360 sync_id_(-1), | 360 sync_id_(-1), |
| 361 blocked_navigations_(NULL) {} | 361 blocked_navigations_(NULL) {} |
| 362 virtual ~SyncedTabDelegateFake() {} | 362 virtual ~SyncedTabDelegateFake() {} |
| 363 | 363 |
| 364 virtual int GetCurrentEntryIndex() const OVERRIDE { | 364 virtual int GetCurrentEntryIndex() const OVERRIDE { |
| 365 return current_entry_index_; | 365 return current_entry_index_; |
| 366 } | 366 } |
| 367 void set_current_entry_index(int i) { | 367 void set_current_entry_index(int i) { |
| 368 current_entry_index_ = i; | 368 current_entry_index_ = i; |
| 369 } | 369 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 400 virtual Profile* profile() const OVERRIDE { return NULL; } | 400 virtual Profile* profile() const OVERRIDE { return NULL; } |
| 401 virtual std::string GetExtensionAppId() const OVERRIDE { | 401 virtual std::string GetExtensionAppId() const OVERRIDE { |
| 402 return std::string(); | 402 return std::string(); |
| 403 } | 403 } |
| 404 virtual content::NavigationEntry* GetPendingEntry() const OVERRIDE { | 404 virtual content::NavigationEntry* GetPendingEntry() const OVERRIDE { |
| 405 return NULL; | 405 return NULL; |
| 406 } | 406 } |
| 407 virtual content::NavigationEntry* GetActiveEntry() const OVERRIDE { | 407 virtual content::NavigationEntry* GetActiveEntry() const OVERRIDE { |
| 408 return NULL; | 408 return NULL; |
| 409 } | 409 } |
| 410 virtual bool ProfileIsManaged() const OVERRIDE { | 410 virtual bool ProfileIsSupervised() const OVERRIDE { |
| 411 return is_managed_; | 411 return is_supervised_; |
| 412 } | 412 } |
| 413 void set_is_managed(bool is_managed) { is_managed_ = is_managed; } | 413 void set_is_supervised(bool is_supervised) { is_supervised_ = is_supervised; } |
| 414 virtual const std::vector<const content::NavigationEntry*>* | 414 virtual const std::vector<const content::NavigationEntry*>* |
| 415 GetBlockedNavigations() const OVERRIDE { | 415 GetBlockedNavigations() const OVERRIDE { |
| 416 return blocked_navigations_; | 416 return blocked_navigations_; |
| 417 } | 417 } |
| 418 void set_blocked_navigations( | 418 void set_blocked_navigations( |
| 419 std::vector<const content::NavigationEntry*>* navs) { | 419 std::vector<const content::NavigationEntry*>* navs) { |
| 420 blocked_navigations_ = navs; | 420 blocked_navigations_ = navs; |
| 421 } | 421 } |
| 422 virtual bool IsPinned() const OVERRIDE { | 422 virtual bool IsPinned() const OVERRIDE { |
| 423 return false; | 423 return false; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 440 void reset() { | 440 void reset() { |
| 441 current_entry_index_ = 0; | 441 current_entry_index_ = 0; |
| 442 pending_entry_index_ = -1; | 442 pending_entry_index_ = -1; |
| 443 sync_id_ = -1; | 443 sync_id_ = -1; |
| 444 entries_.clear(); | 444 entries_.clear(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 private: | 447 private: |
| 448 int current_entry_index_; | 448 int current_entry_index_; |
| 449 int pending_entry_index_; | 449 int pending_entry_index_; |
| 450 bool is_managed_; | 450 bool is_supervised_; |
| 451 int sync_id_; | 451 int sync_id_; |
| 452 std::vector<const content::NavigationEntry*>* blocked_navigations_; | 452 std::vector<const content::NavigationEntry*>* blocked_navigations_; |
| 453 ScopedVector<content::NavigationEntry> entries_; | 453 ScopedVector<content::NavigationEntry> entries_; |
| 454 }; | 454 }; |
| 455 | 455 |
| 456 } // namespace | 456 } // namespace |
| 457 | 457 |
| 458 // Test that we exclude tabs with only chrome:// and file:// schemed navigations | 458 // Test that we exclude tabs with only chrome:// and file:// schemed navigations |
| 459 // from ShouldSyncTab(..). | 459 // from ShouldSyncTab(..). |
| 460 TEST_F(SessionsSyncManagerTest, ValidTabs) { | 460 TEST_F(SessionsSyncManagerTest, ValidTabs) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 EXPECT_EQ(202, session_tab.navigations[2].http_status_code()); | 573 EXPECT_EQ(202, session_tab.navigations[2].http_status_code()); |
| 574 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, | 574 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, |
| 575 session_tab.navigations[0].blocked_state()); | 575 session_tab.navigations[0].blocked_state()); |
| 576 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, | 576 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, |
| 577 session_tab.navigations[1].blocked_state()); | 577 session_tab.navigations[1].blocked_state()); |
| 578 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, | 578 EXPECT_EQ(SerializedNavigationEntry::STATE_INVALID, |
| 579 session_tab.navigations[2].blocked_state()); | 579 session_tab.navigations[2].blocked_state()); |
| 580 EXPECT_TRUE(session_tab.session_storage_persistent_id.empty()); | 580 EXPECT_TRUE(session_tab.session_storage_persistent_id.empty()); |
| 581 } | 581 } |
| 582 | 582 |
| 583 // Tests that for managed users blocked navigations are recorded and marked as | 583 // Tests that for supervised users blocked navigations are recorded and marked |
| 584 // such, while regular navigations are marked as allowed. | 584 // as such, while regular navigations are marked as allowed. |
| 585 TEST_F(SessionsSyncManagerTest, BlockedNavigations) { | 585 TEST_F(SessionsSyncManagerTest, BlockedNavigations) { |
| 586 SyncedTabDelegateFake tab; | 586 SyncedTabDelegateFake tab; |
| 587 content::NavigationEntry* entry1(content::NavigationEntry::Create()); | 587 content::NavigationEntry* entry1(content::NavigationEntry::Create()); |
| 588 entry1->SetVirtualURL(GURL("http://www.google.com")); | 588 entry1->SetVirtualURL(GURL("http://www.google.com")); |
| 589 entry1->SetTimestamp(kTime1); | 589 entry1->SetTimestamp(kTime1); |
| 590 tab.AppendEntry(entry1); | 590 tab.AppendEntry(entry1); |
| 591 | 591 |
| 592 content::NavigationEntry* entry2 = content::NavigationEntry::Create(); | 592 content::NavigationEntry* entry2 = content::NavigationEntry::Create(); |
| 593 entry2->SetVirtualURL(GURL("http://blocked.com/foo")); | 593 entry2->SetVirtualURL(GURL("http://blocked.com/foo")); |
| 594 entry2->SetTimestamp(kTime2); | 594 entry2->SetTimestamp(kTime2); |
| 595 content::NavigationEntry* entry3 = content::NavigationEntry::Create(); | 595 content::NavigationEntry* entry3 = content::NavigationEntry::Create(); |
| 596 entry3->SetVirtualURL(GURL("http://evil.com")); | 596 entry3->SetVirtualURL(GURL("http://evil.com")); |
| 597 entry3->SetTimestamp(kTime3); | 597 entry3->SetTimestamp(kTime3); |
| 598 ScopedVector<const content::NavigationEntry> blocked_navigations; | 598 ScopedVector<const content::NavigationEntry> blocked_navigations; |
| 599 blocked_navigations.push_back(entry2); | 599 blocked_navigations.push_back(entry2); |
| 600 blocked_navigations.push_back(entry3); | 600 blocked_navigations.push_back(entry3); |
| 601 | 601 |
| 602 tab.set_is_managed(true); | 602 tab.set_is_supervised(true); |
| 603 tab.set_blocked_navigations(&blocked_navigations.get()); | 603 tab.set_blocked_navigations(&blocked_navigations.get()); |
| 604 | 604 |
| 605 SessionTab session_tab; | 605 SessionTab session_tab; |
| 606 session_tab.window_id.set_id(1); | 606 session_tab.window_id.set_id(1); |
| 607 session_tab.tab_id.set_id(1); | 607 session_tab.tab_id.set_id(1); |
| 608 session_tab.tab_visual_index = 1; | 608 session_tab.tab_visual_index = 1; |
| 609 session_tab.current_navigation_index = 1; | 609 session_tab.current_navigation_index = 1; |
| 610 session_tab.pinned = true; | 610 session_tab.pinned = true; |
| 611 session_tab.extension_app_id = "app id"; | 611 session_tab.extension_app_id = "app id"; |
| 612 session_tab.user_agent_override = "override"; | 612 session_tab.user_agent_override = "override"; |
| (...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 ASSERT_FALSE(observer.notified_of_refresh()); | 1813 ASSERT_FALSE(observer.notified_of_refresh()); |
| 1814 InitWithNoSyncData(); | 1814 InitWithNoSyncData(); |
| 1815 AddTab(browser(), GURL("http://foo1")); | 1815 AddTab(browser(), GURL("http://foo1")); |
| 1816 EXPECT_FALSE(observer.notified_of_refresh()); | 1816 EXPECT_FALSE(observer.notified_of_refresh()); |
| 1817 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); | 1817 NavigateAndCommitActiveTab(GURL("chrome://newtab/#open_tabs")); |
| 1818 EXPECT_TRUE(observer.notified_of_refresh()); | 1818 EXPECT_TRUE(observer.notified_of_refresh()); |
| 1819 } | 1819 } |
| 1820 #endif // defined(OS_ANDROID) || defined(OS_IOS) | 1820 #endif // defined(OS_ANDROID) || defined(OS_IOS) |
| 1821 | 1821 |
| 1822 } // namespace browser_sync | 1822 } // namespace browser_sync |
| OLD | NEW |