Commit ed6c8d67 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] Convert keyboard command tests

Converts the keyboard_commands_egtest for eg2 compatibility.

- Ports GetRegisteredKeyCommandsCount to an app interface method.
- Makes //net:test_support a public dep of eg_test_support+eg2, to match
  the test_support target and prevent annoying linker errors from other
  code that doesn't cleanly specify dependencies.
- Factors table view constants into a separate target so eg2 tests can
  use them safely.


Bug: 987646
Change-Id: I5c7dcaa6bd29ee1cb1aa507c5386ec92d1c93a0f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1889977
Commit-Queue: Mark Cogan <marq@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711208}
parent 98bc7c08
......@@ -44,7 +44,7 @@ source_set("eg_tests") {
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/table_view:constants",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
......
......@@ -333,7 +333,7 @@ id<GREYMatcher> SearchIconButton() {
- (void)testKeyboardCommandsRegistered_AddBookmark {
// Add the bookmark.
[BookmarksTestCase starCurrentTab];
GREYAssertTrue(chrome_test_util::GetRegisteredKeyCommandsCount() > 0,
GREYAssertTrue([ChromeEarlGrey registeredKeyCommandCount] > 0,
@"Some keyboard commands are registered.");
}
......@@ -363,7 +363,7 @@ id<GREYMatcher> SearchIconButton() {
kPopupMenuToolsMenuTableViewId)]
performAction:grey_tap()];
}
GREYAssertTrue(chrome_test_util::GetRegisteredKeyCommandsCount() == 0,
GREYAssertTrue([ChromeEarlGrey registeredKeyCommandCount] == 0,
@"No keyboard commands are registered.");
}
......
......@@ -29,24 +29,48 @@ source_set("unit_tests") {
}
source_set("eg_tests") {
defines = [ "CHROME_EARL_GREY_1" ]
configs += [ "//build/config/compiler:enable_arc" ]
testonly = true
sources = [
"keyboard_commands_egtest.mm",
]
deps = [
"//base",
"//base/test:test_support",
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/bookmarks:bookmarks_ui",
"//ios/chrome/browser/ui/browser_view",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/app:test_support",
"//ios/chrome/test/earl_grey:test_support",
"//ios/web/public/test/http_server",
"//ios/testing/earl_grey:earl_grey_support",
"//net:test_support",
]
libs = [
"UIKit.framework",
"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 = [
"keyboard_commands_egtest.mm",
]
deps = [
"//components/strings",
"//ios/chrome/app/strings",
"//ios/chrome/browser/ui/bookmarks:bookmarks_ui",
"//ios/chrome/browser/ui/popup_menu:constants",
"//ios/chrome/browser/ui/table_view: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",
"//net:test_support",
]
libs = [
"UIKit.framework",
......
......@@ -2,25 +2,19 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#include "base/test/scoped_feature_list.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/bookmarks/bookmark_ui_constants.h"
#import "ios/chrome/browser/ui/browser_view/browser_view_controller.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_constants.h"
#import "ios/chrome/browser/ui/table_view/table_view_navigation_controller_constants.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.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_ui.h"
#import "ios/chrome/test/earl_grey/chrome_matchers.h"
#import "ios/chrome/test/earl_grey/chrome_test_case.h"
#import "ios/web/public/test/http_server/http_server.h"
#include "ios/web/public/test/http_server/http_server_util.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -41,14 +35,13 @@ using chrome_test_util::SettingsDoneButton;
// Verifies that keyboard commands are registered by the BVC.
- (void)verifyKeyboardCommandsAreRegistered {
BOOL(^block)
() = ^BOOL {
return chrome_test_util::GetRegisteredKeyCommandsCount() > 0;
BOOL (^confirmKeyCommands)() = ^BOOL() {
return [ChromeEarlGrey registeredKeyCommandCount] > 0;
};
GREYCondition* keyboardCommands =
[GREYCondition conditionWithName:@"Keyboard commands registered"
block:block];
block:confirmKeyCommands];
BOOL success = [keyboardCommands waitWithTimeout:5];
if (!success) {
......@@ -58,13 +51,13 @@ using chrome_test_util::SettingsDoneButton;
// Verifies that no keyboard commands are registered by the BVC.
- (void)verifyNoKeyboardCommandsAreRegistered {
BOOL(^block)
() = ^BOOL {
return chrome_test_util::GetRegisteredKeyCommandsCount() == 0;
BOOL (^confirmNoKeyCommands)() = ^BOOL() {
return [ChromeEarlGrey registeredKeyCommandCount] == 0;
};
GREYCondition* noKeyboardCommands =
[GREYCondition conditionWithName:@"No keyboard commands registered"
block:block];
block:confirmNoKeyCommands];
BOOL success = [noKeyboardCommands waitWithTimeout:5];
if (!success) {
......@@ -74,8 +67,7 @@ using chrome_test_util::SettingsDoneButton;
// Waits for the bookmark editor to display.
- (void)waitForSingleBookmarkEditorToDisplay {
BOOL(^block)
() = ^BOOL {
BOOL (^confirmBookmarkEditorVisible)() = ^BOOL() {
NSError* error = nil;
id<GREYMatcher> singleBookmarkEditor =
grey_accessibilityLabel(kBookmarkEditViewContainerIdentifier);
......@@ -86,7 +78,7 @@ using chrome_test_util::SettingsDoneButton;
};
GREYCondition* editorDisplayed = [GREYCondition
conditionWithName:@"Waiting for bookmark editor to display."
block:block];
block:confirmBookmarkEditorVisible];
BOOL success = [editorDisplayed waitWithTimeout:5];
GREYAssert(success, @"The bookmark editor was not displayed.");
......@@ -117,10 +109,8 @@ using chrome_test_util::SettingsDoneButton;
[ChromeEarlGrey clearBookmarks];
// Load a webpage because the NTP is not always bookmarkable.
web::test::SetUpFileBasedHttpServer();
GURL URL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/pony.html");
[ChromeEarlGrey loadURL:URL];
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
[ChromeEarlGrey loadURL:self.testServer->GetURL("/pony.html")];
// Bookmark page
if ([ChromeEarlGrey isIPadIdiom]) {
......@@ -186,18 +176,13 @@ using chrome_test_util::SettingsDoneButton;
// Tests that when the app is opened on a web page and a key is pressed, the
// web view is the first responder.
- (void)testWebViewIsFirstResponderUponKeyPress {
web::test::SetUpFileBasedHttpServer();
GURL URL = web::test::HttpServer::MakeUrl(
"http://ios/testing/data/http_server_files/pony.html");
[ChromeEarlGrey loadURL:URL];
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
[ChromeEarlGrey loadURL:self.testServer->GetURL("/pony.html")];
[self verifyKeyboardCommandsAreRegistered];
UIResponder* firstResponder = GetFirstResponder();
GREYAssert(
[firstResponder isKindOfClass:NSClassFromString(@"WKContentView")],
@"Expected first responder to be a WKContentView. Instead, is a %@",
NSStringFromClass([firstResponder class]));
[[EarlGrey selectElementWithMatcher:grey_firstResponder()]
assertWithMatcher:grey_kindOfClassName(@"WKContentView")];
}
@end
......@@ -13,8 +13,6 @@ source_set("table_view") {
"table_view_model.mm",
"table_view_navigation_controller.h",
"table_view_navigation_controller.mm",
"table_view_navigation_controller_constants.h",
"table_view_navigation_controller_constants.mm",
]
deps = [
":feature_flags",
......@@ -28,10 +26,19 @@ source_set("table_view") {
"//ios/third_party/material_components_ios",
]
public_deps = [
":constants",
"//ios/chrome/browser/ui/table_view/cells",
]
}
source_set("constants") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"table_view_navigation_controller_constants.h",
"table_view_navigation_controller_constants.mm",
]
}
source_set("styler") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
......
......@@ -34,9 +34,6 @@ ios::ChromeBrowserState* GetOriginalBrowserState();
// Returns the current incognito ChromeBrowserState
ios::ChromeBrowserState* GetCurrentIncognitoBrowserState();
// Returns the number of key commands currently registered with the main BVC.
NSUInteger GetRegisteredKeyCommandsCount();
// Returns the dispatcher for the main BVC.
// TODO(crbug.com/738881): Use DispatcherForActiveBrowserViewController()
// instead.
......
......@@ -91,12 +91,6 @@ ios::ChromeBrowserState* GetCurrentIncognitoBrowserState() {
return GetBrowserState(true);
}
NSUInteger GetRegisteredKeyCommandsCount() {
UIViewController* mainViewController =
GetMainController().interfaceProvider.mainInterface.viewController;
return mainViewController.keyCommands.count;
}
id<BrowserCommands> BrowserCommandDispatcherForMainBVC() {
BrowserViewController* mainBVC =
GetMainController().interfaceProvider.mainInterface.bvc;
......
......@@ -231,6 +231,7 @@ source_set("test_support") {
"//components/translate/core/browser",
"//components/ukm/ios:features",
"//components/unified_consent",
"//ios/chrome/app:app_internal",
"//ios/chrome/app/strings",
"//ios/chrome/browser/autofill",
"//ios/chrome/browser/content_settings:content_settings",
......@@ -357,6 +358,7 @@ source_set("eg_app_support+eg2") {
"//components/translate/core/browser",
"//components/ukm/ios:features",
"//components/unified_consent",
"//ios/chrome/app:app_internal",
"//ios/chrome/app/strings",
"//ios/chrome/browser/autofill",
"//ios/chrome/browser/autofill/automation:eg_app_support+eg2",
......@@ -479,8 +481,11 @@ source_set("eg_test_support+eg2") {
"//ios/third_party/gtx:gtx+link",
"//ios/web/public/test:element_selector",
"//ios/web/public/test/http_server",
"//net:test_support",
"//ui/base",
"//url",
]
public_deps = [
"//net:test_support",
]
}
......@@ -432,6 +432,9 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// browser state.
- (void)setPopupPrefValue:(ContentSetting)value;
// The count of key commands registered with the currently active BVC.
- (NSInteger)registeredKeyCommandCount;
@end
// Helpers that only compile under EarlGrey 1 are included in this "EG1"
......
......@@ -724,6 +724,10 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return [ChromeEarlGreyAppInterface setPopupPrefValue:value];
}
- (NSInteger)registeredKeyCommandCount {
return [ChromeEarlGreyAppInterface registeredKeyCommandCount];
}
@end
// The helpers below only compile under EarlGrey1.
......
......@@ -346,6 +346,11 @@
// browser state.
+ (void)setPopupPrefValue:(ContentSetting)value;
#pragma mark - Keyboard Command utilities
// The count of key commands registered with the currently active BVC.
+ (NSInteger)registeredKeyCommandCount;
@end
#endif // IOS_CHROME_TEST_EARL_GREY_CHROME_EARL_GREY_APP_INTERFACE_H_
......@@ -10,6 +10,7 @@
#include "components/content_settings/core/browser/host_content_settings_map.h"
#import "components/payments/core/features.h"
#import "components/ukm/ios/features.h"
#import "ios/chrome/app/main_controller.h"
#include "ios/chrome/browser/autofill/personal_data_manager_factory.h"
#include "ios/chrome/browser/content_settings/host_content_settings_map_factory.h"
#import "ios/chrome/browser/ntp/features.h"
......@@ -588,4 +589,13 @@ using chrome_test_util::BrowserCommandDispatcherForMainBVC;
->SetDefaultContentSetting(ContentSettingsType::POPUPS, value);
}
#pragma mark - Keyboard Command Utilities
+ (NSInteger)registeredKeyCommandCount {
UIViewController* mainViewController =
chrome_test_util::GetMainController()
.interfaceProvider.mainInterface.viewController;
return mainViewController.keyCommands.count;
}
@end
......@@ -72,6 +72,7 @@ chrome_ios_eg2_test("ios_chrome_ui_eg2tests_module") {
"//ios/chrome/browser/ui/download:eg2_tests",
"//ios/chrome/browser/ui/fullscreen:eg2_tests",
"//ios/chrome/browser/ui/integration_tests:eg2_tests",
"//ios/chrome/browser/ui/keyboard:eg2_tests",
"//ios/chrome/browser/ui/ntp:eg2_tests",
"//ios/chrome/browser/ui/omnibox/popup:eg2_tests",
"//ios/chrome/browser/ui/omnibox/popup/shortcuts: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