Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1442)

Side by Side Diff: ios/web/navigation/navigation_manager_util_unittest.mm

Issue 2944093002: Extract NavigationManagerImpl interface for navigation experiment. (Closed)
Patch Set: Patch for landing Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/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 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 14
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 16 #error "This file requires ARC support."
17 #endif 17 #endif
18 18
19 namespace web { 19 namespace web {
20 20
21 // Test fixture testing navigation_manager_util.h functions. 21 // Parameterized fixture testing navigation_manager_util.h functions.
22 class NavigationManagerUtilTest : public PlatformTest { 22 // GetParam() chooses whether to run the tests on LegacyNavigationManagerImpl
23 // or (the soon-to-be-added) WKBasedNavigationManagerImpl.
24 // TODO(crbug.com/734150): cleanup LegacyNavigationManagerImpl use case.
25 class NavigationManagerUtilTest : public PlatformTest,
26 public ::testing::WithParamInterface<bool> {
23 protected: 27 protected:
24 NavigationManagerUtilTest() 28 NavigationManagerUtilTest()
25 : controller_([[CRWSessionController alloc] 29 : controller_([[CRWSessionController alloc]
26 initWithBrowserState:&browser_state_]) { 30 initWithBrowserState:&browser_state_]) {
27 manager_.SetSessionController(controller_); 31 bool test_legacy_navigation_manager = GetParam();
32 if (test_legacy_navigation_manager) {
33 manager_.reset(new LegacyNavigationManagerImpl);
34 manager_->SetSessionController(controller_);
35 } else {
36 DCHECK(false) << "Not yet implemented.";
37 }
28 } 38 }
29 39
30 NavigationManagerImpl manager_; 40 std::unique_ptr<NavigationManagerImpl> manager_;
31 CRWSessionController* controller_; 41 CRWSessionController* controller_;
32 42
33 private: 43 private:
34 TestBrowserState browser_state_; 44 TestBrowserState browser_state_;
35 }; 45 };
36 46
37 // Tests GetCommittedItemWithUniqueID, GetCommittedItemIndexWithUniqueID and 47 // Tests GetCommittedItemWithUniqueID, GetCommittedItemIndexWithUniqueID and
38 // GetItemWithUniqueID functions. 48 // GetItemWithUniqueID functions.
39 // TODO(crbug.com/733658): test was incorrectly moved to a separate target 49 // TODO(crbug.com/733658): test was incorrectly moved to a separate target
40 // and not run and a refactoring broke it. Disable until the issue is fixed. 50 // and not run and a refactoring broke it. Disable until the issue is fixed.
41 TEST_F(NavigationManagerUtilTest, DISABLED_GetCommittedItemWithUniqueID) { 51 TEST_P(NavigationManagerUtilTest, DISABLED_GetCommittedItemWithUniqueID) {
42 // Start with NavigationManager that only has a pending item. 52 // Start with NavigationManager that only has a pending item.
43 manager_.AddPendingItem( 53 manager_->AddPendingItem(
44 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED, 54 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED,
45 web::NavigationInitiationType::USER_INITIATED, 55 web::NavigationInitiationType::USER_INITIATED,
46 web::NavigationManager::UserAgentOverrideOption::INHERIT); 56 web::NavigationManager::UserAgentOverrideOption::INHERIT);
47 NavigationItem* item = manager_.GetPendingItem(); 57 NavigationItem* item = manager_->GetPendingItem();
48 int unique_id = item->GetUniqueID(); 58 int unique_id = item->GetUniqueID();
49 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); 59 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id));
50 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id)); 60 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id));
51 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 61 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id));
52 62
53 // Commit that pending item. 63 // Commit that pending item.
54 [controller_ commitPendingItem]; 64 [controller_ commitPendingItem];
55 EXPECT_EQ(item, GetCommittedItemWithUniqueID(&manager_, unique_id)); 65 EXPECT_EQ(item, GetCommittedItemWithUniqueID(manager_.get(), unique_id));
56 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id)); 66 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id));
57 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 67 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id));
58 68
59 // Remove committed item. 69 // Remove committed item.
60 manager_.RemoveItemAtIndex(0); 70 manager_->RemoveItemAtIndex(0);
61 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); 71 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id));
62 EXPECT_FALSE(GetItemWithUniqueID(&manager_, unique_id)); 72 EXPECT_FALSE(GetItemWithUniqueID(manager_.get(), unique_id));
63 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 73 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id));
64 74
65 // Add transient item. 75 // Add transient item.
66 [controller_ addTransientItemWithURL:GURL("http://chromium.org")]; 76 [controller_ addTransientItemWithURL:GURL("http://chromium.org")];
67 item = manager_.GetTransientItem(); 77 item = manager_->GetTransientItem();
68 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); 78 EXPECT_FALSE(GetCommittedItemWithUniqueID(manager_.get(), unique_id));
69 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id)); 79 EXPECT_EQ(item, GetItemWithUniqueID(manager_.get(), unique_id));
70 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 80 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(manager_.get(), unique_id));
71 } 81 }
72 82
83 INSTANTIATE_TEST_CASE_P(
84 ProgrammaticNavigationManagerUtilTest,
85 NavigationManagerUtilTest,
86 ::testing::Values(true /* test_legacy_navigation_manager */));
87
73 } // namespace web 88 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/navigation/navigation_manager_impl_unittest.mm ('k') | ios/web/navigation/session_storage_builder.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698