Commit 43ad7d94 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add test for Custom Search Engine deletion

This CL adds tests for deleting custom search engine.

Fixed: 1041399
Change-Id: I0ce5434551538dd793fde8098209e37db0813707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2002569
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732318}
parent 779d6a04
......@@ -37,9 +37,7 @@ source_set("settings_root_constants") {
"settings_root_table_constants.h",
"settings_root_table_constants.mm",
]
deps = [
"//base",
]
deps = [ "//base" ]
}
source_set("settings") {
......@@ -363,6 +361,7 @@ source_set("eg_tests") {
testonly = true
sources = [
"block_popups_egtest.mm",
"search_engine_settings_egtest.mm",
"settings_accessibility_egtest.mm",
"settings_egtest.mm",
"signin_settings_egtest.mm",
......@@ -413,6 +412,7 @@ source_set("eg_tests") {
"//ios/web:earl_grey_test_support",
"//ios/web/public/test/http_server",
"//net",
"//net:test_support",
"//ui/base",
"//url",
]
......@@ -444,9 +444,7 @@ source_set("eg_app_support+eg2") {
"//ios/chrome/test/app:test_support",
"//third_party/breakpad:client",
]
public_deps = [
"//components/content_settings/core/common",
]
public_deps = [ "//components/content_settings/core/common" ]
}
source_set("eg_test_support+eg2") {
......@@ -458,12 +456,8 @@ source_set("eg_test_support+eg2") {
"settings_app_interface.h",
"signin_settings_app_interface.h",
]
public_deps = [
"//components/content_settings/core/common",
]
deps = [
"//base",
]
public_deps = [ "//components/content_settings/core/common" ]
deps = [ "//base" ]
}
source_set("eg2_tests") {
......@@ -475,6 +469,7 @@ source_set("eg2_tests") {
testonly = true
sources = [
"block_popups_egtest.mm",
"search_engine_settings_egtest.mm",
"settings_accessibility_egtest.mm",
"settings_egtest.mm",
"signin_settings_egtest.mm",
......@@ -495,6 +490,7 @@ source_set("eg2_tests") {
"//ios/testing/earl_grey:eg_test_support+eg2",
"//ios/third_party/earl_grey2:test_lib",
"//ios/web/public/test/http_server",
"//net:test_support",
"//ui/base",
"//url",
]
......
// Copyright 2020 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.
#include "base/strings/sys_string_conversions.h"
#import "base/test/ios/wait_util.h"
#include "ios/chrome/grit/ios_strings.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"
#include "ios/testing/earl_grey/disabled_test_macros.h"
#import "ios/testing/earl_grey/earl_grey_test.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const char kPageURL[] = "/";
const char kOpenSearch[] = "/opensearch.xml";
const char kSearchURL[] = "/search?q=";
const char kCustomSearchEngineName[] = "Custom Search Engine";
NSString* GetCustomeSearchEngineLabel() {
return [NSString stringWithFormat:@"%s, 127.0.0.1", kCustomSearchEngineName];
}
std::string GetSearchExample() {
return std::string(kSearchURL) + "example";
}
// Responses for the test http server. |server_url| is the URL of the server,
// used for absolute URL in the response. |open_search_queried| is set to true
// when the OpenSearchDescription is queried.
std::unique_ptr<net::test_server::HttpResponse> StandardResponse(
std::string* server_url,
bool* open_search_queried,
const net::test_server::HttpRequest& request) {
std::unique_ptr<net::test_server::BasicHttpResponse> http_response =
std::make_unique<net::test_server::BasicHttpResponse>();
http_response->set_code(net::HTTP_OK);
if (request.relative_url == kPageURL) {
http_response->set_content("<head><link rel=\"search\" "
"type=\"application/opensearchdescription+xml\" "
"title=\"Custom Search Engine\" href=\"" +
std::string(kOpenSearch) +
"\"></head><body>Test Search</body>");
} else if (request.relative_url == kOpenSearch) {
*open_search_queried = true;
http_response->set_content(
"<OpenSearchDescription xmlns=\"http://a9.com/-/spec/opensearch/1.1/\">"
"<ShortName>" +
std::string(kCustomSearchEngineName) +
"</ShortName>"
"<Description>Description</Description>"
"<Url type=\"text/html\" method=\"get\" template=\"" +
*server_url + kSearchURL +
"{searchTerms}\"/>"
"</OpenSearchDescription>");
} else if (request.relative_url == GetSearchExample()) {
http_response->set_content("<head><body>Search Result</body>");
} else {
return nullptr;
}
return std::move(http_response);
}
} // namespace
@interface SearchEngineSettingsTestCase : ChromeTestCase {
std::string _serverURL;
bool _openSearchCalled;
}
@end
@implementation SearchEngineSettingsTestCase
// Deletes a custom search engine by swiping and tapping on the "Delete" button.
- (void)testDeleteCustomSearchEngineSwipeAndTap {
if (@available(iOS 13, *)) {
} else {
EARL_GREY_TEST_SKIPPED(
@"Test disabled on iOS 12 as this feature isn't present.");
}
[self enterSettingsWithCustomSearchEngine];
id<GREYMatcher> customSearchEngineCell =
grey_accessibilityLabel(GetCustomeSearchEngineLabel());
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
performAction:grey_swipeSlowInDirectionWithStartPoint(kGREYDirectionLeft,
0.3, 0.5)];
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(@"Delete")]
performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
assertWithMatcher:grey_nil()];
}
// Deletes a custom engine by swiping it.
- (void)testDeleteCustomSearchEngineSwipe {
[self enterSettingsWithCustomSearchEngine];
id<GREYMatcher> customSearchEngineCell =
grey_accessibilityLabel(GetCustomeSearchEngineLabel());
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
performAction:grey_swipeSlowInDirectionWithStartPoint(kGREYDirectionLeft,
0.9, 0.5)];
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
assertWithMatcher:grey_nil()];
}
// Deletes a custom search engine by entering edit mode.
- (void)testDeleteCustomSearchEngineEdit {
[self enterSettingsWithCustomSearchEngine];
id<GREYMatcher> editButton = grey_allOf(
chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON),
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
[[EarlGrey selectElementWithMatcher:editButton] performAction:grey_tap()];
id<GREYMatcher> customSearchEngineCell =
grey_accessibilityLabel(GetCustomeSearchEngineLabel());
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
assertWithMatcher:grey_sufficientlyVisible()];
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
performAction:grey_tap()];
id<GREYMatcher> deleteButton = grey_allOf(
grey_accessibilityLabel(@"Delete"),
grey_accessibilityTrait(UIAccessibilityTraitButton),
grey_not(grey_accessibilityTrait(UIAccessibilityTraitNotEnabled)), nil);
[[EarlGrey selectElementWithMatcher:deleteButton] performAction:grey_tap()];
[[EarlGrey selectElementWithMatcher:customSearchEngineCell]
assertWithMatcher:grey_nil()];
}
#pragma mark - helpers
// Adds a custom search engine by navigating to a fake search engine page, then
// enters the search engine screen in Settings.
- (void)enterSettingsWithCustomSearchEngine {
_openSearchCalled = false;
self.testServer->RegisterRequestHandler(
base::Bind(&StandardResponse, &(_serverURL), &(_openSearchCalled)));
GREYAssertTrue(self.testServer->Start(), @"Test server failed to start.");
const GURL pageURL = self.testServer->GetURL(kPageURL);
_serverURL = pageURL.spec();
// Remove trailing "/".
_serverURL.pop_back();
[ChromeEarlGrey loadURL:pageURL];
GREYCondition* openSearchQuery =
[GREYCondition conditionWithName:@"Wait for Open Search query"
block:^BOOL {
return _openSearchCalled;
}];
// Wait for the
GREYAssertTrue([openSearchQuery
waitWithTimeout:base::test::ios::kWaitForPageLoadTimeout],
@"The open search XML hasn't been queried.");
[ChromeEarlGrey loadURL:self.testServer->GetURL(GetSearchExample())];
[ChromeEarlGreyUI openSettingsMenu];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::SettingsSearchEngineButton()]
performAction:grey_tap()];
}
@end
......@@ -394,6 +394,9 @@ id<GREYMatcher> SettingsCreditCardMatcher();
// views.
id<GREYMatcher> SettingsBottomToolbarDeleteButton();
// Returns a matcher for the search engine button in the main settings view.
id<GREYMatcher> SettingsSearchEngineButton();
// Returns a matcher for an autofill suggestion view.
id<GREYMatcher> AutofillSuggestionViewMatcher();
......
......@@ -491,6 +491,10 @@ id<GREYMatcher> SettingsBottomToolbarDeleteButton() {
return [ChromeMatchersAppInterface settingsBottomToolbarDeleteButton];
}
id<GREYMatcher> SettingsSearchEngineButton() {
return [ChromeMatchersAppInterface settingsSearchEngineButton];
}
id<GREYMatcher> AutofillSuggestionViewMatcher() {
return [ChromeMatchersAppInterface autofillSuggestionViewMatcher];
}
......
......@@ -399,6 +399,9 @@
// views.
+ (id<GREYMatcher>)settingsBottomToolbarDeleteButton;
// Returns a matcher for the search engine button in the main settings view.
+ (id<GREYMatcher>)settingsSearchEngineButton;
// Returns a matcher for an autofill suggestion view.
+ (id<GREYMatcher>)autofillSuggestionViewMatcher;
......
......@@ -795,6 +795,10 @@ UIView* SubviewWithAccessibilityIdentifier(NSString* accessibility_id,
return grey_accessibilityID(kSettingsToolbarDeleteButtonId);
}
+ (id<GREYMatcher>)settingsSearchEngineButton {
return grey_accessibilityID(kSettingsSearchEngineCellId);
}
+ (id<GREYMatcher>)contentViewSmallerThanScrollView {
GREYMatchesBlock matches = ^BOOL(UIView* view) {
UIScrollView* scrollView = base::mac::ObjCCast<UIScrollView>(view);
......
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