Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: chrome/browser/ui/toolbar/media_router_contextual_menu_unittest.cc

Issue 2115203002: [Reland] [Media Router] Allow users to update cloud services pref when sync is not active. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2743
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/extensions/browser_action_test_util.h"
8 #include "chrome/browser/signin/fake_signin_manager_builder.h"
9 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "chrome/browser/ui/toolbar/media_router_action.h"
11 #include "chrome/browser/ui/toolbar/media_router_contextual_menu.h"
12 #include "chrome/test/base/browser_with_test_window_test.h"
13
14 class MediaRouterContextualMenuUnitTest : public BrowserWithTestWindowTest {
15 public:
16 MediaRouterContextualMenuUnitTest() {}
17 ~MediaRouterContextualMenuUnitTest() override {}
18
19 void SetUp() override {
20 BrowserWithTestWindowTest::SetUp();
21 signin_manager_ = static_cast<FakeSigninManagerForTesting*>(
22 SigninManagerFactory::GetInstance()->GetForProfile(profile()));
23 browser_action_test_util_.reset(
24 new BrowserActionTestUtil(browser(), false));
25 action_.reset(new MediaRouterAction(browser(),
26 browser_action_test_util_->GetToolbarActionsBar()));
27 model_ = static_cast<ui::SimpleMenuModel*>(action_->GetContextMenu());
28 }
29
30 void TearDown() override {
31 action_.reset();
32 browser_action_test_util_.reset();
33 BrowserWithTestWindowTest::TearDown();
34 }
35
36 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
37 ui::SimpleMenuModel* model() { return model_; }
38
39 private:
40 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_;
41 std::unique_ptr<MediaRouterAction> action_;
42 FakeSigninManagerForTesting* signin_manager_;
43 ui::SimpleMenuModel* model_;
44
45 DISALLOW_COPY_AND_ASSIGN(MediaRouterContextualMenuUnitTest);
46 };
47
48 // Tests the basic state of the contextual menu.
49 TEST_F(MediaRouterContextualMenuUnitTest, Basic) {
50 int expected_number_items = 7;
51
52 #if defined(GOOGLE_CHROME_BUILD)
53 // In official Chrome builds, there's an additional menu item to toggle cloud
54 // services settings.
55 expected_number_items++;
56 #endif // GOOGLE_CHROME_BUILD
57
58 // Verify the number of menu items, including separators.
59 EXPECT_EQ(model()->GetItemCount(), expected_number_items);
60
61 for (int i = 0; i < expected_number_items; i++) {
62 EXPECT_TRUE(model()->IsEnabledAt(i));
63 bool expected_visibility = true;
64
65 #if defined(GOOGLE_CHROME_BUILD)
66 // In official Chrome builds, the cloud services toggle exists and is
67 // enabled, but not visible until the user has authenticated their account.
68 expected_visibility =
69 model()->GetCommandIdAt(i) != IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE;
70 #endif // GOOGLE_CHROME_BUILD
71
72 EXPECT_EQ(expected_visibility, model()->IsVisibleAt(i));
73 }
74
75 // Set up an authenticated account.
76 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password");
77
78 // Run the same checks as before. All existing menu items should be now
79 // enabled and visible.
80 EXPECT_EQ(model()->GetItemCount(), expected_number_items);
81 for (int i = 0; i < expected_number_items; i++) {
82 EXPECT_TRUE(model()->IsEnabledAt(i));
83 EXPECT_TRUE(model()->IsVisibleAt(i));
84 }
85 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698