| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/power/power_prefs.h" | 5 #include "chrome/browser/chromeos/power/power_prefs.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
| 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 15 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 17 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 17 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 18 #include "chrome/browser/prefs/browser_prefs.h" | 18 #include "chrome/browser/prefs/browser_prefs.h" |
| 19 #include "chrome/browser/prefs/pref_service_syncable.h" | 19 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "chrome/test/base/testing_pref_service_syncable.h" | 25 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
| 27 #include "chrome/test/base/testing_profile_manager.h" | 27 #include "chrome/test/base/testing_profile_manager.h" |
| 28 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 29 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
| 30 #include "chromeos/dbus/fake_power_manager_client.h" | 30 #include "chromeos/dbus/fake_power_manager_client.h" |
| 31 #include "chromeos/dbus/power_manager/policy.pb.h" | 31 #include "chromeos/dbus/power_manager/policy.pb.h" |
| 32 #include "chromeos/dbus/power_policy_controller.h" | 32 #include "chromeos/dbus/power_policy_controller.h" |
| 33 #include "components/pref_registry/pref_registry_syncable.h" | 33 #include "components/pref_registry/pref_registry_syncable.h" |
| 34 #include "content/public/browser/notification_details.h" | 34 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 36 #include "content/public/browser/notification_source.h" | 36 #include "content/public/browser/notification_source.h" |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 38 |
| 39 namespace chromeos { | 39 namespace chromeos { |
| 40 | 40 |
| 41 class PowerPrefsTest : public testing::Test { | 41 class PowerPrefsTest : public testing::Test { |
| 42 protected: | 42 protected: |
| 43 PowerPrefsTest(); | 43 PowerPrefsTest(); |
| 44 | 44 |
| 45 // testing::Test: | 45 // testing::Test: |
| 46 virtual void SetUp() OVERRIDE; | 46 virtual void SetUp() OVERRIDE; |
| 47 virtual void TearDown() OVERRIDE; | 47 virtual void TearDown() OVERRIDE; |
| 48 | 48 |
| 49 const Profile* GetProfile() const; | 49 const Profile* GetProfile() const; |
| 50 | 50 |
| 51 std::string GetExpectedPowerPolicyForProfile(Profile* profile) const; | 51 std::string GetExpectedPowerPolicyForProfile(Profile* profile) const; |
| 52 std::string GetCurrentPowerPolicy() const; | 52 std::string GetCurrentPowerPolicy() const; |
| 53 bool GetExpectedAllowScreenWakeLocksForProfile(Profile* profile) const; | 53 bool GetExpectedAllowScreenWakeLocksForProfile(Profile* profile) const; |
| 54 bool GetCurrentAllowScreenWakeLocks() const; | 54 bool GetCurrentAllowScreenWakeLocks() const; |
| 55 | 55 |
| 56 TestingProfileManager profile_manager_; | 56 TestingProfileManager profile_manager_; |
| 57 FakeDBusThreadManager fake_dbus_thread_manager_; | |
| 58 PowerPolicyController* power_policy_controller_; // Not owned. | 57 PowerPolicyController* power_policy_controller_; // Not owned. |
| 59 FakePowerManagerClient* fake_power_manager_client_; // Not owned. | 58 FakePowerManagerClient* fake_power_manager_client_; // Not owned. |
| 60 | 59 |
| 61 scoped_ptr<PowerPrefs> power_prefs_; | 60 scoped_ptr<PowerPrefs> power_prefs_; |
| 62 | 61 |
| 63 DISALLOW_COPY_AND_ASSIGN(PowerPrefsTest); | 62 DISALLOW_COPY_AND_ASSIGN(PowerPrefsTest); |
| 64 }; | 63 }; |
| 65 | 64 |
| 66 PowerPrefsTest::PowerPrefsTest() | 65 PowerPrefsTest::PowerPrefsTest() |
| 67 : profile_manager_(TestingBrowserProcess::GetGlobal()), | 66 : profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 68 power_policy_controller_(new PowerPolicyController), | 67 power_policy_controller_(NULL), |
| 69 fake_power_manager_client_(new FakePowerManagerClient) { | 68 fake_power_manager_client_(new FakePowerManagerClient) { |
| 70 fake_dbus_thread_manager_.SetPowerManagerClient( | |
| 71 scoped_ptr<PowerManagerClient>(fake_power_manager_client_)); | |
| 72 fake_dbus_thread_manager_.SetPowerPolicyController( | |
| 73 scoped_ptr<PowerPolicyController>(power_policy_controller_)); | |
| 74 power_policy_controller_->Init(&fake_dbus_thread_manager_); | |
| 75 } | 69 } |
| 76 | 70 |
| 77 void PowerPrefsTest::SetUp() { | 71 void PowerPrefsTest::SetUp() { |
| 78 testing::Test::SetUp(); | 72 testing::Test::SetUp(); |
| 73 |
| 74 scoped_ptr<DBusThreadManagerSetter> dbus_setter = |
| 75 chromeos::DBusThreadManager::GetSetterForTesting(); |
| 76 dbus_setter->SetPowerManagerClient( |
| 77 scoped_ptr<PowerManagerClient>(fake_power_manager_client_)); |
| 78 // Power policy controller is recreated with SetPowerManagerClient(). |
| 79 power_policy_controller_ = |
| 80 chromeos::DBusThreadManager::Get()->GetPowerPolicyController(); |
| 81 |
| 79 ASSERT_TRUE(profile_manager_.SetUp()); | 82 ASSERT_TRUE(profile_manager_.SetUp()); |
| 80 | 83 |
| 81 power_prefs_.reset(new PowerPrefs(power_policy_controller_)); | 84 power_prefs_.reset(new PowerPrefs(power_policy_controller_)); |
| 82 EXPECT_FALSE(GetProfile()); | 85 EXPECT_FALSE(GetProfile()); |
| 83 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( | 86 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( |
| 84 power_manager::PowerManagementPolicy()), | 87 power_manager::PowerManagementPolicy()), |
| 85 GetCurrentPowerPolicy()); | 88 GetCurrentPowerPolicy()); |
| 86 } | 89 } |
| 87 | 90 |
| 88 void PowerPrefsTest::TearDown() { | 91 void PowerPrefsTest::TearDown() { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 content::Source<Profile>(user_profile), | 274 content::Source<Profile>(user_profile), |
| 272 content::NotificationService::NoDetails()); | 275 content::NotificationService::NoDetails()); |
| 273 | 276 |
| 274 // The user profile's prefs should still be used. | 277 // The user profile's prefs should still be used. |
| 275 EXPECT_FALSE(GetProfile()); | 278 EXPECT_FALSE(GetProfile()); |
| 276 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), | 279 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), |
| 277 GetCurrentPowerPolicy()); | 280 GetCurrentPowerPolicy()); |
| 278 } | 281 } |
| 279 | 282 |
| 280 } // namespace chromeos | 283 } // namespace chromeos |
| OLD | NEW |