Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/extensions/browser_action_test_util.h" | 9 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 10 #include "chrome/browser/extensions/extension_action_test_util.h" | 10 #include "chrome/browser/extensions/extension_action_test_util.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 std::unique_ptr<MediaRouterAction> action_; | 53 std::unique_ptr<MediaRouterAction> action_; |
| 54 SigninManagerBase* signin_manager_; | 54 SigninManagerBase* signin_manager_; |
| 55 ui::SimpleMenuModel* model_; | 55 ui::SimpleMenuModel* model_; |
| 56 ToolbarActionsModel* toolbar_actions_model_; | 56 ToolbarActionsModel* toolbar_actions_model_; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(MediaRouterContextualMenuUnitTest); | 58 DISALLOW_COPY_AND_ASSIGN(MediaRouterContextualMenuUnitTest); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Tests the basic state of the contextual menu. | 61 // Tests the basic state of the contextual menu. |
| 62 TEST_F(MediaRouterContextualMenuUnitTest, Basic) { | 62 TEST_F(MediaRouterContextualMenuUnitTest, Basic) { |
| 63 int expected_number_items = 7; | 63 // About |
| 64 // ----- | |
| 65 // Learn more | |
| 66 // Help | |
| 67 // Always show icon (checkbox) | |
| 68 // ----- | |
| 69 // Enable cloud services | |
|
apacible
2016/10/28 02:42:37
nit: also specify this is a check item.
mark a. foltz
2016/10/28 19:54:44
Done.
| |
| 70 // Report an issue | |
| 71 int expected_number_items = 8; | |
| 64 | 72 |
| 65 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 73 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 66 // On all platforms except Linux, there's an additional menu item to access | 74 // On all platforms except Linux, there's an additional menu item to access |
| 67 // Cast device management. | 75 // Cast device management. |
| 68 expected_number_items++; | 76 expected_number_items++; |
| 69 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 77 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
| 70 | 78 |
| 71 #if defined(GOOGLE_CHROME_BUILD) | |
| 72 // In official Chrome builds, there's an additional menu item to toggle cloud | |
| 73 // services settings. | |
| 74 expected_number_items++; | |
| 75 #endif // GOOGLE_CHROME_BUILD | |
| 76 | |
| 77 // Verify the number of menu items, including separators. | 79 // Verify the number of menu items, including separators. |
| 78 EXPECT_EQ(model()->GetItemCount(), expected_number_items); | 80 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 79 | 81 |
| 80 for (int i = 0; i < expected_number_items; i++) { | 82 for (int i = 0; i < expected_number_items; i++) { |
| 81 EXPECT_TRUE(model()->IsEnabledAt(i)); | 83 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 82 bool expected_visibility = true; | |
| 83 | 84 |
| 84 #if defined(GOOGLE_CHROME_BUILD) | 85 // The cloud services toggle exists and is enabled, but not visible until |
| 85 // In official Chrome builds, the cloud services toggle exists and is | 86 // the user has authenticated their account. |
| 86 // enabled, but not visible until the user has authenticated their account. | 87 const bool expected_visibility = |
| 87 expected_visibility = | |
| 88 model()->GetCommandIdAt(i) != IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE; | 88 model()->GetCommandIdAt(i) != IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE; |
| 89 #endif // GOOGLE_CHROME_BUILD | |
| 90 | |
| 91 EXPECT_EQ(expected_visibility, model()->IsVisibleAt(i)); | 89 EXPECT_EQ(expected_visibility, model()->IsVisibleAt(i)); |
| 92 } | 90 } |
| 93 | 91 |
| 94 // Set up an authenticated account. | 92 // Set up an authenticated account. |
| 95 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); | 93 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); |
| 96 | 94 |
| 97 // Run the same checks as before. All existing menu items should be now | 95 // Run the same checks as before. All existing menu items should be now |
| 98 // enabled and visible. | 96 // enabled and visible. |
| 99 EXPECT_EQ(model()->GetItemCount(), expected_number_items); | 97 EXPECT_EQ(model()->GetItemCount(), expected_number_items); |
| 100 for (int i = 0; i < expected_number_items; i++) { | 98 for (int i = 0; i < expected_number_items; i++) { |
| 101 EXPECT_TRUE(model()->IsEnabledAt(i)); | 99 EXPECT_TRUE(model()->IsEnabledAt(i)); |
| 102 EXPECT_TRUE(model()->IsVisibleAt(i)); | 100 EXPECT_TRUE(model()->IsVisibleAt(i)); |
| 103 } | 101 } |
| 104 } | 102 } |
| 105 | 103 |
| 106 #if defined(GOOGLE_CHROME_BUILD) | |
| 107 // Tests whether the cloud services item is correctly toggled. This menu item | 104 // Tests whether the cloud services item is correctly toggled. This menu item |
| 108 // is only availble on official Chrome builds. | 105 // is only availble on official Chrome builds. |
| 109 TEST_F(MediaRouterContextualMenuUnitTest, ToggleCloudServicesItem) { | 106 TEST_F(MediaRouterContextualMenuUnitTest, ToggleCloudServicesItem) { |
| 110 // The Media Router Action has a getter for the model, but not the delegate. | 107 // The Media Router Action has a getter for the model, but not the delegate. |
| 111 // Create the MediaRouterContextualMenu ui::SimpleMenuModel::Delegate here. | 108 // Create the MediaRouterContextualMenu ui::SimpleMenuModel::Delegate here. |
| 112 MediaRouterContextualMenu menu(browser()); | 109 MediaRouterContextualMenu menu(browser()); |
| 113 | 110 |
| 114 // Set up an authenticated account such that the cloud services menu item is | 111 // Set up an authenticated account such that the cloud services menu item is |
| 115 // surfaced. Whether or not it is surfaced is tested in the "Basic" test. | 112 // surfaced. Whether or not it is surfaced is tested in the "Basic" test. |
| 116 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); | 113 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); |
| 117 | 114 |
| 118 // By default, the command is not checked. | 115 // By default, the command is not checked. |
| 119 EXPECT_FALSE(menu.IsCommandIdChecked( | 116 EXPECT_FALSE(menu.IsCommandIdChecked( |
| 120 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); | 117 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); |
| 121 | 118 |
| 122 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); | 119 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); |
| 123 EXPECT_TRUE(menu.IsCommandIdChecked( | 120 EXPECT_TRUE(menu.IsCommandIdChecked( |
| 124 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); | 121 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); |
| 125 | 122 |
| 126 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); | 123 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); |
| 127 EXPECT_FALSE(menu.IsCommandIdChecked( | 124 EXPECT_FALSE(menu.IsCommandIdChecked( |
| 128 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); | 125 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); |
| 129 } | 126 } |
| 130 #endif // GOOGLE_CHROME_BUILD | |
| 131 | 127 |
| 132 TEST_F(MediaRouterContextualMenuUnitTest, ToggleAlwaysShowIconItem) { | 128 TEST_F(MediaRouterContextualMenuUnitTest, ToggleAlwaysShowIconItem) { |
| 133 MediaRouterContextualMenu menu(browser()); | 129 MediaRouterContextualMenu menu(browser()); |
| 134 extensions::ComponentMigrationHelper* const component_migration_helper = | 130 extensions::ComponentMigrationHelper* const component_migration_helper = |
| 135 toolbar_actions_model()->component_migration_helper(); | 131 toolbar_actions_model()->component_migration_helper(); |
| 136 | 132 |
| 137 // Whether the option is checked should reflect the pref. | 133 // Whether the option is checked should reflect the pref. |
| 138 component_migration_helper->SetComponentActionPref( | 134 component_migration_helper->SetComponentActionPref( |
| 139 ComponentToolbarActionsFactory::kMediaRouterActionId, true); | 135 ComponentToolbarActionsFactory::kMediaRouterActionId, true); |
| 140 EXPECT_TRUE( | 136 EXPECT_TRUE( |
| 141 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); | 137 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); |
| 142 | 138 |
| 143 component_migration_helper->SetComponentActionPref( | 139 component_migration_helper->SetComponentActionPref( |
| 144 ComponentToolbarActionsFactory::kMediaRouterActionId, false); | 140 ComponentToolbarActionsFactory::kMediaRouterActionId, false); |
| 145 EXPECT_FALSE( | 141 EXPECT_FALSE( |
| 146 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); | 142 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); |
| 147 | 143 |
| 148 // Executing the option should toggle the pref. | 144 // Executing the option should toggle the pref. |
| 149 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); | 145 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); |
| 150 EXPECT_TRUE(component_migration_helper->GetComponentActionPref( | 146 EXPECT_TRUE(component_migration_helper->GetComponentActionPref( |
| 151 ComponentToolbarActionsFactory::kMediaRouterActionId)); | 147 ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| 152 | 148 |
| 153 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); | 149 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); |
| 154 EXPECT_FALSE(component_migration_helper->GetComponentActionPref( | 150 EXPECT_FALSE(component_migration_helper->GetComponentActionPref( |
| 155 ComponentToolbarActionsFactory::kMediaRouterActionId)); | 151 ComponentToolbarActionsFactory::kMediaRouterActionId)); |
| 156 } | 152 } |
| OLD | NEW |