Chromium Code Reviews| 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/chrome/browser/native_app_launcher/native_app_navigation_utils.h" | |
| 6 | |
| 7 #import "ios/web/navigation/crw_session_controller.h" | |
| 8 #include "ios/web/navigation/navigation_manager_impl.h" | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
s/include/import
pkl (ping after 24h if needed)
2017/01/26 02:26:29
But navigation_manager_impl defines a C++ class, s
Eugene But (OOO till 7-30)
2017/01/26 03:10:02
Line 19 is Objective-C code.
pkl (ping after 24h if needed)
2017/01/26 19:44:24
Done.
| |
| 9 #include "ios/web/public/referrer.h" | |
| 10 #include "ios/web/public/test/web_test.h" | |
| 11 #import "ios/web/web_state/web_state_impl.h" | |
| 12 #include "ui/base/page_transition_types.h" | |
| 13 #include "url/gurl.h" | |
| 14 | |
| 15 namespace { | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
Optional nit: There is no need to put tests into a
pkl (ping after 24h if needed)
2017/01/26 02:26:28
There are differing opinions on putting test code
| |
| 16 | |
| 17 class NativeAppNavigationUtilsTest : public web::WebTest { | |
| 18 protected: | |
| 19 void SetUp() override { | |
| 20 web::WebTest::SetUp(); | |
| 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(nil, nil, NO, 0); | |
| 26 web_state->SetWebUsageEnabled(true); | |
| 27 web_state_.reset(web_state.release()); | |
| 28 } | |
| 29 | |
| 30 void TearDown() override { | |
| 31 web_state_.reset(); | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
Is there a reason for destroying web_state before
pkl (ping after 24h if needed)
2017/01/26 02:26:29
1. WebTestWithWebState does that.
2. It feels righ
| |
| 32 web::WebTest::TearDown(); | |
| 33 } | |
| 34 | |
| 35 web::WebState* web_state() { return web_state_->GetWebState(); } | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
return web_state_.get();
pkl (ping after 24h if needed)
2017/01/26 02:26:28
web_state_.get() returns a WebStateImpl* which is
| |
| 36 | |
| 37 void AddPendingEntry(const std::string& URL, ui::PageTransition transition) { | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
s/URL/url_spec ?
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
AddCommittedItem? (s/Pending/Committed, s/Entry/It
pkl (ping after 24h if needed)
2017/01/26 02:26:28
Done.
pkl (ping after 24h if needed)
2017/01/26 02:26:29
Yes, good point! Renamed to just AddItem.
| |
| 38 CRWSessionController* sessionController = | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
s/sessionController/session_controller
pkl (ping after 24h if needed)
2017/01/26 02:26:28
Done.
| |
| 39 web_state_->GetNavigationManagerImpl().GetSessionController(); | |
| 40 [sessionController addPendingEntry:GURL(URL) | |
| 41 referrer:web::Referrer() | |
| 42 transition:transition | |
| 43 rendererInitiated:NO]; | |
| 44 [sessionController commitPendingEntry]; | |
| 45 } | |
| 46 | |
| 47 private: | |
| 48 std::unique_ptr<web::WebStateImpl> web_state_; | |
| 49 }; | |
| 50 | |
| 51 // Tests that default state is not a link click. | |
| 52 TEST_F(NativeAppNavigationUtilsTest, TestEmpty) { | |
| 53 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state())); | |
| 54 } | |
| 55 | |
| 56 // URL typed by user is not a link click. | |
| 57 TEST_F(NativeAppNavigationUtilsTest, TestTypedURL) { | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
Optional nit: According to C++ Style Guide this sh
pkl (ping after 24h if needed)
2017/01/26 02:26:29
Done.
| |
| 58 AddPendingEntry("http://foo.com/page0", ui::PAGE_TRANSITION_TYPED); | |
| 59 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state())); | |
| 60 } | |
| 61 | |
| 62 // Transition state shows that user navigated via a link click. | |
| 63 TEST_F(NativeAppNavigationUtilsTest, TestLinkClicked) { | |
| 64 AddPendingEntry("http://foo.com/page0", ui::PAGE_TRANSITION_LINK); | |
| 65 EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state())); | |
| 66 } | |
| 67 | |
| 68 // Transition state shows that user navigated through clicking on a bookmark | |
| 69 // is considered *not* a link click. | |
| 70 TEST_F(NativeAppNavigationUtilsTest, TestAutoBookmark) { | |
| 71 AddPendingEntry("http://foo.com/page0", ui::PAGE_TRANSITION_AUTO_BOOKMARK); | |
| 72 EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state())); | |
|
Eugene But (OOO till 7-30)
2017/01/26 01:04:39
Sorry, missed in early reviews, when we did not ha
pkl (ping after 24h if needed)
2017/01/26 02:26:28
Done.
| |
| 73 } | |
| 74 | |
| 75 // When there are redirects along the way, redirects are skipped until the | |
| 76 // first non-redirect entry. | |
| 77 TEST_F(NativeAppNavigationUtilsTest, TestHasTypedURLWithRedirect) { | |
| 78 AddPendingEntry("http://foo.com/page0", ui::PAGE_TRANSITION_TYPED); | |
| 79 AddPendingEntry("http://foo.com/page1", ui::PAGE_TRANSITION_CLIENT_REDIRECT); | |
| 80 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state())); | |
| 81 } | |
| 82 | |
| 83 // When there are multiple redirects along the way, redirects are skipped until | |
| 84 // the first non-redirect entry. | |
| 85 TEST_F(NativeAppNavigationUtilsTest, TestHasLinkClickedWithRedirect) { | |
| 86 AddPendingEntry("http://foo.com/page0", ui::PAGE_TRANSITION_LINK); | |
| 87 AddPendingEntry("http://bar.com/page1", ui::PAGE_TRANSITION_SERVER_REDIRECT); | |
| 88 AddPendingEntry("http://zap.com/page2", ui::PAGE_TRANSITION_SERVER_REDIRECT); | |
| 89 EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state())); | |
| 90 } | |
| 91 | |
| 92 // The first non-redirect entry is tested. Earlier redirects do not matter. | |
| 93 TEST_F(NativeAppNavigationUtilsTest, TestTypedURLWithRedirectEarlier) { | |
| 94 AddPendingEntry("http://foo.com/page0", ui::PAGE_TRANSITION_LINK); | |
| 95 AddPendingEntry("http://bar.com/page1", ui::PAGE_TRANSITION_SERVER_REDIRECT); | |
| 96 AddPendingEntry("http://blah.com/page2", ui::PAGE_TRANSITION_TYPED); | |
| 97 EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state())); | |
| 98 } | |
| 99 | |
| 100 } // namespace | |
| OLD | NEW |