Commit a284b88d authored by Ali Juma's avatar Ali Juma Committed by Commit Bot

Make progress_indicator_egtest.mm compatible with EG2

This adds the file as an EG2 target, updates #includes, and replaces
calls to helpers that can't be used in EG2.

This also adds a ProgressIndicatorAppInterface class that provides
a matcher for MDCProgressViews with a given progress value.

Bug: 987646
Change-Id: I88b8bc9496bf962acbba59d855205cf19cf97fd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1949266
Commit-Queue: Ali Juma <ajuma@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721484}
parent cf72ff53
...@@ -316,6 +316,22 @@ source_set("unit_tests_internal") { ...@@ -316,6 +316,22 @@ source_set("unit_tests_internal") {
] ]
} }
source_set("earl_grey_support") {
configs += [ "//build/config/compiler:enable_arc" ]
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true
sources = [
"progress_indicator_app_interface.h",
"progress_indicator_app_interface.mm",
]
deps = [
"//base",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/third_party/earl_grey:earl_grey+link",
"//ios/third_party/material_components_ios",
]
}
source_set("eg_tests") { source_set("eg_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
defines = [ "CHROME_EARL_GREY_1" ] defines = [ "CHROME_EARL_GREY_1" ]
...@@ -339,6 +355,7 @@ source_set("eg_tests") { ...@@ -339,6 +355,7 @@ source_set("eg_tests") {
"window_open_by_dom_egtest.mm", "window_open_by_dom_egtest.mm",
] ]
deps = [ deps = [
":earl_grey_support",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/content_settings/core/common", "//components/content_settings/core/common",
...@@ -376,6 +393,45 @@ source_set("eg_tests") { ...@@ -376,6 +393,45 @@ source_set("eg_tests") {
] ]
} }
source_set("eg_test_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"progress_indicator_app_interface.h",
]
deps = [
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
]
}
source_set("eg_app_support+eg2") {
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
defines = [ "CHROME_EARL_GREY_2" ]
sources = [
"progress_indicator_app_interface.h",
"progress_indicator_app_interface.mm",
]
deps = [
"//base",
"//ios/testing/earl_grey:eg_app_support+eg2",
"//ios/third_party/earl_grey2:app_framework+link",
"//ios/third_party/material_components_ios",
]
}
source_set("eg2_tests") { source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ] defines = [ "CHROME_EARL_GREY_2" ]
configs += [ configs += [
...@@ -394,6 +450,7 @@ source_set("eg2_tests") { ...@@ -394,6 +450,7 @@ source_set("eg2_tests") {
"http_auth_egtest.mm", "http_auth_egtest.mm",
"js_print_egtest.mm", "js_print_egtest.mm",
"navigation_egtest.mm", "navigation_egtest.mm",
"progress_indicator_egtest.mm",
"restore_egtest.mm", "restore_egtest.mm",
"stop_loading_egtest.mm", "stop_loading_egtest.mm",
"tab_order_egtest.mm", "tab_order_egtest.mm",
...@@ -402,6 +459,7 @@ source_set("eg2_tests") { ...@@ -402,6 +459,7 @@ source_set("eg2_tests") {
] ]
deps = [ deps = [
":eg_test_support+eg2",
"//components/content_settings/core/common", "//components/content_settings/core/common",
"//components/strings", "//components/strings",
"//components/url_formatter", "//components/url_formatter",
......
// Copyright 2019 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_BROWSER_WEB_PROGRESS_INDICATOR_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_WEB_PROGRESS_INDICATOR_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@protocol GREYMatcher;
// ProgressIndicatorAppInterface contains helpers for interacting with
// MDCProgressViews. These helpers are compiled into the app binary and can be
// called from either app or test code.
@interface ProgressIndicatorAppInterface : NSObject
// Matcher for an MDCProgressView with |progress|.
+ (id<GREYMatcher>)progressViewWithProgress:(CGFloat)progress;
@end
#endif // IOS_CHROME_BROWSER_WEB_PROGRESS_INDICATOR_APP_INTERFACE_H_
// Copyright 2019 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.
#import "ios/chrome/browser/web/progress_indicator_app_interface.h"
#import <UIKit/UIKit.h>
#import "base/mac/foundation_util.h"
#import "ios/testing/earl_grey/earl_grey_app.h"
#import "ios/third_party/material_components_ios/src/components/ProgressView/src/MaterialProgressView.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ProgressIndicatorAppInterface
+ (id<GREYMatcher>)progressViewWithProgress:(CGFloat)progress {
GREYMatchesBlock matches = ^BOOL(UIView* view) {
MDCProgressView* progressView = base::mac::ObjCCast<MDCProgressView>(view);
return progressView && progressView.progress == progress;
};
GREYDescribeToBlock describe = ^(id<GREYDescription> description) {
[description appendText:@"progress view with progress: "];
[description appendText:@(progress).stringValue];
};
return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
}
@end
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#include <memory> #include <memory>
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
...@@ -14,11 +12,11 @@ ...@@ -14,11 +12,11 @@
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #import "ios/chrome/browser/web/progress_indicator_app_interface.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_earl_grey_ui.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/third_party/material_components_ios/src/components/ProgressView/src/MaterialProgressView.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#include "ios/web/public/test/http_server/html_response_provider.h" #include "ios/web/public/test/http_server/html_response_provider.h"
#import "ios/web/public/test/http_server/http_server.h" #import "ios/web/public/test/http_server/http_server.h"
#import "ios/web/public/test/http_server/http_server_util.h" #import "ios/web/public/test/http_server/http_server_util.h"
...@@ -28,6 +26,16 @@ ...@@ -28,6 +26,16 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
#if defined(CHROME_EARL_GREY_2)
// TODO(crbug.com/1015113) The EG2 macro is breaking indexing for some reason
// without the trailing semicolon. For now, disable the extra semi warning
// so Xcode indexing works for the egtest.
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ProgressIndicatorAppInterface);
#pragma clang diagnostic pop
#endif // defined(CHROME_EARL_GREY_2)
namespace { namespace {
// Text to display in form page. // Text to display in form page.
...@@ -50,24 +58,7 @@ const char kSimplePageURL[] = "http://simplepage"; ...@@ -50,24 +58,7 @@ const char kSimplePageURL[] = "http://simplepage";
// Matcher for progress view. // Matcher for progress view.
id<GREYMatcher> ProgressView() { id<GREYMatcher> ProgressView() {
return grey_kindOfClass([MDCProgressView class]); return grey_kindOfClassName(@"MDCProgressView");
}
// Matcher for the progress view with |progress|.
id<GREYMatcher> ProgressViewWithProgress(CGFloat progress) {
MatchesBlock matches = ^BOOL(UIView* view) {
MDCProgressView* progressView = base::mac::ObjCCast<MDCProgressView>(view);
return progressView && progressView.progress == progress;
};
DescribeToBlock describe = ^(id<GREYDescription> description) {
[description
appendText:[NSString stringWithFormat:@"progress view with progress:%f",
progress]];
};
return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
} }
// Response provider that serves the page which never finishes loading. // Response provider that serves the page which never finishes loading.
...@@ -191,7 +182,8 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider { ...@@ -191,7 +182,8 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider {
[ChromeEarlGrey waitForWebStateContainingText:kPageText]; [ChromeEarlGrey waitForWebStateContainingText:kPageText];
// Verify progress view visible and halfway progress. // Verify progress view visible and halfway progress.
[[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] [[EarlGrey selectElementWithMatcher:[ProgressIndicatorAppInterface
progressViewWithProgress:0.5]]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[ChromeEarlGreyUI waitForToolbarVisible:YES]; [ChromeEarlGreyUI waitForToolbarVisible:YES];
...@@ -231,7 +223,8 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider { ...@@ -231,7 +223,8 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider {
[ChromeEarlGrey waitForWebStateContainingText:kPageText]; [ChromeEarlGrey waitForWebStateContainingText:kPageText];
// Verify progress view visible and halfway progress. // Verify progress view visible and halfway progress.
[[EarlGrey selectElementWithMatcher:ProgressViewWithProgress(0.5)] [[EarlGrey selectElementWithMatcher:[ProgressIndicatorAppInterface
progressViewWithProgress:0.5]]
assertWithMatcher:grey_sufficientlyVisible()]; assertWithMatcher:grey_sufficientlyVisible()];
[ChromeEarlGreyUI waitForToolbarVisible:YES]; [ChromeEarlGreyUI waitForToolbarVisible:YES];
...@@ -288,7 +281,7 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider { ...@@ -288,7 +281,7 @@ class InfinitePendingResponseProvider : public HtmlResponseProvider {
[ChromeEarlGrey submitWebStateFormWithID:kFormID]; [ChromeEarlGrey submitWebStateFormWithID:kFormID];
// Verify progress view is not visible. // Verify progress view is not visible.
[[EarlGrey selectElementWithMatcher:grey_kindOfClass([MDCProgressView class])] [[EarlGrey selectElementWithMatcher:grey_kindOfClassName(@"MDCProgressView")]
assertWithMatcher:grey_notVisible()]; assertWithMatcher:grey_notVisible()];
} }
......
...@@ -423,6 +423,7 @@ source_set("eg_app_support+eg2") { ...@@ -423,6 +423,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:eg_app_support+eg2", "//ios/chrome/browser/ui/util:eg_app_support+eg2",
"//ios/chrome/browser/web:eg_app_support+eg2",
"//ios/chrome/browser/web:tab_id_tab_helper", "//ios/chrome/browser/web:tab_id_tab_helper",
"//ios/chrome/test/app:test_support", "//ios/chrome/test/app:test_support",
"//ios/testing:block_swizzler", "//ios/testing:block_swizzler",
......
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