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 #import "ios/web/navigation/navigation_manager_impl.h" | 5 #import "ios/web/navigation/navigation_manager_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/scoped_nsobject.h" | 8 #import "base/mac/scoped_nsobject.h" |
9 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 9 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
10 #import "ios/web/navigation/navigation_manager_delegate.h" | 10 #import "ios/web/navigation/navigation_manager_delegate.h" |
11 #include "ios/web/public/navigation_item.h" | 11 #include "ios/web/public/navigation_item.h" |
12 #include "ios/web/public/test/fakes/test_browser_state.h" | 12 #include "ios/web/public/test/fakes/test_browser_state.h" |
| 13 #include "ios/web/test/test_url_constants.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/platform_test.h" | 15 #include "testing/platform_test.h" |
15 | 16 |
16 namespace web { | 17 namespace web { |
17 namespace { | 18 namespace { |
18 // Stub class for NavigationManagerDelegate. | 19 // Stub class for NavigationManagerDelegate. |
19 class TestNavigationManagerDelegate : public NavigationManagerDelegate { | 20 class TestNavigationManagerDelegate : public NavigationManagerDelegate { |
20 void GoToIndex(int index) override {} | 21 void GoToIndex(int index) override {} |
21 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override {} | 22 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override {} |
22 void OnNavigationItemsPruned(size_t pruned_item_count) override {} | 23 void OnNavigationItemsPruned(size_t pruned_item_count) override {} |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 } | 506 } |
506 | 507 |
507 // Tests that desktop user agent can be enforced to use for next pending item. | 508 // Tests that desktop user agent can be enforced to use for next pending item. |
508 TEST_F(NavigationManagerTest, OverrideDesktopUserAgent) { | 509 TEST_F(NavigationManagerTest, OverrideDesktopUserAgent) { |
509 navigation_manager()->OverrideDesktopUserAgentForNextPendingItem(); | 510 navigation_manager()->OverrideDesktopUserAgentForNextPendingItem(); |
510 navigation_manager()->AddPendingItem( | 511 navigation_manager()->AddPendingItem( |
511 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, | 512 GURL("http://www.url.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
512 web::NavigationInitiationType::USER_INITIATED); | 513 web::NavigationInitiationType::USER_INITIATED); |
513 [session_controller() commitPendingItem]; | 514 [session_controller() commitPendingItem]; |
514 NavigationItem* visible_item = navigation_manager()->GetVisibleItem(); | 515 NavigationItem* visible_item = navigation_manager()->GetVisibleItem(); |
515 EXPECT_TRUE(visible_item->IsOverridingUserAgent()); | 516 EXPECT_EQ(visible_item->GetUserAgentType(), UserAgentType::DESKTOP); |
| 517 } |
| 518 |
| 519 // Tests that the UserAgentType is propagated to subsequent NavigationItems. |
| 520 TEST_F(NavigationManagerTest, UserAgentTypePropagation) { |
| 521 // Add and commit two NavigationItems. |
| 522 navigation_manager()->AddPendingItem( |
| 523 GURL("http://www.1.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 524 web::NavigationInitiationType::USER_INITIATED); |
| 525 [session_controller() commitPendingItem]; |
| 526 web::NavigationItem* item1 = navigation_manager()->GetLastCommittedItem(); |
| 527 ASSERT_EQ(web::UserAgentType::MOBILE, item1->GetUserAgentType()); |
| 528 navigation_manager()->AddPendingItem( |
| 529 GURL("http://www.2.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 530 web::NavigationInitiationType::USER_INITIATED); |
| 531 [session_controller() commitPendingItem]; |
| 532 web::NavigationItem* item2 = navigation_manager()->GetLastCommittedItem(); |
| 533 |
| 534 // Verify that the second item's UserAgentType is equal to the first. |
| 535 EXPECT_EQ(item1->GetUserAgentType(), item2->GetUserAgentType()); |
| 536 |
| 537 // Update |item2|'s UA type to DESKTOP and commit a new item. |
| 538 item2->SetUserAgentType(web::UserAgentType::DESKTOP); |
| 539 ASSERT_EQ(web::UserAgentType::DESKTOP, item2->GetUserAgentType()); |
| 540 navigation_manager()->AddPendingItem( |
| 541 GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 542 web::NavigationInitiationType::USER_INITIATED); |
| 543 [session_controller() commitPendingItem]; |
| 544 web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem(); |
| 545 |
| 546 // Verify that the third item's UserAgentType is equal to the second. |
| 547 EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType()); |
| 548 } |
| 549 |
| 550 // Tests that the UserAgentType is propagated to subsequent NavigationItems if |
| 551 // a native URL exists in between naviations. |
| 552 TEST_F(NavigationManagerTest, UserAgentTypePropagationPastNativeItems) { |
| 553 // GURL::Replacements that will replace a GURL's scheme with the test native |
| 554 // scheme. |
| 555 GURL::Replacements native_scheme_replacement; |
| 556 native_scheme_replacement.SetSchemeStr(kTestNativeContentScheme); |
| 557 |
| 558 // Create two non-native navigations that are separated by a native one. |
| 559 navigation_manager()->AddPendingItem( |
| 560 GURL("http://www.1.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 561 web::NavigationInitiationType::USER_INITIATED); |
| 562 [session_controller() commitPendingItem]; |
| 563 web::NavigationItem* item1 = navigation_manager()->GetLastCommittedItem(); |
| 564 ASSERT_EQ(web::UserAgentType::MOBILE, item1->GetUserAgentType()); |
| 565 navigation_manager()->AddPendingItem( |
| 566 item1->GetURL().ReplaceComponents(native_scheme_replacement), Referrer(), |
| 567 ui::PAGE_TRANSITION_TYPED, web::NavigationInitiationType::USER_INITIATED); |
| 568 [session_controller() commitPendingItem]; |
| 569 web::NavigationItem* native_item1 = |
| 570 navigation_manager()->GetLastCommittedItem(); |
| 571 ASSERT_EQ(web::UserAgentType::NONE, native_item1->GetUserAgentType()); |
| 572 navigation_manager()->AddPendingItem( |
| 573 GURL("http://www.2.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 574 web::NavigationInitiationType::USER_INITIATED); |
| 575 [session_controller() commitPendingItem]; |
| 576 web::NavigationItem* item2 = navigation_manager()->GetLastCommittedItem(); |
| 577 |
| 578 // Verify that |item1|'s UserAgentType is propagated to |item2|. |
| 579 EXPECT_EQ(item1->GetUserAgentType(), item2->GetUserAgentType()); |
| 580 |
| 581 // Update |item2|'s UA type to DESKTOP and add a third non-native navigation, |
| 582 // once again separated by a native one. |
| 583 item2->SetUserAgentType(web::UserAgentType::DESKTOP); |
| 584 ASSERT_EQ(web::UserAgentType::DESKTOP, item2->GetUserAgentType()); |
| 585 navigation_manager()->AddPendingItem( |
| 586 item2->GetURL().ReplaceComponents(native_scheme_replacement), Referrer(), |
| 587 ui::PAGE_TRANSITION_TYPED, web::NavigationInitiationType::USER_INITIATED); |
| 588 [session_controller() commitPendingItem]; |
| 589 web::NavigationItem* native_item2 = |
| 590 navigation_manager()->GetLastCommittedItem(); |
| 591 ASSERT_EQ(web::UserAgentType::NONE, native_item2->GetUserAgentType()); |
| 592 navigation_manager()->AddPendingItem( |
| 593 GURL("http://www.3.com"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 594 web::NavigationInitiationType::USER_INITIATED); |
| 595 [session_controller() commitPendingItem]; |
| 596 web::NavigationItem* item3 = navigation_manager()->GetLastCommittedItem(); |
| 597 |
| 598 // Verify that |item2|'s UserAgentType is propagated to |item3|. |
| 599 EXPECT_EQ(item2->GetUserAgentType(), item3->GetUserAgentType()); |
516 } | 600 } |
517 | 601 |
518 } // namespace web | 602 } // namespace web |
OLD | NEW |