Commit 9afd36cf authored by pkl's avatar pkl Committed by Commit Bot

Removed NativeAppNavigationController and related code

These are no longer being used.

BUG=721921

Review-Url: https://codereview.chromium.org/2897213002
Cr-Commit-Position: refs/heads/master@{#481857}
parent ba97ce52
......@@ -183,7 +183,6 @@ source_set("app_internal") {
"//ios/chrome/browser/memory",
"//ios/chrome/browser/metrics",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/net",
"//ios/chrome/browser/omaha",
"//ios/chrome/browser/prefs",
......
......@@ -92,7 +92,6 @@ source_set("browsing_data_internal") {
"//components/signin/ios/browser",
"//ios/chrome/browser:browser_internal",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/sessions:serialisation",
"//ios/chrome/browser/signin",
"//ios/chrome/browser/snapshots",
......
......@@ -48,65 +48,3 @@ source_set("unit_tests") {
"//url",
]
}
source_set("native_app_launcher_internal") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"native_app_navigation_controller.h",
"native_app_navigation_controller.mm",
"native_app_navigation_util.h",
"native_app_navigation_util.mm",
]
deps = [
":native_app_launcher",
"//base",
"//components/image_fetcher/ios",
"//components/infobars/core",
"//ios/chrome/browser",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/net",
"//ios/chrome/browser/store_kit",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/web:web",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/native_app_launcher",
"//ios/public/provider/chrome/browser/signin",
"//ios/public/provider/chrome/browser/ui",
"//ios/web",
"//net",
"//ui/base",
"//url",
]
libs = [ "StoreKit.framework" ]
}
source_set("unit_tests_internal") {
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"native_app_navigation_controller_unittest.mm",
"native_app_navigation_util_unittest.mm",
]
deps = [
":native_app_launcher",
":native_app_launcher_internal",
"//base",
"//base/test:test_support",
"//components/infobars/core",
"//ios/chrome/browser",
"//ios/chrome/browser/infobars:infobars",
"//ios/chrome/browser/web:test_support",
"//ios/chrome/test:test_support",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser:test_support",
"//ios/public/provider/chrome/browser/native_app_launcher:test_support",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/web",
"//ios/web/public/test/fakes",
"//net:test_support",
"//testing/gmock",
"//testing/gtest",
"//ui/base",
"//url",
]
}
// Copyright 2012 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.
#ifndef IOS_CHROME_BROWSER_NATIVE_APP_LAUNCHER_NATIVE_APP_NAVIGATION_CONTROLLER_H_
#define IOS_CHROME_BROWSER_NATIVE_APP_LAUNCHER_NATIVE_APP_NAVIGATION_CONTROLLER_H_
#import <Foundation/Foundation.h>
namespace web {
class WebState;
} // namespace web
// NativeAppNavigationController brings up a GAL Infobar if the webpage directs
// it to do so and there are no other circumstances that would suppress its
// display.
@interface NativeAppNavigationController : NSObject
- (instancetype)initWithWebState:(web::WebState*)webState
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
// Copies the list of applications possibly being installed and register to be
// notified of their installation.
- (void)copyStateFrom:(NativeAppNavigationController*)controller;
@end
#endif // IOS_CHROME_BROWSER_NATIVE_APP_LAUNCHER_NATIVE_APP_NAVIGATION_CONTROLLER_H_
// Copyright 2012 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.
#import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller.h"
#import <StoreKit/StoreKit.h>
#include "base/memory/ptr_util.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/threading/sequenced_worker_pool.h"
#include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
#include "components/infobars/core/infobar_manager.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/installation_notifier.h"
#include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h"
#import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller_protocol.h"
#include "ios/chrome/browser/native_app_launcher/native_app_navigation_util.h"
#import "ios/chrome/browser/open_url_util.h"
#import "ios/chrome/browser/store_kit/store_kit_tab_helper.h"
#import "ios/chrome/browser/tabs/legacy_tab_helper.h"
#import "ios/chrome/browser/tabs/tab.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metadata.h"
#import "ios/public/provider/chrome/browser/native_app_launcher/native_app_types.h"
#import "ios/public/provider/chrome/browser/native_app_launcher/native_app_whitelist_manager.h"
#include "ios/web/public/browser_state.h"
#include "ios/web/public/web_state/web_state.h"
#import "ios/web/public/web_state/web_state_observer_bridge.h"
#include "ios/web/public/web_thread.h"
#import "net/base/mac/url_conversions.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using base::UserMetricsAction;
@interface NativeAppNavigationController ()<
CRWWebStateObserver,
NativeAppNavigationControllerProtocol>
// Shows a native app infobar by looking at the page's URL and by checking
// wheter that infobar should be bypassed or not.
- (void)showInfoBarIfNecessary;
// Returns a pointer to the NSMutableSet of |_appsPossiblyBeingInstalled|
- (NSMutableSet*)appsPossiblyBeingInstalled;
// Records what type of infobar was opened.
- (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type
onLinkNavigation:(BOOL)isLinkNavigation;
@end
@implementation NativeAppNavigationController {
// WebState provides access to the *TabHelper objects.
web::WebState* _webState;
// ImageFetcher needed to fetch the icons.
std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher;
id<NativeAppMetadata> _metadata;
// A set of appIds encoded as NSStrings.
NSMutableSet* _appsPossiblyBeingInstalled;
// Allows this class to subscribe for CRWWebStateObserver callbacks.
std::unique_ptr<web::WebStateObserverBridge> _webStateObserver;
}
// Designated initializer. Use this instead of -init.
- (instancetype)initWithWebState:(web::WebState*)webState {
self = [super init];
if (self) {
DCHECK(webState);
_webState = webState;
_imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>(
_webState->GetBrowserState()->GetRequestContext(),
web::WebThread::GetBlockingPool());
_appsPossiblyBeingInstalled = [[NSMutableSet alloc] init];
_webStateObserver =
base::MakeUnique<web::WebStateObserverBridge>(webState, self);
}
return self;
}
- (void)copyStateFrom:(NativeAppNavigationController*)controller {
DCHECK(controller);
_appsPossiblyBeingInstalled = [[NSMutableSet alloc]
initWithSet:[controller appsPossiblyBeingInstalled]];
for (NSString* appIdString in _appsPossiblyBeingInstalled) {
DCHECK([appIdString isKindOfClass:[NSString class]]);
NSURL* appURL =
[ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager()
schemeForAppId:appIdString];
[[InstallationNotifier sharedInstance]
registerForInstallationNotifications:self
withSelector:@selector(appDidInstall:)
forScheme:[appURL scheme]];
}
[self showInfoBarIfNecessary];
}
- (void)dealloc {
[[InstallationNotifier sharedInstance] unregisterForNotifications:self];
}
- (NSMutableSet*)appsPossiblyBeingInstalled {
return _appsPossiblyBeingInstalled;
}
- (void)showInfoBarIfNecessary {
// Find a potential matching native app.
GURL pageURL = _webState->GetLastCommittedURL();
_metadata = [ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager()
nativeAppForURL:pageURL];
if (!_metadata || [_metadata shouldBypassInfoBars])
return;
// Select the infobar type.
NativeAppControllerType type;
bool isLinkNavigation = native_app_launcher::IsLinkNavigation(_webState);
if ([_metadata canOpenURL:pageURL]) { // App is installed.
type = isLinkNavigation && ![_metadata shouldAutoOpenLinks]
? NATIVE_APP_OPEN_POLICY_CONTROLLER
: NATIVE_APP_LAUNCHER_CONTROLLER;
} else { // App is not installed.
// Check if the user already opened the store for this app.
if ([_appsPossiblyBeingInstalled containsObject:[_metadata appId]])
return;
type = NATIVE_APP_INSTALLER_CONTROLLER;
}
// Inform the metadata that an infobar of |type| will be shown so that metrics
// and ignored behavior can be handled.
[_metadata willBeShownInInfobarOfType:type];
// Display the proper infobar.
infobars::InfoBarManager* infoBarManager =
InfoBarManagerImpl::FromWebState(_webState);
NativeAppInfoBarDelegate::Create(infoBarManager, self, pageURL, type);
[self recordInfobarDisplayedOfType:type onLinkNavigation:isLinkNavigation];
}
- (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type
onLinkNavigation:(BOOL)isLinkNavigation {
switch (type) {
case NATIVE_APP_INSTALLER_CONTROLLER:
base::RecordAction(
isLinkNavigation
? UserMetricsAction("MobileGALInstallInfoBarLinkNavigation")
: UserMetricsAction("MobileGALInstallInfoBarDirectNavigation"));
break;
case NATIVE_APP_LAUNCHER_CONTROLLER:
base::RecordAction(UserMetricsAction("MobileGALLaunchInfoBar"));
break;
case NATIVE_APP_OPEN_POLICY_CONTROLLER:
base::RecordAction(UserMetricsAction("MobileGALOpenPolicyInfoBar"));
break;
default:
NOTREACHED();
break;
}
}
#pragma mark - NativeAppNavigationControllerProtocol methods
- (NSString*)appId {
return [_metadata appId];
}
- (NSString*)appName {
return [_metadata appName];
}
- (void)fetchSmallIconWithCompletionBlock:(void (^)(UIImage*))block {
[_metadata fetchSmallIconWithImageFetcher:_imageFetcher.get()
completionBlock:block];
}
- (void)openStore {
// Register to get a notification when the app is installed.
[[InstallationNotifier sharedInstance]
registerForInstallationNotifications:self
withSelector:@selector(appDidInstall:)
forScheme:[_metadata anyScheme]];
NSString* appIdString = [self appId];
// Defensively early return if native app metadata returns an nil string for
// appId which can cause subsequent -addObject: to throw exceptions.
if (![appIdString length])
return;
DCHECK(![_appsPossiblyBeingInstalled containsObject:appIdString]);
[_appsPossiblyBeingInstalled addObject:appIdString];
StoreKitTabHelper* tabHelper = StoreKitTabHelper::FromWebState(_webState);
if (tabHelper)
tabHelper->OpenAppStore(appIdString);
}
- (void)launchApp:(const GURL&)URL {
// TODO(crbug.com/353957): Pass the ChromeIdentity to
// -launchURLWithURL:identity:
GURL launchURL([_metadata launchURLWithURL:URL identity:nil]);
if (launchURL.is_valid()) {
OpenUrlWithCompletionHandler(net::NSURLWithGURL(launchURL), nil);
}
}
- (void)updateMetadataWithUserAction:(NativeAppActionType)userAction {
[_metadata updateWithUserAction:userAction];
}
#pragma mark - CRWWebStateObserver methods
- (void)webState:(web::WebState*)webState didLoadPageWithSuccess:(BOOL)success {
Tab* tab = LegacyTabHelper::GetTabForWebState(_webState);
if (success && ![tab isPrerenderTab])
[self showInfoBarIfNecessary];
}
- (void)webStateDestroyed:(web::WebState*)webState {
_webState = nullptr;
_webStateObserver.reset();
}
#pragma mark - Private methods
- (void)appDidInstall:(NSNotification*)notification {
[self removeAppFromNotification:notification];
[self showInfoBarIfNecessary];
}
- (void)removeAppFromNotification:(NSNotification*)notification {
DCHECK([[notification object] isKindOfClass:[InstallationNotifier class]]);
NSString* schemeOfInstalledApp = [notification name];
__block NSString* appIDToRemove = nil;
[_appsPossiblyBeingInstalled
enumerateObjectsUsingBlock:^(id appID, BOOL* stop) {
NSURL* appURL =
[ios::GetChromeBrowserProvider()->GetNativeAppWhitelistManager()
schemeForAppId:appID];
if ([[appURL scheme] isEqualToString:schemeOfInstalledApp]) {
appIDToRemove = appID;
*stop = YES;
}
}];
DCHECK(appIDToRemove);
[_appsPossiblyBeingInstalled removeObject:appIDToRemove];
}
@end
// Copyright 2012 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 <memory>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/user_metrics.h"
#include "base/strings/utf_string_conversions.h"
#include "ios/chrome/browser/infobars/infobar_manager_impl.h"
#import "ios/chrome/browser/installation_notifier.h"
#include "ios/chrome/browser/native_app_launcher/native_app_infobar_delegate.h"
#import "ios/chrome/browser/native_app_launcher/native_app_navigation_controller.h"
#import "ios/chrome/browser/web/chrome_web_test.h"
#include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/native_app_launcher/fake_native_app_metadata.h"
#import "ios/public/provider/chrome/browser/native_app_launcher/fake_native_app_whitelist_manager.h"
#include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h"
#import "testing/gtest_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface NativeAppNavigationController (Testing)
- (void)recordInfobarDisplayedOfType:(NativeAppControllerType)type
onLinkNavigation:(BOOL)isLinkNavigation;
- (NSMutableSet*)appsPossiblyBeingInstalled;
- (void)removeAppFromNotification:(NSNotification*)notification;
@end
namespace {
class FakeChromeBrowserProvider : public ios::TestChromeBrowserProvider {
public:
FakeChromeBrowserProvider(FakeNativeAppWhitelistManager* fake_manager) {
manager_ = fake_manager;
}
~FakeChromeBrowserProvider() override {}
id<NativeAppWhitelistManager> GetNativeAppWhitelistManager() const override {
return manager_;
}
private:
id<NativeAppWhitelistManager> manager_;
};
class NativeAppNavigationControllerTest : public ChromeWebTest {
protected:
void SetUp() override {
ChromeWebTest::SetUp();
controller_ =
[[NativeAppNavigationController alloc] initWithWebState:web_state()];
action_callback_ =
base::Bind(&NativeAppNavigationControllerTest::OnUserAction,
base::Unretained(this));
base::AddActionCallback(action_callback_);
handler_called_counter_ = 0;
}
void TearDown() override {
base::RemoveActionCallback(action_callback_);
ChromeWebTest::TearDown();
}
void SetExpectedActionName(const std::string& action_name) {
expected_action_name_.reset(new std::string(action_name));
}
void OnUserAction(const std::string& action_name) {
EXPECT_EQ(*expected_action_name_, action_name);
handler_called_counter_++;
}
void ExpectHandlerCalledAndReset(int number_of_calls) {
EXPECT_EQ(number_of_calls, handler_called_counter_);
handler_called_counter_ = 0;
}
NativeAppNavigationController* controller_;
// The callback to invoke when an action is recorded.
base::ActionCallback action_callback_;
std::unique_ptr<std::string> expected_action_name_;
int handler_called_counter_;
};
TEST_F(NativeAppNavigationControllerTest, TestConstructor) {
EXPECT_TRUE(controller_);
}
TEST_F(NativeAppNavigationControllerTest, TestUMA) {
SetExpectedActionName("MobileGALInstallInfoBarLinkNavigation");
[controller_ recordInfobarDisplayedOfType:NATIVE_APP_INSTALLER_CONTROLLER
onLinkNavigation:YES];
ExpectHandlerCalledAndReset(1);
SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation");
[controller_ recordInfobarDisplayedOfType:NATIVE_APP_INSTALLER_CONTROLLER
onLinkNavigation:NO];
ExpectHandlerCalledAndReset(1);
SetExpectedActionName("MobileGALLaunchInfoBar");
[controller_ recordInfobarDisplayedOfType:NATIVE_APP_LAUNCHER_CONTROLLER
onLinkNavigation:YES];
ExpectHandlerCalledAndReset(1);
[controller_ recordInfobarDisplayedOfType:NATIVE_APP_LAUNCHER_CONTROLLER
onLinkNavigation:NO];
ExpectHandlerCalledAndReset(1);
SetExpectedActionName("MobileGALOpenPolicyInfoBar");
[controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER
onLinkNavigation:YES];
ExpectHandlerCalledAndReset(1);
[controller_ recordInfobarDisplayedOfType:NATIVE_APP_OPEN_POLICY_CONTROLLER
onLinkNavigation:NO];
ExpectHandlerCalledAndReset(1);
}
// Tests presenting NativeAppInfoBar after page is loaded.
TEST_F(NativeAppNavigationControllerTest, NativeAppInfoBar) {
SetExpectedActionName("MobileGALInstallInfoBarDirectNavigation");
InfoBarManagerImpl::CreateForWebState(web_state());
// Set up fake metadata.
FakeNativeAppWhitelistManager* fakeManager =
[[FakeNativeAppWhitelistManager alloc] init];
IOSChromeScopedTestingChromeBrowserProvider provider(
base::MakeUnique<FakeChromeBrowserProvider>(fakeManager));
FakeNativeAppMetadata* metadata = [[FakeNativeAppMetadata alloc] init];
fakeManager.metadata = metadata;
metadata.appName = @"App";
metadata.appId = @"App-ID";
// Load the page to trigger infobar presentation.
LoadHtml(@"<html><body></body></html>", GURL("http://test.com"));
// Verify that infobar was presented
auto* infobar_manager = InfoBarManagerImpl::FromWebState(web_state());
ASSERT_EQ(1U, infobar_manager->infobar_count());
infobars::InfoBar* infobar = infobar_manager->infobar_at(0);
auto* delegate = infobar->delegate()->AsNativeAppInfoBarDelegate();
ASSERT_TRUE(delegate);
// Verify infobar appearance.
EXPECT_EQ("Open this page in the App app?",
base::UTF16ToUTF8(delegate->GetInstallText()));
EXPECT_EQ("Open this page in the App app?",
base::UTF16ToUTF8(delegate->GetLaunchText()));
EXPECT_EQ("Open in App", base::UTF16ToUTF8(delegate->GetOpenPolicyText()));
EXPECT_EQ("Just once", base::UTF16ToUTF8(delegate->GetOpenOnceText()));
EXPECT_EQ("Always", base::UTF16ToUTF8(delegate->GetOpenAlwaysText()));
EXPECT_NSEQ(@"App-ID", delegate->GetAppId());
}
TEST_F(NativeAppNavigationControllerTest,
TestRemovingAppFromListAfterInstallation) {
NSString* const kMapsAppName = @"Maps";
NSString* const kMapsAppId = @"1";
NSString* const kYoutubeAppName = @"Youtube";
NSString* const kYoutubeAppId = @"2";
InstallationNotifier* installationNotifier =
[[InstallationNotifier alloc] init];
FakeNativeAppWhitelistManager* fakeManager =
[[FakeNativeAppWhitelistManager alloc] init];
IOSChromeScopedTestingChromeBrowserProvider provider(
base::MakeUnique<FakeChromeBrowserProvider>(fakeManager));
FakeNativeAppMetadata* metadataMaps = [[FakeNativeAppMetadata alloc] init];
[metadataMaps setAppName:kMapsAppName];
[metadataMaps setAppId:kMapsAppId];
ASSERT_TRUE(metadataMaps);
NSString* appIdMaps = [metadataMaps appId];
NSNotification* notificationMaps =
[NSNotification notificationWithName:kMapsAppName
object:installationNotifier];
FakeNativeAppMetadata* metadataYouTube = [[FakeNativeAppMetadata alloc] init];
[metadataYouTube setAppName:kYoutubeAppName];
[metadataYouTube setAppId:kYoutubeAppId];
ASSERT_TRUE(metadataYouTube);
NSString* appIdYouTube = [metadataYouTube appId];
NSNotification* notificationYouTube =
[NSNotification notificationWithName:kYoutubeAppName
object:installationNotifier];
DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0);
[[controller_ appsPossiblyBeingInstalled] addObject:appIdMaps];
DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1);
[[controller_ appsPossiblyBeingInstalled] addObject:appIdYouTube];
DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 2);
[fakeManager setAppScheme:kMapsAppName];
[controller_ removeAppFromNotification:notificationMaps];
DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 1);
[fakeManager setAppScheme:kYoutubeAppName];
[controller_ removeAppFromNotification:notificationYouTube];
DCHECK([[controller_ appsPossiblyBeingInstalled] count] == 0);
}
} // namespace
// 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.
#ifndef IOS_CHROME_BROWSER_NATIVE_APP_LAUNCHER_NATIVE_APP_NAVIGATION_UTIL_H_
#define IOS_CHROME_BROWSER_NATIVE_APP_LAUNCHER_NATIVE_APP_NAVIGATION_UTIL_H_
namespace web {
class WebState;
} // namespace web
namespace native_app_launcher {
// Returns whether the current state is arrived at via a "link navigation" in
// the sense of Native App Launcher, i.e. a navigation caused by an explicit
// user action in the rectangle of the web content area. |web_state| must not
// be nullptr.
bool IsLinkNavigation(web::WebState* web_state);
} // namespace native_app_launcher
#endif // IOS_CHROME_BROWSER_NATIVE_APP_LAUNCHER_NATIVE_APP_NAVIGATION_UTIL_H_
// 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/chrome/browser/web/navigation_manager_util.h"
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/web_state/web_state.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace native_app_launcher {
bool IsLinkNavigation(web::WebState* web_state) {
DCHECK(web_state);
web::NavigationItem* item =
GetLastCommittedNonRedirectedItem(web_state->GetNavigationManager());
if (!item)
return false;
ui::PageTransition transition = item->GetTransitionType();
return PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_LINK) ||
PageTransitionCoreTypeIs(transition,
ui::PAGE_TRANSITION_AUTO_BOOKMARK);
}
} // namespace native_app_launcher
// 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"
#include "base/memory/ptr_util.h"
#import "ios/web/public/test/fakes/test_navigation_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#include "testing/platform_test.h"
#include "ui/base/page_transition_types.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Tests the implementation of IsLinkNavigation(). The function being tested
// uses public NavigationManager interfaces and can be tested by using
// TestNavigationManager that implements the same interface.
class NativeAppNavigationUtilsTest : public PlatformTest {
protected:
void SetUp() override {
PlatformTest::SetUp();
std::unique_ptr<web::TestNavigationManager> test_navigation_manager =
base::MakeUnique<web::TestNavigationManager>();
test_navigation_manager_ = test_navigation_manager.get();
test_web_state_.SetNavigationManager(std::move(test_navigation_manager));
}
web::WebState* web_state() { return &test_web_state_; }
// Adds a navigation item of |transition| type to current WebState.
void AddItem(const std::string& url_spec, ui::PageTransition transition) {
test_navigation_manager_->AddItem(GURL(url_spec), transition);
}
private:
web::TestNavigationManager* test_navigation_manager_;
web::TestWebState test_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_CLIENT_REDIRECT);
AddItem("http://zap.com/page2", ui::PAGE_TRANSITION_CLIENT_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_CLIENT_REDIRECT);
AddItem("http://blah.com/page2", ui::PAGE_TRANSITION_TYPED);
EXPECT_FALSE(native_app_launcher::IsLinkNavigation(web_state()));
}
......@@ -92,7 +92,6 @@ source_set("tabs_internal") {
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/metrics",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/passwords:passwords_internal",
"//ios/chrome/browser/reading_list",
......
......@@ -258,7 +258,6 @@ source_set("ui_internal_arc") {
"//ios/chrome/browser/geolocation:geolocation_internal",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/net",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/prefs",
......@@ -380,7 +379,6 @@ source_set("ui_internal") {
"//ios/chrome/browser/geolocation:geolocation_internal",
"//ios/chrome/browser/infobars",
"//ios/chrome/browser/metrics:metrics_internal",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/net",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/prefs",
......
......@@ -47,7 +47,6 @@ source_set("downloads") {
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/native_app_launcher",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/store_kit",
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/alert_coordinator",
......
......@@ -142,7 +142,6 @@ source_set("settings") {
"//ios/chrome/browser/browsing_data",
"//ios/chrome/browser/content_settings",
"//ios/chrome/browser/history",
"//ios/chrome/browser/native_app_launcher:native_app_launcher_internal",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/physical_web",
"//ios/chrome/browser/prefs",
......
......@@ -143,7 +143,6 @@ test("ios_chrome_unittests") {
"//ios/chrome/browser/metrics:unit_tests",
"//ios/chrome/browser/metrics:unit_tests_internal",
"//ios/chrome/browser/native_app_launcher:unit_tests",
"//ios/chrome/browser/native_app_launcher:unit_tests_internal",
"//ios/chrome/browser/net:unit_tests",
"//ios/chrome/browser/omaha:unit_tests",
"//ios/chrome/browser/passwords:unit_tests",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment