Commit d6833a59 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][coordinator] Modernize Store Kit Coordinator.

This CL updates StoreKitCoordinator to use the preferred init for
coordinators, which provides a Browser instance, also updates the unit
tests.

Bug: 1029346
Change-Id: Ifa9d080eb4a0c1768e549d01c6282cfe7207a0c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2007188
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732875}
parent bbf8442c
...@@ -33,6 +33,7 @@ source_set("unit_tests") { ...@@ -33,6 +33,7 @@ source_set("unit_tests") {
":store_kit", ":store_kit",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//ios/chrome/browser/main:test_support",
"//ios/chrome/test:test_support", "//ios/chrome/test:test_support",
"//ios/chrome/test/fakes", "//ios/chrome/test/fakes",
"//ios/web", "//ios/web",
......
...@@ -18,6 +18,15 @@ ...@@ -18,6 +18,15 @@
// other keys are optional. Must be set before starting the coordinator. // other keys are optional. Must be set before starting the coordinator.
@property(nonatomic, copy) NSDictionary* iTunesProductParameters; @property(nonatomic, copy) NSDictionary* iTunesProductParameters;
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
NS_UNAVAILABLE;
// Unavailable, use -initWithBaseViewController:browser:.
- (instancetype)initWithBaseViewController:(UIViewController*)viewController
browserState:
(ios::ChromeBrowserState*)browserState
NS_UNAVAILABLE;
@end @end
#endif // IOS_CHROME_BROWSER_STORE_KIT_STORE_KIT_COORDINATOR_H_ #endif // IOS_CHROME_BROWSER_STORE_KIT_STORE_KIT_COORDINATOR_H_
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#import <StoreKit/StoreKit.h> #import <StoreKit/StoreKit.h>
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/test/task_environment.h"
#include "ios/chrome/browser/main/test_browser.h"
#import "ios/chrome/test/fakes/fake_ui_view_controller.h" #import "ios/chrome/test/fakes/fake_ui_view_controller.h"
#import "ios/chrome/test/scoped_key_window.h" #import "ios/chrome/test/scoped_key_window.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -23,9 +25,10 @@ class StoreKitCoordinatorTest : public PlatformTest { ...@@ -23,9 +25,10 @@ class StoreKitCoordinatorTest : public PlatformTest {
StoreKitCoordinatorTest() StoreKitCoordinatorTest()
: root_view_controller_([[UIViewController alloc] init]), : root_view_controller_([[UIViewController alloc] init]),
base_view_controller_([[UIViewController alloc] init]), base_view_controller_([[UIViewController alloc] init]),
browser_(std::make_unique<TestBrowser>()),
coordinator_([[StoreKitCoordinator alloc] coordinator_([[StoreKitCoordinator alloc]
initWithBaseViewController:base_view_controller_]) { initWithBaseViewController:base_view_controller_
browser:browser_.get()]) {
[scoped_key_window_.Get() setRootViewController:root_view_controller_]; [scoped_key_window_.Get() setRootViewController:root_view_controller_];
[root_view_controller_ presentViewController:base_view_controller_ [root_view_controller_ presentViewController:base_view_controller_
animated:NO animated:NO
...@@ -43,8 +46,11 @@ class StoreKitCoordinatorTest : public PlatformTest { ...@@ -43,8 +46,11 @@ class StoreKitCoordinatorTest : public PlatformTest {
} }
} }
base::test::TaskEnvironment task_environment_;
UIViewController* root_view_controller_; UIViewController* root_view_controller_;
UIViewController* base_view_controller_; UIViewController* base_view_controller_;
std::unique_ptr<Browser> browser_;
StoreKitCoordinator* coordinator_; StoreKitCoordinator* coordinator_;
ScopedKeyWindow scoped_key_window_; ScopedKeyWindow scoped_key_window_;
}; };
......
...@@ -342,7 +342,8 @@ ...@@ -342,7 +342,8 @@
/* RepostFormCoordinator is created and started by a delegate method */ /* RepostFormCoordinator is created and started by a delegate method */
self.storeKitCoordinator = [[StoreKitCoordinator alloc] self.storeKitCoordinator = [[StoreKitCoordinator alloc]
initWithBaseViewController:self.viewController]; initWithBaseViewController:self.viewController
browser:self.browser];
self.addCreditCardCoordinator = [[AutofillAddCreditCardCoordinator alloc] self.addCreditCardCoordinator = [[AutofillAddCreditCardCoordinator alloc]
initWithBaseViewController:self.viewController initWithBaseViewController:self.viewController
......
...@@ -472,7 +472,8 @@ class UnopenedDownloadsTracker : public web::DownloadTaskObserver, ...@@ -472,7 +472,8 @@ class UnopenedDownloadsTracker : public web::DownloadTaskObserver,
- (void)presentStoreKitForGoogleDriveApp { - (void)presentStoreKitForGoogleDriveApp {
if (!_storeKitCoordinator) { if (!_storeKitCoordinator) {
_storeKitCoordinator = [[StoreKitCoordinator alloc] _storeKitCoordinator = [[StoreKitCoordinator alloc]
initWithBaseViewController:self.baseViewController]; initWithBaseViewController:self.baseViewController
browser:self.browser];
_storeKitCoordinator.iTunesProductParameters = @{ _storeKitCoordinator.iTunesProductParameters = @{
SKStoreProductParameterITunesItemIdentifier : SKStoreProductParameterITunesItemIdentifier :
kGoogleDriveITunesItemIdentifier kGoogleDriveITunesItemIdentifier
......
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