File: fedcm_interactive_uitest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (137 lines) | stat: -rw-r--r-- 5,365 bytes parent folder | download | duplicates (5)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This class runs CUJ tests for fedCM. Normally fedCM is invoked by javascript
// from webpages, and requires communication with multiple remote endpoints.
// This test suite does not do any of that at the moment.

#include "build/build_config.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/views/webid/account_selection_view_test_base.h"
#include "chrome/browser/ui/views/webid/fake_delegate.h"
#include "chrome/browser/ui/views/webid/fedcm_account_selection_view_desktop.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "content/public/browser/identity_request_dialog_controller.h"
#include "content/public/test/browser_test.h"
#include "ui/base/interaction/interactive_test.h"

namespace webid {
namespace {

class FedCmCUJTest : public InteractiveBrowserTest {
 public:
  void SetUp() override {
    ASSERT_TRUE(embedded_test_server()->InitializeAndListen());
    InteractiveBrowserTest::SetUp();
  }

  void SetUpOnMainThread() override {
    InteractiveBrowserTest::SetUpOnMainThread();
    embedded_test_server()->StartAcceptingConnections();
  }

  auto OpenAccounts(blink::mojom::RpMode mode) {
    return Do([this, mode]() {
      delegate_ = std::make_unique<FakeDelegate>(
          browser()->GetActiveTabInterface()->GetContents());
      account_selection_view_ = std::make_unique<FedCmAccountSelectionView>(
          delegate_.get(), browser()->GetActiveTabInterface());
      idps_ = {base::MakeRefCounted<content::IdentityProviderData>(
          "idp-example.com", content::IdentityProviderMetadata(),
          content::ClientMetadata(GURL(), GURL(), GURL(), gfx::Image()),
          blink::mojom::RpContext::kSignIn, /*format=*/std::nullopt,
          kDefaultDisclosureFields,
          /*has_login_status_mismatch=*/false)};
      accounts_ = {base::MakeRefCounted<Account>(
          "id", "display_identifier", "display_name", "email", "name",
          "given_name", GURL(), "phone", "username",
          /*login_hints=*/std::vector<std::string>(),
          /*domain_hints=*/std::vector<std::string>(),
          /*labels=*/std::vector<std::string>())};
      accounts_[0]->identity_provider = idps_[0];
      account_selection_view_->Show(
          content::RelyingPartyData(u"rp-example.com",
                                    /*iframe_for_display=*/u""),
          idps_, accounts_, mode,
          /*new_accounts=*/std::vector<IdentityRequestAccountPtr>());
    });
  }

  // Opens the modal version of the account chooser.
  auto OpenAccountsModal() {
    return OpenAccounts(blink::mojom::RpMode::kActive);
  }

  // Opens the bubble version of the account chooser.
  auto OpenAccountsBubble() {
    return OpenAccounts(blink::mojom::RpMode::kPassive);
  }

  auto ShowTabModalUI() {
    return Do([this]() {
      tab_modal_ui_ = browser()->GetActiveTabInterface()->ShowModalUI();
    });
  }
  auto HideTabModalUI() {
    return Do([this]() { tab_modal_ui_.reset(); });
  }

 protected:
  std::unique_ptr<FakeDelegate> delegate_;
  std::vector<IdentityProviderDataPtr> idps_;
  std::vector<IdentityRequestAccountPtr> accounts_;
  std::unique_ptr<FedCmAccountSelectionView> account_selection_view_;
  std::unique_ptr<tabs::ScopedTabModalUI> tab_modal_ui_;
};

// Shows the account picker. Selects an account.
IN_PROC_BROWSER_TEST_F(FedCmCUJTest, SelectAccount) {
  RunTestSequence(OpenAccountsModal(),
                  WaitForShow(kFedCmAccountChooserDialogAccountElementId),
                  PressButton(kFedCmAccountChooserDialogAccountElementId));
}

// Shows the bubble account picker. It should hide when a modal UI is shown. It
// should re-show when the modal UI goes away.
IN_PROC_BROWSER_TEST_F(FedCmCUJTest, BubbleHidesWhenModalUIShown) {
  RunTestSequence(
      OpenAccountsBubble(),
      WaitForShow(kFedCmAccountChooserDialogAccountElementId), ShowTabModalUI(),
      WaitForHide(kFedCmAccountChooserDialogAccountElementId), HideTabModalUI(),
      WaitForShow(kFedCmAccountChooserDialogAccountElementId));
}

// TODO(https://crbug.com/387473078): Fix this on windows.
#if BUILDFLAG(IS_WIN)
#define MAYBE_OneClickOutsideBubble DISABLED_OneClickOutsideBubble
#else
#define MAYBE_OneClickOutsideBubble OneClickOutsideBubble
#endif
// When the bubble view is showing, a single click outside the bubble should be
// received by the website.
IN_PROC_BROWSER_TEST_F(FedCmCUJTest, MAYBE_OneClickOutsideBubble) {
  DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kActiveTab);
  // chrome/test/data/button.html
  const GURL url = embedded_test_server()->GetURL("/button.html");
  const DeepQuery kPathToButton{
      "button",
  };

  RunTestSequence(
      InstrumentTab(kActiveTab), NavigateWebContents(kActiveTab, url),
      OpenAccountsBubble(),
      WaitForShow(kFedCmAccountChooserDialogAccountElementId),
      MoveMouseTo(kActiveTab, kPathToButton),
      CheckJsResult(
          kActiveTab,
          "() => document.getElementById('text').style.display == 'none'"),
      ClickMouse(),
      CheckJsResult(
          kActiveTab,
          "() => document.getElementById('text').style.display == 'block'"));
}

}  // namespace
}  // namespace webid