File: side_panel_interactive_uitest.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 (497 lines) | stat: -rw-r--r-- 22,215 bytes parent folder | download | duplicates (4)
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
// Copyright 2022 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/bind.h"
#include "base/test/gtest_util.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/tabs/public/tab_features.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/ui/toolbar/bookmark_sub_menu_model.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar/pinned_toolbar_actions_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/side_panel/side_panel.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_id.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry_key.h"
#include "chrome/browser/ui/views/side_panel/side_panel_registry.h"
#include "chrome/browser/ui/views/toolbar/pinned_action_toolbar_button.h"
#include "chrome/browser/ui/views/toolbar/pinned_toolbar_actions_container.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/test/interaction/interaction_test_util_browser.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/interaction/tracked_element_webcontents.h"
#include "chrome/test/interaction/webcontents_interaction_test_util.h"
#include "components/reading_list/core/reading_list_entry.h"
#include "content/public/test/browser_test.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/interaction/expect_call_in_scope.h"
#include "ui/base/interaction/interaction_sequence.h"
#include "ui/base/interaction/polling_state_observer.h"
#include "ui/base/interaction/state_observer.h"
#include "ui/base/ui_base_features.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_state.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/interaction/interaction_test_util_views.h"
#include "ui/views/layout/animating_layout_manager_test_util.h"
#include "url/gurl.h"

class SidePanelInteractiveTest : public InteractiveBrowserTest {
 public:
  SidePanelInteractiveTest() = default;
  ~SidePanelInteractiveTest() override = default;

  void SetUp() override {
    set_open_about_blank_on_browser_launch(true);
    InteractiveBrowserTest::SetUp();
  }
};

// This test is specifically to guard against this regression
// (crbug.com/1428606).
IN_PROC_BROWSER_TEST_F(SidePanelInteractiveTest, SidePanelNotShownOnPwa) {
  DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kSecondTabElementId);
  GURL second_tab_url("https://test.com");
  auto* coordinator = browser()->GetFeatures().side_panel_coordinator();

  RunTestSequence(
      // Add a second tab to the tab strip
      AddInstrumentedTab(kSecondTabElementId, second_tab_url),
      CheckResult(base::BindLambdaForTesting([this]() {
                    return browser()->tab_strip_model()->active_index();
                  }),
                  testing::Eq(1)),
      // Ensure the side panel isn't open
      EnsureNotPresent(kSidePanelElementId),
      CheckResult(base::BindLambdaForTesting([this]() {
                    return browser()
                        ->tab_strip_model()
                        ->GetActiveWebContents()
                        ->GetLastCommittedURL();
                  }),
                  second_tab_url),
      Do(base::BindLambdaForTesting([=, this]() {
        auto* registry = browser()
                             ->GetActiveTabInterface()
                             ->GetTabFeatures()
                             ->side_panel_registry();
        registry->Register(std::make_unique<SidePanelEntry>(
            SidePanelEntry::Key(SidePanelEntry::Id::kCustomizeChrome),
            base::BindRepeating([](SidePanelEntryScope&) {
              return std::make_unique<views::View>();
            }),
            SidePanelEntry::kSidePanelDefaultContentWidth));
        coordinator->Show(SidePanelEntry::Id::kCustomizeChrome);
      })),
      WaitForShow(kSidePanelElementId),
      CheckResult(base::BindLambdaForTesting([coordinator]() {
                    return coordinator->IsSidePanelEntryShowing(
                        SidePanelEntryKey(SidePanelEntryId::kCustomizeChrome));
                  }),
                  true));

  // Install an app using second_tab_url.
  auto app_id = web_app::test::InstallDummyWebApp(browser()->profile(),
                                                  "App Name", second_tab_url);

  // Move second_tab contents to app, simulating open pwa from omnibox intent
  // picker.
  Browser* app_browser = web_app::ReparentWebContentsIntoAppBrowser(
      browser()->tab_strip_model()->GetActiveWebContents(), app_id);
  EXPECT_TRUE(app_browser->is_type_app());

  // App does not show side panel.
  EXPECT_FALSE(BrowserView::GetBrowserViewForBrowser(app_browser)
                   ->unified_side_panel()
                   ->GetVisible());
}

// Test case for menus that only appear with the kSidePanelPinning feature
// enabled.
class PinnedSidePanelInteractiveTest : public InteractiveBrowserTest {
 public:
  PinnedSidePanelInteractiveTest() = default;
  ~PinnedSidePanelInteractiveTest() override = default;

  void SetUp() override {
    set_open_about_blank_on_browser_launch(true);
    InteractiveBrowserTest::SetUp();
  }

  void SetUpOnMainThread() override {
    InteractiveBrowserTest::SetUpOnMainThread();
    PinnedToolbarActionsModel* const actions_model =
        PinnedToolbarActionsModel::Get(browser()->profile());
    actions_model->UpdatePinnedState(kActionShowChromeLabs, false);
    if (features::HasTabSearchToolbarButton()) {
      actions_model->UpdatePinnedState(kActionTabSearch, false);
    }
    views::test::WaitForAnimatingLayoutManager(
        BrowserView::GetBrowserViewForBrowser(browser())
            ->toolbar()
            ->pinned_toolbar_actions_container());
  }

  auto OpenBookmarksSidePanel() {
    // TODO(crbug.com/40286543): When initially writing this step, opening the
    // bookmarks submenu is flaky and sometimes causes a crash but the crash
    // doesn't seem reproducible anymore. Unsure if the crash was fixed so will
    // need to track down cause of crash if this step becomes flaky again.
    return Steps(
        PressButton(kToolbarAppMenuButtonElementId),
        SelectMenuItem(AppMenuModel::kBookmarksMenuItem),
        SelectMenuItem(BookmarkSubMenuModel::kShowBookmarkSidePanelItem),
        WaitForShow(kSidePanelElementId));
  }

  auto CheckActionPinnedToToolbar(const actions::ActionId& id,
                                  bool should_pin) {
    return CheckResult(
        [&]() {
          PinnedToolbarActionsContainer* const
              pinned_toolbar_actions_container =
                  BrowserView::GetBrowserViewForBrowser(browser())
                      ->toolbar()
                      ->pinned_toolbar_actions_container();
          return pinned_toolbar_actions_container->GetPinnedButtonFor(id) !=
                 nullptr;
        },
        should_pin);
  }

  auto CheckPinButtonToggleState(bool should_toggle) {
    return CheckViewProperty(kSidePanelPinButtonElementId,
                             &views::ToggleImageButton::GetToggled,
                             should_toggle);
  }

  PinnedToolbarActionsContainer* GetPinnedToolbarActionsContainer() {
    return BrowserView::GetBrowserViewForBrowser(browser())
        ->toolbar()
        ->pinned_toolbar_actions_container();
  }

  auto OpenReadingModeSidePanel() {
    return Steps(Do(base::BindLambdaForTesting([=, this]() {
                   chrome::ExecuteCommand(browser(),
                                          IDC_SHOW_READING_MODE_SIDE_PANEL);
                 })),
                 WaitForShow(kSidePanelElementId));
  }

  auto OpenCustomizeChromeSidePanel() {
    return Steps(Do(base::BindLambdaForTesting([=, this]() {
                   chrome::ExecuteCommand(browser(),
                                          IDC_SHOW_CUSTOMIZE_CHROME_SIDE_PANEL);
                 })),
                 WaitForShow(kSidePanelElementId));
  }

  auto CheckPinnedToolbarActionsContainerChildInkDropState(int child_index,
                                                           bool is_active) {
    return Steps(CheckResult(base::BindLambdaForTesting([this, child_index]() {
                               return views::InkDrop::Get(
                                          GetPinnedToolbarActionsContainer()
                                              ->children()[child_index])
                                          ->GetInkDrop()
                                          ->GetTargetInkDropState() ==
                                      views::InkDropState::ACTIVATED;
                             }),
                             is_active));
  }

  auto ShowSidePanelForKey(SidePanelEntryKey key) {
    return Do(base::BindLambdaForTesting([=, this]() {
      browser()->GetFeatures().side_panel_coordinator()->Show(key);
    }));
  }
};

// Verify that we can open the ReadingMode side panel from the 3dot -> More
// tools context menu.
IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       OpenReadingModeSidePanel) {
  // Replace the contents of the ReadingMode side panel with an empty view so it
  // loads faster.
  auto* registry =
      browser()->GetFeatures().side_panel_coordinator()->GetWindowRegistry();
  registry->Deregister(SidePanelEntry::Key(SidePanelEntry::Id::kReadAnything));
  registry->Register(std::make_unique<SidePanelEntry>(
      SidePanelEntry::Key(SidePanelEntry::Id::kReadAnything),
      base::BindRepeating(
          [](SidePanelEntryScope&) { return std::make_unique<views::View>(); }),
      SidePanelEntry::kSidePanelDefaultContentWidth));

  SidePanelCoordinator* const coordinator =
      browser()->GetFeatures().side_panel_coordinator();
  coordinator->SetNoDelaysForTesting(true);

  chrome::ExecuteCommand(browser(), IDC_SHOW_READING_MODE_SIDE_PANEL);

  EXPECT_EQ(SidePanelEntryKey(SidePanelEntryId::kReadAnything),
            coordinator->GetCurrentSidePanelEntryForTesting()->key());
}

// Verify that we can open the CustomizeChrome side panel from the 3dot -> More
// tools context menu.
IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       OpenCustomizeChromeSidePanel) {
  // Replace the contents of the CustomizeChrome side panel with an empty view
  // so it loads faster.
  auto* registry = browser()
                       ->GetActiveTabInterface()
                       ->GetTabFeatures()
                       ->side_panel_registry();
  registry->Deregister(
      SidePanelEntry::Key(SidePanelEntry::Id::kCustomizeChrome));
  registry->Register(std::make_unique<SidePanelEntry>(
      SidePanelEntry::Key(SidePanelEntry::Id::kCustomizeChrome),
      base::BindRepeating(
          [](SidePanelEntryScope&) { return std::make_unique<views::View>(); }),
      SidePanelEntry::kSidePanelDefaultContentWidth));

  SidePanelCoordinator* const coordinator =
      browser()->GetFeatures().side_panel_coordinator();
  coordinator->SetNoDelaysForTesting(true);

  RunTestSequence(
      EnsureNotPresent(kSidePanelElementId), OpenCustomizeChromeSidePanel(),
      CheckResult(base::BindLambdaForTesting([coordinator]() {
                    return coordinator->IsSidePanelEntryShowing(
                        SidePanelEntryKey(SidePanelEntryId::kCustomizeChrome));
                  }),
                  true));
}

// Verify that we can open the history cluster side panel from the app menu.
IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       OpenHistoryClusterSidePanel) {
  auto* registry =
      browser()->GetFeatures().side_panel_coordinator()->GetWindowRegistry();
  registry->Deregister(
      SidePanelEntry::Key(SidePanelEntry::Id::kHistoryClusters));
  registry->Register(std::make_unique<SidePanelEntry>(
      SidePanelEntry::Key(SidePanelEntry::Id::kHistoryClusters),
      base::BindRepeating(
          [](SidePanelEntryScope&) { return std::make_unique<views::View>(); }),
      SidePanelEntry::kSidePanelDefaultContentWidth));

  SidePanelCoordinator* const coordinator =
      browser()->GetFeatures().side_panel_coordinator();

  chrome::ExecuteCommand(browser(), IDC_SHOW_HISTORY_CLUSTERS_SIDE_PANEL);

  EXPECT_EQ(SidePanelEntryKey(SidePanelEntryId::kHistoryClusters),
            coordinator->GetCurrentSidePanelEntryForTesting()->key());
}

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       PanelPinnedStateUpdatesOnPinButtonPress) {
  RunTestSequence(
      EnsureNotPresent(kSidePanelElementId), OpenBookmarksSidePanel(),
      CheckPinButtonToggleState(false),
      // Pin the bookmarks side panel
      PressButton(kSidePanelPinButtonElementId),
      CheckActionPinnedToToolbar(kActionSidePanelShowBookmarks, true),
      WaitForShow(kPinnedToolbarActionsContainerDividerElementId),
      CheckPinButtonToggleState(true),
      PressButton(kSidePanelCloseButtonElementId),
      WaitForHide(kSidePanelElementId),
      CheckActionPinnedToToolbar(kActionSidePanelShowBookmarks, true),
      OpenBookmarksSidePanel(),
      CheckActionPinnedToToolbar(kActionSidePanelShowBookmarks, true),
      CheckPinButtonToggleState(true),
      // Unpin the bookmarks side panel
      PressButton(kSidePanelPinButtonElementId),
      CheckActionPinnedToToolbar(kActionSidePanelShowBookmarks, false),
      WaitForHide(kPinnedToolbarActionsContainerDividerElementId),
      CheckPinButtonToggleState(false));
}

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       SidePanelPinButtonsHideInIncognitoMode) {
  Browser* const incognito = CreateIncognitoBrowser();
  RunTestSequence(
      InContext(incognito->window()->GetElementContext(),
                WaitForShow(kBrowserViewElementId)),
      InSameContext(ActivateSurface(kBrowserViewElementId),
                    EnsureNotPresent(kSidePanelElementId),
                    OpenBookmarksSidePanel(),
                    EnsureNotPresent(kSidePanelPinButtonElementId)));
}

// TODO(crbug.com/417601707): Re-enable this test
#if BUILDFLAG(IS_MAC)
#define MAYBE_PinnedToolbarButtonsHighlightWhileSidePanelVisible \
  DISABLED_PinnedToolbarButtonsHighlightWhileSidePanelVisible
#else
#define MAYBE_PinnedToolbarButtonsHighlightWhileSidePanelVisible \
  PinnedToolbarButtonsHighlightWhileSidePanelVisible
#endif
IN_PROC_BROWSER_TEST_F(
    PinnedSidePanelInteractiveTest,
    MAYBE_PinnedToolbarButtonsHighlightWhileSidePanelVisible) {
  // Replace the contents of the ReadingMode side panel with an empty view so it
  // loads faster.
  auto* registry =
      browser()->GetFeatures().side_panel_coordinator()->GetWindowRegistry();
  registry->Deregister(SidePanelEntry::Key(SidePanelEntry::Id::kReadAnything));
  registry->Register(std::make_unique<SidePanelEntry>(
      SidePanelEntryKey(SidePanelEntry::Id::kReadAnything),
      base::BindRepeating(
          [](SidePanelEntryScope&) { return std::make_unique<views::View>(); }),
      SidePanelEntry::kSidePanelDefaultContentWidth));

  PinnedToolbarActionsModel* const actions_model =
      PinnedToolbarActionsModel::Get(browser()->profile());

  actions_model->UpdatePinnedState(kActionSidePanelShowBookmarks, true);

  RunTestSequence(
      // Verify side panel is closed.
      EnsureNotPresent(kSidePanelElementId),
      // Verify the bookmarks pinned toolbar button is not highlighted.
      CheckPinnedToolbarActionsContainerChildInkDropState(0, false),
      // Open the bookmarks side panel.
      OpenBookmarksSidePanel(),
      // Verify bookmarks is pinned to the toolbar.
      Check(base::BindLambdaForTesting([=]() {
        return actions_model->Contains(kActionSidePanelShowBookmarks);
      })),
      WaitForShow(kPinnedActionToolbarButtonElementId),
      CheckView(
          kPinnedToolbarActionsContainerElementId,
          [](views::View* view) { return view->children().size() == 2u; }),
      // Verify the bookmarks pinned toolbar button is highlighted.
      CheckPinnedToolbarActionsContainerChildInkDropState(0, true),
      CheckViewProperty(kPinnedToolbarActionsContainerDividerElementId,
                        &views::View::GetVisible, true),
      // Close the side panel.
      PressButton(kSidePanelCloseButtonElementId),
      WaitForHide(kSidePanelElementId),
      // Verify the bookmarks pinned toolbar button is not highlighted.
      CheckPinnedToolbarActionsContainerChildInkDropState(0, false),
      // Open non-bookmarks side panel.
      OpenReadingModeSidePanel(),
      // Verify the bookmarks pinned toolbar button is not highlighted.
      CheckPinnedToolbarActionsContainerChildInkDropState(0, false));
}

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       ToggleSidePanelVisibility) {
  RunTestSequence(
      // Ensure the side panel isn't open
      EnsureNotPresent(kSidePanelElementId),
      EnsureNotPresent(kPinnedActionToolbarButtonElementId),
      // Open bookmarks sidepanel
      OpenBookmarksSidePanel(), WaitForShow(kSidePanelElementId),
      WaitForShow(kPinnedToolbarActionsContainerElementId),
      // Pin the button
      CheckPinButtonToggleState(false),
      PressButton(kSidePanelPinButtonElementId),
      CheckActionPinnedToToolbar(kActionSidePanelShowBookmarks, true),
      EnsurePresent(kPinnedToolbarActionsContainerElementId),
      WaitForShow(kPinnedActionToolbarButtonElementId),
      // Toggle side panel
      PressButton(kPinnedActionToolbarButtonElementId),
      WaitForHide(kSidePanelElementId));
}

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       SwitchBetweenDifferentEntries) {
  DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kBookmarksWebContentsId);
  DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kReadLaterWebContentsId);
  auto* coordinator = browser()->GetFeatures().side_panel_coordinator();

  RunTestSequence(
      // Ensure the side panel isn't open
      EnsureNotPresent(kSidePanelElementId),
      // Click the toolbar button to open the side panel
      OpenBookmarksSidePanel(), WaitForShow(kSidePanelElementId),
      InstrumentNonTabWebView(kBookmarksWebContentsId,
                              kBookmarkSidePanelWebViewElementId),

      CheckResult(base::BindLambdaForTesting([coordinator]() {
                    return coordinator->IsSidePanelEntryShowing(
                        SidePanelEntryKey(SidePanelEntryId::kBookmarks));
                  }),
                  true),
      // Switch to the reading list entry.
      ShowSidePanelForKey(SidePanelEntryKey(SidePanelEntry::Id::kReadingList)),
      InstrumentNonTabWebView(kReadLaterWebContentsId,
                              kReadLaterSidePanelWebViewElementId),

      CheckResult(base::BindLambdaForTesting([coordinator]() {
                    return coordinator->IsSidePanelEntryShowing(
                        SidePanelEntryKey(SidePanelEntryId::kReadingList));
                  }),
                  true),
      // Click on the close button to dismiss the side panel
      PressButton(kSidePanelCloseButtonElementId),
      WaitForHide(kSidePanelElementId));
}

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       StaysOpenOnTabSwitchWithActiveGlobalEntry) {
  DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE(kSecondTabElementId);

  RunTestSequence(
      // Add a second tab to the tab strip
      AddInstrumentedTab(kSecondTabElementId, GURL(url::kAboutBlankURL)),
      CheckResult(base::BindLambdaForTesting([this]() {
                    return browser()->tab_strip_model()->active_index();
                  }),
                  testing::Eq(1)),
      // Ensure the side panel isn't open
      EnsureNotPresent(kSidePanelElementId),
      // Click the toolbar button to open the side panel
      OpenBookmarksSidePanel(), WaitForShow(kSidePanelElementId),
      // Switch to the first tab again with the side panel open
      SelectTab(kTabStripElementId, 0),
      // Ensure the side panel is still visible
      CheckViewProperty(kSidePanelElementId, &views::View::GetVisible, true),
      // Click on the close button to dismiss the side panel
      PressButton(kSidePanelCloseButtonElementId),
      WaitForHide(kSidePanelElementId));
}

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
                       ToolbarButtonDisappearsOnEntryDeregister) {
  constexpr char kBookmarksButton[] = "bookmarks_button";
  RunTestSequence(
      // Ensure the side panel isn't open
      EnsureNotPresent(kSidePanelElementId),
      EnsureNotPresent(kPinnedActionToolbarButtonElementId),
      // Open bookmarks sidepanel
      OpenBookmarksSidePanel(), WaitForShow(kSidePanelElementId),
      WaitForShow(kPinnedToolbarActionsContainerElementId),
      WaitForShow(kPinnedActionToolbarButtonElementId),
      NameChildViewByType<PinnedActionToolbarButton>(
          kPinnedToolbarActionsContainerElementId, kBookmarksButton),
      WaitForShow(kBookmarksButton),
      // Deregister the entry and verify the side panel and ephemeral toolbar
      // button are hidden.
      Do([this]() {
        browser()
            ->GetFeatures()
            .side_panel_coordinator()
            ->GetWindowRegistry()
            ->Deregister(SidePanelEntry::Key(SidePanelEntry::Id::kBookmarks));
      }),
      WaitForHide(kSidePanelElementId), WaitForHide(kBookmarksButton));
}