OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ios/web/navigation/navigation_manager_util.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #import "ios/web/navigation/crw_session_controller+private_constructors.h" |
| 9 #import "ios/web/navigation/crw_session_controller.h" |
| 10 #import "ios/web/navigation/navigation_manager_impl.h" |
| 11 #import "ios/web/public/navigation_item.h" |
| 12 #include "ios/web/public/test/fakes/test_browser_state.h" |
| 13 #include "testing/platform_test.h" |
| 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
| 19 namespace web { |
| 20 |
| 21 // Test fixture testing navigation_manager_util.h functions. |
| 22 class NavigationManagerUtilTest : public PlatformTest { |
| 23 protected: |
| 24 NavigationManagerUtilTest() |
| 25 : controller_([[CRWSessionController alloc] |
| 26 initWithBrowserState:&browser_state_]) { |
| 27 manager_.SetSessionController(controller_); |
| 28 } |
| 29 |
| 30 NavigationManagerImpl manager_; |
| 31 CRWSessionController* controller_; |
| 32 |
| 33 private: |
| 34 TestBrowserState browser_state_; |
| 35 }; |
| 36 |
| 37 // Tests GetCommittedItemWithUniqueID and GetCommittedItemIndexWithUniqueID |
| 38 // functions. |
| 39 TEST_F(NavigationManagerUtilTest, GetCommittedItemWithUniqueID) { |
| 40 // Start with NavigationManager that only has a pending item. |
| 41 manager_.AddPendingItem( |
| 42 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED, |
| 43 web::NavigationInitiationType::USER_INITIATED, |
| 44 web::NavigationManager::UserAgentOverrideOption::INHERIT); |
| 45 NavigationItem* item = manager_.GetPendingItem(); |
| 46 int unique_id = item->GetUniqueID(); |
| 47 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); |
| 48 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); |
| 49 |
| 50 // Commit that pending item. |
| 51 [controller_ commitPendingItem]; |
| 52 EXPECT_EQ(item, GetCommittedItemWithUniqueID(&manager_, unique_id)); |
| 53 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); |
| 54 |
| 55 // Remove committed item. |
| 56 manager_.RemoveItemAtIndex(0); |
| 57 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); |
| 58 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); |
| 59 } |
| 60 |
| 61 } // namespace web |
OLD | NEW |