| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/bind_helpers.h" | 6 #include "base/bind_helpers.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 | 615 |
| 616 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); | 616 helper_.AssertSingleWindowWithSingleTab(windows.get(), 1); |
| 617 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); | 617 EXPECT_TRUE(app_id == windows[0]->tabs[0]->extension_app_id); |
| 618 } | 618 } |
| 619 | 619 |
| 620 // Explicitly set the pinned state to true and make sure we get back true. | 620 // Explicitly set the pinned state to true and make sure we get back true. |
| 621 TEST_F(SessionServiceTest, PinnedTrue) { | 621 TEST_F(SessionServiceTest, PinnedTrue) { |
| 622 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); | 622 EXPECT_TRUE(CreateAndWriteSessionWithOneTab(true, true)); |
| 623 } | 623 } |
| 624 | 624 |
| 625 class GetCurrentSessionCallbackHandler { | |
| 626 public: | |
| 627 void OnGotSession(int handle, std::vector<SessionWindow*>* windows) { | |
| 628 EXPECT_EQ(1U, windows->size()); | |
| 629 EXPECT_EQ(2U, (*windows)[0]->tabs.size()); | |
| 630 EXPECT_EQ(2U, (*windows)[0]->tabs[0]->navigations.size()); | |
| 631 EXPECT_EQ(GURL("http://bar/1"), | |
| 632 (*windows)[0]->tabs[0]->navigations[0].virtual_url()); | |
| 633 EXPECT_EQ(GURL("http://bar/2"), | |
| 634 (*windows)[0]->tabs[0]->navigations[1].virtual_url()); | |
| 635 EXPECT_EQ(2U, (*windows)[0]->tabs[1]->navigations.size()); | |
| 636 EXPECT_EQ(GURL("http://foo/1"), | |
| 637 (*windows)[0]->tabs[1]->navigations[0].virtual_url()); | |
| 638 EXPECT_EQ(GURL("http://foo/2"), | |
| 639 (*windows)[0]->tabs[1]->navigations[1].virtual_url()); | |
| 640 } | |
| 641 }; | |
| 642 | |
| 643 TEST_F(SessionServiceTest, GetCurrentSession) { | |
| 644 AddTab(browser(), GURL("http://foo/1")); | |
| 645 NavigateAndCommitActiveTab(GURL("http://foo/2")); | |
| 646 AddTab(browser(), GURL("http://bar/1")); | |
| 647 NavigateAndCommitActiveTab(GURL("http://bar/2")); | |
| 648 | |
| 649 CancelableRequestConsumer consumer; | |
| 650 GetCurrentSessionCallbackHandler handler; | |
| 651 service()->GetCurrentSession( | |
| 652 &consumer, | |
| 653 base::Bind(&GetCurrentSessionCallbackHandler::OnGotSession, | |
| 654 base::Unretained(&handler))); | |
| 655 } | |
| 656 | |
| 657 // Test that the notification for SESSION_SERVICE_SAVED is working properly. | 625 // Test that the notification for SESSION_SERVICE_SAVED is working properly. |
| 658 TEST_F(SessionServiceTest, SavedSessionNotification) { | 626 TEST_F(SessionServiceTest, SavedSessionNotification) { |
| 659 content::NotificationRegistrar registrar_; | 627 content::NotificationRegistrar registrar_; |
| 660 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, | 628 registrar_.Add(this, chrome::NOTIFICATION_SESSION_SERVICE_SAVED, |
| 661 content::NotificationService::AllSources()); | 629 content::NotificationService::AllSources()); |
| 662 service()->Save(); | 630 service()->Save(); |
| 663 EXPECT_EQ(sync_save_count_, 1); | 631 EXPECT_EQ(sync_save_count_, 1); |
| 664 } | 632 } |
| 665 | 633 |
| 666 // Makes sure a tab closed by a user gesture is not restored. | 634 // Makes sure a tab closed by a user gesture is not restored. |
| 667 TEST_F(SessionServiceTest, CloseTabUserGesture) { | 635 TEST_F(SessionServiceTest, CloseTabUserGesture) { |
| 668 SessionID tab_id; | 636 SessionID tab_id; |
| 669 ASSERT_NE(window_id.id(), tab_id.id()); | 637 ASSERT_NE(window_id.id(), tab_id.id()); |
| 670 | 638 |
| 671 TabNavigation nav1(0, GURL("http://google.com"), | 639 TabNavigation nav1(0, GURL("http://google.com"), |
| 672 content::Referrer(GURL("http://www.referrer.com"), | 640 content::Referrer(GURL("http://www.referrer.com"), |
| 673 WebKit::WebReferrerPolicyDefault), | 641 WebKit::WebReferrerPolicyDefault), |
| 674 ASCIIToUTF16("abc"), "def", | 642 ASCIIToUTF16("abc"), "def", |
| 675 content::PAGE_TRANSITION_QUALIFIER_MASK); | 643 content::PAGE_TRANSITION_QUALIFIER_MASK); |
| 676 | 644 |
| 677 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); | 645 helper_.PrepareTabInWindow(window_id, tab_id, 0, true); |
| 678 UpdateNavigation(window_id, tab_id, nav1, 0, true); | 646 UpdateNavigation(window_id, tab_id, nav1, 0, true); |
| 679 service()->TabClosed(window_id, tab_id, true); | 647 service()->TabClosed(window_id, tab_id, true); |
| 680 | 648 |
| 681 ScopedVector<SessionWindow> windows; | 649 ScopedVector<SessionWindow> windows; |
| 682 ReadWindows(&(windows.get())); | 650 ReadWindows(&(windows.get())); |
| 683 | 651 |
| 684 ASSERT_TRUE(windows->empty()); | 652 ASSERT_TRUE(windows->empty()); |
| 685 } | 653 } |
| OLD | NEW |