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

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

Issue 2942103002: Fix failing NavigationManagerUtil test that wasn't being run. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_delegate.h"
10 #import "ios/web/navigation/navigation_manager_impl.h" 11 #import "ios/web/navigation/navigation_manager_impl.h"
11 #import "ios/web/public/navigation_item.h" 12 #import "ios/web/public/navigation_item.h"
12 #include "ios/web/public/test/fakes/test_browser_state.h" 13 #include "ios/web/public/test/fakes/test_browser_state.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
22 class UtilTestNavigationManagerDelegate : public NavigationManagerDelegate {
Eugene But (OOO till 7-30) 2017/06/16 03:41:06 Would it make sense to move it to web/public/test/
kkhorimoto 2017/06/21 20:50:18 NavigationManagerDelegate is not a public interfac
23 public:
24 void GoToIndex(int index) override {}
25 void LoadURLWithParams(const NavigationManager::WebLoadParams&) override {}
26 void Reload() override {}
27 void OnNavigationItemsPruned(size_t pruned_item_count) override {}
28 void OnNavigationItemChanged() override {}
29 void OnNavigationItemCommitted(
30 const LoadCommittedDetails& load_details) override {}
31 WebState* GetWebState() override { return nullptr; }
32 };
33
21 // Test fixture testing navigation_manager_util.h functions. 34 // Test fixture testing navigation_manager_util.h functions.
22 class NavigationManagerUtilTest : public PlatformTest { 35 class NavigationManagerUtilTest : public PlatformTest {
23 protected: 36 protected:
24 NavigationManagerUtilTest() 37 NavigationManagerUtilTest()
25 : controller_([[CRWSessionController alloc] 38 : controller_([[CRWSessionController alloc]
26 initWithBrowserState:&browser_state_]) { 39 initWithBrowserState:&browser_state_]) {
40 manager_.SetBrowserState(&browser_state_);
41 manager_.SetDelegate(&delegate_);
27 manager_.SetSessionController(controller_); 42 manager_.SetSessionController(controller_);
28 } 43 }
29 44
30 NavigationManagerImpl manager_; 45 NavigationManagerImpl manager_;
46 UtilTestNavigationManagerDelegate delegate_;
31 CRWSessionController* controller_; 47 CRWSessionController* controller_;
32 48
33 private: 49 private:
34 TestBrowserState browser_state_; 50 TestBrowserState browser_state_;
35 }; 51 };
36 52
37 // Tests GetCommittedItemWithUniqueID, GetCommittedItemIndexWithUniqueID and 53 // Tests GetCommittedItemWithUniqueID, GetCommittedItemIndexWithUniqueID and
38 // GetItemWithUniqueID functions. 54 // GetItemWithUniqueID functions.
39 TEST_F(NavigationManagerUtilTest, GetCommittedItemWithUniqueID) { 55 TEST_F(NavigationManagerUtilTest, GetCommittedItemWithUniqueID) {
sdefresne 2017/06/16 13:39:43 Once you rebase, you'll have to change this line t
kkhorimoto 2017/06/21 20:50:18 Done.
40 // Start with NavigationManager that only has a pending item. 56 // Start with NavigationManager that only has a pending item.
41 manager_.AddPendingItem( 57 manager_.AddPendingItem(
42 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED, 58 GURL("http://chromium.org"), Referrer(), ui::PAGE_TRANSITION_TYPED,
43 web::NavigationInitiationType::USER_INITIATED, 59 web::NavigationInitiationType::USER_INITIATED,
44 web::NavigationManager::UserAgentOverrideOption::INHERIT); 60 web::NavigationManager::UserAgentOverrideOption::INHERIT);
45 NavigationItem* item = manager_.GetPendingItem(); 61 NavigationItem* item = manager_.GetPendingItem();
46 int unique_id = item->GetUniqueID(); 62 int unique_id = item->GetUniqueID();
47 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); 63 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id));
48 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id)); 64 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id));
49 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 65 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id));
50 66
51 // Commit that pending item. 67 // Commit that pending item.
52 [controller_ commitPendingItem]; 68 manager_.CommitPendingItem();
53 EXPECT_EQ(item, GetCommittedItemWithUniqueID(&manager_, unique_id)); 69 EXPECT_EQ(item, GetCommittedItemWithUniqueID(&manager_, unique_id));
54 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id)); 70 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id));
55 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 71 EXPECT_EQ(0, GetCommittedItemIndexWithUniqueID(&manager_, unique_id));
56 72
57 // Remove committed item. 73 // Commit another navigation so that the current item is updated. This allows
74 // for removing the item with |unique_id|.
75 manager_.AddPendingItem(
76 GURL("http://test.org"), Referrer(), ui::PAGE_TRANSITION_TYPED,
77 web::NavigationInitiationType::USER_INITIATED,
78 web::NavigationManager::UserAgentOverrideOption::INHERIT);
79 manager_.CommitPendingItem();
58 manager_.RemoveItemAtIndex(0); 80 manager_.RemoveItemAtIndex(0);
59 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); 81 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id));
60 EXPECT_FALSE(GetItemWithUniqueID(&manager_, unique_id)); 82 EXPECT_FALSE(GetItemWithUniqueID(&manager_, unique_id));
61 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 83 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id));
62 84
63 // Add transient item. 85 // Add transient item.
64 [controller_ addTransientItemWithURL:GURL("http://chromium.org")]; 86 [controller_ addTransientItemWithURL:GURL("http://chromium.org")];
65 item = manager_.GetTransientItem(); 87 item = manager_.GetTransientItem();
88 unique_id = item->GetUniqueID();
66 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id)); 89 EXPECT_FALSE(GetCommittedItemWithUniqueID(&manager_, unique_id));
67 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id)); 90 EXPECT_EQ(item, GetItemWithUniqueID(&manager_, unique_id));
68 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id)); 91 EXPECT_EQ(-1, GetCommittedItemIndexWithUniqueID(&manager_, unique_id));
69 } 92 }
70 93
71 } // namespace web 94 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698