Commit 21f89769 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Fix bug of opening 2 tabs when returning to foreground from 3d-touch options.

Procedure of App returning to foreground:
1. applicationWillEnterForeground (normal App event)
2. performActionForShortcutItem (3d-touch event like 'open new tab')
3. applicationDidBecomeActive (normal App event)

Current impl judges if an NTP should be opened in step1, and create that NTP
in step3. Step2 also creates an NTP because no one exists after step1.

Bug: 831124
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ib77cabca10b4afdfd01cd0ade20a7ea254f04188
Reviewed-on: https://chromium-review.googlesource.com/1172689
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582926}
parent d83d2aa0
...@@ -81,9 +81,6 @@ NSString* const kStartupAttemptReset = @"StartupAttempReset"; ...@@ -81,9 +81,6 @@ NSString* const kStartupAttemptReset = @"StartupAttempReset";
base::TimeTicks _sessionStartTime; base::TimeTicks _sessionStartTime;
// YES if the app is currently in the process of terminating. // YES if the app is currently in the process of terminating.
BOOL _appIsTerminating; BOOL _appIsTerminating;
// Indicates if an NTP tab should be opened once the application has become
// active.
BOOL _shouldOpenNTPTabOnActive;
// Interstitial view used to block any incognito tabs after backgrounding. // Interstitial view used to block any incognito tabs after backgrounding.
UIView* _incognitoBlocker; UIView* _incognitoBlocker;
// Whether the application is currently in the background. // Whether the application is currently in the background.
...@@ -291,17 +288,6 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -291,17 +288,6 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
browserViewInformation]]; browserViewInformation]];
[memoryHelper resetForegroundMemoryWarningCount]; [memoryHelper resetForegroundMemoryWarningCount];
// Check if a NTP tab should be opened; the tab will actually be opened in
// |applicationDidBecomeActive| after the application gets prepared to
// record user actions.
// TODO(crbug.com/623491): opening a tab when the application is launched
// without a tab should not be counted as a user action. Revisit the way tab
// creation is counted.
_shouldOpenNTPTabOnActive = [tabOpener
shouldOpenNTPTabOnActivationOfTabModel:[[_browserLauncher
browserViewInformation]
currentTabModel]];
ios::ChromeBrowserState* currentBrowserState = ios::ChromeBrowserState* currentBrowserState =
[[_browserLauncher browserViewInformation] currentBrowserState]; [[_browserLauncher browserViewInformation] currentBrowserState];
if ([SignedInAccountsViewController if ([SignedInAccountsViewController
...@@ -354,7 +340,13 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -354,7 +340,13 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
startupInformation:_startupInformation startupInformation:_startupInformation
browserViewInformation:[_browserLauncher browserViewInformation:[_browserLauncher
browserViewInformation]]; browserViewInformation]];
} else if (_shouldOpenNTPTabOnActive) { } else if ([tabOpener shouldOpenNTPTabOnActivationOfTabModel:
[[_browserLauncher browserViewInformation]
currentTabModel]]) {
// Opens an NTP if needed.
// TODO(crbug.com/623491): opening a tab when the application is launched
// without a tab should not be counted as a user action. Revisit the way tab
// creation is counted.
if (![tabSwitcher openNewTabFromTabSwitcher]) { if (![tabSwitcher openNewTabFromTabSwitcher]) {
BrowserViewController* bvc = BrowserViewController* bvc =
[[_browserLauncher browserViewInformation] currentBVC]; [[_browserLauncher browserViewInformation] currentBVC];
...@@ -367,7 +359,6 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -367,7 +359,6 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
[[[_browserLauncher browserViewInformation] currentBVC] [[[_browserLauncher browserViewInformation] currentBVC]
presentBubblesIfEligible]; presentBubblesIfEligible];
} }
_shouldOpenNTPTabOnActive = NO;
[MetricsMediator logStartupDuration:_startupInformation]; [MetricsMediator logStartupDuration:_startupInformation];
} }
...@@ -506,22 +497,3 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher ...@@ -506,22 +497,3 @@ initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
} }
@end @end
@implementation AppState (Testing)
- (instancetype)
initWithBrowserLauncher:(id<BrowserLauncher>)browserLauncher
startupInformation:(id<StartupInformation>)startupInformation
applicationDelegate:(MainApplicationDelegate*)applicationDelegate
window:(UIWindow*)window
shouldOpenNTP:(BOOL)shouldOpenNTP {
self = [self initWithBrowserLauncher:browserLauncher
startupInformation:startupInformation
applicationDelegate:applicationDelegate];
if (self) {
_shouldOpenNTPTabOnActive = shouldOpenNTP;
}
return self;
}
@end
...@@ -637,13 +637,16 @@ TEST_F(AppStateTest, resumeSessionShouldOpenNTPTabSwitcher) { ...@@ -637,13 +637,16 @@ TEST_F(AppStateTest, resumeSessionShouldOpenNTPTabSwitcher) {
[[[getStartupInformationMock() stub] andReturn:nil] startupParameters]; [[[getStartupInformationMock() stub] andReturn:nil] startupParameters];
[[[getStartupInformationMock() stub] andReturnValue:@NO] isColdStart]; [[[getStartupInformationMock() stub] andReturnValue:@NO] isColdStart];
// TabOpening.
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
// BrowserViewInformation. // BrowserViewInformation.
id mainTabModel = [OCMockObject mockForClass:[TabModel class]]; id mainTabModel = [OCMockObject mockForClass:[TabModel class]];
[[mainTabModel expect] resetSessionMetrics]; [[mainTabModel expect] resetSessionMetrics];
[[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel];
[[[browserViewInformation stub] andReturn:mainTabModel] currentTabModel];
// TabOpening.
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
[[[tabOpener stub] andReturnValue:@YES]
shouldOpenNTPTabOnActivationOfTabModel:mainTabModel];
// TabSwitcher. // TabSwitcher.
id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)];
...@@ -682,9 +685,6 @@ TEST_F(AppStateTest, resumeSessionShouldOpenNTPNoTabSwitcher) { ...@@ -682,9 +685,6 @@ TEST_F(AppStateTest, resumeSessionShouldOpenNTPNoTabSwitcher) {
[[[getStartupInformationMock() stub] andReturn:nil] startupParameters]; [[[getStartupInformationMock() stub] andReturn:nil] startupParameters];
[[[getStartupInformationMock() stub] andReturnValue:@NO] isColdStart]; [[[getStartupInformationMock() stub] andReturnValue:@NO] isColdStart];
// TabOpening.
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
// BrowserViewInformation. // BrowserViewInformation.
id mainTabModel = [OCMockObject mockForClass:[TabModel class]]; id mainTabModel = [OCMockObject mockForClass:[TabModel class]];
[[mainTabModel expect] resetSessionMetrics]; [[mainTabModel expect] resetSessionMetrics];
...@@ -697,9 +697,15 @@ TEST_F(AppStateTest, resumeSessionShouldOpenNTPNoTabSwitcher) { ...@@ -697,9 +697,15 @@ TEST_F(AppStateTest, resumeSessionShouldOpenNTPNoTabSwitcher) {
[[[currentBVC stub] andReturn:dispatcher] dispatcher]; [[[currentBVC stub] andReturn:dispatcher] dispatcher];
[[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel]; [[[browserViewInformation stub] andReturn:mainTabModel] mainTabModel];
[[[browserViewInformation stub] andReturn:mainTabModel] currentTabModel];
[[[browserViewInformation stub] andReturn:currentBVC] currentBVC]; [[[browserViewInformation stub] andReturn:currentBVC] currentBVC];
[[[browserViewInformation stub] andReturn:nil] otrBVC]; [[[browserViewInformation stub] andReturn:nil] otrBVC];
// TabOpening.
id tabOpener = [OCMockObject mockForProtocol:@protocol(TabOpening)];
[[[tabOpener stub] andReturnValue:@YES]
shouldOpenNTPTabOnActivationOfTabModel:mainTabModel];
// TabSwitcher. // TabSwitcher.
id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)]; id tabSwitcher = [OCMockObject mockForProtocol:@protocol(TabSwitching)];
[[[tabSwitcher stub] andReturnValue:@NO] openNewTabFromTabSwitcher]; [[[tabSwitcher stub] andReturnValue:@NO] openNewTabFromTabSwitcher];
......
...@@ -218,9 +218,7 @@ TEST_F(URLOpenerTest, HandleOpenURLWithNoOpenTab) { ...@@ -218,9 +218,7 @@ TEST_F(URLOpenerTest, HandleOpenURLWithNoOpenTab) {
AppState* appState = AppState* appState =
[[AppState alloc] initWithBrowserLauncher:controller [[AppState alloc] initWithBrowserLauncher:controller
startupInformation:controller startupInformation:controller
applicationDelegate:mainApplicationDelegate applicationDelegate:mainApplicationDelegate];
window:controller.window
shouldOpenNTP:YES];
controller.appState = appState; controller.appState = appState;
NSDictionary<NSString*, id>* options = nil; NSDictionary<NSString*, id>* options = nil;
......
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