| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "ios/web/navigation/navigation_manager_util.h" | 5 #include "ios/web/navigation/navigation_manager_util.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #import "ios/web/navigation/crw_session_controller+private_constructors.h" | 8 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
| 9 #import "ios/web/navigation/crw_session_controller.h" | 9 #import "ios/web/navigation/crw_session_controller.h" |
| 10 #import "ios/web/navigation/legacy_navigation_manager_impl.h" | 10 #import "ios/web/navigation/legacy_navigation_manager_impl.h" |
| 11 #import "ios/web/public/navigation_item.h" | 11 #import "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 #import "ios/web/test/fakes/test_navigation_manager_delegate.h" |
| 13 #include "testing/platform_test.h" | 14 #include "testing/platform_test.h" |
| 14 | 15 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 namespace web { | 20 namespace web { |
| 20 | 21 |
| 21 // Parameterized fixture testing navigation_manager_util.h functions. | 22 // Parameterized fixture testing navigation_manager_util.h functions. |
| 22 // GetParam() chooses whether to run the tests on LegacyNavigationManagerImpl | 23 // GetParam() chooses whether to run the tests on LegacyNavigationManagerImpl |
| 23 // or (the soon-to-be-added) WKBasedNavigationManagerImpl. | 24 // or (the soon-to-be-added) WKBasedNavigationManagerImpl. |
| 24 // TODO(crbug.com/734150): cleanup LegacyNavigationManagerImpl use case. | 25 // TODO(crbug.com/734150): cleanup LegacyNavigationManagerImpl use case. |
| 25 class NavigationManagerUtilTest : public PlatformTest, | 26 class NavigationManagerUtilTest : public PlatformTest, |
| 26 public ::testing::WithParamInterface<bool> { | 27 public ::testing::WithParamInterface<bool> { |
| 27 protected: | 28 protected: |
| 28 NavigationManagerUtilTest() | 29 NavigationManagerUtilTest() |
| 29 : controller_([[CRWSessionController alloc] | 30 : controller_([[CRWSessionController alloc] |
| 30 initWithBrowserState:&browser_state_]) { | 31 initWithBrowserState:&browser_state_]) { |
| 31 bool test_legacy_navigation_manager = GetParam(); | 32 bool test_legacy_navigation_manager = GetParam(); |
| 32 if (test_legacy_navigation_manager) { | 33 if (test_legacy_navigation_manager) { |
| 33 manager_.reset(new LegacyNavigationManagerImpl); | 34 manager_.reset(new LegacyNavigationManagerImpl); |
| 35 manager_->SetBrowserState(&browser_state_); |
| 36 manager_->SetDelegate(&delegate_); |
| 34 manager_->SetSessionController(controller_); | 37 manager_->SetSessionController(controller_); |
| 35 } else { | 38 } else { |
| 36 DCHECK(false) << "Not yet implemented."; | 39 DCHECK(false) << "Not yet implemented."; |
| 37 } | 40 } |
| 38 } | 41 } |
| 39 | 42 |
| 40 std::unique_ptr<NavigationManagerImpl> manager_; | 43 std::unique_ptr<NavigationManagerImpl> manager_; |
| 44 web::TestNavigationManagerDelegate delegate_; |
| 41 CRWSessionController* controller_; | 45 CRWSessionController* controller_; |
| 42 | 46 |
| 43 private: | 47 private: |
| 44 TestBrowserState browser_state_; | 48 TestBrowserState browser_state_; |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 // Tests GetCommittedItemWithUniqueID, GetCommittedItemIndexWithUniqueID and | 51 // Tests GetCommittedItemWithUniqueID, GetCommittedItemIndexWithUniqueID and |
| 48 // GetItemWithUniqueID functions. | 52 // GetItemWithUniqueID functions. |
| 49 // TODO(crbug.com/733658): test was incorrectly moved to a separate target | 53 TEST_P(NavigationManagerUtilTest, GetCommittedItemWithUniqueID) { |
| 50 // and not run and a refactoring broke it. Disable until the issue is fixed. | |
| 51 TEST_P(NavigationManagerUtilTest, DISABLED_GetCommittedItemWithUniqueID) { | |
| 52 // Start with NavigationManager that only has a pending item. | 54 // Start with NavigationManager that only has a pending item. |
| 53 manager_->AddPendingItem( | 55 manager_->AddPendingItem( |
| 54 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED, | 56 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 55 web::NavigationInitiationType::USER_INITIATED, | 57 web::NavigationInitiationType::USER_INITIATED, |
| 56 web::NavigationManager::UserAgentOverrideOption::INHERIT); | 58 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 57 NavigationItem* item = manager_->GetPendingItem(); | 59 NavigationItem* item = manager_->GetPendingItem(); |
| 58 int unique_id = item->GetUniqueID(); | 60 int unique_id = item->GetUniqueID(); |
| 59 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id)); | 61 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id)); |
| 60 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id)); | 62 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id)); |
| 61 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); | 63 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); |
| 62 | 64 |
| 63 // Commit that pending item. | 65 // Commit that pending item. |
| 64 [controller_ commitPendingItem]; | 66 manager_->CommitPendingItem(); |
| 65 EXPECT_EQ(item, GetCommittedItemWithUniqueID(manager_.get(), unique_id)); | 67 EXPECT_EQ(item, GetCommittedItemWithUniqueID(manager_.get(), unique_id)); |
| 66 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id)); | 68 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id)); |
| 67 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); | 69 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); |
| 68 | 70 |
| 69 // Remove committed item. | 71 // Commit another navigation so that the current item is updated. This allows |
| 72 // for removing the item with |unique_id|. |
| 73 manager_->AddPendingItem( |
| 74 GURL("http://test.org"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 75 web::NavigationInitiationType::USER_INITIATED, |
| 76 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 77 manager_->CommitPendingItem(); |
| 70 manager_->RemoveItemAtIndex(0); | 78 manager_->RemoveItemAtIndex(0); |
| 71 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id)); | 79 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id)); |
| 72 EXPECT_FALSE(GetItemWithUniqueID(manager_.get(), unique_id)); | 80 EXPECT_FALSE(GetItemWithUniqueID(manager_.get(), unique_id)); |
| 73 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); | 81 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); |
| 74 | 82 |
| 75 // Add transient item. | 83 // Add transient item. |
| 76 [controller_ addTransientItemWithURL:GURL("http://chromium.org")]; | 84 [controller_ addTransientItemWithURL:GURL("http://chromium.org")]; |
| 77 item = manager_->GetTransientItem(); | 85 item = manager_->GetTransientItem(); |
| 86 unique_id = item->GetUniqueID(); |
| 78 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id)); | 87 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id)); |
| 79 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id)); | 88 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id)); |
| 80 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); | 89 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id)); |
| 81 } | 90 } |
| 82 | 91 |
| 83 INSTANTIATE_TEST_CASE_P( | 92 INSTANTIATE_TEST_CASE_P( |
| 84 ProgrammaticNavigationManagerUtilTest, | 93 ProgrammaticNavigationManagerUtilTest, |
| 85 NavigationManagerUtilTest, | 94 NavigationManagerUtilTest, |
| 86 ::testing::Values(true /* test_legacy_navigation_manager */)); | 95 ::testing::Values(true /* test_legacy_navigation_manager */)); |
| 87 | 96 |
| 88 } // namespace web | 97 } // namespace web |
| OLD | NEW |