Commit ef7dd40d authored by Eugene But's avatar Eugene But Committed by Commit Bot

Extract StoreKitCoordinator class from BVC.

This removes code from BVC and allows reusing Store Kit code in
DownloadManagerCoordinator.

Bug: 791806
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Id5d33de9666a0bdc35fb3d451158b33a8636bf4d
Reviewed-on: https://chromium-review.googlesource.com/934315
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538867}
parent 10d206f0
......@@ -5,25 +5,35 @@
source_set("store_kit") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"store_kit_coordinator.h",
"store_kit_coordinator.mm",
"store_kit_launcher.h",
"store_kit_tab_helper.h",
"store_kit_tab_helper.mm",
]
deps = [
"//base",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/web",
]
libs = [
"StoreKit.framework",
"UIKit.framework",
]
}
source_set("unit_tests") {
testonly = true
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"store_kit_coordinator_unittest.mm",
"store_kit_tab_helper_unittest.mm",
]
deps = [
":store_kit",
"//base",
"//ios/chrome/test:test_support",
"//ios/testing:ios_test_support",
"//ios/web",
"//ios/web/public/test",
"//testing/gtest",
......
// Copyright 2018 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_STORE_KIT_STORE_KIT_COORDINATOR_H_
#define IOS_CHROME_BROWSER_STORE_KIT_STORE_KIT_COORDINATOR_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/store_kit/store_kit_launcher.h"
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
// Coordinates presentation of SKStoreProductViewController.
@interface StoreKitCoordinator : ChromeCoordinator<StoreKitLauncher>
// iTunes Store item identifier of the product. Must be set before starting the
// coordinator.
@property(nonatomic, copy) NSString* iTunesItemIdentifier;
@end
#endif // IOS_CHROME_BROWSER_STORE_KIT_STORE_KIT_COORDINATOR_H_
// Copyright 2018 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/store_kit/store_kit_coordinator.h"
#import <StoreKit/StoreKit.h>
#import <UIKit/UIKit.h>
#include "base/logging.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface StoreKitCoordinator ()<SKStoreProductViewControllerDelegate> {
SKStoreProductViewController* _viewController;
}
@end
@implementation StoreKitCoordinator
@synthesize iTunesItemIdentifier = _iTunesItemIdentifier;
#pragma mark - Public
- (void)start {
DCHECK(self.iTunesItemIdentifier.length);
DCHECK(!_viewController);
_viewController = [[SKStoreProductViewController alloc] init];
_viewController.delegate = self;
NSDictionary* product = @{
SKStoreProductParameterITunesItemIdentifier : self.iTunesItemIdentifier,
};
[_viewController loadProductWithParameters:product completionBlock:nil];
[self.baseViewController presentViewController:_viewController
animated:YES
completion:nil];
}
- (void)stop {
[_viewController dismissViewControllerAnimated:YES completion:nil];
_viewController = nil;
}
#pragma mark - StoreKitLauncher
- (void)openAppStore:(NSString*)iTunesItemIdentifier {
self.iTunesItemIdentifier = iTunesItemIdentifier;
[self start];
}
#pragma mark - SKStoreProductViewControllerDelegate
- (void)productViewControllerDidFinish:
(SKStoreProductViewController*)viewController {
[self stop];
}
@end
// Copyright 2018 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/store_kit/store_kit_coordinator.h"
#import <StoreKit/StoreKit.h>
#import "ios/chrome/test/scoped_key_window.h"
#import "ios/testing/wait_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using testing::WaitUntilConditionOrTimeout;
using testing::kWaitForUIElementTimeout;
// Test fixture for StoreKitCoordinator class.
class StoreKitCoordinatorTest : public PlatformTest {
protected:
StoreKitCoordinatorTest()
: base_view_controller_([[UIViewController alloc] init]),
coordinator_([[StoreKitCoordinator alloc]
initWithBaseViewController:base_view_controller_]) {
[scoped_key_window_.Get() setRootViewController:base_view_controller_];
}
UIViewController* base_view_controller_;
StoreKitCoordinator* coordinator_;
ScopedKeyWindow scoped_key_window_;
};
// Tests that StoreKitCoordinator presents SKStoreProductViewController.
TEST_F(StoreKitCoordinatorTest, PresentingViewController) {
NSString* kTestITunesItemIdentifier = @"TestITunesItemIdentifier";
[coordinator_ openAppStore:kTestITunesItemIdentifier];
EXPECT_NSEQ(kTestITunesItemIdentifier, coordinator_.iTunesItemIdentifier);
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{
return [base_view_controller_.presentedViewController class] ==
[SKStoreProductViewController class];
}));
[coordinator_ stop];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, ^{
return base_view_controller_.presentedViewController == nil;
}));
}
......@@ -102,6 +102,7 @@
#import "ios/chrome/browser/snapshots/snapshot_tab_helper.h"
#import "ios/chrome/browser/ssl/captive_portal_detector_tab_helper.h"
#import "ios/chrome/browser/ssl/captive_portal_detector_tab_helper_delegate.h"
#import "ios/chrome/browser/store_kit/store_kit_coordinator.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"
......@@ -436,9 +437,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
RepostFormTabHelperDelegate,
SideSwipeControllerDelegate,
SigninPresenter,
SKStoreProductViewControllerDelegate,
SnapshotGeneratorDelegate,
StoreKitLauncher,
TabDialogDelegate,
TabHeadersDelegate,
TabHistoryPresentation,
......@@ -610,6 +609,9 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Coordinator for the Download Manager UI.
DownloadManagerCoordinator* _downloadManagerCoordinator;
// Coordinator for presenting SKStoreProductViewController.
StoreKitCoordinator* _storeKitCoordinator;
// Coordinator for the language selection UI.
LanguageSelectionCoordinator* _languageSelectionCoordinator;
......@@ -1016,6 +1018,9 @@ applicationCommandEndpoint:(id<ApplicationCommands>)applicationCommandEndpoint {
_downloadManagerCoordinator.presenter =
[[VerticalAnimationContainer alloc] init];
_storeKitCoordinator =
[[StoreKitCoordinator alloc] initWithBaseViewController:self];
_languageSelectionCoordinator =
[[LanguageSelectionCoordinator alloc] initWithBaseViewController:self];
_languageSelectionCoordinator.presenter =
......@@ -2967,11 +2972,9 @@ bubblePresenterForFeature:(const base::Feature&)feature
// Install the proper CRWWebController delegates.
tab.webController.nativeProvider = self;
tab.webController.swipeRecognizerProvider = self.sideSwipeController;
// BrowserViewController presents SKStoreKitViewController on behalf of a
// tab.
StoreKitTabHelper* tabHelper = StoreKitTabHelper::FromWebState(tab.webState);
if (tabHelper)
tabHelper->SetLauncher(self);
tabHelper->SetLauncher(_storeKitCoordinator);
tab.webState->SetDelegate(_webStateDelegate.get());
// BrowserViewController owns the coordinator that displays the Sad Tab.
if (!SadTabTabHelper::FromWebState(tab.webState)) {
......@@ -5302,27 +5305,6 @@ bubblePresenterForFeature:(const base::Feature&)feature
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - SKStoreProductViewControllerDelegate
- (void)productViewControllerDidFinish:
(SKStoreProductViewController*)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - StoreKitLauncher methods
- (void)openAppStore:(NSString*)appId {
if (![appId length])
return;
NSDictionary* product =
@{SKStoreProductParameterITunesItemIdentifier : appId};
SKStoreProductViewController* storeViewController =
[[SKStoreProductViewController alloc] init];
[storeViewController setDelegate:self];
[storeViewController loadProductWithParameters:product completionBlock:nil];
[self presentViewController:storeViewController animated:YES completion:nil];
}
#pragma mark - TabDialogDelegate methods
- (void)cancelDialogForTab:(Tab*)tab {
......
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