Commit 31919d90 authored by Olivier Robin's avatar Olivier Robin Committed by Commit Bot

[EG2] Convert UKM_egtests

Change-Id: If54ec885d33968950b827e91b0fda0d1619d8807
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1919147
Commit-Queue: Olivier Robin <olivierrobin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718099}
parent 325e4efb
......@@ -185,6 +185,7 @@ source_set("unit_tests_internal") {
}
source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
......@@ -221,6 +222,7 @@ source_set("eg_tests") {
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//ios/web:earl_grey_test_support",
"//ios/web/public/test",
"//ios/web/public/test:element_selector",
......@@ -232,16 +234,49 @@ source_set("eg_tests") {
libs = [ "XCTest.framework" ]
}
source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"ukm_egtest.mm",
]
deps = [
":eg_test_support+eg2",
"//base/test:test_support",
"//components/strings:components_strings_grit",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser/ui/authentication:eg_test_support+eg2",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ui/base:base",
]
libs = [ "UIKit.framework" ]
}
source_set("test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true
sources = [
"metrics_app_interface.h",
"metrics_app_interface.mm",
"tab_usage_recorder_test_util.h",
"tab_usage_recorder_test_util.mm",
]
deps = [
":metrics",
"//base",
"//base/test:test_support",
"//components/metrics_services_manager",
"//components/ukm",
"//ios/chrome/app:app_internal",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/popup_menu:constants",
......@@ -250,7 +285,9 @@ source_set("test_support") {
"//ios/chrome/test:eg_test_support",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/testing/earl_grey:earl_grey_support",
"//net:test_support",
"//services/metrics/public/cpp:metrics_cpp",
"//ui/base",
]
configs += [ "//build/config/compiler:enable_arc" ]
......@@ -268,3 +305,43 @@ generate_expired_histograms_array("expired_histograms_array") {
major_branch_date_filepath = "//chrome/MAJOR_BRANCH_DATE"
milestone_filepath = "//chrome/VERSION"
}
source_set("eg_app_support+eg2") {
defines = [ "CHROME_EARL_GREY_2" ]
configs += [
"//build/config/compiler:enable_arc",
"//build/config/ios:xctest_config",
]
testonly = true
sources = [
"metrics_app_interface.h",
"metrics_app_interface.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//components/metrics_services_manager",
"//components/metrics_services_manager:metrics_services_manager",
"//components/ukm",
"//ios/chrome/browser",
"//ios/chrome/browser/metrics",
"//services/metrics/public/cpp:metrics_cpp",
]
}
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 = [
"metrics_app_interface.h",
"metrics_app_interface_stub.mm",
]
deps = [
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
]
}
// 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_METRICS_METRICS_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_METRICS_METRICS_APP_INTERFACE_H_
#import <Foundation/Foundation.h>
// MetricsAppInterface contains the app-side
// implementation for helpers. These helpers are compiled into
// the app binary and can be called from either app or test code.
@interface MetricsAppInterface : NSObject
// Enable/Disable the metrics in the app for test.
// |overrideMetricsAndCrashReportingForTesting| must be called before setting
// the value
// |stopOverridingMetricsAndCrashReportingForTesting| must be called at the end
// of the test for cleanup.
// |setMetricsAndCrashReportingForTesting:| can be called to set to
// enable/disable metrics. It returns whether metrics were previously enabled.
+ (void)overrideMetricsAndCrashReportingForTesting;
+ (void)stopOverridingMetricsAndCrashReportingForTesting;
+ (BOOL)setMetricsAndCrashReportingForTesting:(BOOL)enabled;
// Returns whether the UKM recording is |enabled|.
+ (BOOL)checkUKMRecordingEnabled:(BOOL)enabled;
// Returns the current UKM client ID.
+ (uint64_t)UKMClientID;
// Checks whether a sourceID is registered for UKM.
+ (BOOL)UKMHasDummySource:(int64_t)sourceId;
// Adds a new sourceID for UKM.
+ (void)UKMRecordDummySource:(int64_t)sourceId;
@end
#endif // IOS_CHROME_BROWSER_METRICS_METRICS_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.
#include "ios/chrome/browser/metrics/metrics_app_interface.h"
#include "base/stl_util.h"
#import "base/test/ios/wait_util.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/ukm/ukm_service.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
// Constant for timeout while waiting for asynchronous sync and UKM operations.
const NSTimeInterval kSyncUKMOperationsTimeout = 10.0;
bool g_metrics_enabled = false;
namespace metrics {
// Helper class that provides access to UKM internals.
// This class is a friend of UKMService and UkmRecorderImpl.
class UkmEGTestHelper {
public:
UkmEGTestHelper() {}
UkmEGTestHelper(const UkmEGTestHelper&) = delete;
UkmEGTestHelper& operator=(UkmEGTestHelper&) = delete;
static bool ukm_enabled() {
auto* service = ukm_service();
return service ? service->recording_enabled_ : false;
}
static uint64_t client_id() {
auto* service = ukm_service();
return service ? service->client_id_ : 0;
}
static bool HasDummySource(int64_t source_id_as_int64) {
auto* service = ukm_service();
ukm::SourceId source_id = source_id_as_int64;
return service && base::Contains(service->sources(), source_id);
}
static void RecordDummySource(ukm::SourceId source_id_as_int64) {
ukm::UkmService* service = ukm_service();
ukm::SourceId source_id = source_id_as_int64;
if (service)
service->UpdateSourceURL(source_id, GURL("http://example.com"));
}
private:
static ukm::UkmService* ukm_service() {
return GetApplicationContext()
->GetMetricsServicesManager()
->GetUkmService();
}
};
} // namespace metrics
@implementation MetricsAppInterface : NSObject
+ (void)overrideMetricsAndCrashReportingForTesting {
IOSChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
&g_metrics_enabled);
}
+ (void)stopOverridingMetricsAndCrashReportingForTesting {
IOSChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting(
nullptr);
}
+ (BOOL)setMetricsAndCrashReportingForTesting:(BOOL)enabled {
BOOL previousValue = g_metrics_enabled;
g_metrics_enabled = enabled;
GetApplicationContext()->GetMetricsServicesManager()->UpdateUploadPermissions(
true);
return previousValue;
}
+ (BOOL)checkUKMRecordingEnabled:(BOOL)enabled {
ConditionBlock condition = ^{
return metrics::UkmEGTestHelper::ukm_enabled() == enabled;
};
return base::test::ios::WaitUntilConditionOrTimeout(kSyncUKMOperationsTimeout,
condition);
}
+ (uint64_t)UKMClientID {
return metrics::UkmEGTestHelper::client_id();
}
+ (BOOL)UKMHasDummySource:(int64_t)sourceId {
return metrics::UkmEGTestHelper::HasDummySource(sourceId);
}
+ (void)UKMRecordDummySource:(int64_t)sourceID {
return metrics::UkmEGTestHelper::RecordDummySource(sourceID);
}
@end
// 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/metrics/metrics_app_interface.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#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(MetricsAppInterface);
#pragma clang diagnostic pop
#endif // defined(CHROME_EARL_GREY_2)
This diff is collapsed.
......@@ -22,27 +22,6 @@
#error "This file requires ARC support."
#endif
namespace {
// Returns a matcher to test whether the element is a scroll view with a content
// smaller than the scroll view bounds.
id<GREYMatcher> ContentViewSmallerThanScrollView() {
GREYMatchesBlock matches = ^BOOL(UIView* view) {
UIScrollView* scrollView = base::mac::ObjCCast<UIScrollView>(view);
return scrollView &&
scrollView.contentSize.height < scrollView.bounds.size.height;
};
GREYDescribeToBlock describe = ^void(id<GREYDescription> description) {
[description appendText:
@"Not a scroll view or the scroll view content is bigger "
@"than the scroll view bounds"];
};
return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
}
} // namespace
using chrome_test_util::AccountConsistencyConfirmationOkButton;
using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::PrimarySignInButton;
......@@ -117,7 +96,7 @@ using chrome_test_util::UnifiedConsentAddAccountButton;
grey_accessibilityID(kUnifiedConsentScrollViewIdentifier);
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:confirmationScrollViewMatcher]
assertWithMatcher:ContentViewSmallerThanScrollView()
assertWithMatcher:chrome_test_util::ContentViewSmallerThanScrollView()
error:&error];
if (error) {
// If the consent is bigger than the scroll view, the primary button should
......@@ -139,7 +118,7 @@ using chrome_test_util::UnifiedConsentAddAccountButton;
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:confirmationScrollViewMatcher]
assertWithMatcher:ContentViewSmallerThanScrollView()
assertWithMatcher:chrome_test_util::ContentViewSmallerThanScrollView()
error:&error];
if (error) {
// If the consent is bigger than the scroll view, the primary button should
......
......@@ -367,6 +367,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/content_settings:content_settings",
"//ios/chrome/browser/device_sharing:eg_app_support+eg2",
"//ios/chrome/browser/find_in_page",
"//ios/chrome/browser/metrics:eg_app_support+eg2",
"//ios/chrome/browser/ntp:features",
"//ios/chrome/browser/passwords",
"//ios/chrome/browser/passwords:eg_app_support+eg2",
......
......@@ -583,6 +583,7 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
+ (BOOL)isUKMEnabled {
return base::FeatureList::IsEnabled(ukm::kUkmFeature);
}
+ (BOOL)isWebPaymentsModifiersEnabled {
return base::FeatureList::IsEnabled(
payments::features::kWebPaymentsModifiers);
......
......@@ -238,6 +238,9 @@ id<GREYMatcher> ContentSettingsButton();
// screen.
id<GREYMatcher> GoogleServicesSettingsButton();
// Returns matcher for the Google Services Settings view.
id<GREYMatcher> GoogleServicesSettingsView();
// Returns matcher for the back button on a settings menu.
id<GREYMatcher> SettingsMenuBackButton();
......@@ -390,6 +393,10 @@ id<GREYMatcher> SettingsBottomToolbarDeleteButton();
// Returns a matcher for an autofill suggestion view.
id<GREYMatcher> AutofillSuggestionViewMatcher();
// Returns a matcher to test whether the element is a scroll view with a content
// smaller than the scroll view bounds.
id<GREYMatcher> ContentViewSmallerThanScrollView();
#pragma mark - Manual Fallback
// Returns a matcher for the scroll view in keyboard accessory bar.
......
......@@ -299,6 +299,10 @@ id<GREYMatcher> GoogleServicesSettingsButton() {
return [ChromeMatchersAppInterface googleServicesSettingsButton];
}
id<GREYMatcher> GoogleServicesSettingsView() {
return [ChromeMatchersAppInterface googleServicesSettingsView];
}
id<GREYMatcher> SettingsMenuBackButton() {
return [ChromeMatchersAppInterface settingsMenuBackButton];
}
......@@ -487,6 +491,10 @@ id<GREYMatcher> AutofillSuggestionViewMatcher() {
return [ChromeMatchersAppInterface autofillSuggestionViewMatcher];
}
id<GREYMatcher> ContentViewSmallerThanScrollView() {
return [ChromeMatchersAppInterface contentViewSmallerThanScrollView];
}
#pragma mark - Manual Fallback
id<GREYMatcher> ManualFallbackFormSuggestionViewMatcher() {
......
......@@ -243,6 +243,9 @@
// screen.
+ (id<GREYMatcher>)googleServicesSettingsButton;
// Returns matcher for the Google Services Settings view.
+ (id<GREYMatcher>)googleServicesSettingsView;
// Returns matcher for the back button on a settings menu.
+ (id<GREYMatcher>)settingsMenuBackButton;
......@@ -395,6 +398,10 @@
// Returns a matcher for an autofill suggestion view.
+ (id<GREYMatcher>)autofillSuggestionViewMatcher;
// Returns a matcher to test whether the element is a scroll view with a content
// smaller than the scroll view bounds.
+ (id<GREYMatcher>)contentViewSmallerThanScrollView;
#pragma mark - Manual Fallback
// Returns a matcher for the scroll view in keyboard accessory bar.
......
......@@ -43,6 +43,7 @@
#import "ios/chrome/browser/ui/settings/credit_card_scanner/credit_card_scanner_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/accounts_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/google_services/advanced_signin_settings_coordinator.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_view_controller.h"
#import "ios/chrome/browser/ui/settings/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/password/passwords_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/privacy_table_view_controller.h"
......@@ -539,6 +540,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
grey_descendant(mainTextLabelMatcher), nil);
}
+ (id<GREYMatcher>)googleServicesSettingsView {
return grey_accessibilityID(kGoogleServicesSettingsViewIdentifier);
}
+ (id<GREYMatcher>)settingsMenuBackButton {
UINavigationBar* navBar = base::mac::ObjCCastStrict<UINavigationBar>(
SubviewWithAccessibilityIdentifier(
......@@ -769,6 +774,21 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSettingsToolbarDeleteButtonId);
}
+ (id<GREYMatcher>)contentViewSmallerThanScrollView {
GREYMatchesBlock matches = ^BOOL(UIView* view) {
UIScrollView* scrollView = base::mac::ObjCCast<UIScrollView>(view);
return scrollView &&
scrollView.contentSize.height < scrollView.bounds.size.height;
};
GREYDescribeToBlock describe = ^void(id<GREYDescription> description) {
[description
appendText:@"Not a scroll view or the scroll view content is bigger "
@"than the scroll view bounds"];
};
return [[GREYElementMatcherBlock alloc] initWithMatchesBlock:matches
descriptionBlock:describe];
}
#pragma mark - Manual Fallback
+ (id<GREYMatcher>)manualFallbackFormSuggestionViewMatcher {
......
......@@ -37,6 +37,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") {
"//ios/chrome/browser/autofill:eg2_tests",
"//ios/chrome/browser/context_menu:eg2_tests",
"//ios/chrome/browser/device_sharing:eg2_tests",
"//ios/chrome/browser/metrics:eg2_tests",
"//ios/chrome/browser/net:eg2_tests",
"//ios/chrome/browser/ntp_tiles:eg2_tests",
"//ios/chrome/browser/passwords:eg2_tests",
......
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