Commit 62a87c91 authored by Nazerke's avatar Nazerke Committed by Commit Bot

[iOS][eg2] Convert google_services_settings_egtest to EG2.

This CL
 - adds the source file to sources list,
 - adds required gn dependencies,
 - links to both eg1 and eg2 frameworks,
 _ creates the app interface for google_services_settings_egtests.

Bug: 866147
Change-Id: I37701cf3e315ab56d37d5229236af2ed78cebf1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1960313
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Auto-Submit: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#727381}
parent 57f7d86d
...@@ -110,20 +110,65 @@ source_set("eg_tests") { ...@@ -110,20 +110,65 @@ source_set("eg_tests") {
] ]
deps = [ deps = [
":google_services", ":google_services",
"//ios/chrome/app:app_internal", ":test_support",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser/tabs", "//ios/chrome/browser/tabs",
"//ios/chrome/browser/ui/authentication:eg_test_support", "//ios/chrome/browser/ui/authentication:eg_test_support",
"//ios/chrome/browser/web_state_list",
"//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:fake_chrome_identity", "//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/public/provider/chrome/browser/signin:test_support",
"//ios/testing/earl_grey:earl_grey_support", "//ios/testing/earl_grey:earl_grey_support",
"//ui/base", "//ui/base",
] ]
} }
source_set("test_support") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"google_services_settings_app_interface.h",
"google_services_settings_app_interface.mm",
]
deps = [
"//ios/chrome/app:app_internal",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/web_state_list",
"//ios/chrome/test/app:test_support",
"//ios/web/public/navigation",
]
}
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 = [
"google_services_settings_app_interface.h",
"google_services_settings_app_interface.mm",
]
deps = [
"//ios/chrome/app:app_internal",
"//ios/chrome/browser/tabs",
"//ios/chrome/browser/web_state_list",
"//ios/chrome/test/app:test_support",
"//ios/web/public/navigation",
]
}
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 = [
"google_services_settings_app_interface.h",
]
}
source_set("eg2_tests") { source_set("eg2_tests") {
defines = [ "CHROME_EARL_GREY_2" ] defines = [ "CHROME_EARL_GREY_2" ]
configs += [ configs += [
...@@ -133,14 +178,19 @@ source_set("eg2_tests") { ...@@ -133,14 +178,19 @@ source_set("eg2_tests") {
testonly = true testonly = true
sources = [ sources = [
"accounts_table_egtest.mm", "accounts_table_egtest.mm",
"google_services_settings_egtest.mm",
] ]
deps = [ deps = [
":eg_test_support+eg2",
"//base", "//base",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/authentication:eg_test_support+eg2", "//ios/chrome/browser/ui/authentication:eg_test_support+eg2",
"//ios/chrome/browser/ui/settings/google_services:constants",
"//ios/chrome/test/earl_grey:eg_test_support+eg2", "//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/public/provider/chrome/browser/signin:fake_chrome_identity", "//ios/public/provider/chrome/browser/signin:fake_chrome_identity",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib", "//ios/third_party/earl_grey2:test_lib",
"//ui/base",
] ]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
} }
// 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_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_APP_INTERFACE_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_APP_INTERFACE_H_
#import <UIKit/UIKit.h>
// The app interface for Google services settings tests.
@interface GoogleServicesSettingsAppInterface : NSObject
// Blocks all navigation requests to be loaded in Chrome.
+ (void)blockAllNavigationRequestsForCurrentWebState;
// Unblocks all navigation requests to be loaded in Chrome.
+ (void)unblockAllNavigationRequestsForCurrentWebState;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_GOOGLE_SERVICES_GOOGLE_SERVICES_SETTINGS_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/ui/settings/google_services/google_services_settings_app_interface.h"
#import "ios/chrome/app/main_controller.h"
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/tab_test_util.h"
#import "ios/web/public/navigation/web_state_policy_decider.h"
#import "ios/web/public/web_state_user_data.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using chrome_test_util::GetMainController;
namespace {
// This decider blocks all navigation.
class NavigationBlockerDecider
: public web::WebStatePolicyDecider,
public web::WebStateUserData<NavigationBlockerDecider> {
public:
NavigationBlockerDecider(web::WebState* web_state)
: web::WebStatePolicyDecider(web_state) {}
bool ShouldAllowRequest(NSURLRequest* request,
const RequestInfo& request_info) override {
return false;
}
WEB_STATE_USER_DATA_KEY_DECL();
private:
DISALLOW_COPY_AND_ASSIGN(NavigationBlockerDecider);
};
WEB_STATE_USER_DATA_KEY_IMPL(NavigationBlockerDecider)
} // namespace
@implementation GoogleServicesSettingsAppInterface
+ (void)blockAllNavigationRequestsForCurrentWebState {
NavigationBlockerDecider::CreateForWebState(
chrome_test_util::GetCurrentWebState());
}
+ (void)unblockAllNavigationRequestsForCurrentWebState {
NavigationBlockerDecider::RemoveFromWebState(
chrome_test_util::GetCurrentWebState());
}
@end
...@@ -2,57 +2,35 @@ ...@@ -2,57 +2,35 @@
// 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 "ios/chrome/app/main_controller.h"
#import "ios/chrome/browser/tabs/tab_model.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" #import "ios/chrome/browser/ui/settings/google_services/google_services_settings_app_interface.h"
#import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_table_view_controller.h" #import "ios/chrome/browser/ui/settings/google_services/google_services_settings_constants.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h" #import "ios/chrome/browser/ui/settings/google_services/manage_sync_settings_constants.h"
#include "ios/chrome/grit/ios_chromium_strings.h" #include "ios/chrome/grit/ios_chromium_strings.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_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_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/web/public/navigation/web_state_policy_decider.h" #import "ios/testing/earl_grey/earl_grey_test.h"
#import "ui/base/l10n/l10n_util.h" #import "ui/base/l10n/l10n_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
#if defined(CHROME_EARL_GREY_2)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc++98-compat-extra-semi"
GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(GoogleServicesSettingsAppInterface);
#pragma clang diagnostic pop
#endif // defined(CHROME_EARL_GREY_2)
using l10n_util::GetNSString; using l10n_util::GetNSString;
using chrome_test_util::GoogleServicesSettingsButton; using chrome_test_util::GoogleServicesSettingsButton;
using chrome_test_util::SettingsDoneButton; using chrome_test_util::SettingsDoneButton;
namespace {
// Blocks the media content to avoid starting background playing.
class Decider : public web::WebStatePolicyDecider {
public:
Decider(web::WebState* web_state) : web::WebStatePolicyDecider(web_state) {}
bool ShouldAllowRequest(NSURLRequest* request,
const RequestInfo& request_info) override {
return false;
}
private:
DISALLOW_COPY_AND_ASSIGN(Decider);
};
TabModel* GetNormalTabModel() {
return chrome_test_util::GetMainController()
.interfaceProvider.mainInterface.tabModel;
}
} // namespace
// Integration tests using the Google services settings screen. // Integration tests using the Google services settings screen.
@interface GoogleServicesSettingsTestCase : ChromeTestCase @interface GoogleServicesSettingsTestCase : ChromeTestCase
...@@ -87,12 +65,13 @@ TabModel* GetNormalTabModel() { ...@@ -87,12 +65,13 @@ TabModel* GetNormalTabModel() {
// + Taps on the settings link to open the advanced sign-in settings // + Taps on the settings link to open the advanced sign-in settings
// + Opens "Data from Chromium sync" to interrupt sign-in // + Opens "Data from Chromium sync" to interrupt sign-in
- (void)testInterruptSigninFromGoogleServicesSettings { - (void)testInterruptSigninFromGoogleServicesSettings {
// Policy decider to avoid loading "Data from Chrome Sync". Since Chrome is [GoogleServicesSettingsAppInterface
// not really signed (just using a fake identity), Google server would answer blockAllNavigationRequestsForCurrentWebState];
// to start a sign-in workflow by loading this URL.
std::unique_ptr<Decider> _webStatePolicyDecider(
new Decider(GetNormalTabModel().webStateList->GetActiveWebState()));
// Adds default identity. // Adds default identity.
[self setTearDownHandler:^{
[GoogleServicesSettingsAppInterface
unblockAllNavigationRequestsForCurrentWebState];
}];
FakeChromeIdentity* fakeIdentity = [SigninEarlGreyUtils fakeIdentity1]; FakeChromeIdentity* fakeIdentity = [SigninEarlGreyUtils fakeIdentity1];
[SigninEarlGreyUtils addFakeIdentity:fakeIdentity]; [SigninEarlGreyUtils addFakeIdentity:fakeIdentity];
// Open "Google Services" settings. // Open "Google Services" settings.
...@@ -157,7 +136,7 @@ TabModel* GetNormalTabModel() { ...@@ -157,7 +136,7 @@ TabModel* GetNormalTabModel() {
GetNSString(detailTextID)]; GetNSString(detailTextID)];
} }
return grey_allOf(grey_accessibilityLabel(accessibilityLabel), return grey_allOf(grey_accessibilityLabel(accessibilityLabel),
grey_kindOfClass([UITableViewCell class]), grey_kindOfClassName(@"UITableViewCell"),
grey_sufficientlyVisible(), nil); grey_sufficientlyVisible(), nil);
} }
......
...@@ -418,6 +418,7 @@ source_set("eg_app_support+eg2") { ...@@ -418,6 +418,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/browser/ui/settings/clear_browsing_data", "//ios/chrome/browser/ui/settings/clear_browsing_data",
"//ios/chrome/browser/ui/settings/credit_card_scanner", "//ios/chrome/browser/ui/settings/credit_card_scanner",
"//ios/chrome/browser/ui/settings/google_services", "//ios/chrome/browser/ui/settings/google_services",
"//ios/chrome/browser/ui/settings/google_services:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings/password:eg_app_support+eg2", "//ios/chrome/browser/ui/settings/password:eg_app_support+eg2",
"//ios/chrome/browser/ui/settings/password:password_constants", "//ios/chrome/browser/ui/settings/password:password_constants",
"//ios/chrome/browser/ui/settings/sync", "//ios/chrome/browser/ui/settings/sync",
......
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