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

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

Issue 2451573003: [Media Router] Update Media Router flags post-launch. (Closed)
Patch Set: Remove Cast-extension-specific browser test Created 4 years, 1 month 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
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 int expected_number_items = 7;
64 64
65 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 65 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
66 // On all platforms except Linux, there's an additional menu item to access 66 // On all platforms except Linux, there's an additional menu item to access
67 // Cast device management. 67 // Cast device management.
68 expected_number_items++; 68 expected_number_items++;
69 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) 69 #endif // defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS)
70 70
71 #if defined(GOOGLE_CHROME_BUILD) 71 // An additional menu item to toggle cloud services settings.
msw 2016/10/27 18:14:31 nit: just init |expected_number_items| to 8 instea
mark a. foltz 2016/10/27 20:16:49 Done.
72 // In official Chrome builds, there's an additional menu item to toggle cloud
73 // services settings.
74 expected_number_items++; 72 expected_number_items++;
75 #endif // GOOGLE_CHROME_BUILD
76 73
77 // Verify the number of menu items, including separators. 74 // Verify the number of menu items, including separators.
78 EXPECT_EQ(model()->GetItemCount(), expected_number_items); 75 EXPECT_EQ(model()->GetItemCount(), expected_number_items);
79 76
80 for (int i = 0; i < expected_number_items; i++) { 77 for (int i = 0; i < expected_number_items; i++) {
81 EXPECT_TRUE(model()->IsEnabledAt(i)); 78 EXPECT_TRUE(model()->IsEnabledAt(i));
82 bool expected_visibility = true; 79 bool expected_visibility = true;
msw 2016/10/27 18:14:31 nit: combine |expected_visibility| decl and init.
mark a. foltz 2016/10/27 20:16:49 Done.
83 80
84 #if defined(GOOGLE_CHROME_BUILD) 81 // The cloud services toggle exists and is enabled, but not visible until
85 // In official Chrome builds, the cloud services toggle exists and is 82 // the user has authenticated their account.
86 // enabled, but not visible until the user has authenticated their account.
87 expected_visibility = 83 expected_visibility =
88 model()->GetCommandIdAt(i) != IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE; 84 model()->GetCommandIdAt(i) != IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE;
89 #endif // GOOGLE_CHROME_BUILD
90 85
91 EXPECT_EQ(expected_visibility, model()->IsVisibleAt(i)); 86 EXPECT_EQ(expected_visibility, model()->IsVisibleAt(i));
92 } 87 }
93 88
94 // Set up an authenticated account. 89 // Set up an authenticated account.
95 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); 90 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password");
96 91
97 // Run the same checks as before. All existing menu items should be now 92 // Run the same checks as before. All existing menu items should be now
98 // enabled and visible. 93 // enabled and visible.
99 EXPECT_EQ(model()->GetItemCount(), expected_number_items); 94 EXPECT_EQ(model()->GetItemCount(), expected_number_items);
100 for (int i = 0; i < expected_number_items; i++) { 95 for (int i = 0; i < expected_number_items; i++) {
101 EXPECT_TRUE(model()->IsEnabledAt(i)); 96 EXPECT_TRUE(model()->IsEnabledAt(i));
102 EXPECT_TRUE(model()->IsVisibleAt(i)); 97 EXPECT_TRUE(model()->IsVisibleAt(i));
103 } 98 }
104 } 99 }
105 100
106 #if defined(GOOGLE_CHROME_BUILD)
107 // Tests whether the cloud services item is correctly toggled. This menu item 101 // Tests whether the cloud services item is correctly toggled. This menu item
108 // is only availble on official Chrome builds. 102 // is only availble on official Chrome builds.
109 TEST_F(MediaRouterContextualMenuUnitTest, ToggleCloudServicesItem) { 103 TEST_F(MediaRouterContextualMenuUnitTest, ToggleCloudServicesItem) {
110 // The Media Router Action has a getter for the model, but not the delegate. 104 // The Media Router Action has a getter for the model, but not the delegate.
111 // Create the MediaRouterContextualMenu ui::SimpleMenuModel::Delegate here. 105 // Create the MediaRouterContextualMenu ui::SimpleMenuModel::Delegate here.
112 MediaRouterContextualMenu menu(browser()); 106 MediaRouterContextualMenu menu(browser());
113 107
114 // Set up an authenticated account such that the cloud services menu item is 108 // 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. 109 // surfaced. Whether or not it is surfaced is tested in the "Basic" test.
116 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password"); 110 signin_manager()->SetAuthenticatedAccountInfo("foo@bar.com", "password");
117 111
118 // By default, the command is not checked. 112 // By default, the command is not checked.
119 EXPECT_FALSE(menu.IsCommandIdChecked( 113 EXPECT_FALSE(menu.IsCommandIdChecked(
120 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); 114 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE));
121 115
122 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); 116 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0);
123 EXPECT_TRUE(menu.IsCommandIdChecked( 117 EXPECT_TRUE(menu.IsCommandIdChecked(
124 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); 118 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE));
125 119
126 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0); 120 menu.ExecuteCommand(IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE, 0);
127 EXPECT_FALSE(menu.IsCommandIdChecked( 121 EXPECT_FALSE(menu.IsCommandIdChecked(
128 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE)); 122 IDC_MEDIA_ROUTER_CLOUD_SERVICES_TOGGLE));
129 } 123 }
130 #endif // GOOGLE_CHROME_BUILD
131 124
132 TEST_F(MediaRouterContextualMenuUnitTest, ToggleAlwaysShowIconItem) { 125 TEST_F(MediaRouterContextualMenuUnitTest, ToggleAlwaysShowIconItem) {
133 MediaRouterContextualMenu menu(browser()); 126 MediaRouterContextualMenu menu(browser());
134 extensions::ComponentMigrationHelper* const component_migration_helper = 127 extensions::ComponentMigrationHelper* const component_migration_helper =
135 toolbar_actions_model()->component_migration_helper(); 128 toolbar_actions_model()->component_migration_helper();
136 129
137 // Whether the option is checked should reflect the pref. 130 // Whether the option is checked should reflect the pref.
138 component_migration_helper->SetComponentActionPref( 131 component_migration_helper->SetComponentActionPref(
139 ComponentToolbarActionsFactory::kMediaRouterActionId, true); 132 ComponentToolbarActionsFactory::kMediaRouterActionId, true);
140 EXPECT_TRUE( 133 EXPECT_TRUE(
141 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); 134 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION));
142 135
143 component_migration_helper->SetComponentActionPref( 136 component_migration_helper->SetComponentActionPref(
144 ComponentToolbarActionsFactory::kMediaRouterActionId, false); 137 ComponentToolbarActionsFactory::kMediaRouterActionId, false);
145 EXPECT_FALSE( 138 EXPECT_FALSE(
146 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION)); 139 menu.IsCommandIdChecked(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION));
147 140
148 // Executing the option should toggle the pref. 141 // Executing the option should toggle the pref.
149 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); 142 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0);
150 EXPECT_TRUE(component_migration_helper->GetComponentActionPref( 143 EXPECT_TRUE(component_migration_helper->GetComponentActionPref(
151 ComponentToolbarActionsFactory::kMediaRouterActionId)); 144 ComponentToolbarActionsFactory::kMediaRouterActionId));
152 145
153 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0); 146 menu.ExecuteCommand(IDC_MEDIA_ROUTER_ALWAYS_SHOW_TOOLBAR_ACTION, 0);
154 EXPECT_FALSE(component_migration_helper->GetComponentActionPref( 147 EXPECT_FALSE(component_migration_helper->GetComponentActionPref(
155 ComponentToolbarActionsFactory::kMediaRouterActionId)); 148 ComponentToolbarActionsFactory::kMediaRouterActionId));
156 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698