Commit 68fcf03a authored by zhaoyangli's avatar zhaoyangli Committed by Commit Bot

Call test method setups after relaunching app in EG2 tests

- Added test method setups in |-appLaunchManagerDidRelaunchApp| in
|ChromeTestCase|, which will do resets and open a new tab after app is
relaunched. Introduced a flag in |ChromeTestCase| to prevent these
setups from called twice after one relaunch.

- Added in smoke test to test if new tab is opened after relaunch.

- Remove user's [ChromeEarlGrey openNewTab] call after calling
|ensureAppLaunchedWithFeaturesEnabled|.


Bug: 922813, 1004565
Change-Id: I525fb7492777fdd29b9491a2d6927b64fd58df7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835022
Commit-Queue: Zhaoyang Li <zhaoyangli@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702492}
parent 649aa432
...@@ -100,7 +100,6 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) { ...@@ -100,7 +100,6 @@ id<GREYMatcher> CardNumberIconView(NSString* icon_type) {
@"SettingsAddPaymentMethod should be enabled"); @"SettingsAddPaymentMethod should be enabled");
GREYAssertTrue([ChromeEarlGrey isCreditCardScannerEnabled], GREYAssertTrue([ChromeEarlGrey isCreditCardScannerEnabled],
@"CreditCardScanner should be enabled"); @"CreditCardScanner should be enabled");
[ChromeEarlGrey openNewTab];
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:PaymentMethodsButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:PaymentMethodsButton()];
[[EarlGrey selectElementWithMatcher:AddPaymentMethodButton()] [[EarlGrey selectElementWithMatcher:AddPaymentMethodButton()]
......
...@@ -122,6 +122,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface) ...@@ -122,6 +122,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
// Block to be executed during object tearDown. // Block to be executed during object tearDown.
ProceduralBlock _tearDownHandler; ProceduralBlock _tearDownHandler;
// This flag indicates whether test method -setUp steps are executed during a
// test method.
BOOL _executedTestMethodSetUp;
BOOL _isHTTPServerStopped; BOOL _isHTTPServerStopped;
BOOL _isMockAuthenticationDisabled; BOOL _isMockAuthenticationDisabled;
std::unique_ptr<net::EmbeddedTestServer> _testServer; std::unique_ptr<net::EmbeddedTestServer> _testServer;
...@@ -248,6 +252,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface) ...@@ -248,6 +252,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
// Reset any remaining sign-in state from previous tests. // Reset any remaining sign-in state from previous tests.
[ChromeEarlGrey signOutAndClearAccounts]; [ChromeEarlGrey signOutAndClearAccounts];
[ChromeEarlGrey openNewTab]; [ChromeEarlGrey openNewTab];
_executedTestMethodSetUp = YES;
} }
// Tear down called once per test, to close all tabs and menus, and clear the // Tear down called once per test, to close all tabs and menus, and clear the
...@@ -291,6 +296,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface) ...@@ -291,6 +296,7 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
#endif #endif
} }
[super tearDown]; [super tearDown];
_executedTestMethodSetUp = NO;
} }
#pragma mark - Public methods #pragma mark - Public methods
...@@ -439,8 +445,20 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface) ...@@ -439,8 +445,20 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeTestCaseAppInterface)
// +setUpHelper can not be called twice during setup process. // +setUpHelper can not be called twice during setup process.
if (gExecutedSetUpForTestCase) { if (gExecutedSetUpForTestCase) {
[ChromeTestCase setUpHelper]; [ChromeTestCase setUpHelper];
// Do not call test method setup steps if the app was relaunched before
// -setUp is executed. If do so, two new tabs will be opened before test
// method starts.
if (_executedTestMethodSetUp) {
[self resetAppState];
ResetAuthentication();
// Reset any remaining sign-in state from previous tests.
[ChromeEarlGrey signOutAndClearAccounts];
[ChromeEarlGrey openNewTab];
}
} }
[self resetAppState];
} }
@end @end
...@@ -208,6 +208,9 @@ ...@@ -208,6 +208,9 @@
@"NewOmniboxPopupLayout should be enabled"); @"NewOmniboxPopupLayout should be enabled");
GREYAssertTrue([ChromeEarlGrey isSlimNavigationManagerEnabled], GREYAssertTrue([ChromeEarlGrey isSlimNavigationManagerEnabled],
@"SlimNavigationManager should be enabled"); @"SlimNavigationManager should be enabled");
GREYAssertEqual([ChromeEarlGrey mainTabCount], 1U,
@"Exactly one new tab should be opened.");
} }
// Tests isCompactWidth method in chrome_earl_grey.h. // Tests isCompactWidth method in chrome_earl_grey.h.
......
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