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

Side by Side Diff: ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm

Issue 2742173002: Removed use of CRWSessionController from NativeAppNavigationUtilsTest. (Closed)
Patch Set: removed unneeded includes Created 3 years, 9 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 | « ios/chrome/browser/native_app_launcher/DEPS ('k') | 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/chrome/browser/native_app_launcher/native_app_navigation_util.h" 5 #include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h"
6 6
7 #import "ios/web/navigation/crw_session_controller.h" 7 #include "base/memory/ptr_util.h"
8 #import "ios/web/navigation/navigation_manager_impl.h" 8 #import "ios/web/public/navigation_item.h"
9 #include "ios/web/public/referrer.h" 9 #import "ios/web/public/navigation_item_list.h"
Eugene But (OOO till 7-30) 2017/03/13 21:05:40 nit: s/import/include
pkl (ping after 24h if needed) 2017/03/14 02:12:48 Acknowledged.
10 #include "ios/web/public/test/web_test.h" 10 #import "ios/web/public/test/fakes/test_navigation_manager.h"
11 #import "ios/web/web_state/web_state_impl.h" 11 #import "ios/web/public/test/fakes/test_web_state.h"
12 #include "testing/platform_test.h"
12 #include "ui/base/page_transition_types.h" 13 #include "ui/base/page_transition_types.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace { 16 // Overrides underlying NavigationManager methods used by IsLinkNavigation().
16 17 class TestNavigationManager : public web::TestNavigationManager {
17 class NativeAppNavigationUtilsTest : public web::WebTest { 18 public:
18 protected: 19 int GetCurrentItemIndex() const override {
19 void SetUp() override { 20 // For testing, just return the last item. Returns -1 if |items_| is empty.
20 web::WebTest::SetUp(); 21 return items_.size() - 1;
21 // WebStateImpl object is needed here to have access to CRWSessionController
22 // for setting up NavigationManager entries.
23 std::unique_ptr<web::WebStateImpl> web_state(
24 new web::WebStateImpl(GetBrowserState()));
25 web_state->GetNavigationManagerImpl().InitializeSession(NO);
26 web_state->SetWebUsageEnabled(true);
27 web_state_.reset(web_state.release());
28 } 22 }
29 23
30 void TearDown() override { 24 web::NavigationItem* GetItemAtIndex(size_t index) const override {
31 web_state_.reset(); 25 return items_[index].get();
32 web::WebTest::TearDown();
33 } 26 }
34 27
35 web::WebState* web_state() { return web_state_->GetWebState(); } 28 // Adds a new navigation item of |transition| type at the end of this
36 29 // navigation manager.
37 void AddItem(const std::string& url_spec, ui::PageTransition transition) { 30 void AddItem(const std::string& url_spec, ui::PageTransition transition) {
Eugene But (OOO till 7-30) 2017/03/13 21:05:41 This could be useful for other tests. Could you pl
pkl (ping after 24h if needed) 2017/03/14 02:12:48 Moved to test_navigation_manager.mm
38 CRWSessionController* session_controller = 31 items_.push_back(web::NavigationItem::Create());
39 web_state_->GetNavigationManagerImpl().GetSessionController(); 32 items_.back()->SetTransitionType(transition);
40 web_state_->GetNavigationManagerImpl().AddPendingItem( 33 items_.back()->SetURL(GURL(url_spec));
41 GURL(url_spec), web::Referrer(), transition,
42 web::NavigationInitiationType::USER_INITIATED);
43 [session_controller commitPendingItem];
44 } 34 }
45 35
46 private: 36 private:
47 std::unique_ptr<web::WebStateImpl> web_state_; 37 web::ScopedNavigationItemList items_;
38 };
39
40 // Tests the implementation of IsLinkNavigation(). The function being tested
41 // uses public NavigationManager interfaces and can be tested by using
42 // TestNavigationManager that implements the same interface.
43 class NativeAppNavigationUtilsTest : public PlatformTest {
44 protected:
45 void SetUp() override {
46 PlatformTest::SetUp();
47 std::unique_ptr<TestNavigationManager> test_navigation_manager =
48 base::MakeUnique<TestNavigationManager>();
49 test_navigation_manager_ = test_navigation_manager.get();
50 test_web_state_.SetNavigationManager(std::move(test_navigation_manager));
51 }
52
53 web::WebState* web_state() { return &test_web_state_; }
54
55 // Adds a navigation item of |transition| type to current WebState.
56 void AddItem(const std::string& url_spec, ui::PageTransition transition) {
57 test_navigation_manager_->AddItem(url_spec, transition);
58 }
59
60 private:
61 TestNavigationManager* test_navigation_manager_;
62 web::TestWebState test_web_state_;
48 }; 63 };
49 64
50 // Tests that default state is not a link click. 65 // Tests that default state is not a link click.
51 TEST_F(NativeAppNavigationUtilsTest, TestEmpty) { 66 TEST_F(NativeAppNavigationUtilsTest, TestEmpty) {
52 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state())); 67 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
53 } 68 }
54 69
55 // URL typed by user is not a link click. 70 // URL typed by user is not a link click.
56 TEST_F(NativeAppNavigationUtilsTest, TestTypedUrl) { 71 TEST_F(NativeAppNavigationUtilsTest, TestTypedUrl) {
57 AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_TYPED); 72 AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_TYPED);
(...skipping 30 matching lines...) Expand all
88 EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state())); 103 EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state()));
89 } 104 }
90 105
91 // The first non-redirect entry is tested. Earlier redirects do not matter. 106 // The first non-redirect entry is tested. Earlier redirects do not matter.
92 TEST_F(NativeAppNavigationUtilsTest, TestTypedUrlWithRedirectEarlier) { 107 TEST_F(NativeAppNavigationUtilsTest, TestTypedUrlWithRedirectEarlier) {
93 AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_LINK); 108 AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_LINK);
94 AddItem("http://bar.com/page1", ui::PAGE_TRANSITION_SERVER_REDIRECT); 109 AddItem("http://bar.com/page1", ui::PAGE_TRANSITION_SERVER_REDIRECT);
95 AddItem("http://blah.com/page2", ui::PAGE_TRANSITION_TYPED); 110 AddItem("http://blah.com/page2", ui::PAGE_TRANSITION_TYPED);
96 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state())); 111 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
97 } 112 }
98
99 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/native_app_launcher/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698