| 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/extensions/extension_special_storage_policy.h" | 14 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 15 #include "chrome/browser/prefs/browser_prefs.h" | 15 #include "chrome/browser/prefs/browser_prefs.h" |
| 16 #include "chrome/browser/prefs/pref_service_syncable.h" | 16 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 22 #include "chrome/test/base/testing_pref_service_syncable.h" | 22 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "chrome/test/base/testing_profile_manager.h" | 24 #include "chrome/test/base/testing_profile_manager.h" |
| 25 #include "chromeos/chromeos_switches.h" | 25 #include "chromeos/chromeos_switches.h" |
| 26 #include "chromeos/dbus/fake_dbus_thread_manager.h" | 26 #include "chromeos/dbus/dbus_thread_manager.h" |
| 27 #include "chromeos/dbus/fake_power_manager_client.h" | 27 #include "chromeos/dbus/fake_power_manager_client.h" |
| 28 #include "chromeos/dbus/power_manager/policy.pb.h" | 28 #include "chromeos/dbus/power_manager/policy.pb.h" |
| 29 #include "chromeos/dbus/power_policy_controller.h" | 29 #include "chromeos/dbus/power_policy_controller.h" |
| 30 #include "components/pref_registry/pref_registry_syncable.h" | 30 #include "components/pref_registry/pref_registry_syncable.h" |
| 31 #include "content/public/browser/notification_details.h" | 31 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_service.h" | 32 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 namespace chromeos { | 36 namespace chromeos { |
| 37 | 37 |
| 38 class PowerPrefsTest : public testing::Test { | 38 class PowerPrefsTest : public testing::Test { |
| 39 protected: | 39 protected: |
| 40 PowerPrefsTest(); | 40 PowerPrefsTest(); |
| 41 | 41 |
| 42 // testing::Test: | 42 // testing::Test: |
| 43 virtual void SetUp() OVERRIDE; | 43 virtual void SetUp() OVERRIDE; |
| 44 virtual void TearDown() OVERRIDE; | 44 virtual void TearDown() OVERRIDE; |
| 45 | 45 |
| 46 const Profile* GetProfile() const; | 46 const Profile* GetProfile() const; |
| 47 | 47 |
| 48 std::string GetExpectedPowerPolicyForProfile(Profile* profile) const; | 48 std::string GetExpectedPowerPolicyForProfile(Profile* profile) const; |
| 49 std::string GetCurrentPowerPolicy() const; | 49 std::string GetCurrentPowerPolicy() const; |
| 50 bool GetExpectedAllowScreenWakeLocksForProfile(Profile* profile) const; | 50 bool GetExpectedAllowScreenWakeLocksForProfile(Profile* profile) const; |
| 51 bool GetCurrentAllowScreenWakeLocks() const; | 51 bool GetCurrentAllowScreenWakeLocks() const; |
| 52 | 52 |
| 53 TestingProfileManager profile_manager_; | 53 TestingProfileManager profile_manager_; |
| 54 FakeDBusThreadManager fake_dbus_thread_manager_; | |
| 55 PowerPolicyController* power_policy_controller_; // Not owned. | 54 PowerPolicyController* power_policy_controller_; // Not owned. |
| 56 FakePowerManagerClient* fake_power_manager_client_; // Not owned. | 55 FakePowerManagerClient* fake_power_manager_client_; // Not owned. |
| 57 | 56 |
| 58 scoped_ptr<PowerPrefs> power_prefs_; | 57 scoped_ptr<PowerPrefs> power_prefs_; |
| 59 | 58 |
| 60 DISALLOW_COPY_AND_ASSIGN(PowerPrefsTest); | 59 DISALLOW_COPY_AND_ASSIGN(PowerPrefsTest); |
| 61 }; | 60 }; |
| 62 | 61 |
| 63 PowerPrefsTest::PowerPrefsTest() | 62 PowerPrefsTest::PowerPrefsTest() |
| 64 : profile_manager_(TestingBrowserProcess::GetGlobal()), | 63 : profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 65 power_policy_controller_(new PowerPolicyController), | 64 power_policy_controller_(new PowerPolicyController), |
| 66 fake_power_manager_client_(new FakePowerManagerClient) { | 65 fake_power_manager_client_(new FakePowerManagerClient) { |
| 67 fake_dbus_thread_manager_.SetPowerManagerClient( | |
| 68 scoped_ptr<PowerManagerClient>(fake_power_manager_client_)); | |
| 69 fake_dbus_thread_manager_.SetPowerPolicyController( | |
| 70 scoped_ptr<PowerPolicyController>(power_policy_controller_)); | |
| 71 power_policy_controller_->Init(&fake_dbus_thread_manager_); | |
| 72 } | 66 } |
| 73 | 67 |
| 74 void PowerPrefsTest::SetUp() { | 68 void PowerPrefsTest::SetUp() { |
| 75 testing::Test::SetUp(); | 69 testing::Test::SetUp(); |
| 70 |
| 71 scoped_ptr<DBusThreadManagerTestHelper> dbus_helper = |
| 72 chromeos::DBusThreadManager::InitializeForTesting(); |
| 73 dbus_helper->SetPowerManagerClient( |
| 74 scoped_ptr<PowerManagerClient>(fake_power_manager_client_)); |
| 75 dbus_helper->SetPowerPolicyController( |
| 76 scoped_ptr<PowerPolicyController>(power_policy_controller_)); |
| 77 power_policy_controller_->Init(chromeos::DBusThreadManager::Get()); |
| 78 |
| 76 ASSERT_TRUE(profile_manager_.SetUp()); | 79 ASSERT_TRUE(profile_manager_.SetUp()); |
| 77 | 80 |
| 78 power_prefs_.reset(new PowerPrefs(power_policy_controller_)); | 81 power_prefs_.reset(new PowerPrefs(power_policy_controller_)); |
| 79 EXPECT_FALSE(GetProfile()); | 82 EXPECT_FALSE(GetProfile()); |
| 80 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( | 83 EXPECT_EQ(PowerPolicyController::GetPolicyDebugString( |
| 81 power_manager::PowerManagementPolicy()), | 84 power_manager::PowerManagementPolicy()), |
| 82 GetCurrentPowerPolicy()); | 85 GetCurrentPowerPolicy()); |
| 83 } | 86 } |
| 84 | 87 |
| 85 void PowerPrefsTest::TearDown() { | 88 void PowerPrefsTest::TearDown() { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 content::Source<Profile>(user_profile), | 262 content::Source<Profile>(user_profile), |
| 260 content::NotificationService::NoDetails()); | 263 content::NotificationService::NoDetails()); |
| 261 | 264 |
| 262 // The user profile's prefs should still be used. | 265 // The user profile's prefs should still be used. |
| 263 EXPECT_FALSE(GetProfile()); | 266 EXPECT_FALSE(GetProfile()); |
| 264 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), | 267 EXPECT_EQ(GetExpectedPowerPolicyForProfile(user_profile), |
| 265 GetCurrentPowerPolicy()); | 268 GetCurrentPowerPolicy()); |
| 266 } | 269 } |
| 267 | 270 |
| 268 } // namespace chromeos | 271 } // namespace chromeos |
| OLD | NEW |