File: browser_actions_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 (101 lines) | stat: -rw-r--r-- 4,403 bytes parent folder | download | duplicates (3)
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
// 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.

#include "chrome/browser/ui/browser_actions.h"

#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/actions/chrome_action_id.h"
#include "chrome/browser/ui/autofill/address_bubbles_controller.h"
#include "chrome/browser/ui/autofill/payments/save_card_bubble_controller.h"
#include "chrome/browser/ui/autofill/payments/save_card_bubble_controller_impl.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "components/autofill/core/browser/payments/payments_autofill_client.h"
#include "components/autofill/core/browser/test_utils/autofill_test_utils.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "ui/actions/actions.h"
#include "url/url_constants.h"

namespace chrome {

class BrowserActionsBrowserTest : public InProcessBrowserTest {
 public:
  BrowserActionsBrowserTest() = default;

 protected:
  raw_ptr<content::WebContents> GetActiveWebContents() const {
    return browser()->tab_strip_model()->GetActiveWebContents();
  }
};

IN_PROC_BROWSER_TEST_F(BrowserActionsBrowserTest, ShowAddressesBubbleOrPage) {
  auto& action_manager = actions::ActionManager::GetForTesting();
  const GURL addresses_url = GURL("chrome://settings/addresses");

  ASSERT_NE(GetActiveWebContents()->GetURL(), addresses_url);
  action_manager.FindAction(kActionShowAddressesBubbleOrPage)->InvokeAction();
  EXPECT_EQ(GetActiveWebContents()->GetURL(), addresses_url);

  autofill::AddressBubblesController::CreateForWebContents(
      GetActiveWebContents());
  auto* bubble_controller = autofill::AddressBubblesController::FromWebContents(
      GetActiveWebContents());
  ASSERT_EQ(bubble_controller->GetBubbleView(), nullptr);
  action_manager.FindAction(kActionShowAddressesBubbleOrPage)->InvokeAction();
  EXPECT_EQ(bubble_controller->GetBubbleView(), nullptr);

  ASSERT_TRUE(content::NavigateToURL(GetActiveWebContents(),
                                     GURL(url::kAboutBlankURL)));
  ASSERT_NE(GetActiveWebContents()->GetURL(), addresses_url);
  action_manager.FindAction(kActionShowAddressesBubbleOrPage)->InvokeAction();
  EXPECT_EQ(GetActiveWebContents()->GetURL(), addresses_url);
}

IN_PROC_BROWSER_TEST_F(BrowserActionsBrowserTest, ShowPaymentsBubbleOrPage) {
  CHECK(ui_test_utils::BringBrowserWindowToFront(browser()));
  auto& action_manager = actions::ActionManager::GetForTesting();
  const GURL payments_url = GURL("chrome://settings/payments");

  ASSERT_NE(GetActiveWebContents()->GetURL(), payments_url);
  action_manager.FindAction(kActionShowPaymentsBubbleOrPage)->InvokeAction();
  EXPECT_EQ(GetActiveWebContents()->GetURL(), payments_url);

  autofill::SaveCardBubbleControllerImpl::CreateForWebContents(
      GetActiveWebContents());
  autofill::SaveCardBubbleControllerImpl* bubble_controller =
      autofill::SaveCardBubbleControllerImpl::FromWebContents(
          GetActiveWebContents());
  CHECK(bubble_controller);

  ASSERT_EQ(bubble_controller->GetPaymentBubbleView(), nullptr);
  bubble_controller->OfferLocalSave(
      autofill::test::GetCreditCard(),
      autofill::payments::PaymentsAutofillClient::SaveCreditCardOptions()
          .with_show_prompt(true),
      base::DoNothing());
  ASSERT_NE(bubble_controller->GetPaymentBubbleView(), nullptr);
  action_manager.FindAction(kActionShowPaymentsBubbleOrPage)->InvokeAction();
  EXPECT_EQ(bubble_controller->GetPaymentBubbleView(), nullptr);
}

IN_PROC_BROWSER_TEST_F(BrowserActionsBrowserTest,
                       NewIncognitoWindowEnabledState) {
  auto& action_manager = actions::ActionManager::GetForTesting();
  EXPECT_TRUE(
      action_manager.FindAction(kActionNewIncognitoWindow)->GetEnabled());

  // Set Incognito to DISABLED and verify the action item is updated.
  IncognitoModePrefs::SetAvailability(
      browser()->profile()->GetPrefs(),
      policy::IncognitoModeAvailability::kDisabled);
  EXPECT_FALSE(
      action_manager.FindAction(kActionNewIncognitoWindow)->GetEnabled());
}

}  // namespace chrome