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

Unified Diff: ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm

Issue 2650563002: Pass WebState to NativeAppNavigationController (Closed)
Patch Set: fixed import vs. include Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
diff --git a/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm b/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1efbbfa8917ea6ae34ae5bdc1d2481ca4b80f927
--- /dev/null
+++ b/ios/chrome/browser/native_app_launcher/native_app_navigation_util_unittest.mm
@@ -0,0 +1,100 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h"
+
+#import "ios/web/navigation/crw_session_controller.h"
+#import "ios/web/navigation/navigation_manager_impl.h"
+#include "ios/web/public/referrer.h"
+#include "ios/web/public/test/web_test.h"
+#import "ios/web/web_state/web_state_impl.h"
+#include "ui/base/page_transition_types.h"
+#include "url/gurl.h"
+
+namespace {
+
+class NativeAppNavigationUtilsTest : public web::WebTest {
+ protected:
+ void SetUp() override {
+ web::WebTest::SetUp();
+ // WebStateImpl object is needed here to have access to CRWSessionController
+ // for setting up NavigationManager entries.
+ std::unique_ptr<web::WebStateImpl> web_state(
+ new web::WebStateImpl(GetBrowserState()));
+ web_state->GetNavigationManagerImpl().InitializeSession(nil, nil, NO, 0);
+ web_state->SetWebUsageEnabled(true);
+ web_state_.reset(web_state.release());
+ }
+
+ void TearDown() override {
+ web_state_.reset();
+ web::WebTest::TearDown();
+ }
+
+ web::WebState* web_state() { return web_state_->GetWebState(); }
+
+ void AddItem(const std::string& url_spec, ui::PageTransition transition) {
+ CRWSessionController* session_controller =
+ web_state_->GetNavigationManagerImpl().GetSessionController();
+ [session_controller addPendingEntry:GURL(url_spec)
+ referrer:web::Referrer()
+ transition:transition
+ rendererInitiated:NO];
+ [session_controller commitPendingEntry];
+ }
+
+ private:
+ std::unique_ptr<web::WebStateImpl> web_state_;
+};
+
+// Tests that default state is not a link click.
+TEST_F(NativeAppNavigationUtilsTest, TestEmpty) {
+ EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+// URL typed by user is not a link click.
+TEST_F(NativeAppNavigationUtilsTest, TestTypedUrl) {
+ AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_TYPED);
+ EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+// Transition state shows that user navigated via a link click.
+TEST_F(NativeAppNavigationUtilsTest, TestLinkClicked) {
+ AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_LINK);
+ EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+// Transition state shows that user navigated through clicking on a bookmark
+// is considered *not* a link click.
+TEST_F(NativeAppNavigationUtilsTest, TestAutoBookmark) {
+ AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_AUTO_BOOKMARK);
+ EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+// When there are redirects along the way, redirects are skipped until the
+// first non-redirect entry.
+TEST_F(NativeAppNavigationUtilsTest, TestHasTypedUrlWithRedirect) {
+ AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_TYPED);
+ AddItem("http://foo.com/page1", ui::PAGE_TRANSITION_CLIENT_REDIRECT);
+ EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+// When there are multiple redirects along the way, redirects are skipped until
+// the first non-redirect entry.
+TEST_F(NativeAppNavigationUtilsTest, TestHasLinkClickedWithRedirect) {
+ AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_LINK);
+ AddItem("http://bar.com/page1", ui::PAGE_TRANSITION_SERVER_REDIRECT);
+ AddItem("http://zap.com/page2", ui::PAGE_TRANSITION_SERVER_REDIRECT);
+ EXPECT_TRUE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+// The first non-redirect entry is tested. Earlier redirects do not matter.
+TEST_F(NativeAppNavigationUtilsTest, TestTypedUrlWithRedirectEarlier) {
+ AddItem("http://foo.com/page0", ui::PAGE_TRANSITION_LINK);
+ AddItem("http://bar.com/page1", ui::PAGE_TRANSITION_SERVER_REDIRECT);
+ AddItem("http://blah.com/page2", ui::PAGE_TRANSITION_TYPED);
+ EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
+}
+
+} // namespace
« no previous file with comments | « ios/chrome/browser/native_app_launcher/native_app_navigation_util.mm ('k') | ios/chrome/browser/tabs/tab.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698