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") { ...@@ -185,6 +185,7 @@ source_set("unit_tests_internal") {
} }
source_set("eg_tests") { source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
sources = [ sources = [
...@@ -221,6 +222,7 @@ source_set("eg_tests") { ...@@ -221,6 +222,7 @@ source_set("eg_tests") {
"//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/public/provider/chrome/browser/signin: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:earl_grey_test_support",
"//ios/web/public/test", "//ios/web/public/test",
"//ios/web/public/test:element_selector", "//ios/web/public/test:element_selector",
...@@ -232,16 +234,49 @@ source_set("eg_tests") { ...@@ -232,16 +234,49 @@ source_set("eg_tests") {
libs = [ "XCTest.framework" ] 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") { source_set("test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
testonly = true testonly = true
sources = [ sources = [
"metrics_app_interface.h",
"metrics_app_interface.mm",
"tab_usage_recorder_test_util.h", "tab_usage_recorder_test_util.h",
"tab_usage_recorder_test_util.mm", "tab_usage_recorder_test_util.mm",
] ]
deps = [ deps = [
":metrics",
"//base", "//base",
"//base/test:test_support",
"//components/metrics_services_manager",
"//components/ukm",
"//ios/chrome/app:app_internal", "//ios/chrome/app:app_internal",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/main", "//ios/chrome/browser/ui/main",
"//ios/chrome/browser/ui/popup_menu:constants", "//ios/chrome/browser/ui/popup_menu:constants",
...@@ -250,7 +285,9 @@ source_set("test_support") { ...@@ -250,7 +285,9 @@ source_set("test_support") {
"//ios/chrome/test:eg_test_support", "//ios/chrome/test:eg_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/earl_grey:earl_grey_support",
"//net:test_support", "//net:test_support",
"//services/metrics/public/cpp:metrics_cpp",
"//ui/base", "//ui/base",
] ]
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
...@@ -268,3 +305,43 @@ generate_expired_histograms_array("expired_histograms_array") { ...@@ -268,3 +305,43 @@ generate_expired_histograms_array("expired_histograms_array") {
major_branch_date_filepath = "//chrome/MAJOR_BRANCH_DATE" major_branch_date_filepath = "//chrome/MAJOR_BRANCH_DATE"
milestone_filepath = "//chrome/VERSION" 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)
...@@ -2,25 +2,16 @@ ...@@ -2,25 +2,16 @@
// 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>
#import <XCTest/XCTest.h> #import <XCTest/XCTest.h>
#include "base/macros.h" #include "base/macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#import "base/test/ios/wait_util.h" #import "base/test/ios/wait_util.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics_services_manager/metrics_services_manager.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/ukm/ukm_service.h" #import "ios/chrome/browser/metrics/metrics_app_interface.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.h"
#import "ios/chrome/browser/ui/authentication/cells/signin_promo_view.h"
#import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h" #import "ios/chrome/browser/ui/authentication/signin_earl_grey_ui.h"
#import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h" #import "ios/chrome/browser/ui/authentication/signin_earlgrey_utils.h"
#import "ios/chrome/browser/ui/settings/google_services/google_services_settings_view_controller.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h" #import "ios/chrome/test/earl_grey/chrome_actions.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"
...@@ -28,6 +19,7 @@ ...@@ -28,6 +19,7 @@
#import "ios/chrome/test/earl_grey/chrome_test_case.h" #import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h"
#import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h" #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -47,62 +39,11 @@ using chrome_test_util::SettingsMenuPrivacyButton; ...@@ -47,62 +39,11 @@ using chrome_test_util::SettingsMenuPrivacyButton;
using chrome_test_util::SyncSwitchCell; using chrome_test_util::SyncSwitchCell;
using chrome_test_util::TurnSyncSwitchOn; using chrome_test_util::TurnSyncSwitchOn;
namespace metrics {
// Helper class that provides access to UKM internals.
class UkmEGTestHelper {
public:
UkmEGTestHelper() {}
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(ukm::SourceId source_id) {
auto* service = ukm_service();
return service && base::Contains(service->sources(), source_id);
}
static void RecordDummySource(ukm::SourceId source_id) {
auto* service = ukm_service();
if (service)
service->UpdateSourceURL(source_id, GURL("http://example.com"));
}
private:
static ukm::UkmService* ukm_service() {
return GetApplicationContext()
->GetMetricsServicesManager()
->GetUkmService();
}
DISALLOW_COPY_AND_ASSIGN(UkmEGTestHelper);
};
} // namespace metrics
namespace { namespace {
bool g_metrics_enabled = false;
// Constant for timeout while waiting for asynchronous sync and UKM operations. // Constant for timeout while waiting for asynchronous sync and UKM operations.
const NSTimeInterval kSyncUKMOperationsTimeout = 10.0; const NSTimeInterval kSyncUKMOperationsTimeout = 10.0;
void AssertUKMEnabled(bool is_enabled) {
ConditionBlock condition = ^{
return metrics::UkmEGTestHelper::ukm_enabled() == is_enabled;
};
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
kSyncUKMOperationsTimeout, condition),
@"Failed to assert whether UKM was enabled or not.");
}
void ClearBrowsingData() { void ClearBrowsingData() {
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI tapSettingsMenuButton:SettingsMenuPrivacyButton()]; [ChromeEarlGreyUI tapSettingsMenuButton:SettingsMenuPrivacyButton()];
...@@ -154,13 +95,6 @@ void OpenNewRegularTab() { ...@@ -154,13 +95,6 @@ void OpenNewRegularTab() {
[ChromeEarlGrey waitForMainTabCount:(tab_count + 1)]; [ChromeEarlGrey waitForMainTabCount:(tab_count + 1)];
} }
// Grant/revoke metrics consent and update MetricsServicesManager.
void UpdateMetricsConsent(bool new_state) {
g_metrics_enabled = new_state;
GetApplicationContext()->GetMetricsServicesManager()->UpdateUploadPermissions(
true);
}
// Signs out of sync. // Signs out of sync.
void SignOut() { void SignOut() {
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
...@@ -190,8 +124,21 @@ void SignOut() { ...@@ -190,8 +124,21 @@ void SignOut() {
@implementation UKMTestCase @implementation UKMTestCase
#if defined(CHROME_EARL_GREY_2)
+ (void)setUpForTestCase {
[super setUpForTestCase];
[self setUpHelper];
}
#elif defined(CHROME_EARL_GREY_1)
+ (void)setUp { + (void)setUp {
[super setUp]; [super setUp];
[self setUpHelper];
}
#else
#error Not an EarlGrey Test
#endif
+ (void)setUpHelper {
if (![ChromeEarlGrey isUKMEnabled]) { if (![ChromeEarlGrey isUKMEnabled]) {
// ukm::kUkmFeature feature is not enabled. You need to pass // ukm::kUkmFeature feature is not enabled. You need to pass
// --enable-features=Ukm command line argument in order to run this test. // --enable-features=Ukm command line argument in order to run this test.
...@@ -204,8 +151,8 @@ void SignOut() { ...@@ -204,8 +151,8 @@ void SignOut() {
[ChromeEarlGrey waitForSyncInitialized:NO [ChromeEarlGrey waitForSyncInitialized:NO
syncTimeout:kSyncUKMOperationsTimeout]; syncTimeout:kSyncUKMOperationsTimeout];
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
// Sign in to Chrome and turn sync on. // Sign in to Chrome and turn sync on.
// //
// Note: URL-keyed anonymized data collection is turned on as part of the // Note: URL-keyed anonymized data collection is turned on as part of the
...@@ -216,28 +163,25 @@ void SignOut() { ...@@ -216,28 +163,25 @@ void SignOut() {
syncTimeout:kSyncUKMOperationsTimeout]; syncTimeout:kSyncUKMOperationsTimeout];
// Grant metrics consent and update MetricsServicesManager. // Grant metrics consent and update MetricsServicesManager.
GREYAssert(!g_metrics_enabled, @"Unpaired set/reset of user consent."); [MetricsAppInterface overrideMetricsAndCrashReportingForTesting];
g_metrics_enabled = true; GREYAssert(![MetricsAppInterface setMetricsAndCrashReportingForTesting:YES],
IOSChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( @"Unpaired set/reset of user consent.");
&g_metrics_enabled); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
GetApplicationContext()->GetMetricsServicesManager()->UpdateUploadPermissions( @"Failed to assert that UKM was enabled.");
true);
AssertUKMEnabled(true);
} }
- (void)tearDown { - (void)tearDown {
[ChromeEarlGrey waitForSyncInitialized:YES [ChromeEarlGrey waitForSyncInitialized:YES
syncTimeout:kSyncUKMOperationsTimeout]; syncTimeout:kSyncUKMOperationsTimeout];
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
// Revoke metrics consent and update MetricsServicesManager. // Revoke metrics consent and update MetricsServicesManager.
GREYAssert(g_metrics_enabled, @"Unpaired set/reset of user consent."); GREYAssert([MetricsAppInterface setMetricsAndCrashReportingForTesting:NO],
g_metrics_enabled = false; @"Unpaired set/reset of user consent.");
GetApplicationContext()->GetMetricsServicesManager()->UpdateUploadPermissions( [MetricsAppInterface stopOverridingMetricsAndCrashReportingForTesting];
true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
IOSChromeMetricsServiceAccessor::SetMetricsAndCrashReportingForTesting( @"Failed to assert that UKM was not enabled.");
nullptr);
AssertUKMEnabled(false);
// Sign out of Chrome and Turn sync off. // Sign out of Chrome and Turn sync off.
// //
...@@ -257,85 +201,98 @@ void SignOut() { ...@@ -257,85 +201,98 @@ void SignOut() {
// Make sure that UKM is disabled while an incognito tab is open. // Make sure that UKM is disabled while an incognito tab is open.
- (void)testRegularPlusIncognito { - (void)testRegularPlusIncognito {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t originalClientID = [MetricsAppInterface UKMClientID];
OpenNewIncognitoTab(); OpenNewIncognitoTab();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
// Opening another regular tab mustn't enable UKM. // Opening another regular tab mustn't enable UKM.
OpenNewRegularTab(); OpenNewRegularTab();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
// Opening and closing an incognito tab mustn't enable UKM. // Opening and closing an incognito tab mustn't enable UKM.
OpenNewIncognitoTab(); OpenNewIncognitoTab();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
CloseCurrentIncognitoTab(); CloseCurrentIncognitoTab();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
CloseAllIncognitoTabs(); CloseAllIncognitoTabs();
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
// Client ID should not have been reset. // Client ID should not have been reset.
GREYAssert(original_client_id == metrics::UkmEGTestHelper::client_id(), GREYAssertEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was reset."); @"Client ID was reset.");
} }
// Make sure opening a real tab after Incognito doesn't enable UKM. // Make sure opening a real tab after Incognito doesn't enable UKM.
- (void)testIncognitoPlusRegular { - (void)testIncognitoPlusRegular {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t originalClientID = [MetricsAppInterface UKMClientID];
[ChromeEarlGrey closeAllTabs]; [ChromeEarlGrey closeAllTabs];
[ChromeEarlGrey waitForMainTabCount:0]; [ChromeEarlGrey waitForMainTabCount:0];
OpenNewIncognitoTab(); OpenNewIncognitoTab();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
// Opening another regular tab mustn't enable UKM. // Opening another regular tab mustn't enable UKM.
OpenNewRegularTab(); OpenNewRegularTab();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
[ChromeEarlGrey closeAllIncognitoTabs]; [ChromeEarlGrey closeAllIncognitoTabs];
[ChromeEarlGrey waitForIncognitoTabCount:0]; [ChromeEarlGrey waitForIncognitoTabCount:0];
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
// Client ID should not have been reset. // Client ID should not have been reset.
GREYAssert(original_client_id == metrics::UkmEGTestHelper::client_id(), GREYAssertEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was reset."); @"Client ID was reset.");
} }
// testOpenNonSync not needed, since there can't be multiple profiles. // testOpenNonSync not needed, since there can't be multiple profiles.
// Make sure that UKM is disabled when metrics consent is revoked. // Make sure that UKM is disabled when metrics consent is revoked.
- (void)testMetricsConsent { - (void)testMetricsConsent {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t originalClientID = [MetricsAppInterface UKMClientID];
UpdateMetricsConsent(false); [MetricsAppInterface setMetricsAndCrashReportingForTesting:NO];
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
UpdateMetricsConsent(true); [MetricsAppInterface setMetricsAndCrashReportingForTesting:YES];
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
// Client ID should have been reset. // Client ID should have been reset.
GREYAssert(original_client_id != metrics::UkmEGTestHelper::client_id(), GREYAssertNotEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was not reset."); @"Client ID was not reset.");
} }
// Make sure that providing metrics consent doesn't enable UKM w/o sync. // Make sure that providing metrics consent doesn't enable UKM w/o sync.
- (void)testConsentAddedButNoSync { - (void)testConsentAddedButNoSync {
SignOut(); SignOut();
UpdateMetricsConsent(false); [MetricsAppInterface setMetricsAndCrashReportingForTesting:NO];
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
UpdateMetricsConsent(true); [MetricsAppInterface setMetricsAndCrashReportingForTesting:YES];
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
[SigninEarlGreyUI signinWithIdentity:[SigninEarlGreyUtils fakeIdentity1]]; [SigninEarlGreyUI signinWithIdentity:[SigninEarlGreyUtils fakeIdentity1]];
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
} }
// Make sure that UKM is disabled when sync is disabled. // Make sure that UKM is disabled when sync is disabled.
- (void)testSingleDisableSync { - (void)testSingleDisableSync {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t originalClientID = [MetricsAppInterface UKMClientID];
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
// Open Sync and Google services settings // Open Sync and Google services settings
...@@ -347,11 +304,11 @@ void SignOut() { ...@@ -347,11 +304,11 @@ void SignOut() {
@"betterSearchAndBrowsingItem_switch", @"betterSearchAndBrowsingItem_switch",
YES)] YES)]
usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200) usingSearchAction:grey_scrollInDirection(kGREYDirectionDown, 200)
onElementWithMatcher:grey_accessibilityID( onElementWithMatcher:chrome_test_util::GoogleServicesSettingsView()]
kGoogleServicesSettingsViewIdentifier)]
performAction:chrome_test_util::TurnSettingsSwitchOn(NO)]; performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
// Toggle "Make searches and browsing better" switch on. // Toggle "Make searches and browsing better" switch on.
[[EarlGrey [[EarlGrey
...@@ -359,35 +316,38 @@ void SignOut() { ...@@ -359,35 +316,38 @@ void SignOut() {
@"betterSearchAndBrowsingItem_switch", NO)] @"betterSearchAndBrowsingItem_switch", NO)]
performAction:chrome_test_util::TurnSettingsSwitchOn(YES)]; performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
// Client ID should have been reset. @"Failed to assert that UKM was enabled.");
GREYAssert(original_client_id != metrics::UkmEGTestHelper::client_id(), // Client ID should have been reset.
@"Client ID was not reset."); GREYAssertNotEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was not reset.");
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()]; performAction:grey_tap()];
} }
// testMultiDisableSync not needed, since there can't be multiple profiles. // testMultiDisableSync not needed, since there can't be multiple profiles.
// Make sure that UKM is disabled when sync is not enabled. // Make sure that UKM is disabled when sync is not enabled.
- (void)testSingleSyncSignout { - (void)testSingleSyncSignout {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t originalClientID = [MetricsAppInterface UKMClientID];
SignOut(); SignOut();
AssertUKMEnabled(false); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:NO],
@"Failed to assert that UKM was not enabled.");
// Client ID should have been reset by signout. // Client ID should have been reset by signout.
GREYAssert(original_client_id != metrics::UkmEGTestHelper::client_id(), GREYAssertNotEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was not reset."); @"Client ID was not reset.");
original_client_id = metrics::UkmEGTestHelper::client_id(); originalClientID = [MetricsAppInterface UKMClientID];
[SigninEarlGreyUI signinWithIdentity:[SigninEarlGreyUtils fakeIdentity1]]; [SigninEarlGreyUI signinWithIdentity:[SigninEarlGreyUtils fakeIdentity1]];
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
// Client ID should not have been reset. // Client ID should not have been reset.
GREYAssert(original_client_id == metrics::UkmEGTestHelper::client_id(), GREYAssertEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was reset."); @"Client ID was reset.");
} }
// testMultiSyncSignout not needed, since there can't be multiple profiles. // testMultiSyncSignout not needed, since there can't be multiple profiles.
...@@ -396,22 +356,23 @@ void SignOut() { ...@@ -396,22 +356,23 @@ void SignOut() {
// TODO(crbug.com/866598): Re-enable this test. // TODO(crbug.com/866598): Re-enable this test.
- (void)DISABLED_testHistoryDelete { - (void)DISABLED_testHistoryDelete {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t originalClientID = [MetricsAppInterface UKMClientID];
const ukm::SourceId kDummySourceId = 0x54321; const uint64_t kDummySourceId = 0x54321;
metrics::UkmEGTestHelper::RecordDummySource(kDummySourceId); [MetricsAppInterface UKMRecordDummySource:kDummySourceId];
GREYAssert(metrics::UkmEGTestHelper::HasDummySource(kDummySourceId), GREYAssert([MetricsAppInterface UKMHasDummySource:kDummySourceId],
@"Dummy source failed to record."); @"Dummy source failed to record.");
ClearBrowsingData(); ClearBrowsingData();
// Other sources may already have been recorded since the data was cleared, // Other sources may already have been recorded since the data was cleared,
// but the dummy source should be gone. // but the dummy source should be gone.
GREYAssert(!metrics::UkmEGTestHelper::HasDummySource(kDummySourceId), GREYAssert(![MetricsAppInterface UKMHasDummySource:kDummySourceId],
@"Dummy source was not purged."); @"Dummy source was not purged.");
GREYAssert(original_client_id == metrics::UkmEGTestHelper::client_id(), GREYAssertEqual(originalClientID, [MetricsAppInterface UKMClientID],
@"Client ID was reset."); @"Client ID was reset.");
AssertUKMEnabled(true); GREYAssert([MetricsAppInterface checkUKMRecordingEnabled:YES],
@"Failed to assert that UKM was enabled.");
} }
@end @end
...@@ -22,27 +22,6 @@ ...@@ -22,27 +22,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #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::AccountConsistencyConfirmationOkButton;
using chrome_test_util::ButtonWithAccessibilityLabel; using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::PrimarySignInButton; using chrome_test_util::PrimarySignInButton;
...@@ -117,7 +96,7 @@ using chrome_test_util::UnifiedConsentAddAccountButton; ...@@ -117,7 +96,7 @@ using chrome_test_util::UnifiedConsentAddAccountButton;
grey_accessibilityID(kUnifiedConsentScrollViewIdentifier); grey_accessibilityID(kUnifiedConsentScrollViewIdentifier);
NSError* error = nil; NSError* error = nil;
[[EarlGrey selectElementWithMatcher:confirmationScrollViewMatcher] [[EarlGrey selectElementWithMatcher:confirmationScrollViewMatcher]
assertWithMatcher:ContentViewSmallerThanScrollView() assertWithMatcher:chrome_test_util::ContentViewSmallerThanScrollView()
error:&error]; error:&error];
if (error) { if (error) {
// If the consent is bigger than the scroll view, the primary button should // If the consent is bigger than the scroll view, the primary button should
...@@ -139,7 +118,7 @@ using chrome_test_util::UnifiedConsentAddAccountButton; ...@@ -139,7 +118,7 @@ using chrome_test_util::UnifiedConsentAddAccountButton;
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; [[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
NSError* error = nil; NSError* error = nil;
[[EarlGrey selectElementWithMatcher:confirmationScrollViewMatcher] [[EarlGrey selectElementWithMatcher:confirmationScrollViewMatcher]
assertWithMatcher:ContentViewSmallerThanScrollView() assertWithMatcher:chrome_test_util::ContentViewSmallerThanScrollView()
error:&error]; error:&error];
if (error) { if (error) {
// If the consent is bigger than the scroll view, the primary button should // If the consent is bigger than the scroll view, the primary button should
......
...@@ -367,6 +367,7 @@ source_set("eg_app_support+eg2") { ...@@ -367,6 +367,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/content_settings:content_settings", "//ios/chrome/browser/content_settings:content_settings",
"//ios/chrome/browser/device_sharing:eg_app_support+eg2", "//ios/chrome/browser/device_sharing:eg_app_support+eg2",
"//ios/chrome/browser/find_in_page", "//ios/chrome/browser/find_in_page",
"//ios/chrome/browser/metrics:eg_app_support+eg2",
"//ios/chrome/browser/ntp:features", "//ios/chrome/browser/ntp:features",
"//ios/chrome/browser/passwords", "//ios/chrome/browser/passwords",
"//ios/chrome/browser/passwords:eg_app_support+eg2", "//ios/chrome/browser/passwords:eg_app_support+eg2",
......
...@@ -583,6 +583,7 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC; ...@@ -583,6 +583,7 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
+ (BOOL)isUKMEnabled { + (BOOL)isUKMEnabled {
return base::FeatureList::IsEnabled(ukm::kUkmFeature); return base::FeatureList::IsEnabled(ukm::kUkmFeature);
} }
+ (BOOL)isWebPaymentsModifiersEnabled { + (BOOL)isWebPaymentsModifiersEnabled {
return base::FeatureList::IsEnabled( return base::FeatureList::IsEnabled(
payments::features::kWebPaymentsModifiers); payments::features::kWebPaymentsModifiers);
......
...@@ -238,6 +238,9 @@ id<GREYMatcher> ContentSettingsButton(); ...@@ -238,6 +238,9 @@ id<GREYMatcher> ContentSettingsButton();
// screen. // screen.
id<GREYMatcher> GoogleServicesSettingsButton(); id<GREYMatcher> GoogleServicesSettingsButton();
// Returns matcher for the Google Services Settings view.
id<GREYMatcher> GoogleServicesSettingsView();
// Returns matcher for the back button on a settings menu. // Returns matcher for the back button on a settings menu.
id<GREYMatcher> SettingsMenuBackButton(); id<GREYMatcher> SettingsMenuBackButton();
...@@ -390,6 +393,10 @@ id<GREYMatcher> SettingsBottomToolbarDeleteButton(); ...@@ -390,6 +393,10 @@ id<GREYMatcher> SettingsBottomToolbarDeleteButton();
// Returns a matcher for an autofill suggestion view. // Returns a matcher for an autofill suggestion view.
id<GREYMatcher> AutofillSuggestionViewMatcher(); 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 #pragma mark - Manual Fallback
// Returns a matcher for the scroll view in keyboard accessory bar. // Returns a matcher for the scroll view in keyboard accessory bar.
......
...@@ -299,6 +299,10 @@ id<GREYMatcher> GoogleServicesSettingsButton() { ...@@ -299,6 +299,10 @@ id<GREYMatcher> GoogleServicesSettingsButton() {
return [ChromeMatchersAppInterface googleServicesSettingsButton]; return [ChromeMatchersAppInterface googleServicesSettingsButton];
} }
id<GREYMatcher> GoogleServicesSettingsView() {
return [ChromeMatchersAppInterface googleServicesSettingsView];
}
id<GREYMatcher> SettingsMenuBackButton() { id<GREYMatcher> SettingsMenuBackButton() {
return [ChromeMatchersAppInterface settingsMenuBackButton]; return [ChromeMatchersAppInterface settingsMenuBackButton];
} }
...@@ -487,6 +491,10 @@ id<GREYMatcher> AutofillSuggestionViewMatcher() { ...@@ -487,6 +491,10 @@ id<GREYMatcher> AutofillSuggestionViewMatcher() {
return [ChromeMatchersAppInterface autofillSuggestionViewMatcher]; return [ChromeMatchersAppInterface autofillSuggestionViewMatcher];
} }
id<GREYMatcher> ContentViewSmallerThanScrollView() {
return [ChromeMatchersAppInterface contentViewSmallerThanScrollView];
}
#pragma mark - Manual Fallback #pragma mark - Manual Fallback
id<GREYMatcher> ManualFallbackFormSuggestionViewMatcher() { id<GREYMatcher> ManualFallbackFormSuggestionViewMatcher() {
......
...@@ -243,6 +243,9 @@ ...@@ -243,6 +243,9 @@
// screen. // screen.
+ (id<GREYMatcher>)googleServicesSettingsButton; + (id<GREYMatcher>)googleServicesSettingsButton;
// Returns matcher for the Google Services Settings view.
+ (id<GREYMatcher>)googleServicesSettingsView;
// Returns matcher for the back button on a settings menu. // Returns matcher for the back button on a settings menu.
+ (id<GREYMatcher>)settingsMenuBackButton; + (id<GREYMatcher>)settingsMenuBackButton;
...@@ -395,6 +398,10 @@ ...@@ -395,6 +398,10 @@
// Returns a matcher for an autofill suggestion view. // Returns a matcher for an autofill suggestion view.
+ (id<GREYMatcher>)autofillSuggestionViewMatcher; + (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 #pragma mark - Manual Fallback
// Returns a matcher for the scroll view in keyboard accessory bar. // Returns a matcher for the scroll view in keyboard accessory bar.
......
...@@ -43,6 +43,7 @@ ...@@ -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/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/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/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/import_data_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/password/passwords_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" #import "ios/chrome/browser/ui/settings/privacy_table_view_controller.h"
...@@ -539,6 +540,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -539,6 +540,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
grey_descendant(mainTextLabelMatcher), nil); grey_descendant(mainTextLabelMatcher), nil);
} }
+ (id<GREYMatcher>)googleServicesSettingsView {
return grey_accessibilityID(kGoogleServicesSettingsViewIdentifier);
}
+ (id<GREYMatcher>)settingsMenuBackButton { + (id<GREYMatcher>)settingsMenuBackButton {
UINavigationBar* navBar = base::mac::ObjCCastStrict<UINavigationBar>( UINavigationBar* navBar = base::mac::ObjCCastStrict<UINavigationBar>(
SubviewWithAccessibilityIdentifier( SubviewWithAccessibilityIdentifier(
...@@ -769,6 +774,21 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id, ...@@ -769,6 +774,21 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSettingsToolbarDeleteButtonId); 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 #pragma mark - Manual Fallback
+ (id<GREYMatcher>)manualFallbackFormSuggestionViewMatcher { + (id<GREYMatcher>)manualFallbackFormSuggestionViewMatcher {
......
...@@ -37,6 +37,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") { ...@@ -37,6 +37,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") {
"//ios/chrome/browser/autofill:eg2_tests", "//ios/chrome/browser/autofill:eg2_tests",
"//ios/chrome/browser/context_menu:eg2_tests", "//ios/chrome/browser/context_menu:eg2_tests",
"//ios/chrome/browser/device_sharing:eg2_tests", "//ios/chrome/browser/device_sharing:eg2_tests",
"//ios/chrome/browser/metrics:eg2_tests",
"//ios/chrome/browser/net:eg2_tests", "//ios/chrome/browser/net:eg2_tests",
"//ios/chrome/browser/ntp_tiles:eg2_tests", "//ios/chrome/browser/ntp_tiles:eg2_tests",
"//ios/chrome/browser/passwords: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