Skip to content

Commit

Permalink
[SidePanel] Hide pin button for incognito and guest mode
Browse files Browse the repository at this point in the history
Users in guest and incognito mode should not be able to modify which
side panels are pinned and unpinned. As such, the pin button should
be hidden in these cases.

Fixed: b:299463614
Change-Id: I0da52df0a8a528494a642644ecdedf98a14a78ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4979955
Reviewed-by: Caroline Rising <corising@chromium.org>
Reviewed-by: Ryan Sultanem <rsult@google.com>
Commit-Queue: Steven Luong <stluong@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1216394}
  • Loading branch information
stluong authored and Chromium LUCI CQ committed Oct 27, 2023
1 parent bc96b7d commit bc8ab4c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/profiles/profile_keyed_service_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ IN_PROC_BROWSER_TEST_F(ProfileKeyedServiceBrowserTest,
#if BUILDFLAG(ENABLE_PDF)
"PdfViewerPrivateEventRouter",
#endif // BUILDFLAG(ENABLE_PDF)
"PinnedToolbarActionsModel",
"PlatformNotificationService",
"PredictionModelHandlerProvider",
"PrefWatcher",
Expand Down Expand Up @@ -449,6 +450,7 @@ IN_PROC_BROWSER_TEST_F(ProfileKeyedServiceBrowserTest,
"PermissionsUpdaterShutdownFactory",
"PersonalDataManager",
"PinnedTabService",
"PinnedToolbarActionsModel",
"PlatformNotificationService",
"PluginManager",
"PluginPrefs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ PinnedToolbarActionsModelFactory::PinnedToolbarActionsModelFactory()
"PinnedToolbarActionsModel",
ProfileSelections::Builder()
.WithRegular(ProfileSelection::kOwnInstance)
.WithGuest(ProfileSelection::kOwnInstance)
.Build()) {}

PinnedToolbarActionsModelFactory::~PinnedToolbarActionsModelFactory() = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ void SidePanelCoordinator::UpdateHeaderPinButtonState() {
CHECK(action_id.has_value());
header_pin_button_->SetToggled(actions_model->Contains(action_id.value()));
header_pin_button_->SetVisible(
!profile->IsIncognitoProfile() && !profile->IsGuestSession() &&
action_item->GetProperty(actions::kActionItemPinnableKey));
} else {
PrefService* pref_service = profile->GetPrefs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/test/icu_test_util.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar_actions_model.h"
#include "chrome/browser/ui/toolbar/pinned_toolbar_actions_model_factory.h"
#include "chrome/browser/ui/ui_features.h"
Expand All @@ -28,6 +29,7 @@
#include "chrome/browser/ui/views/side_panel/side_panel_view_state_observer.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "components/strings/grit/components_strings.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -1743,6 +1745,16 @@ TEST_F(SidePanelPinningCoordinatorTest, SidePanelTitleUpdates) {
l10n_util::GetStringUTF16(IDS_PAGE_INFO_ABOUT_THIS_PAGE_TITLE));
}

TEST_F(SidePanelPinningCoordinatorTest, SidePanelPinButtonsHideInGuestMode) {
coordinator_->Show(SidePanelEntry::Id::kBookmarks);
EXPECT_TRUE(coordinator_->GetHeaderPinButtonForTesting()->GetVisible());
coordinator_->Close();
TestingProfile* const testprofile = browser()->profile()->AsTestingProfile();
testprofile->SetGuestSession(true);
coordinator_->Show(SidePanelEntry::Id::kBookmarks);
EXPECT_FALSE(coordinator_->GetHeaderPinButtonForTesting()->GetVisible());
}

// Test that the SidePanelCoordinator behaves and updates corrected when dealing
// with entries that load/display asynchronously.
class SidePanelCoordinatorLoadingContentTest : public SidePanelCoordinatorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
CheckPinButtonToggleState(false));
}

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

IN_PROC_BROWSER_TEST_F(PinnedSidePanelInteractiveTest,
PinnedToolbarButtonsHighlightWhileSidePanelVisible) {
// Replace the contents of the ReadingMode side panel with an empty view so it
Expand Down

0 comments on commit bc8ab4c

Please sign in to comment.