Chromium Code Reviews| Index: chrome/browser/chromeos/system/tray_accessibility_browsertest.cc |
| diff --git a/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc b/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc |
| index d70ab70bb9b6dc9cecacccdb935c2bbdb6067397..ab0cae6c61aba8f1cb5bae6520577a9e97aa081d 100644 |
| --- a/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc |
| +++ b/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc |
| @@ -18,6 +18,10 @@ |
| #include "chrome/browser/chromeos/login/startup_utils.h" |
| #include "chrome/browser/chromeos/login/user_manager.h" |
| #include "chrome/browser/chromeos/login/user_manager_impl.h" |
| +#include "chrome/browser/policy/browser_policy_connector.h" |
| +#include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| +#include "chrome/browser/policy/policy_map.h" |
| +#include "chrome/browser/policy/policy_types.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| #include "chrome/common/chrome_notification_types.h" |
| @@ -26,20 +30,43 @@ |
| #include "chrome/test/base/testing_profile.h" |
| #include "chromeos/chromeos_switches.h" |
| #include "content/public/test/test_utils.h" |
| +#include "policy/policy_constants.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/views/widget/widget.h" |
| +using policy::BrowserPolicyConnector; |
| +using policy::MockConfigurationPolicyProvider; |
| +using policy::PolicyMap; |
|
Mattias Nissler (ping if slow)
2013/05/13 08:27:44
Why usually don't add using declarations for these
David Roche
2013/05/16 22:20:57
Done.
|
| +using testing::AnyNumber; |
| +using testing::Return; |
| +using testing::_; |
| +using testing::WithParamInterface; |
| + |
| namespace chromeos { |
| +enum PrefSettingMechanism { |
| + PREF_SERVICE, |
| + POLICY, |
| +}; |
| + |
| void SetMagnifierEnabled(bool enabled) { |
| MagnificationManager::Get()->SetMagnifierEnabled(enabled); |
| } |
| -class TrayAccessibilityTest : public CrosInProcessBrowserTest { |
| +class TrayAccessibilityTest |
| + : public CrosInProcessBrowserTest, |
| + public WithParamInterface<PrefSettingMechanism> { |
|
Mattias Nissler (ping if slow)
2013/05/13 08:27:44
I'm not sure whether it's a good idea essentially
dmazzoni
2013/05/14 17:42:14
Actually in this case it seems reasonable. The tes
David Roche
2013/05/16 22:20:57
The test names look like so:
TrayAccessibilityTes
|
| protected: |
| TrayAccessibilityTest() {} |
| virtual ~TrayAccessibilityTest() {} |
| + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| + EXPECT_CALL(provider_, IsInitializationComplete(_)) |
| + .WillRepeatedly(Return(true)); |
| + EXPECT_CALL(provider_, RegisterPolicyDomain(_, _)).Times(AnyNumber()); |
| + BrowserPolicyConnector::SetPolicyProviderForTesting(&provider_); |
| + } |
| + |
| virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| command_line->AppendSwitch(switches::kLoginManager); |
| command_line->AppendSwitchASCII(switches::kLoginProfile, |
| @@ -52,6 +79,25 @@ class TrayAccessibilityTest : public CrosInProcessBrowserTest { |
| CrosInProcessBrowserTest::RunTestOnMainThreadLoop(); |
| } |
| + void SetShowAccessibilityOptionsInSystemTrayMenu(bool value) { |
| + if (GetParam() == PREF_SERVICE) { |
| + Profile* profile = ProfileManager::GetDefaultProfile(); |
| + PrefService* prefs = profile->GetPrefs(); |
| + prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, value); |
| + prefs->CommitPendingWrite(); |
|
Mattias Nissler (ping if slow)
2013/05/13 08:27:44
This shouldn't be necessary.
David Roche
2013/05/16 22:20:57
Done.
|
| + } else if (GetParam() == POLICY) { |
| + PolicyMap policy_map; |
| + policy_map.Set(policy::key::kShowAccessibilityOptionsInSystemTrayMenu, |
| + policy::POLICY_LEVEL_MANDATORY, |
| + policy::POLICY_SCOPE_USER, |
| + base::Value::CreateBooleanValue(value)); |
| + provider_.UpdateChromePolicy(policy_map); |
| + base::RunLoop().RunUntilIdle(); |
|
Mattias Nissler (ping if slow)
2013/05/13 08:27:44
#include "base/run_loop.h"
David Roche
2013/05/16 22:20:57
Done.
|
| + } else { |
| + FAIL() << "Unknown test parameterization"; |
| + } |
| + } |
| + |
| ash::internal::TrayAccessibility* tray() { |
| return ash::Shell::GetInstance()->GetPrimarySystemTray()-> |
| GetTrayAccessibilityForTest(); |
| @@ -122,9 +168,11 @@ class TrayAccessibilityTest : public CrosInProcessBrowserTest { |
| bool IsScreenMagnifierEnabledOnDetailMenu() { |
| return tray()->detailed_menu_->screen_magnifier_enabled_; |
| } |
| + |
| + MockConfigurationPolicyProvider provider_; |
| }; |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, LoginStatus) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, LoginStatus) { |
| EXPECT_EQ(ash::user::LOGGED_IN_NONE, GetLoginStatus()); |
| UserManager::Get()->UserLoggedIn( |
| @@ -134,7 +182,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, LoginStatus) { |
| EXPECT_EQ(ash::user::LOGGED_IN_USER, GetLoginStatus()); |
| } |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowTrayIcon) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowTrayIcon) { |
| SetLoginStatus(ash::user::LOGGED_IN_NONE); |
| // Confirms that the icon is invisible before login. |
| @@ -147,19 +195,19 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowTrayIcon) { |
| // Confirms that the icon is invisible just after login. |
| EXPECT_FALSE(IsTrayIconVisible()); |
| - // Toggling spoken feedback changes the visibillity of the icon. |
| + // Toggling spoken feedback changes the visibility of the icon. |
| accessibility::EnableSpokenFeedback(true, NULL, ash::A11Y_NOTIFICATION_NONE); |
| EXPECT_TRUE(IsTrayIconVisible()); |
| accessibility::EnableSpokenFeedback(false, NULL, ash::A11Y_NOTIFICATION_NONE); |
| EXPECT_FALSE(IsTrayIconVisible()); |
| - // Toggling high contrast the visibillity of the icon. |
| + // Toggling high contrast the visibility of the icon. |
| accessibility::EnableHighContrast(true); |
| EXPECT_TRUE(IsTrayIconVisible()); |
| accessibility::EnableHighContrast(false); |
| EXPECT_FALSE(IsTrayIconVisible()); |
| - // Toggling magnifier the visibillity of the icon. |
| + // Toggling magnifier the visibility of the icon. |
| SetMagnifierEnabled(true); |
| EXPECT_TRUE(IsTrayIconVisible()); |
| SetMagnifierEnabled(false); |
| @@ -181,44 +229,37 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowTrayIcon) { |
| // Confirms that prefs::kShouldAlwaysShowAccessibilityMenu doesn't affect |
| // the icon on the tray. |
| - Profile* profile = ProfileManager::GetDefaultProfile(); |
| - PrefService* prefs = profile->GetPrefs(); |
| - prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, true); |
| - prefs->CommitPendingWrite(); |
| + SetShowAccessibilityOptionsInSystemTrayMenu(true); |
| accessibility::EnableHighContrast(true); |
| EXPECT_TRUE(IsTrayIconVisible()); |
| accessibility::EnableHighContrast(false); |
| EXPECT_FALSE(IsTrayIconVisible()); |
| } |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenu) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowMenu) { |
| // Login |
| UserManager::Get()->UserLoggedIn( |
| "owner@invalid.domain", "owner@invalid.domain", true); |
| UserManager::Get()->SessionStarted(); |
| - // Sets prefs::kShouldAlwaysShowAccessibilityMenu = false. |
| - Profile* profile = ProfileManager::GetDefaultProfile(); |
| - PrefService* prefs = profile->GetPrefs(); |
| - prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, false); |
| - prefs->CommitPendingWrite(); |
| + SetShowAccessibilityOptionsInSystemTrayMenu(false); |
| // Confirms that the menu is hidden. |
| EXPECT_FALSE(CanCreateMenuItem()); |
| - // Toggling spoken feedback changes the visibillity of the menu. |
| + // Toggling spoken feedback changes the visibility of the menu. |
| accessibility::EnableSpokenFeedback(true, NULL, ash::A11Y_NOTIFICATION_NONE); |
| EXPECT_TRUE(CanCreateMenuItem()); |
| accessibility::EnableSpokenFeedback(false, NULL, ash::A11Y_NOTIFICATION_NONE); |
| EXPECT_FALSE(CanCreateMenuItem()); |
| - // Toggling high contrast changes the visibillity of the menu. |
| + // Toggling high contrast changes the visibility of the menu. |
| accessibility::EnableHighContrast(true); |
| EXPECT_TRUE(CanCreateMenuItem()); |
| accessibility::EnableHighContrast(false); |
| EXPECT_FALSE(CanCreateMenuItem()); |
| - // Toggling screen magnifier changes the visibillity of the menu. |
| + // Toggling screen magnifier changes the visibility of the menu. |
| SetMagnifierEnabled(true); |
| EXPECT_TRUE(CanCreateMenuItem()); |
| SetMagnifierEnabled(false); |
| @@ -239,17 +280,13 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenu) { |
| EXPECT_FALSE(CanCreateMenuItem()); |
| } |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowMenuOption) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowMenuWithShowMenuOption) { |
| // Login |
| UserManager::Get()->UserLoggedIn( |
| "owner@invalid.domain", "owner@invalid.domain", true); |
| UserManager::Get()->SessionStarted(); |
| - // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true. |
| - Profile* profile = ProfileManager::GetDefaultProfile(); |
| - PrefService* prefs = profile->GetPrefs(); |
| - prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, true); |
| - prefs->CommitPendingWrite(); |
| + SetShowAccessibilityOptionsInSystemTrayMenu(true); |
| // Confirms that the menu is visible. |
| EXPECT_TRUE(CanCreateMenuItem()); |
| @@ -286,14 +323,13 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowMenuOption) { |
| SetMagnifierEnabled(false); |
| EXPECT_TRUE(CanCreateMenuItem()); |
| - // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true. |
| - prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, false); |
| + SetShowAccessibilityOptionsInSystemTrayMenu(false); |
| // Confirms that the menu is invisible. |
| EXPECT_FALSE(CanCreateMenuItem()); |
| } |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) { |
| SetLoginStatus(ash::user::LOGGED_IN_NONE); |
| // Confirms that the menu is visible. |
| @@ -331,24 +367,18 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, ShowMenuWithShowOnLoginScreen) { |
| SetMagnifierEnabled(false); |
| EXPECT_TRUE(CanCreateMenuItem()); |
| - // Sets prefs::kShouldAlwaysShowAccessibilityMenu = true. |
| - Profile* profile = ProfileManager::GetDefaultProfile(); |
| - PrefService* prefs = profile->GetPrefs(); |
| - prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, true); |
| - prefs->CommitPendingWrite(); |
| + SetShowAccessibilityOptionsInSystemTrayMenu(true); |
| // Confirms that the menu is keeping visible. |
| EXPECT_TRUE(CanCreateMenuItem()); |
| - // Sets prefs::kShouldAlwaysShowAccessibilityMenu = false. |
| - prefs->SetBoolean(prefs::kShouldAlwaysShowAccessibilityMenu, false); |
| - prefs->CommitPendingWrite(); |
| + SetShowAccessibilityOptionsInSystemTrayMenu(false); |
| // Confirms that the menu is keeping visible. |
| EXPECT_TRUE(CanCreateMenuItem()); |
| } |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { |
| // Enables high contrast mode. |
| accessibility::EnableHighContrast(true); |
| EXPECT_TRUE(CanCreateMenuItem()); |
| @@ -370,7 +400,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, KeepMenuVisibilityOnLockScreen) { |
| #define MAYBE_ClickDetailMenu ClickDetailMenu |
| #endif |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, MAYBE_ClickDetailMenu) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, MAYBE_ClickDetailMenu) { |
| // Confirms that the check item toggles the spoken feedback. |
| EXPECT_FALSE(accessibility::IsSpokenFeedbackEnabled()); |
| @@ -406,7 +436,7 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, MAYBE_ClickDetailMenu) { |
| EXPECT_FALSE(MagnificationManager::Get()->IsMagnifierEnabled()); |
| } |
| -IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { |
| +IN_PROC_BROWSER_TEST_P(TrayAccessibilityTest, CheckMarksOnDetailMenu) { |
| // At first, all of the check is unchecked. |
| EXPECT_TRUE(CreateDetailedMenu()); |
| EXPECT_FALSE(IsSpokenFeedbackEnabledOnDetailMenu()); |
| @@ -483,4 +513,9 @@ IN_PROC_BROWSER_TEST_F(TrayAccessibilityTest, CheckMarksOnDetailMenu) { |
| CloseDetailMenu(); |
| } |
| +INSTANTIATE_TEST_CASE_P(TrayAccessibilityTestInstance, |
| + TrayAccessibilityTest, |
| + testing::Values(PREF_SERVICE, |
| + POLICY)); |
| + |
| } // namespace chromeos |