Commit 3a375f95 authored by mrefaat's avatar mrefaat Committed by Commit Bot

Fix a problem when storekit view is allocated and not presented.

Some websites try to open itunes app, then redirects immediatly to
http itunes url, in that case Chrome present app launch prompt and
while it's there itunes url is loaded, so it allocates a storekit view
and tries to present it and fails.
The problem is on subsequent itunes http navigations, the coordinator
check if there's a controller allocated, if so it will exit. And because
the one allocated in the previous case was never dismissed it breaks the
expected behavior.

Bug: 892503
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Ie08160e37c6f27c02a081e06c9b956bc835cf4c7
Reviewed-on: https://chromium-review.googlesource.com/c/1263876
Commit-Queue: Mohammad Refaat <mrefaat@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#597355}
parent bb9f005d
...@@ -27,8 +27,9 @@ ...@@ -27,8 +27,9 @@
- (void)start { - (void)start {
DCHECK(self.iTunesProductParameters DCHECK(self.iTunesProductParameters
[SKStoreProductParameterITunesItemIdentifier]); [SKStoreProductParameterITunesItemIdentifier]);
// StoreKit shouldn't be launched, if there is one already presented. // StoreKit shouldn't be launched, if there is one already presented or if
if (_viewController) // there is another view presented by the base view controller.
if (_viewController || self.baseViewController.presentedViewController)
return; return;
_viewController = [[SKStoreProductViewController alloc] init]; _viewController = [[SKStoreProductViewController alloc] init];
_viewController.delegate = self; _viewController.delegate = self;
......
...@@ -68,7 +68,7 @@ TEST_F(StoreKitCoordinatorTest, OpenStorePresentViewController) { ...@@ -68,7 +68,7 @@ TEST_F(StoreKitCoordinatorTest, OpenStorePresentViewController) {
// Tests that when there is a SKStoreProductViewController presented, starting // Tests that when there is a SKStoreProductViewController presented, starting
// the coordinator doesn't present new view controller. // the coordinator doesn't present new view controller.
TEST_F(StoreKitCoordinatorTest, NoOverlappingPresentedViewControllers) { TEST_F(StoreKitCoordinatorTest, NoOverlappingStoreKitsPresented) {
NSString* kTestITunesItemIdentifier = @"TestITunesItemIdentifier"; NSString* kTestITunesItemIdentifier = @"TestITunesItemIdentifier";
coordinator_.iTunesProductParameters = @{ coordinator_.iTunesProductParameters = @{
SKStoreProductParameterITunesItemIdentifier : kTestITunesItemIdentifier, SKStoreProductParameterITunesItemIdentifier : kTestITunesItemIdentifier,
...@@ -97,3 +97,32 @@ TEST_F(StoreKitCoordinatorTest, NoOverlappingPresentedViewControllers) { ...@@ -97,3 +97,32 @@ TEST_F(StoreKitCoordinatorTest, NoOverlappingPresentedViewControllers) {
EXPECT_NSNE(presented_controller, EXPECT_NSNE(presented_controller,
base_view_controller_.presentedViewController); base_view_controller_.presentedViewController);
} }
// Tests that if the base view controller is presenting any view controller,
// starting the coordinator doesn't present new view controller.
TEST_F(StoreKitCoordinatorTest, NoOverlappingPresentedViewControllers) {
NSString* kTestITunesItemIdentifier = @"TestITunesItemIdentifier";
coordinator_.iTunesProductParameters = @{
SKStoreProductParameterITunesItemIdentifier : kTestITunesItemIdentifier,
};
EXPECT_FALSE(base_view_controller_.presentedViewController);
UIViewController* dummy_view_controller = [[UIViewController alloc] init];
[base_view_controller_ presentViewController:dummy_view_controller
animated:NO
completion:nil];
EXPECT_NSEQ(dummy_view_controller,
base_view_controller_.presentedViewController);
[coordinator_ start];
// Verify that that presented view controlled is not changed.
EXPECT_NSEQ(dummy_view_controller,
base_view_controller_.presentedViewController);
[coordinator_ stop];
EXPECT_FALSE(base_view_controller_.presentedViewController);
[coordinator_ start];
// After reseting the view controller, a new storekit view should be
// presented.
EXPECT_NSEQ([SKStoreProductViewController class],
[base_view_controller_.presentedViewController class]);
}
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