| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/login/signed_settings_temp_storage.h" | 5 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/common/logging_chrome.h" | 16 #include "chrome/common/logging_chrome.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 18 |
| 20 namespace chromeos { | 19 namespace chromeos { |
| 21 | 20 |
| 22 class SignedSettingsTempStorageTest : public ::testing::Test { | 21 class SignedSettingsTempStorageTest : public ::testing::Test { |
| 23 protected: | 22 protected: |
| 24 virtual void SetUp() { | 23 virtual void SetUp() { |
| 25 ref_map_["some_stuff"] = "a=35;code=64"; | 24 ref_map_["some_stuff"] = "a=35;code=64"; |
| 26 ref_map_["another_stuff"] = ""; | 25 ref_map_["another_stuff"] = ""; |
| 27 ref_map_["name"] = "value"; | 26 ref_map_["name"] = "value"; |
| 28 ref_map_["2bc6aa16-e0ea-11df-b13d-18a90520e2e5"] = "512"; | 27 ref_map_["2bc6aa16-e0ea-11df-b13d-18a90520e2e5"] = "512"; |
| 29 | 28 |
| 30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 31 FilePath temp_file; | 30 FilePath temp_file; |
| 32 ASSERT_TRUE( | 31 ASSERT_TRUE( |
| 33 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); | 32 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); |
| 34 local_state_.reset(PrefService::CreatePrefService(temp_file, NULL)); | 33 local_state_.reset(PrefService::CreatePrefService(temp_file, NULL)); |
| 35 ASSERT_TRUE(NULL != local_state_.get()); | 34 ASSERT_TRUE(NULL != local_state_.get()); |
| 36 SignedSettingsTempStorage::RegisterPrefs(local_state_.get()); | 35 SignedSettingsTempStorage::RegisterPrefs(local_state_.get()); |
| 37 } | 36 } |
| 38 | 37 |
| 39 std::map<std::string, std::string> ref_map_; | 38 std::map<std::string, std::string> ref_map_; |
| 40 ScopedTempDir temp_dir_; | 39 ScopedTempDir temp_dir_; |
| 41 scoped_ptr<PrefService> local_state_; | 40 scoped_ptr<PrefService> local_state_; |
| 42 }; | 41 }; |
| 43 | 42 |
| 44 TEST_F(SignedSettingsTempStorageTest, Basic) { | 43 TEST_F(SignedSettingsTempStorageTest, Basic) { |
| 45 EXPECT_GT(ref_map_.size(), 3u); // Number above 3 is many. | 44 EXPECT_GT(ref_map_.size(), 3u); // Number above 3 is many. |
| 46 typedef std::map<std::string, std::string>::iterator It; | 45 typedef std::map<std::string, std::string>::iterator It; |
| 47 std::vector<It> a_list; | 46 std::vector<It> a_list; |
| 48 for (It it = ref_map_.begin(); it != ref_map_.end(); ++it) { | 47 for (It it = ref_map_.begin(); it != ref_map_.end(); ++it) { |
| 49 a_list.push_back(it); | 48 a_list.push_back(it); |
| 50 } | 49 } |
| 51 std::random_shuffle(a_list.begin(), a_list.end()); | 50 std::random_shuffle(a_list.begin(), a_list.end()); |
| 52 std::vector<It> b_list(a_list); | 51 std::vector<It> b_list(a_list); |
| 53 std::copy(b_list.begin(), | 52 std::copy(b_list.begin(), |
| 54 b_list.begin() + b_list.size() / 2, | 53 b_list.begin() + b_list.size() / 2, |
| 55 std::back_inserter(a_list)); | 54 std::back_inserter(a_list)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 EXPECT_TRUE(SignedSettingsTempStorage::Retrieve(b_list[i]->first, &value, | 67 EXPECT_TRUE(SignedSettingsTempStorage::Retrieve(b_list[i]->first, &value, |
| 69 local_state_.get())); | 68 local_state_.get())); |
| 70 EXPECT_EQ(b_list[i]->second, value); | 69 EXPECT_EQ(b_list[i]->second, value); |
| 71 EXPECT_FALSE(SignedSettingsTempStorage::Retrieve("non-existent tv-series", | 70 EXPECT_FALSE(SignedSettingsTempStorage::Retrieve("non-existent tv-series", |
| 72 &value, | 71 &value, |
| 73 local_state_.get())); | 72 local_state_.get())); |
| 74 } | 73 } |
| 75 } | 74 } |
| 76 | 75 |
| 77 } // namespace chromeos | 76 } // namespace chromeos |
| 78 | |
| OLD | NEW |