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 TestSimpleMenuModel : public ui::SimpleMenuModel { |
| 15 |
| 16 }; |
| 17 |
| 18 class MediaRouterContextualMenuUnitTest : public BrowserWithTestWindowTest { |
| 19 public: |
| 20 MediaRouterContextualMenuUnitTest() {} |
| 21 ~MediaRouterContextualMenuUnitTest() override {} |
| 22 |
| 23 void SetUp() override { |
| 24 BrowserWithTestWindowTest::SetUp(); |
| 25 signin_manager_ = static_cast<FakeSigninManagerForTesting*>( |
| 26 SigninManagerFactory::GetInstance()->GetForProfile(profile())); |
| 27 browser_action_test_util_.reset( |
| 28 new BrowserActionTestUtil(browser(), false)); |
| 29 action_.reset(new MediaRouterAction(browser(), |
| 30 browser_action_test_util_->GetToolbarActionsBar())); |
| 31 model_ = static_cast<ui::SimpleMenuModel*>(action_->GetContextMenu()); |
| 32 } |
| 33 |
| 34 void TearDown() override { |
| 35 action_.reset(); |
| 36 browser_action_test_util_.reset(); |
| 37 BrowserWithTestWindowTest::TearDown(); |
| 38 } |
| 39 |
| 40 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } |
| 41 ui::SimpleMenuModel* model() { return model_; } |
| 42 |
| 43 private: |
| 44 std::unique_ptr<BrowserActionTestUtil> browser_action_test_util_; |
| 45 std::unique_ptr<MediaRouterAction> action_; |
| 46 FakeSigninManagerForTesting* signin_manager_; |
| 47 ui::SimpleMenuModel* model_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(MediaRouterContextualMenuUnitTest); |
| 50 }; |
| 51 |
| 52 #if !defined(GOOGLE_CHROME_BUILD) |
| 53 // Tests the basic state of the contextual menu when not using an official |
| 54 // Chrome build. |
| 55 TEST_F(MediaRouterContextualMenuUnitTest, BasicNotOfficialChromeBuild) { |
| 56 // Verify the number of menu items, including separators. |
| 57 int expected_number_items = 7; |
| 58 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 59 |
| 60 // For non-official Chrome builds, all menu items are enabled and visible. |
| 61 for (int i = 0; i < expected_number_items; i++) { |
| 62 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 63 EXPECT_TRUE(model()->IsVisibleAt(i)); |
| 64 } |
| 65 |
| 66 // Set up an authenticated account. There should be no difference in the |
| 67 // menu since this is not an official Chrome build. |
| 68 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); |
| 69 |
| 70 // Run the same checks as before. |
| 71 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 72 for (int i = 0; i < expected_number_items; i++) { |
| 73 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 74 EXPECT_TRUE(model()->IsVisibleAt(i)); |
| 75 } |
| 76 } |
| 77 #else |
| 78 // Tests the basic state of the contextual menu when using an official |
| 79 // Chrome build. |
| 80 TEST_F(MediaRouterContextualMenuUnitTest, BasicOfficialChromeBuild) { |
| 81 // Verify the number of menu items, including separators. In official Chrome |
| 82 // builds, there's an additional menu item for cloud services. |
| 83 int expected_number_items = 8; |
| 84 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 85 |
| 86 for (int i = 0; i < expected_number_items; i++) { |
| 87 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 88 |
| 89 // The cloud services toggle exists an is enabled, but not visible until |
| 90 // the user has authenticated their account. |
| 91 if (model()->GetCommandIdAt(i) == IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE) |
| 92 EXPECT_FALSE(model()->IsVisibleAt(i)); |
| 93 else |
| 94 EXPECT_TRUE(model()->IsVisibleAt(i)); |
| 95 } |
| 96 |
| 97 // Set up an authenticated account. The cloud services menu item should now |
| 98 // be visible. |
| 99 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); |
| 100 |
| 101 // Verify the number of menu items is the same. |
| 102 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 103 |
| 104 // Verify all of the menu items are enabled and visible. |
| 105 for (int i = 0; i < expected_number_items; i++) { |
| 106 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 107 EXPECT_TRUE(model()->IsVisibleAt(i)); |
| 108 } |
| 109 } |
| 110 #endif // defined(GOOGLE_CHROME_BUILD) |
OLD | NEW |