File: modifiers_browsertest.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (94 lines) | stat: -rw-r--r-- 3,754 bytes parent folder | download | duplicates (6)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <vector>

#include "base/strings/utf_string_conversions.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 "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"

namespace payments {

class PaymentRequestModifiersTest : public PaymentRequestBrowserTestBase {
 public:
  PaymentRequestModifiersTest(const PaymentRequestModifiersTest&) = delete;
  PaymentRequestModifiersTest& operator=(const PaymentRequestModifiersTest&) =
      delete;

 protected:
  PaymentRequestModifiersTest() = default;

  void SetUpCommandLine(base::CommandLine* command_line) override {
    PaymentRequestBrowserTestBase::SetUpCommandLine(command_line);
    command_line->AppendSwitch(
        switches::kEnableExperimentalWebPlatformFeatures);
  }

  size_t GetLineCount() {
    auto* top = dialog_view()->view_stack_for_testing()->top();
    const auto* content =
        top->GetViewByID(static_cast<int>(DialogViewID::CONTENT_VIEW));
    return content->children().size();
  }
};

IN_PROC_BROWSER_TEST_F(PaymentRequestModifiersTest,
                       NoModifierAppliedIfNoSelectedInstrument) {
  // We need to control the default-selected payment app in the UI, to know that
  // the modifiers should not apply. To achieve this, we install one of the apps
  // without an icon - this makes ServiceWorkerPaymentApp::CanPreselect false
  // for it and so the other app should be selected.
  std::string payment_method_name_1;
  InstallPaymentApp("a.com", "/payment_request_success_responder.js",
                    &payment_method_name_1);
  std::string payment_method_name_2;
  InstallPaymentAppWithoutIcon("b.com", "/payment_request_success_responder.js",
                               &payment_method_name_2);

  NavigateTo("/payment_request_with_modifiers_test.html");

  InvokePaymentRequestUIWithJs(
      content::JsReplace("modifierToSecondaryMethod([{supportedMethods:$1}, "
                         "{supportedMethods:$2}]);",
                         payment_method_name_1, payment_method_name_2));

  OpenOrderSummaryScreen();

  EXPECT_EQ(u"$5.00",
            GetLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL));
  // There's only the total line.
  EXPECT_EQ(1u, GetLineCount());
}

IN_PROC_BROWSER_TEST_F(PaymentRequestModifiersTest,
                       NoTotalInModifierDoesNotCrash) {
  // The modifier without the total applies to the first method; to make sure
  // that it is always selected we install the second method without an icon.
  std::string payment_method_name_1;
  InstallPaymentApp("a.com", "/payment_request_success_responder.js",
                    &payment_method_name_1);
  std::string payment_method_name_2;
  InstallPaymentAppWithoutIcon("b.com", "/payment_request_success_responder.js",
                               &payment_method_name_2);

  NavigateTo("/payment_request_with_modifiers_test.html");

  InvokePaymentRequestUIWithJs(content::JsReplace(
      "modifierWithNoTotal([{supportedMethods:$1}, {supportedMethods:$2}]);",
      payment_method_name_1, payment_method_name_2));

  OpenOrderSummaryScreen();

  // The price is the global total, because the modifier does not have total.
  EXPECT_EQ(u"$5.00",
            GetLabelText(DialogViewID::ORDER_SUMMARY_TOTAL_AMOUNT_LABEL));
  // Only global total is available.
  EXPECT_EQ(1u, GetLineCount());
}

}  // namespace payments