1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
#include "chrome/test/payments/payment_app_install_util.h"
#include "components/omnibox/browser/buildflags.h"
#include "components/payments/content/icon/icon_size.h"
#include "components/payments/core/features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features_generated.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom.h"
#include "ui/views/controls/image_view.h"
namespace payments {
namespace {
class PaymentHandlerHeaderViewUITest : public PaymentRequestBrowserTestBase {
public:
PaymentHandlerHeaderViewUITest() = default;
~PaymentHandlerHeaderViewUITest() override = default;
void SetUpOnMainThread() override {
PaymentRequestBrowserTestBase::SetUpOnMainThread();
NavigateTo("/payment_handler.html");
}
};
IN_PROC_BROWSER_TEST_F(PaymentHandlerHeaderViewUITest,
HeaderHasCorrectDetails) {
std::string method_name;
InstallPaymentApp("a.com", "/payment_handler_sw.js", &method_name);
// Trigger PaymentRequest, and wait until the PaymentHandler has loaded a
// web-contents that has set a title.
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED,
DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::PAYMENT_HANDLER_WINDOW_OPENED,
DialogEvent::PAYMENT_HANDLER_TITLE_SET});
ASSERT_EQ(
"success",
content::EvalJs(
GetActiveWebContents(),
content::JsReplace("launchWithoutWaitForResponse($1)", method_name)));
ASSERT_TRUE(WaitForObservedEvent());
// We always push the initial browser sheet to the stack, even if it isn't
// shown. Since it also defines a SHEET_TITLE, we have to explicitly test the
// front PaymentHandler view here.
ViewStack* view_stack = dialog_view()->view_stack_for_testing();
EXPECT_TRUE(IsViewVisible(DialogViewID::CANCEL_BUTTON, view_stack->top()));
EXPECT_FALSE(IsViewVisible(DialogViewID::BACK_BUTTON, view_stack->top()));
EXPECT_TRUE(IsViewVisible(DialogViewID::SHEET_TITLE, view_stack->top()));
EXPECT_TRUE(
IsViewVisible(DialogViewID::PAYMENT_APP_HEADER_ICON, view_stack->top()));
EXPECT_TRUE(IsViewVisible(DialogViewID::PAYMENT_APP_OPENED_WINDOW_SHEET,
view_stack->top()));
// Only the origin is shown and is marked as the title. For this test, the
// origin can be derived from the method name.
ASSERT_TRUE(base::StartsWith(method_name, "https://"));
EXPECT_EQ(base::ASCIIToUTF16(method_name.substr(8)),
GetLabelText(DialogViewID::SHEET_TITLE, view_stack->top()));
}
IN_PROC_BROWSER_TEST_F(PaymentHandlerHeaderViewUITest, HeaderWithoutIcon) {
std::string method_name;
InstallPaymentAppWithoutIcon("a.com", "/payment_handler_sw.js", &method_name);
// Trigger PaymentRequest. Since the Payment App has no icon this will show
// the browser sheet first, and we have to manually select the payment app to
// continue.
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED});
ASSERT_EQ(
"success",
content::EvalJs(
GetActiveWebContents(),
content::JsReplace("launchWithoutWaitForResponse($1)", method_name)));
ASSERT_TRUE(WaitForObservedEvent());
// Select the installed payment app.
OpenPaymentMethodScreen();
ResetEventWaiter(DialogEvent::BACK_NAVIGATION);
views::View* list_view = dialog_view()->GetViewByID(
static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
ASSERT_TRUE(list_view);
EXPECT_EQ(1u, list_view->children().size());
ClickOnDialogViewAndWait(list_view->children()[0]);
// The pay button should be enabled now.
ASSERT_TRUE(IsPayButtonEnabled());
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::PAYMENT_HANDLER_WINDOW_OPENED,
DialogEvent::PAYMENT_HANDLER_TITLE_SET});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON);
// The payment app has no icon, so it should not be displayed on the header.
EXPECT_FALSE(IsViewVisible(DialogViewID::PAYMENT_APP_HEADER_ICON));
}
IN_PROC_BROWSER_TEST_F(PaymentHandlerHeaderViewUITest, CloseButtonPressed) {
std::string a_method_name;
InstallPaymentApp("a.com", "/payment_handler_sw.js", &a_method_name);
std::string b_method_name;
InstallPaymentApp("b.com", "/payment_handler_sw.js", &b_method_name);
// Trigger PaymentRequest. Since there are two payment apps this will show
// the browser sheet first, and we have to manually select the payment app to
// continue.
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED});
ASSERT_EQ(
"success",
content::EvalJs(
GetActiveWebContents(),
content::JsReplace(
"launchWithoutWaitForResponseWithMethods([{supportedMethods:$1}"
", {supportedMethods:$2}])",
a_method_name, b_method_name)));
ASSERT_TRUE(WaitForObservedEvent());
// Select the installed payment app.
OpenPaymentMethodScreen();
ResetEventWaiter(DialogEvent::BACK_NAVIGATION);
views::View* list_view = dialog_view()->GetViewByID(
static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
ASSERT_TRUE(list_view);
EXPECT_EQ(2u, list_view->children().size());
ClickOnDialogViewAndWait(list_view->children()[0]);
// The pay button should be enabled now.
ASSERT_TRUE(IsPayButtonEnabled());
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::PAYMENT_HANDLER_WINDOW_OPENED,
DialogEvent::PAYMENT_HANDLER_TITLE_SET});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON);
// The cancel button is shown and closes the dialog.
ResetEventWaiter(DialogEvent::DIALOG_CLOSED);
ClickOnDialogViewAndWait(DialogViewID::CANCEL_BUTTON,
/*wait_for_animation=*/false);
}
// Test that the header and dialog heights are consistent with when there is no
// title.
// Flakily failing: https://crbug.com/1430351
IN_PROC_BROWSER_TEST_F(PaymentHandlerHeaderViewUITest,
DISABLED_ConsistentHeaderHeight) {
// Install a payment app that will open a window.
std::string method_name;
InstallPaymentApp("a.com", "/payment_handler_sw.js", &method_name);
// Trigger PaymentRequest.
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED,
DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::PAYMENT_HANDLER_WINDOW_OPENED,
DialogEvent::PAYMENT_HANDLER_TITLE_SET});
ASSERT_EQ(
"success",
content::EvalJs(
GetActiveWebContents(),
content::JsReplace("launchWithoutWaitForResponse($1)", method_name)));
ASSERT_TRUE(WaitForObservedEvent());
ViewStack* view_stack = dialog_view()->view_stack_for_testing();
int header_height_with_title =
view_stack->top()
->GetViewByID(static_cast<int>(DialogViewID::PAYMENT_APP_HEADER))
->height();
int dialog_height_with_title = view_stack->top()->height();
// Close the dialog.
ClickOnCancel();
// Now trigger PaymentRequest for a PaymentHandler with a window that has no
// title.
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED,
DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::PAYMENT_HANDLER_WINDOW_OPENED});
ASSERT_EQ("success",
content::EvalJs(
GetActiveWebContents(),
content::JsReplace("launchWithoutWaitForResponse($1, "
"'payment_handler_window_no_title.html')",
method_name)));
ASSERT_TRUE(WaitForObservedEvent());
// Expect the dialog and header height with a title to be the same as before.
view_stack = dialog_view()->view_stack_for_testing();
EXPECT_EQ(dialog_height_with_title, view_stack->top()->height());
EXPECT_EQ(
header_height_with_title,
view_stack->top()
->GetViewByID(static_cast<int>(DialogViewID::PAYMENT_APP_HEADER))
->height());
ClickOnCancel();
}
IN_PROC_BROWSER_TEST_F(PaymentHandlerHeaderViewUITest, LargeIcon) {
// Install a payment app with a large icon that will be sized down at render.
std::string method_name = PaymentAppInstallUtil::InstallPaymentApp(
*GetActiveWebContents(), *https_server(), "a.com",
"/payment_handler_sw.js",
PaymentAppInstallUtil::IconInstall::kWithLargeIcon);
// Trigger PaymentRequest, and wait until the PaymentHandler has loaded a
// web-contents that has set a title.
ResetEventWaiterForSequence({DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::DIALOG_OPENED,
DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN,
DialogEvent::PAYMENT_HANDLER_WINDOW_OPENED,
DialogEvent::PAYMENT_HANDLER_TITLE_SET});
ASSERT_EQ(
"success",
content::EvalJs(
GetActiveWebContents(),
content::JsReplace("launchWithoutWaitForResponse($1)", method_name)));
ASSERT_TRUE(WaitForObservedEvent());
// We always push the initial browser sheet to the stack, even if it isn't
// shown. Since it also defines a SHEET_TITLE, we have to explicitly test the
// front PaymentHandler view here.
ViewStack* view_stack = dialog_view()->view_stack_for_testing();
EXPECT_TRUE(
IsViewVisible(DialogViewID::PAYMENT_APP_HEADER_ICON, view_stack->top()));
EXPECT_EQ(
gfx::Size(
IconSizeCalculator::kPaymentAppDeviceIndependentIdealIconHeight,
IconSizeCalculator::kPaymentAppDeviceIndependentIdealIconHeight),
static_cast<views::ImageView*>(
GetChildByDialogViewID(view_stack,
DialogViewID::PAYMENT_APP_HEADER_ICON))
->GetImageBounds()
.size());
}
} // namespace
} // namespace payments
|