Commit 4cce6875 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Add testDownloadWhileBrowsing EG test.

After tapping Download this test opens a separate tabs and loads the URL
there. Then closes the tab and waits for the download completion.

Bug: 854232
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Id05c9344d1da80a57b6c7cc663b2b8a835f18e82
Reviewed-on: https://chromium-review.googlesource.com/1111916
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574599}
parent f7c234b0
...@@ -116,6 +116,7 @@ source_set("eg_tests") { ...@@ -116,6 +116,7 @@ source_set("eg_tests") {
"//ios/chrome/browser/download:test_support", "//ios/chrome/browser/download:test_support",
"//ios/chrome/browser/ui:ui_internal", "//ios/chrome/browser/ui:ui_internal",
"//ios/chrome/browser/ui:ui_util", "//ios/chrome/browser/ui:ui_util",
"//ios/chrome/test:test_support",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support", "//ios/chrome/test/earl_grey:test_support",
"//ios/testing:embedded_test_server_support", "//ios/testing:embedded_test_server_support",
......
...@@ -5,11 +5,14 @@ ...@@ -5,11 +5,14 @@
#import <EarlGrey/EarlGrey.h> #import <EarlGrey/EarlGrey.h>
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/tab_test_util.h" #import "ios/chrome/test/app/tab_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h" #import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/chrome/test/scoped_eg_synchronization_disabler.h"
#include "ios/testing/embedded_test_server_handlers.h" #include "ios/testing/embedded_test_server_handlers.h"
#import "ios/testing/wait_util.h" #import "ios/testing/wait_util.h"
#include "ios/web/public/features.h" #include "ios/web/public/features.h"
...@@ -44,6 +47,20 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse( ...@@ -44,6 +47,20 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
return result; return result;
} }
// Waits until Open in... button is shown.
bool WaitForOpenInButton() WARN_UNUSED_RESULT;
bool WaitForOpenInButton() {
// These downloads usually take longer and need a longer timeout.
const NSTimeInterval kLongDownloadTimeout = 25;
return testing::WaitUntilConditionOrTimeout(kLongDownloadTimeout, ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:OpenInButton()]
assertWithMatcher:grey_notNil()
error:&error];
return (error == nil);
});
}
} // namespace } // namespace
// Tests critical user journeys for Download Manager. // Tests critical user journeys for Download Manager.
...@@ -71,7 +88,7 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse( ...@@ -71,7 +88,7 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
} }
// Tests sucessfull download up to the point where "Open in..." button is // Tests sucessfull download up to the point where "Open in..." button is
// presented. EarlGreay does not allow testing "Open in..." dialog, because it // presented. EarlGrey does not allow testing "Open in..." dialog, because it
// is run in a separate process. // is run in a separate process.
- (void)testSucessfullDownload { - (void)testSucessfullDownload {
[ChromeEarlGrey loadURL:self.testServer->GetURL("/")]; [ChromeEarlGrey loadURL:self.testServer->GetURL("/")];
...@@ -81,21 +98,11 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse( ...@@ -81,21 +98,11 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
[[EarlGrey selectElementWithMatcher:DownloadButton()] [[EarlGrey selectElementWithMatcher:DownloadButton()]
performAction:grey_tap()]; performAction:grey_tap()];
// Wait until Open in... button is shown. GREYAssert(WaitForOpenInButton(), @"Open in... button did not show up");
ConditionBlock openInShown = ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:OpenInButton()]
assertWithMatcher:grey_notNil()
error:&error];
return (error == nil);
};
GREYAssert(testing::WaitUntilConditionOrTimeout(
testing::kWaitForDownloadTimeout, openInShown),
@"Open in... button did not show up");
} }
// Tests sucessfull download up to the point where "Open in..." button is // Tests sucessfull download up to the point where "Open in..." button is
// presented. EarlGreay does not allow testing "Open in..." dialog, because it // presented. EarlGrey does not allow testing "Open in..." dialog, because it
// is run in a separate process. Performs download in Incognito. // is run in a separate process. Performs download in Incognito.
- (void)testSucessfullDownloadInIncognito { - (void)testSucessfullDownloadInIncognito {
chrome_test_util::OpenNewIncognitoTab(); chrome_test_util::OpenNewIncognitoTab();
...@@ -108,17 +115,7 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse( ...@@ -108,17 +115,7 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
[[EarlGrey selectElementWithMatcher:DownloadButton()] [[EarlGrey selectElementWithMatcher:DownloadButton()]
performAction:grey_tap()]; performAction:grey_tap()];
// Wait until Open in... button is shown. GREYAssert(WaitForOpenInButton(), @"Open in... button did not show up");
ConditionBlock openInShown = ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:OpenInButton()]
assertWithMatcher:grey_notNil()
error:&error];
return (error == nil);
};
GREYAssert(testing::WaitUntilConditionOrTimeout(
testing::kWaitForDownloadTimeout, openInShown),
@"Open in... button did not show up");
} }
// Tests cancelling download UI. // Tests cancelling download UI.
...@@ -137,4 +134,36 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse( ...@@ -137,4 +134,36 @@ std::unique_ptr<net::test_server::HttpResponse> GetResponse(
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
} }
// Tests sucessfull download up to the point where "Open in..." button is
// presented. EarlGrey does not allow testing "Open in..." dialog, because it
// is run in a separate process. After tapping Download this test opens a
// separate tabs and loads the URL there. Then closes the tab and waits for
// the download completion.
- (void)testDownloadWhileBrowsing {
[ChromeEarlGrey loadURL:self.testServer->GetURL("/")];
[ChromeEarlGrey waitForWebViewContainingText:"Download"];
[ChromeEarlGrey tapWebViewElementWithID:@"download"];
[[EarlGrey selectElementWithMatcher:DownloadButton()]
performAction:grey_tap()];
{
// In order to open a new Tab, disable EG synchronization so the framework
// does not wait until the download progress bar becomes idle (which will
// not happen until the download is complete).
ScopedSynchronizationDisabler disabler;
chrome_test_util::OpenNewTab();
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
// Load a URL in a separate Tab and close that tab.
[ChromeEarlGrey loadURL:GURL(kChromeUITermsURL)];
const char kTermsText[] = "Google Chrome Terms of Service";
[ChromeEarlGrey waitForWebViewContainingText:kTermsText];
chrome_test_util::CloseCurrentTab();
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
GREYAssert(WaitForOpenInButton(), @"Open in... button did not show up");
}
@end @end
...@@ -32,6 +32,7 @@ source_set("test_support") { ...@@ -32,6 +32,7 @@ source_set("test_support") {
"root_view_controller_test.mm", "root_view_controller_test.mm",
"scoped_block_popups_pref.h", "scoped_block_popups_pref.h",
"scoped_block_popups_pref.mm", "scoped_block_popups_pref.mm",
"scoped_eg_synchronization_disabler.h",
"scoped_key_window.h", "scoped_key_window.h",
"testing_application_context.h", "testing_application_context.h",
"testing_application_context.mm", "testing_application_context.mm",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_TEST_SCOPED_EG_SYNCHRONIZATION_DISABLER_H_
#define IOS_CHROME_TEST_SCOPED_EG_SYNCHRONIZATION_DISABLER_H_
#import <EarlGrey/EarlGrey.h>
#include "base/macros.h"
// Disables EarlGrey synchronization in constructor and returns back to the
// original value in destructor.
class ScopedSynchronizationDisabler {
public:
ScopedSynchronizationDisabler()
: saved_eg_synchronization_enabled_value_(GetEgSynchronizationEnabled()) {
SetEgSynchronizationEnabled(NO);
}
~ScopedSynchronizationDisabler() {
SetEgSynchronizationEnabled(saved_eg_synchronization_enabled_value_);
}
private:
static bool GetEgSynchronizationEnabled() {
return [[GREYConfiguration sharedInstance]
boolValueForConfigKey:kGREYConfigKeySynchronizationEnabled];
}
static void SetEgSynchronizationEnabled(BOOL flag) {
[[GREYConfiguration sharedInstance]
setValue:@(flag)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
}
BOOL saved_eg_synchronization_enabled_value_ = NO;
DISALLOW_COPY_AND_ASSIGN(ScopedSynchronizationDisabler);
};
#endif // IOS_CHROME_TEST_SCOPED_EG_SYNCHRONIZATION_DISABLER_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