Commit 3f69ed74 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Remove DialogPresenter and kNonModalDialogs flag.

Now that the kNonModalDialogs flag has been enabled for multiple
releases, we can remove the legacy dialog implementation and the flag.

Bug: 1068418
Change-Id: I687ca85f004e675e1d462c11cc745887ce1e285d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2140776
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#757663}
parent 07438e68
...@@ -105,7 +105,6 @@ source_set("browser") { ...@@ -105,7 +105,6 @@ source_set("browser") {
"//ios/chrome/browser/sync/glue", "//ios/chrome/browser/sync/glue",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/dialogs:feature_flags",
"//ios/chrome/browser/ui/fullscreen:feature_flags", "//ios/chrome/browser/ui/fullscreen:feature_flags",
"//ios/chrome/browser/ui/omnibox", "//ios/chrome/browser/ui/omnibox",
"//ios/chrome/browser/ui/toolbar/public:feature_flags", "//ios/chrome/browser/ui/toolbar/public:feature_flags",
......
...@@ -29,7 +29,6 @@ source_set("app_launcher") { ...@@ -29,7 +29,6 @@ source_set("app_launcher") {
"//ios/chrome/browser/overlays/public/web_content_area", "//ios/chrome/browser/overlays/public/web_content_area",
"//ios/chrome/browser/reading_list", "//ios/chrome/browser/reading_list",
"//ios/chrome/browser/u2f", "//ios/chrome/browser/u2f",
"//ios/chrome/browser/ui/dialogs:feature_flags",
"//ios/chrome/browser/web_state_list", "//ios/chrome/browser/web_state_list",
"//ios/public/provider/chrome/browser", "//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/mailto", "//ios/public/provider/chrome/browser/mailto",
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#import "ios/chrome/browser/chrome_url_util.h" #import "ios/chrome/browser/chrome_url_util.h"
#include "ios/chrome/browser/reading_list/reading_list_model_factory.h" #include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#import "ios/chrome/browser/u2f/u2f_tab_helper.h" #import "ios/chrome/browser/u2f/u2f_tab_helper.h"
#import "ios/chrome/browser/ui/dialogs/dialog_features.h"
#import "ios/web/common/url_scheme_util.h" #import "ios/web/common/url_scheme_util.h"
#import "ios/web/public/navigation/navigation_item.h" #import "ios/web/public/navigation/navigation_item.h"
#import "ios/web/public/navigation/navigation_manager.h" #import "ios/web/public/navigation/navigation_manager.h"
......
...@@ -47,7 +47,6 @@ source_set("flags") { ...@@ -47,7 +47,6 @@ source_set("flags") {
"//ios/chrome/browser/find_in_page:feature_flags", "//ios/chrome/browser/find_in_page:feature_flags",
"//ios/chrome/browser/passwords:feature_flags", "//ios/chrome/browser/passwords:feature_flags",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/dialogs:feature_flags",
"//ios/chrome/browser/ui/download:features", "//ios/chrome/browser/ui/download:features",
"//ios/chrome/browser/ui/fullscreen:feature_flags", "//ios/chrome/browser/ui/fullscreen:feature_flags",
"//ios/chrome/browser/ui/infobars:feature_flags", "//ios/chrome/browser/ui/infobars:feature_flags",
......
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
#include "ios/chrome/browser/flags/ios_chrome_flag_descriptions.h" #include "ios/chrome/browser/flags/ios_chrome_flag_descriptions.h"
#include "ios/chrome/browser/passwords/password_manager_features.h" #include "ios/chrome/browser/passwords/password_manager_features.h"
#include "ios/chrome/browser/system_flags.h" #include "ios/chrome/browser/system_flags.h"
#import "ios/chrome/browser/ui/dialogs/dialog_features.h"
#import "ios/chrome/browser/ui/download/features.h" #import "ios/chrome/browser/ui/download/features.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
...@@ -391,9 +390,6 @@ const flags_ui::FeatureEntry kFeatureEntries[] = { ...@@ -391,9 +390,6 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
omnibox::kUIExperimentMaxAutocompleteMatches, omnibox::kUIExperimentMaxAutocompleteMatches,
kOmniboxUIMaxAutocompleteMatchesVariations, kOmniboxUIMaxAutocompleteMatchesVariations,
"OmniboxUIMaxAutocompleteVariations")}, "OmniboxUIMaxAutocompleteVariations")},
{"non-modal-dialogs", flag_descriptions::kNonModalDialogsName,
flag_descriptions::kNonModalDialogsDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(dialogs::kNonModalDialogs)},
{"infobar-ui-reboot", flag_descriptions::kInfobarUIRebootName, {"infobar-ui-reboot", flag_descriptions::kInfobarUIRebootName,
flag_descriptions::kInfobarUIRebootDescription, flags_ui::kOsIos, flag_descriptions::kInfobarUIRebootDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(kIOSInfobarUIReboot)}, FEATURE_VALUE_TYPE(kIOSInfobarUIReboot)},
......
...@@ -286,11 +286,6 @@ const char kMobileGoogleSRPDescription[] = ...@@ -286,11 +286,6 @@ const char kMobileGoogleSRPDescription[] =
"Request the Mobile version of Google SRP by default when the desktop mode " "Request the Mobile version of Google SRP by default when the desktop mode "
"is requested by default."; "is requested by default.";
const char kNonModalDialogsName[] = "Use non-modal JavaScript dialogs";
const char kNonModalDialogsDescription[] =
"Presents JavaScript dialogs non-modally so that the user can change tabs "
"while a dialog is displayed.";
const char kOmniboxPreserveDefaultMatchAgainstAsyncUpdateName[] = const char kOmniboxPreserveDefaultMatchAgainstAsyncUpdateName[] =
"Omnibox Preserve Default Match Against Async Update"; "Omnibox Preserve Default Match Against Async Update";
const char kOmniboxPreserveDefaultMatchAgainstAsyncUpdateDescription[] = const char kOmniboxPreserveDefaultMatchAgainstAsyncUpdateDescription[] =
......
...@@ -245,10 +245,6 @@ extern const char kMarkHttpAsDescription[]; ...@@ -245,10 +245,6 @@ extern const char kMarkHttpAsDescription[];
extern const char kMobileGoogleSRPName[]; extern const char kMobileGoogleSRPName[];
extern const char kMobileGoogleSRPDescription[]; extern const char kMobileGoogleSRPDescription[];
// Title and description for the flag to enable non-modal JavaScript dialogs.
extern const char kNonModalDialogsName[];
extern const char kNonModalDialogsDescription[];
// Title and description for the flag to preserve the default match when an // Title and description for the flag to preserve the default match when an
// async match updates. // async match updates.
extern const char kOmniboxPreserveDefaultMatchAgainstAsyncUpdateName[]; extern const char kOmniboxPreserveDefaultMatchAgainstAsyncUpdateName[];
......
...@@ -93,7 +93,6 @@ source_set("browser_view") { ...@@ -93,7 +93,6 @@ source_set("browser_view") {
"//ios/chrome/browser/ui/context_menu", "//ios/chrome/browser/ui/context_menu",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators", "//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/dialogs:dialogs_internal", "//ios/chrome/browser/ui/dialogs:dialogs_internal",
"//ios/chrome/browser/ui/dialogs:feature_flags",
"//ios/chrome/browser/ui/download", "//ios/chrome/browser/ui/download",
"//ios/chrome/browser/ui/download:features", "//ios/chrome/browser/ui/download:features",
"//ios/chrome/browser/ui/elements:elements_internal", "//ios/chrome/browser/ui/elements:elements_internal",
......
...@@ -16,20 +16,6 @@ source_set("dialogs") { ...@@ -16,20 +16,6 @@ source_set("dialogs") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
} }
source_set("feature_flags") {
sources = [
"dialog_features.h",
"dialog_features.mm",
]
configs += [ "//build/config/compiler:enable_arc" ]
deps = [
"//base",
"//components/flags_ui",
]
}
source_set("unit_tests") { source_set("unit_tests") {
testonly = true testonly = true
...@@ -56,12 +42,8 @@ source_set("constants") { ...@@ -56,12 +42,8 @@ source_set("constants") {
source_set("dialogs_internal") { source_set("dialogs_internal") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"dialog_presenter.h",
"dialog_presenter.mm",
"java_script_dialog_metrics.cc", "java_script_dialog_metrics.cc",
"java_script_dialog_metrics.h", "java_script_dialog_metrics.h",
"java_script_dialog_presenter_impl.h",
"java_script_dialog_presenter_impl.mm",
"nsurl_protection_space_util.h", "nsurl_protection_space_util.h",
"nsurl_protection_space_util.mm", "nsurl_protection_space_util.mm",
"overlay_java_script_dialog_presenter.h", "overlay_java_script_dialog_presenter.h",
...@@ -101,8 +83,6 @@ source_set("unit_tests_internal") { ...@@ -101,8 +83,6 @@ source_set("unit_tests_internal") {
testonly = true testonly = true
sources = [ sources = [
"completion_block_util_unittest.mm", "completion_block_util_unittest.mm",
"dialog_presenter_unittest.mm",
"java_script_dialog_presenter_impl_unittest.mm",
"nsurl_protection_space_util_unittest.mm", "nsurl_protection_space_util_unittest.mm",
"overlay_java_script_dialog_presenter_unittest.mm", "overlay_java_script_dialog_presenter_unittest.mm",
] ]
...@@ -130,7 +110,6 @@ source_set("eg_tests") { ...@@ -130,7 +110,6 @@ source_set("eg_tests") {
sources = [ "javascript_dialog_egtest.mm" ] sources = [ "javascript_dialog_egtest.mm" ]
deps = [ deps = [
":constants", ":constants",
":feature_flags",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/strings", "//components/strings",
...@@ -167,7 +146,6 @@ source_set("eg2_tests") { ...@@ -167,7 +146,6 @@ source_set("eg2_tests") {
sources = [ "javascript_dialog_egtest.mm" ] sources = [ "javascript_dialog_egtest.mm" ]
deps = [ deps = [
":constants", ":constants",
":feature_flags",
"//base", "//base",
"//base/test:test_support", "//base/test:test_support",
"//components/strings", "//components/strings",
......
// Copyright 2018 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_DIALOGS_DIALOG_FEATURES_H_
#define IOS_CHROME_BROWSER_UI_DIALOGS_DIALOG_FEATURES_H_
#include "base/feature_list.h"
namespace dialogs {
// Feature flag to use non-modal UI for JavaScript dialogs.
extern const base::Feature kNonModalDialogs;
} // namespace dialogs
#endif // IOS_CHROME_BROWSER_UI_DIALOGS_DIALOG_FEATURES_H_
// Copyright 2018 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/dialogs/dialog_features.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace dialogs {
const base::Feature kNonModalDialogs{"kNonModalDialogs",
base::FEATURE_ENABLED_BY_DEFAULT};
} // namespace dialogs
// Copyright 2015 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_DIALOGS_DIALOG_PRESENTER_H_
#define IOS_CHROME_BROWSER_UI_DIALOGS_DIALOG_PRESENTER_H_
#import <UIKit/UIKit.h>
#import "base/ios/block_types.h"
@protocol DialogPresenterDelegate;
class GURL;
@class AlertCoordinator;
namespace web {
class WebState;
}
// Handles the queued display of modal dialogs.
@interface DialogPresenter : NSObject
// Whether the DialogPresenter should attempt to show dialogs. When |active| is
// NO, dialogs will be queued and displayed when the DialogPresenter is
// activated.
@property(nonatomic, assign, getter=isActive) BOOL active;
// Dialogs will be presented from |viewController|.
- (instancetype)initWithDelegate:(id<DialogPresenterDelegate>)delegate
presentingViewController:(UIViewController*)viewController
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
// Methods to show JavaScriptDialogs of each JavaScriptAlertType. If a dialog
// is already being presented, these functions will enqueue a new dialog to be
// shown when the visible dialog is dismissed. |context| will be retained until
// its associated dialog is dismissed or |-cancelDialogForContext:| is called.
- (void)runJavaScriptAlertPanelWithMessage:(NSString*)message
requestURL:(const GURL&)requestURL
webState:(web::WebState*)webState
completionHandler:(void (^)(void))completionHandler;
- (void)runJavaScriptConfirmPanelWithMessage:(NSString*)message
requestURL:(const GURL&)requestURL
webState:(web::WebState*)webState
completionHandler:
(void (^)(BOOL isConfirmed))completionHandler;
- (void)runJavaScriptTextInputPanelWithPrompt:(NSString*)message
defaultText:(NSString*)defaultText
requestURL:(const GURL&)requestURL
webState:(web::WebState*)webState
completionHandler:
(void (^)(NSString* input))completionHandler;
// Displays an HTTP authentication dialog, which has 2 text fields
// (username and password), Login and Cancel button. If Login was tapped,
// |completionHandler| is called with valid strings which represent username
// and password inputs. If cancel is tapped then |completionHandler| is
// called with nil |user| and nil |password|. Username will be pre-populated
// from provided |credential|.
- (void)runAuthDialogForProtectionSpace:(NSURLProtectionSpace*)protectionSpace
proposedCredential:(NSURLCredential*)credential
webState:(web::WebState*)webState
completionHandler:
(void (^)(NSString* user, NSString* password))handler;
// Cancels the display of the dialog associated with |context|.
- (void)cancelDialogForWebState:(web::WebState*)webState;
// Dismisses the currently presented dialog and cancels all queued dialogs.
- (void)cancelAllDialogs;
// Tries to present an alert if needed and possible. Called by the view
// controller which will present the alert to notify that it has dismissed a
// view controller.
- (void)tryToPresent;
@end
@interface DialogPresenter (ExposedForTesting)
// The dialog currently being shown.
@property(nonatomic, readonly) AlertCoordinator* presentedDialogCoordinator;
// Called when |coordinator| is stopped.
- (void)dialogCoordinatorWasStopped:(AlertCoordinator*)coordinator;
@end
// Delegate protocol for DialogPresenter.
@protocol DialogPresenterDelegate<NSObject>
// Called by |presenter| before showing the queued modal dialog associated with
// |context|.
- (void)dialogPresenter:(DialogPresenter*)presenter
willShowDialogForWebState:(web::WebState*)webState;
// Whether |presenter| should present a dialog.
- (BOOL)shouldDialogPresenterPresentDialog:(DialogPresenter*)presenter;
@end
#endif // IOS_CHROME_BROWSER_UI_DIALOGS_DIALOG_PRESENTER_H_
This diff is collapsed.
// Copyright 2016 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_DIALOGS_JAVA_SCRIPT_DIALOG_PRESENTER_IMPL_H_
#define IOS_CHROME_BROWSER_UI_DIALOGS_JAVA_SCRIPT_DIALOG_PRESENTER_IMPL_H_
#include "ios/web/public/ui/java_script_dialog_presenter.h"
@class AlertCoordinator;
@class DialogPresenter;
// The maximum characters to use for the JavaScript dialog message text.
extern const size_t kJavaScriptDialogMaxMessageLength;
class JavaScriptDialogPresenterImpl final
: public web::JavaScriptDialogPresenter {
public:
explicit JavaScriptDialogPresenterImpl(DialogPresenter* dialogPresenter);
~JavaScriptDialogPresenterImpl() override;
void RunJavaScriptDialog(web::WebState* web_state,
const GURL& origin_url,
web::JavaScriptDialogType dialog_type,
NSString* message_text,
NSString* default_prompt_text,
web::DialogClosedCallback callback) override;
void CancelDialogs(web::WebState* web_state) override;
// JavaScript dialogs presented by this class cap the message text length to
// kJavaScriptDialogMaxMessageLength. This utility function performs that
// operation on an input NSString.
// TODO(crbug.com/674649): Remove this after switching to custom dialog
// implementation.
static NSString* GetTruncatedMessageText(NSString* message_text);
private:
// The underlying DialogPresenter handling the dialog UI.
DialogPresenter* dialog_presenter_;
DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogPresenterImpl);
};
#endif // IOS_CHROME_BROWSER_UI_DIALOGS_JAVA_SCRIPT_DIALOG_PRESENTER_IMPL_H_
// Copyright 2016 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 "ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/dialogs/dialog_presenter.h"
#import "ios/chrome/browser/ui/dialogs/java_script_dialog_blocking_state.h"
#include "ios/chrome/browser/ui/dialogs/java_script_dialog_metrics.h"
#include "ui/gfx/text_elider.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const size_t kJavaScriptDialogMaxMessageLength = 150;
JavaScriptDialogPresenterImpl::JavaScriptDialogPresenterImpl(
DialogPresenter* dialogPresenter)
: dialog_presenter_(dialogPresenter) {}
JavaScriptDialogPresenterImpl::~JavaScriptDialogPresenterImpl() {}
void JavaScriptDialogPresenterImpl::RunJavaScriptDialog(
web::WebState* web_state,
const GURL& origin_url,
web::JavaScriptDialogType dialog_type,
NSString* message_text,
NSString* default_prompt_text,
web::DialogClosedCallback callback) {
JavaScriptDialogBlockingState::CreateForWebState(web_state);
if (JavaScriptDialogBlockingState::FromWebState(web_state)->blocked()) {
// Block the dialog if needed.
RecordDialogDismissalCause(IOSJavaScriptDialogDismissalCause::kBlocked);
std::move(callback).Run(NO, nil);
return;
}
message_text =
JavaScriptDialogPresenterImpl::GetTruncatedMessageText(message_text);
switch (dialog_type) {
case web::JAVASCRIPT_DIALOG_TYPE_ALERT: {
__block web::DialogClosedCallback scoped_callback = std::move(callback);
[dialog_presenter_
runJavaScriptAlertPanelWithMessage:message_text
requestURL:origin_url
webState:web_state
completionHandler:^{
RecordDialogDismissalCause(
IOSJavaScriptDialogDismissalCause::kUser);
if (!scoped_callback.is_null()) {
std::move(scoped_callback).Run(YES, nil);
}
}];
break;
}
case web::JAVASCRIPT_DIALOG_TYPE_CONFIRM: {
__block web::DialogClosedCallback scoped_callback = std::move(callback);
[dialog_presenter_
runJavaScriptConfirmPanelWithMessage:message_text
requestURL:origin_url
webState:web_state
completionHandler:^(BOOL is_confirmed) {
RecordDialogDismissalCause(
IOSJavaScriptDialogDismissalCause::kUser);
if (!scoped_callback.is_null()) {
std::move(scoped_callback)
.Run(is_confirmed, nil);
}
}];
break;
}
case web::JAVASCRIPT_DIALOG_TYPE_PROMPT: {
__block web::DialogClosedCallback scoped_callback = std::move(callback);
[dialog_presenter_
runJavaScriptTextInputPanelWithPrompt:message_text
defaultText:default_prompt_text
requestURL:origin_url
webState:web_state
completionHandler:^(NSString* text_input) {
RecordDialogDismissalCause(
IOSJavaScriptDialogDismissalCause::kUser);
if (!scoped_callback.is_null()) {
std::move(scoped_callback)
.Run(YES, text_input);
}
}];
break;
}
default:
break;
}
}
void JavaScriptDialogPresenterImpl::CancelDialogs(web::WebState* web_state) {
[dialog_presenter_ cancelDialogForWebState:web_state];
}
// static
NSString* JavaScriptDialogPresenterImpl::GetTruncatedMessageText(
NSString* message_text) {
if (message_text.length <= kJavaScriptDialogMaxMessageLength)
return message_text;
return base::SysUTF16ToNSString(gfx::TruncateString(
base::SysNSStringToUTF16(message_text), kJavaScriptDialogMaxMessageLength,
gfx::CHARACTER_BREAK));
}
// Copyright 2017 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/dialogs/java_script_dialog_presenter_impl.h"
#import <Foundation/Foundation.h>
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
using JavaScriptDialogPresenterImplTest = PlatformTest;
// Tests that GetTruncatedMessageText() correctly truncates the length of a
// string to the expected length.
TEST_F(JavaScriptDialogPresenterImplTest, GetTruncatedMessageText) {
NSMutableString* text = [@"text" mutableCopy];
while (text.length < kJavaScriptDialogMaxMessageLength) {
[text appendString:text];
}
ASSERT_GT(text.length, kJavaScriptDialogMaxMessageLength);
EXPECT_EQ(JavaScriptDialogPresenterImpl::GetTruncatedMessageText(text).length,
kJavaScriptDialogMaxMessageLength);
}
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "components/url_formatter/elide_url.h" #include "components/url_formatter/elide_url.h"
#import "ios/chrome/browser/ui/dialogs/dialog_constants.h" #import "ios/chrome/browser/ui/dialogs/dialog_constants.h"
#import "ios/chrome/browser/ui/dialogs/dialog_features.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/chrome/test/earl_grey/chrome_actions.h" #import "ios/chrome/test/earl_grey/chrome_actions.h"
#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" #import "ios/chrome/test/earl_grey/chrome_earl_grey.h"
...@@ -45,11 +44,6 @@ using base::test::ios::WaitUntilConditionOrTimeout; ...@@ -45,11 +44,6 @@ using base::test::ios::WaitUntilConditionOrTimeout;
namespace { namespace {
// Whether non-modal dialogs are being used.
bool AreDialogsNonModal() {
return base::FeatureList::IsEnabled(dialogs::kNonModalDialogs);
}
// Body script for test page that shows an alert with kAlertMessage and returns // Body script for test page that shows an alert with kAlertMessage and returns
// kAlertResult. // kAlertResult.
const char kAlertURLPath[] = "/alert"; const char kAlertURLPath[] = "/alert";
...@@ -187,24 +181,6 @@ std::unique_ptr<net::test_server::HttpResponse> LoadPageWithLinkToOnLoadPage( ...@@ -187,24 +181,6 @@ std::unique_ptr<net::test_server::HttpResponse> LoadPageWithLinkToOnLoadPage(
return GetHttpResponseWithContent(GetLinkPageContents(on_load_page_url)); return GetHttpResponseWithContent(GetLinkPageContents(on_load_page_url));
} }
// Assert that an alert with |alert_text| has been shown or hidden.
void WaitForAlertWithText(NSString* alert_text, bool visible) {
ConditionBlock condition = ^{
NSError* error = nil;
id<GREYMatcher> text_matcher =
chrome_test_util::StaticTextWithAccessibilityLabel(alert_text);
[[EarlGrey selectElementWithMatcher:text_matcher]
assertWithMatcher:visible ? grey_notNil() : grey_nil()
error:&error];
return !error;
};
NSString* error_text_format = visible
? @"Dialog with text was not shown: %@"
: @"Dialog with text was not hidden: %@";
GREYAssert(WaitUntilConditionOrTimeout(kWaitForUIElementTimeout, condition),
error_text_format, alert_text);
}
// Waits for a JavaScript dialog from |url| with |message| to be shown or // Waits for a JavaScript dialog from |url| with |message| to be shown or
// hidden. // hidden.
void WaitForJavaScriptDialog(const GURL& url, void WaitForJavaScriptDialog(const GURL& url,
...@@ -228,7 +204,7 @@ void WaitForJavaScriptDialog(const GURL& url, ...@@ -228,7 +204,7 @@ void WaitForJavaScriptDialog(const GURL& url,
error_text); error_text);
// Check the title. Non-modal main-frame dialogs do not have a title label. // Check the title. Non-modal main-frame dialogs do not have a title label.
if (!AreDialogsNonModal() || !is_main_frame) { if (!is_main_frame) {
base::string16 url_string = url_formatter::FormatUrlForSecurityDisplay( base::string16 url_string = url_formatter::FormatUrlForSecurityDisplay(
url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS); url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
NSString* expected_title = NSString* expected_title =
...@@ -469,18 +445,6 @@ void TapSuppressDialogsButton() { ...@@ -469,18 +445,6 @@ void TapSuppressDialogsButton() {
WaitForJavaScriptDialog(kURL, kAlertLoopMessage, /*visible=*/false, WaitForJavaScriptDialog(kURL, kAlertLoopMessage, /*visible=*/false,
/*is_main_frame=*/true); /*is_main_frame=*/true);
// Modal dialogs have an additional action sheet for dialog suppression.
if (!AreDialogsNonModal()) {
// Wait for confirmation action sheet to be shown.
NSString* alertLabel =
l10n_util::GetNSString(IDS_JAVASCRIPT_MESSAGEBOX_SUPPRESS_OPTION);
WaitForAlertWithText(alertLabel, /*visible=*/true);
// Tap the suppress dialogs confirmation button.
TapSuppressDialogsButton();
WaitForAlertWithText(alertLabel, /*visible=*/false);
}
// Wait for the html to be reset to the loop finished text. // Wait for the html to be reset to the loop finished text.
[ChromeEarlGrey waitForWebStateContainingText:kAlertLoopFinishedText]; [ChromeEarlGrey waitForWebStateContainingText:kAlertLoopFinishedText];
} }
...@@ -509,12 +473,6 @@ void TapSuppressDialogsButton() { ...@@ -509,12 +473,6 @@ void TapSuppressDialogsButton() {
// Tap the link to trigger the dialog. // Tap the link to trigger the dialog.
[ChromeEarlGrey tapWebStateElementWithID:@(kTestPageLinkID)]; [ChromeEarlGrey tapWebStateElementWithID:@(kTestPageLinkID)];
// Make sure the alert is not presented modally over settings.
if (!AreDialogsNonModal()) {
WaitForJavaScriptDialog(kURL, kAlertMessage, /*visible=*/false,
/*is_main_frame=*/true);
}
// Close the settings. // Close the settings.
[[EarlGrey selectElementWithMatcher:SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:SettingsDoneButton()]
performAction:grey_tap()]; performAction:grey_tap()];
...@@ -562,64 +520,4 @@ void TapSuppressDialogsButton() { ...@@ -562,64 +520,4 @@ void TapSuppressDialogsButton() {
[ChromeEarlGrey waitForWebStateContainingText:kAlertResult]; [ChromeEarlGrey waitForWebStateContainingText:kAlertResult];
} }
// Tests that an alert is presented after a new tab animation is finished.
- (void)testShowJavaScriptAfterNewTabAnimation {
// TODO(crbug.com/1007986) Test flaky on iOS13.
if (@available(iOS 13, *)) {
EARL_GREY_TEST_DISABLED(@"Test disabled on iOS13.");
}
// This tests is for DialogPresenter behavior, and does not apply to
// OverlayPresenter, which is used for the non-modal dialog solution.
if (AreDialogsNonModal()) {
EARL_GREY_TEST_DISABLED(@"Test disabled for non-modal dialogs.");
}
// Load the test page with a link to kOnLoadAlertURL and long tap on the link.
const GURL kURL = self.testServer->GetURL(kLinkPageURLPath);
[ChromeEarlGrey loadURL:kURL];
[ChromeEarlGrey waitForWebStateContainingText:kLinkPageLinkText];
// TODO(crbug.com/712358): Use method LongPressElementAndTapOnButton once
// it is moved out of context_menu_egtests.mm and into a shared location.
[[EarlGrey selectElementWithMatcher:WebViewMatcher()]
performAction:chrome_test_util::LongPressElementForContextMenu(
[ElementSelector selectorWithElementID:kLinkID],
true /* menu should appear */)];
// Tap on the "Open In New Tab" button.
id<GREYMatcher> newTabMatcher = ButtonWithAccessibilityLabel(
l10n_util::GetNSStringWithFixup(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB));
[[EarlGrey selectElementWithMatcher:newTabMatcher] performAction:grey_tap()];
// This test case requires that a dialog is presented in the onload event so
// that the DialogPresenter attempts to display during a new tab animation.
// Because presenting a dialog halts the JavaScript execution on the page,
// this prevents the page loaded event from being received until the alert is
// closed. On iPad, this means that there is a loading indicator that
// continues to animate until the dialog is closed. Disabling EarlGrey
// synchronization code for iPad allows the test to detect and dismiss the
// dialog while this animation is occurring.
{
std::unique_ptr<ScopedSynchronizationDisabler> disabler =
std::make_unique<ScopedSynchronizationDisabler>();
if (![ChromeEarlGrey isIPadIdiom]) {
disabler.reset();
}
// Wait for the alert to be shown.
GURL kOnLoadURL = self.testServer->GetURL(kOnLoadURLPath);
WaitForJavaScriptDialog(kURL, kOnLoadAlertMessage, /*visible=*/true,
/*is_main_frame=*/true);
// Verify that the omnibox shows the correct URL when the dialog is visible.
std::string title =
base::SysNSStringToUTF8([ChromeEarlGrey displayTitleForURL:kOnLoadURL]);
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(title)]
assertWithMatcher:grey_notNil()];
[[EarlGrey selectElementWithMatcher:OKButton()] performAction:grey_tap()];
}
}
@end @end
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