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