OLD | NEW |
(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(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 53 // On all platforms except Linux, there's an additional menu item to access |
| 54 // Cast device management. |
| 55 expected_number_items++; |
| 56 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 57 |
| 58 #if defined(GOOGLE_CHROME_BUILD) |
| 59 // In official Chrome builds, there's an additional menu item to toggle cloud |
| 60 // services settings. |
| 61 expected_number_items++; |
| 62 #endif // GOOGLE_CHROME_BUILD |
| 63 |
| 64 // Verify the number of menu items, including separators. |
| 65 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 66 |
| 67 for (int i = 0; i < expected_number_items; i++) { |
| 68 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 69 bool expected_visibility = true; |
| 70 |
| 71 #if defined(GOOGLE_CHROME_BUILD) |
| 72 // In official Chrome builds, the cloud services toggle exists and is |
| 73 // enabled, but not visible until the user has authenticated their account. |
| 74 expected_visibility = |
| 75 model()->GetCommandIdAt(i) != IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE; |
| 76 #endif // GOOGLE_CHROME_BUILD |
| 77 |
| 78 EXPECT_EQ(expected_visibility, model()->IsVisibleAt(i)); |
| 79 } |
| 80 |
| 81 // Set up an authenticated account. |
| 82 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); |
| 83 |
| 84 // Run the same checks as before. All existing menu items should be now |
| 85 // enabled and visible. |
| 86 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 87 for (int i = 0; i < expected_number_items; i++) { |
| 88 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 89 EXPECT_TRUE(model()->IsVisibleAt(i)); |
| 90 } |
| 91 } |
OLD | NEW |