| 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 #import "ios/web/navigation/crw_session_controller.h" | 5 #import "ios/web/navigation/crw_session_controller.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 @end | 43 @end |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| 46 | 46 |
| 47 class CRWSessionControllerTest : public PlatformTest { | 47 class CRWSessionControllerTest : public PlatformTest { |
| 48 protected: | 48 protected: |
| 49 void SetUp() override { | 49 void SetUp() override { |
| 50 session_controller_.reset( | 50 session_controller_.reset( |
| 51 [[CRWSessionController alloc] initWithWindowName:@"test window" | 51 [[CRWSessionController alloc] initWithWindowName:@"test window" |
| 52 openerId:@"opener" | |
| 53 openedByDOM:NO | 52 openedByDOM:NO |
| 54 openerNavigationIndex:0 | |
| 55 browserState:&browser_state_]); | 53 browserState:&browser_state_]); |
| 56 } | 54 } |
| 57 | 55 |
| 58 web::Referrer MakeReferrer(const std::string& url) { | 56 web::Referrer MakeReferrer(const std::string& url) { |
| 59 return web::Referrer(GURL(url), web::ReferrerPolicyDefault); | 57 return web::Referrer(GURL(url), web::ReferrerPolicyDefault); |
| 60 } | 58 } |
| 61 | 59 |
| 62 web::TestWebThreadBundle thread_bundle_; | 60 web::TestWebThreadBundle thread_bundle_; |
| 63 web::TestBrowserState browser_state_; | 61 web::TestBrowserState browser_state_; |
| 64 base::scoped_nsobject<CRWSessionController> session_controller_; | 62 base::scoped_nsobject<CRWSessionController> session_controller_; |
| 65 }; | 63 }; |
| 66 | 64 |
| 67 TEST_F(CRWSessionControllerTest, InitWithWindowName) { | 65 TEST_F(CRWSessionControllerTest, InitWithWindowName) { |
| 68 EXPECT_NSEQ(@"test window", [session_controller_ windowName]); | 66 EXPECT_NSEQ(@"test window", [session_controller_ windowName]); |
| 69 EXPECT_NSEQ(@"opener", [session_controller_ openerId]); | |
| 70 EXPECT_FALSE([session_controller_ isOpenedByDOM]); | 67 EXPECT_FALSE([session_controller_ isOpenedByDOM]); |
| 71 EXPECT_EQ(0U, [[session_controller_ entries] count]); | 68 EXPECT_EQ(0U, [[session_controller_ entries] count]); |
| 72 EXPECT_EQ(nil, [session_controller_ currentEntry]); | 69 EXPECT_EQ(nil, [session_controller_ currentEntry]); |
| 73 } | 70 } |
| 74 | 71 |
| 75 // Tests session controller state after setting a pending index. | 72 // Tests session controller state after setting a pending index. |
| 76 TEST_F(CRWSessionControllerTest, SetPendingIndex) { | 73 TEST_F(CRWSessionControllerTest, SetPendingIndex) { |
| 77 [session_controller_ | 74 [session_controller_ |
| 78 addPendingItem:GURL("http://www.example.com") | 75 addPendingItem:GURL("http://www.example.com") |
| 79 referrer:web::Referrer() | 76 referrer:web::Referrer() |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 [session_controller_ commitPendingItem]; | 504 [session_controller_ commitPendingItem]; |
| 508 [session_controller_ | 505 [session_controller_ |
| 509 addPendingItem:GURL("http://www.url.com/3") | 506 addPendingItem:GURL("http://www.url.com/3") |
| 510 referrer:web::Referrer() | 507 referrer:web::Referrer() |
| 511 transition:ui::PAGE_TRANSITION_TYPED | 508 transition:ui::PAGE_TRANSITION_TYPED |
| 512 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 509 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 513 | 510 |
| 514 // Create source session controller with 1 committed entry. | 511 // Create source session controller with 1 committed entry. |
| 515 base::scoped_nsobject<CRWSessionController> other_session_controller( | 512 base::scoped_nsobject<CRWSessionController> other_session_controller( |
| 516 [[CRWSessionController alloc] initWithWindowName:nil | 513 [[CRWSessionController alloc] initWithWindowName:nil |
| 517 openerId:nil | |
| 518 openedByDOM:NO | 514 openedByDOM:NO |
| 519 openerNavigationIndex:0 | |
| 520 browserState:&browser_state_]); | 515 browserState:&browser_state_]); |
| 521 [other_session_controller setWindowName:@"test-window"]; | 516 [other_session_controller setWindowName:@"test-window"]; |
| 522 [other_session_controller | 517 [other_session_controller |
| 523 addPendingItem:GURL("http://www.url.com/0") | 518 addPendingItem:GURL("http://www.url.com/0") |
| 524 referrer:web::Referrer() | 519 referrer:web::Referrer() |
| 525 transition:ui::PAGE_TRANSITION_TYPED | 520 transition:ui::PAGE_TRANSITION_TYPED |
| 526 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 521 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 527 [other_session_controller commitPendingItem]; | 522 [other_session_controller commitPendingItem]; |
| 528 [other_session_controller | 523 [other_session_controller |
| 529 addPendingItem:GURL("http://www.url.com/1") | 524 addPendingItem:GURL("http://www.url.com/1") |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 [session_controller_ | 556 [session_controller_ |
| 562 addPendingItem:GURL("http://www.url.com/1") | 557 addPendingItem:GURL("http://www.url.com/1") |
| 563 referrer:web::Referrer() | 558 referrer:web::Referrer() |
| 564 transition:ui::PAGE_TRANSITION_TYPED | 559 transition:ui::PAGE_TRANSITION_TYPED |
| 565 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 560 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 566 [session_controller_ commitPendingItem]; | 561 [session_controller_ commitPendingItem]; |
| 567 | 562 |
| 568 // Create empty source session controller. | 563 // Create empty source session controller. |
| 569 base::scoped_nsobject<CRWSessionController> other_session_controller( | 564 base::scoped_nsobject<CRWSessionController> other_session_controller( |
| 570 [[CRWSessionController alloc] initWithWindowName:nil | 565 [[CRWSessionController alloc] initWithWindowName:nil |
| 571 openerId:nil | |
| 572 openedByDOM:NO | 566 openedByDOM:NO |
| 573 openerNavigationIndex:0 | |
| 574 browserState:&browser_state_]); | 567 browserState:&browser_state_]); |
| 575 [other_session_controller setWindowName:@"test-window"]; | 568 [other_session_controller setWindowName:@"test-window"]; |
| 576 | 569 |
| 577 // Insert and verify the state of target session controller. | 570 // Insert and verify the state of target session controller. |
| 578 [session_controller_ | 571 [session_controller_ |
| 579 insertStateFromSessionController:other_session_controller.get()]; | 572 insertStateFromSessionController:other_session_controller.get()]; |
| 580 | 573 |
| 581 EXPECT_NSEQ(@"test-window", [session_controller_ windowName]); | 574 EXPECT_NSEQ(@"test-window", [session_controller_ windowName]); |
| 582 EXPECT_EQ(2U, [[session_controller_ entries] count]); | 575 EXPECT_EQ(2U, [[session_controller_ entries] count]); |
| 583 EXPECT_EQ(1, [session_controller_ currentNavigationIndex]); | 576 EXPECT_EQ(1, [session_controller_ currentNavigationIndex]); |
| 584 EXPECT_EQ(0, [session_controller_ previousNavigationIndex]); | 577 EXPECT_EQ(0, [session_controller_ previousNavigationIndex]); |
| 585 EXPECT_EQ(-1, [session_controller_ pendingItemIndex]); | 578 EXPECT_EQ(-1, [session_controller_ pendingItemIndex]); |
| 586 EXPECT_FALSE([session_controller_ pendingEntry]); | 579 EXPECT_FALSE([session_controller_ pendingEntry]); |
| 587 EXPECT_EQ(GURL("http://www.url.com/0"), | 580 EXPECT_EQ(GURL("http://www.url.com/0"), |
| 588 [session_controller_ URLForSessionAtIndex:0]); | 581 [session_controller_ URLForSessionAtIndex:0]); |
| 589 EXPECT_EQ(GURL("http://www.url.com/1"), | 582 EXPECT_EQ(GURL("http://www.url.com/1"), |
| 590 [session_controller_ URLForSessionAtIndex:1]); | 583 [session_controller_ URLForSessionAtIndex:1]); |
| 591 } | 584 } |
| 592 | 585 |
| 593 // Tests inserting session controller state to empty session controller. | 586 // Tests inserting session controller state to empty session controller. |
| 594 TEST_F(CRWSessionControllerTest, InsertStateToEmptySessionController) { | 587 TEST_F(CRWSessionControllerTest, InsertStateToEmptySessionController) { |
| 595 // Create source session controller with 2 committed entries and one | 588 // Create source session controller with 2 committed entries and one |
| 596 // pending entry. | 589 // pending entry. |
| 597 base::scoped_nsobject<CRWSessionController> other_session_controller( | 590 base::scoped_nsobject<CRWSessionController> other_session_controller( |
| 598 [[CRWSessionController alloc] initWithWindowName:nil | 591 [[CRWSessionController alloc] initWithWindowName:nil |
| 599 openerId:nil | |
| 600 openedByDOM:NO | 592 openedByDOM:NO |
| 601 openerNavigationIndex:0 | |
| 602 browserState:&browser_state_]); | 593 browserState:&browser_state_]); |
| 603 [other_session_controller setWindowName:@"test-window"]; | 594 [other_session_controller setWindowName:@"test-window"]; |
| 604 [other_session_controller | 595 [other_session_controller |
| 605 addPendingItem:GURL("http://www.url.com/0") | 596 addPendingItem:GURL("http://www.url.com/0") |
| 606 referrer:web::Referrer() | 597 referrer:web::Referrer() |
| 607 transition:ui::PAGE_TRANSITION_TYPED | 598 transition:ui::PAGE_TRANSITION_TYPED |
| 608 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 599 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 609 [other_session_controller commitPendingItem]; | 600 [other_session_controller commitPendingItem]; |
| 610 [other_session_controller | 601 [other_session_controller |
| 611 addPendingItem:GURL("http://www.url.com/1") | 602 addPendingItem:GURL("http://www.url.com/1") |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 addPendingItem:GURL("http://www.url.com/3") | 641 addPendingItem:GURL("http://www.url.com/3") |
| 651 referrer:web::Referrer() | 642 referrer:web::Referrer() |
| 652 transition:ui::PAGE_TRANSITION_TYPED | 643 transition:ui::PAGE_TRANSITION_TYPED |
| 653 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 644 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 654 [session_controller_ commitPendingItem]; | 645 [session_controller_ commitPendingItem]; |
| 655 [session_controller_ setPendingItemIndex:0]; | 646 [session_controller_ setPendingItemIndex:0]; |
| 656 | 647 |
| 657 // Create source session controller with 1 committed entry. | 648 // Create source session controller with 1 committed entry. |
| 658 base::scoped_nsobject<CRWSessionController> other_session_controller( | 649 base::scoped_nsobject<CRWSessionController> other_session_controller( |
| 659 [[CRWSessionController alloc] initWithWindowName:nil | 650 [[CRWSessionController alloc] initWithWindowName:nil |
| 660 openerId:nil | |
| 661 openedByDOM:NO | 651 openedByDOM:NO |
| 662 openerNavigationIndex:0 | |
| 663 browserState:&browser_state_]); | 652 browserState:&browser_state_]); |
| 664 [other_session_controller setWindowName:@"test-window"]; | 653 [other_session_controller setWindowName:@"test-window"]; |
| 665 [other_session_controller | 654 [other_session_controller |
| 666 addPendingItem:GURL("http://www.url.com/0") | 655 addPendingItem:GURL("http://www.url.com/0") |
| 667 referrer:web::Referrer() | 656 referrer:web::Referrer() |
| 668 transition:ui::PAGE_TRANSITION_TYPED | 657 transition:ui::PAGE_TRANSITION_TYPED |
| 669 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 658 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| 670 [other_session_controller commitPendingItem]; | 659 [other_session_controller commitPendingItem]; |
| 671 | 660 |
| 672 // Insert and verify the state of target session controller. | 661 // Insert and verify the state of target session controller. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 browserState:&browser_state_]); | 728 browserState:&browser_state_]); |
| 740 | 729 |
| 741 EXPECT_EQ(controller.get().entries.count, 3U); | 730 EXPECT_EQ(controller.get().entries.count, 3U); |
| 742 EXPECT_EQ(controller.get().currentNavigationIndex, 1); | 731 EXPECT_EQ(controller.get().currentNavigationIndex, 1); |
| 743 EXPECT_EQ(controller.get().previousNavigationIndex, -1); | 732 EXPECT_EQ(controller.get().previousNavigationIndex, -1); |
| 744 // Sanity check the current entry, the CRWSessionEntry unit test will ensure | 733 // Sanity check the current entry, the CRWSessionEntry unit test will ensure |
| 745 // the entire object is created properly. | 734 // the entire object is created properly. |
| 746 CRWSessionEntry* current_entry = controller.get().currentEntry; | 735 CRWSessionEntry* current_entry = controller.get().currentEntry; |
| 747 EXPECT_EQ(current_entry.navigationItem->GetURL(), | 736 EXPECT_EQ(current_entry.navigationItem->GetURL(), |
| 748 GURL("http://www.yahoo.com")); | 737 GURL("http://www.yahoo.com")); |
| 749 EXPECT_EQ([[controller openerId] length], 0UL); | |
| 750 } | 738 } |
| 751 | 739 |
| 752 // Tests index of previous navigation entry. | 740 // Tests index of previous navigation entry. |
| 753 TEST_F(CRWSessionControllerTest, PreviousNavigationEntry) { | 741 TEST_F(CRWSessionControllerTest, PreviousNavigationEntry) { |
| 754 EXPECT_EQ(session_controller_.get().previousNavigationIndex, -1); | 742 EXPECT_EQ(session_controller_.get().previousNavigationIndex, -1); |
| 755 [session_controller_ | 743 [session_controller_ |
| 756 addPendingItem:GURL("http://www.url.com") | 744 addPendingItem:GURL("http://www.url.com") |
| 757 referrer:MakeReferrer("http://www.referer.com") | 745 referrer:MakeReferrer("http://www.referer.com") |
| 758 transition:ui::PAGE_TRANSITION_TYPED | 746 transition:ui::PAGE_TRANSITION_TYPED |
| 759 initiationType:web::NavigationInitiationType::USER_INITIATED]; | 747 initiationType:web::NavigationInitiationType::USER_INITIATED]; |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 [session_controller_ | 1158 [session_controller_ |
| 1171 addPendingItem:GURL("http://www.example.com/0") | 1159 addPendingItem:GURL("http://www.example.com/0") |
| 1172 referrer:MakeReferrer("http://www.example.com/b") | 1160 referrer:MakeReferrer("http://www.example.com/b") |
| 1173 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT | 1161 transition:ui::PAGE_TRANSITION_CLIENT_REDIRECT |
| 1174 initiationType:web::NavigationInitiationType::RENDERER_INITIATED]; | 1162 initiationType:web::NavigationInitiationType::RENDERER_INITIATED]; |
| 1175 [session_controller_ commitPendingItem]; | 1163 [session_controller_ commitPendingItem]; |
| 1176 EXPECT_EQ(0U, [session_controller_ backwardEntries].count); | 1164 EXPECT_EQ(0U, [session_controller_ backwardEntries].count); |
| 1177 } | 1165 } |
| 1178 | 1166 |
| 1179 } // anonymous namespace | 1167 } // anonymous namespace |
| OLD | NEW |