Commit 9d54a0e7 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Wait for tab usage recorder new tabs to completely load.

Previously calling -loadURL immediately after loading an NTP in
a test would yield expected ios/web callbacks.  With a non-native
content NTP, -loadURL must be called after the NTP webState load
completes.  This is similar to loading any other web site.

Bug: 826369
Change-Id: Ice1364aee6299ab00b5fd9f0188e56ab0c73095c
Reviewed-on: https://chromium-review.googlesource.com/c/1316591Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605192}
parent d032ae82
...@@ -86,7 +86,7 @@ void Wait(id<GREYMatcher> matcher, NSString* name) { ...@@ -86,7 +86,7 @@ void Wait(id<GREYMatcher> matcher, NSString* name) {
// page. // page.
void NewMainTabWithURL(const GURL& url, const std::string& word) { void NewMainTabWithURL(const GURL& url, const std::string& word) {
int number_of_tabs = chrome_test_util::GetMainTabCount(); int number_of_tabs = chrome_test_util::GetMainTabCount();
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
[ChromeEarlGrey loadURL:url]; [ChromeEarlGrey loadURL:url];
[ChromeEarlGrey waitForWebViewContainingText:word]; [ChromeEarlGrey waitForWebViewContainingText:word];
[ChromeEarlGrey waitForMainTabCount:(number_of_tabs + 1)]; [ChromeEarlGrey waitForMainTabCount:(number_of_tabs + 1)];
...@@ -186,7 +186,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -186,7 +186,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
// Open three tabs with http:// urls. // Open three tabs with http:// urls.
for (NSUInteger i = 0; i < numberOfTabs; i++) { for (NSUInteger i = 0; i < numberOfTabs; i++) {
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
[ChromeEarlGrey loadURL:url1]; [ChromeEarlGrey loadURL:url1];
[ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
[ChromeEarlGrey waitForMainTabCount:(i + 1)]; [ChromeEarlGrey waitForMainTabCount:(i + 1)];
...@@ -221,7 +221,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -221,7 +221,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
// Evict the tab. Create a dummy tab so that switching back to normal mode // Evict the tab. Create a dummy tab so that switching back to normal mode
// does not trigger a reload immediately. // does not trigger a reload immediately.
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
OpenNewIncognitoTabUsingUIAndEvictMainTabs(); OpenNewIncognitoTabUsingUIAndEvictMainTabs();
[ChromeEarlGrey waitForIncognitoTabCount:1]; [ChromeEarlGrey waitForIncognitoTabCount:1];
...@@ -382,8 +382,8 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -382,8 +382,8 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
}; };
// A blank tab needed to switch to it after reloading. // A blank tab needed to switch to it after reloading.
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
chrome_test_util::LoadUrl(slowURL); chrome_test_util::LoadUrl(slowURL);
OpenNewIncognitoTabUsingUIAndEvictMainTabs(); OpenNewIncognitoTabUsingUIAndEvictMainTabs();
...@@ -452,7 +452,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -452,7 +452,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
grey_sufficientlyVisible(), nil); grey_sufficientlyVisible(), nil);
Wait(toolMenuMatcher, @"Tool Menu"); Wait(toolMenuMatcher, @"Tool Menu");
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
[[GREYConfiguration sharedInstance] [[GREYConfiguration sharedInstance]
setValue:@(YES) setValue:@(YES)
forConfigKey:kGREYConfigKeySynchronizationEnabled]; forConfigKey:kGREYConfigKeySynchronizationEnabled];
...@@ -504,7 +504,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -504,7 +504,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
web::test::SetUpHttpServer(std::make_unique<HtmlResponseProvider>(responses)); web::test::SetUpHttpServer(std::make_unique<HtmlResponseProvider>(responses));
chrome_test_util::HistogramTester histogramTester; chrome_test_util::HistogramTester histogramTester;
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
chrome_test_util::LoadUrl(slowURL); chrome_test_util::LoadUrl(slowURL);
OpenNewIncognitoTabUsingUIAndEvictMainTabs(); OpenNewIncognitoTabUsingUIAndEvictMainTabs();
...@@ -553,7 +553,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -553,7 +553,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
chrome_test_util::HistogramTester histogramTester; chrome_test_util::HistogramTester histogramTester;
// We need two tabs to be able to switch. // We need two tabs to be able to switch.
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
[[GREYConfiguration sharedInstance] [[GREYConfiguration sharedInstance]
setValue:@(NO) setValue:@(NO)
forConfigKey:kGREYConfigKeySynchronizationEnabled]; forConfigKey:kGREYConfigKeySynchronizationEnabled];
...@@ -591,7 +591,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -591,7 +591,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1;
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
OpenNewIncognitoTabUsingUIAndEvictMainTabs(); OpenNewIncognitoTabUsingUIAndEvictMainTabs();
SwitchToNormalMode(); SwitchToNormalMode();
chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex);
...@@ -638,7 +638,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -638,7 +638,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
[ChromeEarlGrey waitForWebViewContainingText:"Whee"]; [ChromeEarlGrey waitForWebViewContainingText:"Whee"];
NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1;
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
OpenNewIncognitoTabUsingUIAndEvictMainTabs(); OpenNewIncognitoTabUsingUIAndEvictMainTabs();
SwitchToNormalMode(); SwitchToNormalMode();
chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex);
...@@ -716,7 +716,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) { ...@@ -716,7 +716,7 @@ void CloseTabAtIndexAndSync(NSUInteger i) {
chrome_test_util::HistogramTester histogramTester; chrome_test_util::HistogramTester histogramTester;
ResetTabUsageRecorder(); ResetTabUsageRecorder();
chrome_test_util::OpenNewTab(); [ChromeEarlGrey openNewTab];
GURL url(kTestUrl1); GURL url(kTestUrl1);
chrome_test_util::OpenChromeFromExternalApp(url); chrome_test_util::OpenChromeFromExternalApp(url);
......
...@@ -58,6 +58,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error); ...@@ -58,6 +58,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// within a timeout, or a GREYAssert is induced. // within a timeout, or a GREYAssert is induced.
+ (void)goForward; + (void)goForward;
// Opens a new tab and waits for the new tab animation to complete.
+ (void)openNewTab;
// Waits for the page to finish loading within a timeout, or a GREYAssert is // Waits for the page to finish loading within a timeout, or a GREYAssert is
// induced. // induced.
+ (void)waitForPageToFinishLoading; + (void)waitForPageToFinishLoading;
......
...@@ -131,6 +131,11 @@ id ExecuteJavaScript(NSString* javascript, ...@@ -131,6 +131,11 @@ id ExecuteJavaScript(NSString* javascript,
[ChromeEarlGrey waitForPageToFinishLoading]; [ChromeEarlGrey waitForPageToFinishLoading];
} }
+ (void)openNewTab {
chrome_test_util::OpenNewTab();
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
+ (void)waitForPageToFinishLoading { + (void)waitForPageToFinishLoading {
GREYAssert(chrome_test_util::WaitForPageToFinishLoading(), GREYAssert(chrome_test_util::WaitForPageToFinishLoading(),
@"Page did not complete loading."); @"Page did not complete loading.");
......
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