Chromium Code Reviews| Index: chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc |
| diff --git a/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc b/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ffbe2a36450a325060da8283e98d3ec2d2f7be8 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc |
| @@ -0,0 +1,169 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/command_line.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
| +#include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
| +#include "chrome/browser/chromeos/cros/cros_mock.h" |
| +#include "chrome/browser/chromeos/cros/mock_network_library.h" |
| +#include "chrome/browser/chromeos/login/helper.h" |
| +#include "chrome/browser/chromeos/login/login_utils.h" |
| +#include "chrome/browser/chromeos/login/user_manager.h" |
| +#include "chrome/browser/chromeos/login/user_manager_impl.h" |
| +#include "chrome/browser/prefs/pref_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/profiles/profile_manager.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "chrome/common/chrome_notification_types.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/test/base/testing_profile.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "chromeos/dbus/mock_cros_disks_client.h" |
| +#include "chromeos/dbus/mock_dbus_thread_manager.h" |
| +#include "chromeos/dbus/mock_media_transfer_protocol_daemon_client.h" |
| +#include "chromeos/dbus/mock_power_manager_client.h" |
| +#include "chromeos/dbus/mock_session_manager_client.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
|
DaveMoore
2012/10/11 20:09:27
I believe we are avoiding new uses of gmock. Addin
yoshiki
2012/10/12 15:00:55
Thanks, waiting for Ben's comment.
|
| + |
| +using ::testing::_; |
| +using ::testing::AnyNumber; |
| +using ::testing::Return; |
| + |
| +namespace chromeos { |
| + |
| +class MagnificationManagerTest : public CrosInProcessBrowserTest { |
| + protected: |
| + MagnificationManagerTest() {} |
| + virtual ~MagnificationManagerTest() {} |
| + |
| + virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| + MockDBusThreadManager* mock_dbus_thread_manager = |
| + new MockDBusThreadManager; |
| + EXPECT_CALL(*mock_dbus_thread_manager, GetSystemBus()) |
| + .WillRepeatedly(Return(reinterpret_cast<dbus::Bus*>(NULL))); |
| + |
| + DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager); |
| + CrosInProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| + cros_mock_->InitStatusAreaMocks(); |
| + cros_mock_->SetStatusAreaMocksExpectations(); |
| + |
| + MockNetworkLibrary* mock_network_library_ = |
| + cros_mock_->mock_network_library(); |
| + EXPECT_CALL(*mock_network_library_, AddUserActionObserver(_)) |
| + .Times(AnyNumber()); |
| + EXPECT_CALL(*mock_network_library_, LoadOncNetworks(_, _, _, _, _)) |
| + .WillRepeatedly(Return(true)); |
| + |
| + MockSessionManagerClient* mock_session_manager_client = |
| + mock_dbus_thread_manager->mock_session_manager_client(); |
| + EXPECT_CALL(*mock_session_manager_client, RetrieveDevicePolicy(_)) |
| + .Times(AnyNumber()); |
| + EXPECT_CALL(*mock_session_manager_client, HasObserver(_)) |
| + .WillRepeatedly(Return(false)); |
| + |
| + MockPowerManagerClient* mock_update_engine_client = |
| + mock_dbus_thread_manager->mock_power_manager_client(); |
| + EXPECT_CALL(*mock_update_engine_client, HasObserver(_)) |
| + .WillRepeatedly(Return(false)); |
| + |
| + MockCrosDisksClient* mock_cros_disks_client = |
| + mock_dbus_thread_manager->mock_cros_disks_client(); |
| + EXPECT_CALL(*mock_cros_disks_client, EnumerateAutoMountableDevices(_, _)) |
| + .Times(AnyNumber()); |
| + EXPECT_CALL(*mock_cros_disks_client, SetUpConnections(_, _)) |
| + .Times(AnyNumber()); |
| + |
| + MockMediaTransferProtocolDaemonClient* |
| + mock_media_transfer_protocol_daemon_client = |
| + mock_dbus_thread_manager-> |
| + mock_media_transfer_protocol_daemon_client(); |
| + EXPECT_CALL(*mock_media_transfer_protocol_daemon_client, |
| + SetUpConnections(_)) |
| + .Times(AnyNumber()); |
| + EXPECT_CALL(*mock_media_transfer_protocol_daemon_client, |
| + EnumerateStorage(_, _)) |
| + .Times(AnyNumber()); |
| + } |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + command_line->AppendSwitch(switches::kLoginManager); |
| + command_line->AppendSwitchASCII(switches::kLoginProfile, |
| + TestingProfile::kTestUserProfileDir); |
| + } |
| + |
| + Profile* profile() { |
| + Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| + DCHECK(profile); |
| + return profile; |
| + } |
| + |
| + PrefServiceBase* prefs() { |
| + return PrefServiceBase::FromBrowserContext(profile()); |
| + } |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MagnificationManagerTest); |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, Login) { |
| + // Confirms that magnifier is enabled on the login screen. |
| + EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); |
| + |
| + // Logs in. |
| + UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); |
| + UserManager::Get()->SessionStarted(); |
| + |
| + // Confirms that magnifier is disabled just after login. |
| + EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); |
| + |
| + // Enables magnifier. |
| + MagnificationManager::GetInstance()->SetEnabled(true); |
| + |
| + // Confirms that magnifier is enabled. |
| + EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, WorkingWithPref) { |
| + // Logs in |
| + UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); |
| + UserManager::Get()->SessionStarted(); |
| + |
| + // Confirms that magnifier is disabled just after login. |
| + EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); |
| + |
| + // Sets the pref as true to enable magnifier. |
| + prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); |
| + |
| + // Confirms that magnifier is enabled. |
| + EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); |
| + |
| + // Sets the pref as false to disabled magnifier. |
| + prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, false); |
| + |
| + // Confirms that magnifier is disabled. |
| + EXPECT_FALSE(MagnificationManager::GetInstance()->IsEnabled()); |
| + |
| + // Sets the pref as true to enable magnifier again. |
| + prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); |
| + |
| + // Confirms that magnifier is enabled. |
| + EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MagnificationManagerTest, ResumeSavedPref) { |
| + // Loads the profile of the user. |
| + UserManager::Get()->UserLoggedIn("owner@invalid.domain", true); |
| + |
| + // Sets the pref as true to enable magnifier before login. |
| + prefs()->SetBoolean(prefs::kScreenMagnifierEnabled, true); |
| + |
| + // Logs in. |
| + UserManager::Get()->SessionStarted(); |
| + |
| + // Confirms that magnifier is enabled just after login. |
| + EXPECT_TRUE(MagnificationManager::GetInstance()->IsEnabled()); |
| +} |
| + |
| +} // namespace chromeos |