Commit 3c5026f4 authored by Peter K. Lee's avatar Peter K. Lee Committed by Commit Bot

Convert translate_egtest.mm to EG2

Reduce dependencies on Translate internals
- Refactored some constants out into their own targets
- Stopped using LanguageDetectionDetails where simple alternatives exist
- Use url.SchemeIs()
- Use executeJavaScript:error: from ChromeEarlGreyAppInterface
- TranslateAppInterface setUp needs to be passed switch for HttpServer

Bug: 987646
Change-Id: I4c47b9abca4a64d09a267b526dadc87cb10fe76b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1979768
Commit-Queue: Peter Lee <pkl@chromium.org>
Auto-Submit: Peter Lee <pkl@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#727310}
parent 19d83c05
...@@ -125,11 +125,11 @@ source_set("eg_tests") { ...@@ -125,11 +125,11 @@ source_set("eg_tests") {
"//components/translate/core/common", "//components/translate/core/common",
"//components/translate/ios/browser", "//components/translate/ios/browser",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser", "//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/popup_menu:constants", "//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/translate:legacy_translate", "//ios/chrome/browser/ui/translate:legacy_translate_constants",
"//ios/chrome/browser/ui/translate:translate_ui", "//ios/chrome/browser/ui/translate:translate_ui_constants",
"//ios/chrome/browser/ui/util:util", "//ios/chrome/browser/ui/util:util",
"//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",
...@@ -152,8 +152,28 @@ source_set("eg2_tests") { ...@@ -152,8 +152,28 @@ source_set("eg2_tests") {
"//build/config/ios:xctest_config", "//build/config/ios:xctest_config",
] ]
testonly = true testonly = true
sources = [] sources = [
deps = [] "translate_egtest.mm",
]
deps = [
":eg_test_support+eg2",
"//base/test:test_support",
"//components/strings:components_strings_grit",
"//components/translate/core/browser:browser",
"//components/translate/core/common:common",
"//ios/chrome/app/strings:ios_strings_grit",
"//ios/chrome/browser:chrome_url_constants",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/translate:legacy_translate_constants",
"//ios/chrome/browser/ui/translate:translate_ui_constants",
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public:public",
"//ios/web/public/test/http_server:http_server",
"//ui/base:base",
"//url:url",
]
libs = [ "UIKit.framework" ] libs = [ "UIKit.framework" ]
} }
...@@ -183,7 +203,21 @@ source_set("eg_app_support+eg2") { ...@@ -183,7 +203,21 @@ source_set("eg_app_support+eg2") {
"//build/config/ios:xctest_config", "//build/config/ios:xctest_config",
] ]
testonly = true testonly = true
sources = [] sources = [
"translate_app_interface.h",
"translate_app_interface.mm",
]
deps = [
"//base:base",
"//components/translate/core/browser:browser",
"//components/translate/core/common:common",
"//components/translate/ios/browser:browser",
"//ios/chrome/browser/browser_state:browser_state",
"//ios/chrome/browser/translate:translate",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/fakes:fakes",
"//net:net",
]
} }
source_set("eg_test_support+eg2") { source_set("eg_test_support+eg2") {
...@@ -193,8 +227,13 @@ source_set("eg_test_support+eg2") { ...@@ -193,8 +227,13 @@ source_set("eg_test_support+eg2") {
"//build/config/ios:xctest_config", "//build/config/ios:xctest_config",
] ]
testonly = true testonly = true
sources = [] sources = [
"translate_app_interface.h",
"translate_app_interface_stub.mm",
]
deps = [ deps = [
"//ios/chrome/test/earl_grey:eg_test_support+eg2",
"//ios/testing/earl_grey:eg_test_support+eg2", "//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
] ]
} }
...@@ -9,8 +9,9 @@ ...@@ -9,8 +9,9 @@
@interface TranslateAppInterface : NSObject @interface TranslateAppInterface : NSObject
// Sets up the app for testing. // Sets up the app for testing. |translateScriptServer| is the URL
+ (void)setUp; // for the server that can serve up translate scripts to app.
+ (void)setUpWithScriptServer:(NSString*)translateScriptServerURL;
// Tears down the testing set up for the app. // Tears down the testing set up for the app.
+ (void)tearDown; + (void)tearDown;
...@@ -56,6 +57,13 @@ ...@@ -56,6 +57,13 @@
// Whether user has set a preference to translate any pages on |hostName|. // Whether user has set a preference to translate any pages on |hostName|.
+ (BOOL)isBlockedSite:(NSString*)hostName; + (BOOL)isBlockedSite:(NSString*)hostName;
// The following are Translate Infobar UI constants. Test client needs to know
// to verify that Translate Infobar is behaving correctly.
+ (int)infobarAutoAlwaysThreshold;
+ (int)infobarAutoNeverThreshold;
+ (int)infobarMaximumNumberOfAutoAlways;
+ (int)infobarMaximumNumberOfAutoNever;
@end @end
#endif // IOS_CHROME_BROWSER_TRANSLATE_TRANSLATE_APP_INTERFACE_H_ #endif // IOS_CHROME_BROWSER_TRANSLATE_TRANSLATE_APP_INTERFACE_H_
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#import "ios/chrome/browser/translate/translate_app_interface.h" #import "ios/chrome/browser/translate/translate_app_interface.h"
#include "base/command_line.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/translate/core/browser/translate_infobar_delegate.h"
#include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_manager.h"
#include "components/translate/core/browser/translate_prefs.h" #include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/common/language_detection_details.h" #include "components/translate/core/common/language_detection_details.h"
#include "components/translate/core/common/translate_switches.h"
#import "components/translate/ios/browser/js_translate_manager.h" #import "components/translate/ios/browser/js_translate_manager.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/translate/chrome_ios_translate_client.h" #include "ios/chrome/browser/translate/chrome_ios_translate_client.h"
...@@ -161,7 +164,7 @@ class TranslateAppInterfaceHelper { ...@@ -161,7 +164,7 @@ class TranslateAppInterfaceHelper {
#pragma mark public methods #pragma mark public methods
+ (void)setUp { + (void)setUpWithScriptServer:(NSString*)translateScriptServerURL {
// Allows the offering of translate in builds without an API key. // Allows the offering of translate in builds without an API key.
translate::TranslateManager::SetIgnoreMissingKeyForTesting(true); translate::TranslateManager::SetIgnoreMissingKeyForTesting(true);
[self setUpLanguageDetectionTabHelperObserver]; [self setUpLanguageDetectionTabHelperObserver];
...@@ -169,6 +172,13 @@ class TranslateAppInterfaceHelper { ...@@ -169,6 +172,13 @@ class TranslateAppInterfaceHelper {
// Sets up a fake JsTranslateManager that does not use the translate script. // Sets up a fake JsTranslateManager that does not use the translate script.
[self setUpFakeJSTranslateManagerInCurrentTab]; [self setUpFakeJSTranslateManagerInCurrentTab];
TranslateAppInterfaceHelper::GetInstance()->SetUpFakeWiFiConnection(); TranslateAppInterfaceHelper::GetInstance()->SetUpFakeWiFiConnection();
// Sets URL for the translate script to hit a HTTP server selected by
// the test app
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
command_line->AppendSwitchASCII(
translate::switches::kTranslateScriptURL,
base::SysNSStringToUTF8(translateScriptServerURL));
} }
+ (void)tearDown { + (void)tearDown {
...@@ -260,6 +270,22 @@ class TranslateAppInterfaceHelper { ...@@ -260,6 +270,22 @@ class TranslateAppInterfaceHelper {
return prefs->IsSiteBlacklisted(base::SysNSStringToUTF8(hostName)); return prefs->IsSiteBlacklisted(base::SysNSStringToUTF8(hostName));
} }
+ (int)infobarAutoAlwaysThreshold {
return translate::TranslateInfoBarDelegate::GetAutoAlwaysThreshold();
}
+ (int)infobarAutoNeverThreshold {
return translate::TranslateInfoBarDelegate::GetAutoNeverThreshold();
}
+ (int)infobarMaximumNumberOfAutoAlways {
return translate::TranslateInfoBarDelegate::GetMaximumNumberOfAutoAlways();
}
+ (int)infobarMaximumNumberOfAutoNever {
return translate::TranslateInfoBarDelegate::GetMaximumNumberOfAutoNever();
}
#pragma mark private methods #pragma mark private methods
// Reset translate prefs to default. // Reset translate prefs to default.
......
...@@ -11,6 +11,7 @@ source_set("legacy_translate") { ...@@ -11,6 +11,7 @@ source_set("legacy_translate") {
"legacy_translate_infobar_mediator.mm", "legacy_translate_infobar_mediator.mm",
] ]
deps = [ deps = [
":legacy_translate_constants",
":translate_ui", ":translate_ui",
"//base", "//base",
"//components/strings:components_strings_grit", "//components/strings:components_strings_grit",
...@@ -30,6 +31,14 @@ source_set("legacy_translate") { ...@@ -30,6 +31,14 @@ source_set("legacy_translate") {
] ]
} }
source_set("legacy_translate_constants") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"legacy_translate_infobar_constants.h",
"legacy_translate_infobar_constants.mm",
]
}
source_set("translate_ui") { source_set("translate_ui") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
...@@ -48,6 +57,7 @@ source_set("translate_ui") { ...@@ -48,6 +57,7 @@ source_set("translate_ui") {
"translate_notification_presenter.mm", "translate_notification_presenter.mm",
] ]
deps = [ deps = [
":translate_ui_constants",
"//base", "//base",
"//components/strings:components_strings", "//components/strings:components_strings",
"//ios/chrome/app/strings:ios_strings_grit", "//ios/chrome/app/strings:ios_strings_grit",
...@@ -70,6 +80,14 @@ source_set("translate_ui") { ...@@ -70,6 +80,14 @@ source_set("translate_ui") {
] ]
} }
source_set("translate_ui_constants") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"translate_infobar_view_constants.h",
"translate_infobar_view_constants.mm",
]
}
source_set("unit_tests") { source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
......
// 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_TRANSLATE_LEGACY_TRANSLATE_INFOBAR_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_TRANSLATE_LEGACY_TRANSLATE_INFOBAR_CONSTANTS_H_
#import <UIKit/UIKit.h>
// The a11y identifier for the translate infobar's language selection menu.
extern NSString* const kLanguageSelectorPopupMenuId;
// The a11y identifier for the translate infobar's translate options menu.
extern NSString* const kTranslateOptionsPopupMenuId;
#endif // IOS_CHROME_BROWSER_UI_TRANSLATE_LEGACY_TRANSLATE_INFOBAR_CONSTANTS_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/translate/legacy_translate_infobar_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
NSString* const kLanguageSelectorPopupMenuId = @"kLanguageSelectorPopupMenuId";
NSString* const kTranslateOptionsPopupMenuId = @"kTranslateOptionsPopupMenuId";
...@@ -9,11 +9,6 @@ ...@@ -9,11 +9,6 @@
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h" #import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
// The a11y identifier for the translate infobar's language selection menu.
extern NSString* const kLanguageSelectorPopupMenuId;
// The a11y identifier for the translate infobar's translate options menu.
extern NSString* const kTranslateOptionsPopupMenuId;
@protocol SnackbarCommands; @protocol SnackbarCommands;
class WebStateList; class WebStateList;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#import "ios/chrome/browser/ui/popup_menu/public/popup_menu_table_view_controller_delegate.h" #import "ios/chrome/browser/ui/popup_menu/public/popup_menu_table_view_controller_delegate.h"
#import "ios/chrome/browser/ui/popup_menu/public/popup_menu_ui_constants.h" #import "ios/chrome/browser/ui/popup_menu/public/popup_menu_ui_constants.h"
#import "ios/chrome/browser/ui/translate/cells/select_language_popup_menu_item.h" #import "ios/chrome/browser/ui/translate/cells/select_language_popup_menu_item.h"
#import "ios/chrome/browser/ui/translate/legacy_translate_infobar_constants.h"
#import "ios/chrome/browser/ui/translate/legacy_translate_infobar_mediator.h" #import "ios/chrome/browser/ui/translate/legacy_translate_infobar_mediator.h"
#import "ios/chrome/browser/ui/translate/translate_notification_presenter.h" #import "ios/chrome/browser/ui/translate/translate_notification_presenter.h"
#import "ios/chrome/browser/ui/util/layout_guide_names.h" #import "ios/chrome/browser/ui/util/layout_guide_names.h"
...@@ -27,9 +28,6 @@ ...@@ -27,9 +28,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
NSString* const kLanguageSelectorPopupMenuId = @"kLanguageSelectorPopupMenuId";
NSString* const kTranslateOptionsPopupMenuId = @"kTranslateOptionsPopupMenuId";
@interface LegacyTranslateInfobarCoordinator () < @interface LegacyTranslateInfobarCoordinator () <
LanguageSelectionHandler, LanguageSelectionHandler,
PopupMenuPresenterDelegate, PopupMenuPresenterDelegate,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_strip_view_delegate.h" #import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_strip_view_delegate.h"
#import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_view_delegate.h" #import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_view_delegate.h"
#import "ios/chrome/browser/ui/translate/translate_infobar_view.h" #import "ios/chrome/browser/ui/translate/translate_infobar_view_constants.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h" #import "ios/chrome/common/ui_util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
......
...@@ -16,12 +16,6 @@ typedef NS_ENUM(NSInteger, TranslateInfobarViewState) { ...@@ -16,12 +16,6 @@ typedef NS_ENUM(NSInteger, TranslateInfobarViewState) {
TranslateInfobarViewStateAfterTranslate, TranslateInfobarViewStateAfterTranslate,
}; };
// Height of the infobar.
extern const CGFloat kInfobarHeight;
// The a11y identifier for the translate infobar view.
extern NSString* const kTranslateInfobarViewId;
@protocol TranslateInfobarViewDelegate; @protocol TranslateInfobarViewDelegate;
// An infobar for translating the page. Starting from the leading edge, it // An infobar for translating the page. Starting from the leading edge, it
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h"
#import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_strip_view.h" #import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_strip_view.h"
#import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_strip_view_delegate.h" #import "ios/chrome/browser/ui/translate/translate_infobar_language_tab_strip_view_delegate.h"
#import "ios/chrome/browser/ui/translate/translate_infobar_view_constants.h"
#import "ios/chrome/browser/ui/translate/translate_infobar_view_delegate.h" #import "ios/chrome/browser/ui/translate/translate_infobar_view_delegate.h"
#import "ios/chrome/browser/ui/util/label_link_controller.h" #import "ios/chrome/browser/ui/util/label_link_controller.h"
#import "ios/chrome/browser/ui/util/layout_guide_names.h" #import "ios/chrome/browser/ui/util/layout_guide_names.h"
...@@ -30,10 +31,6 @@ ...@@ -30,10 +31,6 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
const CGFloat kInfobarHeight = 54;
NSString* const kTranslateInfobarViewId = @"kTranslateInfobarViewId";
namespace { namespace {
// Size of the infobar buttons. // Size of the infobar buttons.
......
// 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_TRANSLATE_TRANSLATE_INFOBAR_VIEW_CONSTANTS_H_
#define IOS_CHROME_BROWSER_UI_TRANSLATE_TRANSLATE_INFOBAR_VIEW_CONSTANTS_H_
#import <UIKit/UIKit.h>
// Height of the infobar.
extern const CGFloat kInfobarHeight;
// The a11y identifier for the translate infobar view.
extern NSString* const kTranslateInfobarViewId;
#endif // IOS_CHROME_BROWSER_UI_TRANSLATE_TRANSLATE_INFOBAR_VIEW_CONSTANTS_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/translate/translate_infobar_view_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const CGFloat kInfobarHeight = 54;
NSString* const kTranslateInfobarViewId = @"kTranslateInfobarViewId";
...@@ -377,6 +377,7 @@ source_set("eg_app_support+eg2") { ...@@ -377,6 +377,7 @@ source_set("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",
"//ios/chrome/browser/translate:eg_app_support+eg2",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/authentication:eg_app_support+eg2", "//ios/chrome/browser/ui/authentication:eg_app_support+eg2",
"//ios/chrome/browser/ui/authentication/cells", "//ios/chrome/browser/ui/authentication/cells",
......
...@@ -52,6 +52,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") { ...@@ -52,6 +52,7 @@ chrome_ios_eg2_test("ios_chrome_integration_eg2tests_module") {
"//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",
"//ios/chrome/browser/prerender:eg2_tests", "//ios/chrome/browser/prerender:eg2_tests",
"//ios/chrome/browser/translate:eg2_tests",
"//ios/chrome/browser/ui/autofill:eg2_tests", "//ios/chrome/browser/ui/autofill:eg2_tests",
"//ios/chrome/browser/ui/autofill/manual_fill:eg2_tests", "//ios/chrome/browser/ui/autofill/manual_fill:eg2_tests",
"//ios/chrome/browser/ui/content_suggestions:eg2_tests", "//ios/chrome/browser/ui/content_suggestions: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