Skip to content

Commit

Permalink
Hide sync menu from app menu if it's disabled
Browse files Browse the repository at this point in the history
and fix failed app menu test.

fix brave/brave-browser#8160
fix brave/brave-browser#8158 (only for 1.3)
  • Loading branch information
simonhong committed Feb 10, 2020
1 parent 2972cb3 commit 6c6c279
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
19 changes: 14 additions & 5 deletions browser/ui/toolbar/brave_app_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
#include "brave/app/brave_command_ids.h"
#include "brave/browser/profiles/profile_util.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_sync/buildflags/buildflags.h"
#include "brave/components/brave_wallet/browser/buildflags/buildflags.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "components/prefs/pref_service.h"

#if BUILDFLAG(ENABLE_BRAVE_SYNC)
#include "components/sync/driver/sync_driver_switches.h"
#endif

BraveAppMenuModel::BraveAppMenuModel(
ui::AcceleratorProvider* provider,
Browser* browser,
Expand Down Expand Up @@ -46,14 +51,18 @@ void BraveAppMenuModel::InsertBraveMenuItems() {
IDC_SHOW_BRAVE_WALLET, IDS_SHOW_BRAVE_WALLET);
#endif
}
InsertItemWithStringIdAt(
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
if (switches::IsSyncAllowedByFlag()) {
InsertItemWithStringIdAt(
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
GetIndexOfCommandId(walletEnabled ? IDC_SHOW_BRAVE_WALLET :
IDC_SHOW_BRAVE_REWARDS),
GetIndexOfCommandId(walletEnabled ? IDC_SHOW_BRAVE_WALLET :
IDC_SHOW_BRAVE_REWARDS),
#else
GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS),
GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS),
#endif
IDC_SHOW_BRAVE_SYNC, IDS_SHOW_BRAVE_SYNC);
}
#endif
IDC_SHOW_BRAVE_SYNC, IDS_SHOW_BRAVE_SYNC);
}

// Insert Create New Profile item
Expand Down
32 changes: 28 additions & 4 deletions browser/ui/toolbar/brave_app_menu_model_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "content/public/browser/notification_service.h"
#include "content/public/test/test_utils.h"

#if BUILDFLAG(ENABLE_BRAVE_SYNC)
#include "components/sync/driver/sync_driver_switches.h"
#endif

using BraveAppMenuBrowserTest = InProcessBrowserTest;

IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) {
Expand All @@ -39,7 +43,14 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) {
// Check normal window has both menu items.
// -1 means |model| doesn't have passed command id.
EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS));
EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
if (switches::IsSyncAllowedByFlag())
EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
else
EXPECT_EQ(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
#else
EXPECT_EQ(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
#endif
#if BUILDFLAG(BRAVE_WALLET_ENABLED)
EXPECT_NE(-1, normal_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_WALLET));
#else
Expand All @@ -64,7 +75,10 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) {
#endif

#if BUILDFLAG(ENABLE_BRAVE_SYNC)
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
if (switches::IsSyncAllowedByFlag())
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
else
EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
#else
EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
#endif
Expand All @@ -86,7 +100,14 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) {
// Check private window has both menu items.
// -1 means |model| doesn't have passed command id.
EXPECT_NE(-1, private_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_REWARDS));
EXPECT_NE(-1, private_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
if (switches::IsSyncAllowedByFlag())
EXPECT_NE(-1, private_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
else
EXPECT_EQ(-1, private_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
#else
EXPECT_EQ(-1, private_model.GetIndexOfCommandId(IDC_SHOW_BRAVE_SYNC));
#endif

command_controller = private_browser->command_controller();
#if BUILDFLAG(BRAVE_REWARDS_ENABLED)
Expand All @@ -95,7 +116,10 @@ IN_PROC_BROWSER_TEST_F(BraveAppMenuBrowserTest, BasicTest) {
EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_REWARDS));
#endif
#if BUILDFLAG(ENABLE_BRAVE_SYNC)
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
if (switches::IsSyncAllowedByFlag())
EXPECT_TRUE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
else
EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
#else
EXPECT_FALSE(command_controller->IsCommandEnabled(IDC_SHOW_BRAVE_SYNC));
#endif
Expand Down

0 comments on commit 6c6c279

Please sign in to comment.