Commit 4447879e authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Fix Earl Grey tests for Unified Consent.

This CL updates earl grey tests to work with Unified Consent feature
enabled on iOS. It also runs all first run ui earl grey tests on the
ios_chrome_unified_consent_egtests bot.

Bug: 960260
Change-Id: I537e2c3b3c8b096d7ca0acb600eb362cbca38c34
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1609905Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Reviewed-by: default avatarYuly Novikov <ynovikov@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661330}
parent 644100d8
...@@ -191,6 +191,7 @@ source_set("eg_tests") { ...@@ -191,6 +191,7 @@ source_set("eg_tests") {
"//components/strings", "//components/strings",
"//components/ukm", "//components/ukm",
"//components/ukm:test_support", "//components/ukm:test_support",
"//components/unified_consent:unified_consent",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/metrics", "//ios/chrome/browser/metrics",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "components/metrics_services_manager/metrics_services_manager.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" #include "components/ukm/ukm_service.h"
#include "components/unified_consent/feature.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/metrics/ios_chrome_metrics_service_accessor.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/cells/signin_promo_view.h"
...@@ -42,6 +43,7 @@ using chrome_test_util::ButtonWithAccessibilityLabel; ...@@ -42,6 +43,7 @@ using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::ButtonWithAccessibilityLabelId; using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::ClearBrowsingDataView; using chrome_test_util::ClearBrowsingDataView;
using chrome_test_util::GetIncognitoTabCount; using chrome_test_util::GetIncognitoTabCount;
using chrome_test_util::GoogleServicesSettingsButton;
using chrome_test_util::IsIncognitoMode; using chrome_test_util::IsIncognitoMode;
using chrome_test_util::SettingsAccountButton; using chrome_test_util::SettingsAccountButton;
using chrome_test_util::SettingsDoneButton; using chrome_test_util::SettingsDoneButton;
...@@ -348,36 +350,54 @@ void SignOut() { ...@@ -348,36 +350,54 @@ void SignOut() {
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t original_client_id = metrics::UkmEGTestHelper::client_id();
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
// Open accounts settings, then sync settings. if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
[[EarlGrey selectElementWithMatcher:SettingsAccountButton()] // Open Sync and Google services settings
performAction:grey_tap()]; [ChromeEarlGreyUI tapSettingsMenuButton:GoogleServicesSettingsButton()];
[[EarlGrey selectElementWithMatcher:AccountsSyncButton()] // Toggle "Make searches and browsing better" switch off.
performAction:grey_tap()]; [[EarlGrey
// Toggle "Sync Everything" then "History" switches off. selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
[[EarlGrey selectElementWithMatcher:SyncSwitchCell( @"betterSearchAndBrowsingItem_switch",
l10n_util::GetNSString( YES)]
IDS_IOS_SYNC_EVERYTHING_TITLE), performAction:chrome_test_util::TurnSettingsSwitchOn(NO)];
YES)] } else {
performAction:TurnSyncSwitchOn(NO)]; // Open accounts settings, then sync settings.
[[EarlGrey [[EarlGrey selectElementWithMatcher:SettingsAccountButton()]
selectElementWithMatcher:SyncSwitchCell(l10n_util::GetNSString( performAction:grey_tap()];
IDS_SYNC_DATATYPE_TYPED_URLS), [[EarlGrey selectElementWithMatcher:AccountsSyncButton()]
YES)] performAction:grey_tap()];
performAction:TurnSyncSwitchOn(NO)]; // Toggle "Sync Everything" then "History" switches off.
[[EarlGrey selectElementWithMatcher:SyncSwitchCell(
l10n_util::GetNSString(
IDS_IOS_SYNC_EVERYTHING_TITLE),
YES)]
performAction:TurnSyncSwitchOn(NO)];
[[EarlGrey selectElementWithMatcher:SyncSwitchCell(
l10n_util::GetNSString(
IDS_SYNC_DATATYPE_TYPED_URLS),
YES)]
performAction:TurnSyncSwitchOn(NO)];
}
AssertUKMEnabled(false); AssertUKMEnabled(false);
// Toggle "History" then "Sync Everything" switches on. if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
[[EarlGrey // Toggle "Make searches and browsing better" switch on.
selectElementWithMatcher:SyncSwitchCell(l10n_util::GetNSString( [[EarlGrey
IDS_SYNC_DATATYPE_TYPED_URLS), selectElementWithMatcher:chrome_test_util::SettingsSwitchCell(
NO)] @"betterSearchAndBrowsingItem_switch", NO)]
performAction:TurnSyncSwitchOn(YES)]; performAction:chrome_test_util::TurnSettingsSwitchOn(YES)];
[[EarlGrey selectElementWithMatcher:SyncSwitchCell( } else {
l10n_util::GetNSString( // Toggle "History" then "Sync Everything" switches on.
IDS_IOS_SYNC_EVERYTHING_TITLE), [[EarlGrey selectElementWithMatcher:SyncSwitchCell(
NO)] l10n_util::GetNSString(
performAction:TurnSyncSwitchOn(YES)]; IDS_SYNC_DATATYPE_TYPED_URLS),
NO)]
performAction:TurnSyncSwitchOn(YES)];
[[EarlGrey selectElementWithMatcher:SyncSwitchCell(
l10n_util::GetNSString(
IDS_IOS_SYNC_EVERYTHING_TITLE),
NO)]
performAction:TurnSyncSwitchOn(YES)];
}
AssertUKMEnabled(true); AssertUKMEnabled(true);
// Client ID should have been reset. // Client ID should have been reset.
...@@ -392,6 +412,12 @@ void SignOut() { ...@@ -392,6 +412,12 @@ void SignOut() {
// Make sure that UKM is disabled when a secondary passphrase is used. // Make sure that UKM is disabled when a secondary passphrase is used.
- (void)testSecondaryPassphrase { - (void)testSecondaryPassphrase {
if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
EARL_GREY_TEST_DISABLED(
@"When Unified Consent feature is enabled, setting a custom passphrase "
"does not disable UKM anymore, so this test is not needed");
}
uint64_t original_client_id = metrics::UkmEGTestHelper::client_id(); uint64_t original_client_id = metrics::UkmEGTestHelper::client_id();
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
......
...@@ -243,6 +243,7 @@ source_set("eg_tests") { ...@@ -243,6 +243,7 @@ source_set("eg_tests") {
"//components/reading_list/core", "//components/reading_list/core",
"//components/search_engines", "//components/search_engines",
"//components/strings", "//components/strings",
"//components/unified_consent",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "components/ntp_snippets/content_suggestions_service.h" #include "components/ntp_snippets/content_suggestions_service.h"
#include "components/ntp_snippets/mock_content_suggestions_provider.h" #include "components/ntp_snippets/mock_content_suggestions_provider.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/unified_consent/feature.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/chrome_switches.h" #include "ios/chrome/browser/chrome_switches.h"
#include "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.h" #include "ios/chrome/browser/ntp_snippets/ios_chrome_content_suggestions_service_factory.h"
...@@ -240,6 +241,14 @@ GREYElementInteraction* CellWithMatcher(id<GREYMatcher> matcher) { ...@@ -240,6 +241,14 @@ GREYElementInteraction* CellWithMatcher(id<GREYMatcher> matcher) {
// behavior depends on having a real remote provider, so it cannot be tested // behavior depends on having a real remote provider, so it cannot be tested
// here. // here.
- (void)testPrivacySwitch { - (void)testPrivacySwitch {
if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
EARL_GREY_TEST_DISABLED(
@"Privacy swich for ContentSuggestion was moved to the Sync and Google "
"services settings screen, so it is no longer present in the privacy "
"section. This test is now covered by "
"-[GoogleServicesSettingsTestCase testOpeningServices].");
}
[ChromeEarlGreyUI openSettingsMenu]; [ChromeEarlGreyUI openSettingsMenu];
[ChromeEarlGreyUI [ChromeEarlGreyUI
tapSettingsMenuButton:chrome_test_util::SettingsMenuPrivacyButton()]; tapSettingsMenuButton:chrome_test_util::SettingsMenuPrivacyButton()];
......
...@@ -95,6 +95,7 @@ source_set("eg_tests") { ...@@ -95,6 +95,7 @@ source_set("eg_tests") {
"//base/test:test_support", "//base/test:test_support",
"//components/metrics", "//components/metrics",
"//components/prefs", "//components/prefs",
"//components/unified_consent",
"//ios/chrome/app:app_internal", "//ios/chrome/app:app_internal",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/metrics/metrics_reporting_default_state.h" #include "components/metrics/metrics_reporting_default_state.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/unified_consent/feature.h"
#import "ios/chrome/app/main_controller.h" #import "ios/chrome/app/main_controller.h"
#include "ios/chrome/browser/application_context.h" #include "ios/chrome/browser/application_context.h"
#import "ios/chrome/browser/geolocation/omnibox_geolocation_controller+Testing.h" #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller+Testing.h"
...@@ -18,6 +19,7 @@ ...@@ -18,6 +19,7 @@
#import "ios/chrome/browser/geolocation/test_location_manager.h" #import "ios/chrome/browser/geolocation/test_location_manager.h"
#include "ios/chrome/browser/sync/sync_setup_service.h" #include "ios/chrome/browser/sync/sync_setup_service.h"
#include "ios/chrome/browser/sync/sync_setup_service_factory.h" #include "ios/chrome/browser/sync/sync_setup_service_factory.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/first_run/first_run_chrome_signin_view_controller.h" #import "ios/chrome/browser/ui/first_run/first_run_chrome_signin_view_controller.h"
#include "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" #include "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h"
...@@ -40,6 +42,7 @@ using chrome_test_util::ButtonWithAccessibilityLabel; ...@@ -40,6 +42,7 @@ using chrome_test_util::ButtonWithAccessibilityLabel;
using chrome_test_util::ButtonWithAccessibilityLabelId; using chrome_test_util::ButtonWithAccessibilityLabelId;
using chrome_test_util::SettingsDoneButton; using chrome_test_util::SettingsDoneButton;
using chrome_test_util::SettingsMenuBackButton; using chrome_test_util::SettingsMenuBackButton;
using chrome_test_util::SyncSettingsConfirmButton;
namespace { namespace {
...@@ -65,19 +68,6 @@ id<GREYMatcher> UndoAccountConsistencyButton() { ...@@ -65,19 +68,6 @@ id<GREYMatcher> UndoAccountConsistencyButton() {
return ButtonWithAccessibilityLabelId( return ButtonWithAccessibilityLabelId(
IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON); IDS_IOS_ACCOUNT_CONSISTENCY_CONFIRMATION_UNDO_BUTTON);
} }
// Wait until |matcher| is accessible (not nil)
void WaitForMatcher(id<GREYMatcher> matcher) {
ConditionBlock condition = ^{
NSError* error = nil;
[[EarlGrey selectElementWithMatcher:matcher] assertWithMatcher:grey_notNil()
error:&error];
return error == nil;
};
GREYAssert(base::test::ios::WaitUntilConditionOrTimeout(
base::test::ios::kWaitForUIElementTimeout, condition),
@"Waiting for matcher %@ failed.", matcher);
}
} }
@interface MainController (ExposedForTesting) @interface MainController (ExposedForTesting)
...@@ -209,6 +199,12 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -209,6 +199,12 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
// Signs in to an account and then taps the Undo button to sign out. // Signs in to an account and then taps the Undo button to sign out.
- (void)testSignInAndUndo { - (void)testSignInAndUndo {
if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
LOG(WARNING) << "Skipping test as there is no undo operation when "
"Unified Consent is enabled.";
return;
}
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1]; ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity); identity);
...@@ -237,6 +233,15 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -237,6 +233,15 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
// Signs in to an account and then taps the Advanced link to go to settings. // Signs in to an account and then taps the Advanced link to go to settings.
- (void)testSignInAndTapSettingsLink { - (void)testSignInAndTapSettingsLink {
if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
// TODO(crbug.com/963412): Update the test once opening the Sync and Google
// Services settings screen is correctly open when the user taps on
// the Settings link from the FRE.
EARL_GREY_TEST_DISABLED(
@"This test was disabled as the Sync and Google Services screen "
"is not correctly open when the user taps on the Settings links");
}
ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1]; ChromeIdentity* identity = [SigninEarlGreyUtils fakeIdentity1];
ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity( ios::FakeChromeIdentityService::GetInstanceFromChromeProvider()->AddIdentity(
identity); identity);
...@@ -246,34 +251,37 @@ void WaitForMatcher(id<GREYMatcher> matcher) { ...@@ -246,34 +251,37 @@ void WaitForMatcher(id<GREYMatcher> matcher) {
[[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()] [[EarlGrey selectElementWithMatcher:FirstRunOptInAcceptButton()]
performAction:grey_tap()]; performAction:grey_tap()];
// Sign In |identity|. if (!unified_consent::IsUnifiedConsentFeatureEnabled()) {
[[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()] // Sign In |identity|.
performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:AccountConsistencySetupSigninButton()]
performAction:grey_tap()];
NSError* signedInError =
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]; NSError* signedInError =
// TODO(crbug.com/951600): Avoid asserting directly unless the test fails, [SigninEarlGreyUtils checkSignedInWithIdentity:identity];
// due to timing issues. // TODO(crbug.com/951600): Avoid asserting directly unless the test fails,
if (signedInError != nil) { // due to timing issues.
GREYAssert(false, signedInError.localizedDescription); if (signedInError != nil) {
GREYAssert(false, signedInError.localizedDescription);
}
} }
// Tap Settings link. // Tap Settings link.
id<GREYMatcher> settings_link_matcher = grey_allOf( [SigninEarlGreyUI tapSettingsLink];
grey_accessibilityLabel(@"Settings"), grey_sufficientlyVisible(), nil);
WaitForMatcher(settings_link_matcher);
[[EarlGrey selectElementWithMatcher:settings_link_matcher]
performAction:grey_tap()];
// Check Sync hasn't started yet, allowing the user to change somes settings. // Check Sync hasn't started yet, allowing the user to change some settings.
SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState( SyncSetupService* sync_service = SyncSetupServiceFactory::GetForBrowserState(
chrome_test_util::GetOriginalBrowserState()); chrome_test_util::GetOriginalBrowserState());
GREYAssertFalse(sync_service->HasFinishedInitialSetup(), GREYAssertFalse(sync_service->HasFinishedInitialSetup(),
@"Sync shouldn't have finished its original setup yet"); @"Sync shouldn't have finished its original setup yet");
// Close Settings, user is still signed in and sync is now starting. // Close Settings, user is still signed in and sync is now starting.
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] if (unified_consent::IsUnifiedConsentFeatureEnabled()) {
performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:SyncSettingsConfirmButton()]
performAction:grey_tap()];
} else {
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()];
}
CHROME_EG_ASSERT_NO_ERROR( CHROME_EG_ASSERT_NO_ERROR(
[SigninEarlGreyUtils checkSignedInWithIdentity:identity]); [SigninEarlGreyUtils checkSignedInWithIdentity:identity]);
......
...@@ -45,6 +45,9 @@ typedef NSArray<TableViewItem*>* ItemArray; ...@@ -45,6 +45,9 @@ typedef NSArray<TableViewItem*>* ItemArray;
namespace { namespace {
NSString* const kBetterSearchAndBrowsingItemAccessibilityID =
@"betterSearchAndBrowsingItem_switch";
// List of sections. // List of sections.
typedef NS_ENUM(NSInteger, SectionIdentifier) { typedef NS_ENUM(NSInteger, SectionIdentifier) {
IdentitySectionIdentifier = kSectionIdentifierEnumZero, IdentitySectionIdentifier = kSectionIdentifierEnumZero,
...@@ -554,6 +557,8 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error"; ...@@ -554,6 +557,8 @@ NSString* kGoogleServicesSyncErrorImage = @"google_services_sync_error";
detailStringID: detailStringID:
IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_DETAIL IDS_IOS_GOOGLE_SERVICES_SETTINGS_BETTER_SEARCH_AND_BROWSING_DETAIL
dataType:0]; dataType:0];
betterSearchAndBrowsingItemType.accessibilityIdentifier =
kBetterSearchAndBrowsingItemAccessibilityID;
_nonPersonalizedItems = @[ _nonPersonalizedItems = @[
autocompleteSearchesAndURLsItem, improveChromeItem, autocompleteSearchesAndURLsItem, improveChromeItem,
betterSearchAndBrowsingItemType betterSearchAndBrowsingItemType
......
...@@ -210,6 +210,7 @@ chrome_ios_eg_test("ios_chrome_external_url_egtests") { ...@@ -210,6 +210,7 @@ chrome_ios_eg_test("ios_chrome_external_url_egtests") {
chrome_ios_eg_test("ios_chrome_unified_consent_egtests") { chrome_ios_eg_test("ios_chrome_unified_consent_egtests") {
deps = [ deps = [
"//ios/chrome/browser/ui/first_run:eg_tests",
"//ios/chrome/browser/ui/settings/google_services:unified_consent_eg_tests", "//ios/chrome/browser/ui/settings/google_services:unified_consent_eg_tests",
"//ios/chrome/browser/ui/signin_interaction:unity_eg_tests", "//ios/chrome/browser/ui/signin_interaction:unity_eg_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