summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/settings
diff options
context:
space:
mode:
authorpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-17 12:11:19 +0000
committerpastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-17 12:11:19 +0000
commitfd8c8b580022c46e335709047f845d592d3cf850 (patch)
tree6dd7148c65f2207d2e0c9f5eb5a03a280d4ecf35 /chrome/browser/chromeos/settings
parent39e5b0934ce0cf3adecb36afa9d4116afc2f8e18 (diff)
downloadchromium_src-fd8c8b580022c46e335709047f845d592d3cf850.zip
chromium_src-fd8c8b580022c46e335709047f845d592d3cf850.tar.gz
chromium_src-fd8c8b580022c46e335709047f845d592d3cf850.tar.bz2
Fix the unit test to run in a clean profile dir and add a new test to check proper migration.
The test was not producing correct results on one of the bots because the pref checked has a special migration path that might populate it even if not set in the policy file. To avoid this we run all tests from this group in a clean profile directory and also to make sure migration works as expected I added a new test to the suit too. BUG=148356 TEST=unit_tests: DeviceSettingsProviderTest.SetPrefFailed should pass on all bots. Review URL: https://chromiumcodereview.appspot.com/10916288 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/settings')
-rw-r--r--chrome/browser/chromeos/settings/device_settings_provider_unittest.cc33
1 files changed, 33 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/settings/device_settings_provider_unittest.cc b/chrome/browser/chromeos/settings/device_settings_provider_unittest.cc
index 8943eee3e..3835748 100644
--- a/chrome/browser/chromeos/settings/device_settings_provider_unittest.cc
+++ b/chrome/browser/chromeos/settings/device_settings_provider_unittest.cc
@@ -8,7 +8,10 @@
#include "base/bind.h"
#include "base/callback.h"
+#include "base/file_util.h"
#include "base/message_loop.h"
+#include "base/path_service.h"
+#include "base/scoped_temp_dir.h"
#include "base/values.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/settings/cros_settings_names.h"
@@ -17,6 +20,7 @@
#include "chrome/browser/policy/policy_builder.h"
#include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/policy/proto/device_management_backend.pb.h"
+#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
#include "content/public/test/test_browser_thread.h"
@@ -45,6 +49,11 @@ class DeviceSettingsProviderTest: public testing::Test {
owner_key_util_(new MockOwnerKeyUtil()) {}
virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA,
+ &original_user_data_dir_));
+ ASSERT_TRUE(user_data_dir_.CreateUniqueTempDir());
+ ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA,
+ user_data_dir_.path()));
policy_.payload().mutable_metrics_enabled()->set_metrics_enabled(false);
policy_.Build();
@@ -64,6 +73,8 @@ class DeviceSettingsProviderTest: public testing::Test {
virtual void TearDown() OVERRIDE {
device_settings_service_.Shutdown();
+ ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA,
+ original_user_data_dir_));
}
MessageLoop message_loop_;
@@ -83,6 +94,9 @@ class DeviceSettingsProviderTest: public testing::Test {
scoped_ptr<DeviceSettingsProvider> provider_;
+ ScopedTempDir user_data_dir_;
+ FilePath original_user_data_dir_;
+
private:
DISALLOW_COPY_AND_ASSIGN(DeviceSettingsProviderTest);
};
@@ -250,4 +264,23 @@ TEST_F(DeviceSettingsProviderTest, PolicyLoadNotification) {
Mock::VerifyAndClearExpectations(this);
}
+TEST_F(DeviceSettingsProviderTest, StatsReportingMigration) {
+ // Create the legacy consent file.
+ FilePath consent_file =
+ user_data_dir_.path().AppendASCII("Consent To Send Stats");
+ ASSERT_EQ(1, file_util::WriteFile(consent_file, "0", 1));
+
+ // This should trigger migration because the metrics policy isn't in the blob.
+ device_settings_test_helper_.set_policy_blob(std::string());
+ device_settings_test_helper_.Flush();
+ EXPECT_EQ(std::string(), device_settings_test_helper_.policy_blob());
+
+ // Verify that migration has kicked in.
+ const base::Value* saved_value = provider_->Get(kStatsReportingPref);
+ ASSERT_TRUE(saved_value);
+ bool bool_value;
+ EXPECT_TRUE(saved_value->GetAsBoolean(&bool_value));
+ EXPECT_FALSE(bool_value);
+}
+
} // namespace chromeos