Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: chrome/browser/chromeos/login/signed_settings_temp_storage_unittest.cc

Issue 8091002: PART2: Make SignedSettings use proper Value types instead of string all around the place. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased on ToT and made clang happy. Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/scoped_temp_dir.h" 14 #include "base/scoped_temp_dir.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/common/logging_chrome.h" 16 #include "chrome/common/logging_chrome.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 18
19 namespace chromeos { 19 namespace chromeos {
20 20
21 class SignedSettingsTempStorageTest : public testing::Test { 21 class SignedSettingsTempStorageTest : public testing::Test {
22 protected: 22 protected:
23 virtual void SetUp() { 23 virtual void SetUp() {
24 ref_map_["some_stuff"] = "a=35;code=64"; 24 ref_map_.Set("some_stuff", new base::StringValue("a=35;code=64"));
Mattias Nissler (ping if slow) 2011/10/07 11:02:57 You should rather use Value::CreateStringValue() (
pastarmovj 2011/10/13 11:25:06 Done.
25 ref_map_["another_stuff"] = ""; 25 ref_map_.Set("another_stuff", new base::FundamentalValue(false));
26 ref_map_["name"] = "value"; 26 ref_map_.Set("name", new base::StringValue("value"));
27 ref_map_["2bc6aa16-e0ea-11df-b13d-18a90520e2e5"] = "512"; 27 ref_map_.Set("2bc6aa16-e0ea-11df-b13d-18a90520e2e5",
28 new base::FundamentalValue("512"));
28 29
29 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 30 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
30 FilePath temp_file; 31 FilePath temp_file;
31 ASSERT_TRUE( 32 ASSERT_TRUE(
32 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file)); 33 file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_file));
33 local_state_.reset( 34 local_state_.reset(
34 PrefService::CreatePrefService(temp_file, NULL, false)); 35 PrefService::CreatePrefService(temp_file, NULL, false));
35 ASSERT_TRUE(NULL != local_state_.get()); 36 ASSERT_TRUE(NULL != local_state_.get());
36 SignedSettingsTempStorage::RegisterPrefs(local_state_.get()); 37 SignedSettingsTempStorage::RegisterPrefs(local_state_.get());
37 } 38 }
38 39
39 std::map<std::string, std::string> ref_map_; 40 base::DictionaryValue ref_map_;
41 //std::map<std::string, std::string> ref_map_;
Mattias Nissler (ping if slow) 2011/10/07 11:02:57 remove.
pastarmovj 2011/10/13 11:25:06 Done. P.S This file will be changed heavily when
40 ScopedTempDir temp_dir_; 42 ScopedTempDir temp_dir_;
41 scoped_ptr<PrefService> local_state_; 43 scoped_ptr<PrefService> local_state_;
42 }; 44 };
43 45
44 TEST_F(SignedSettingsTempStorageTest, Basic) { 46 TEST_F(SignedSettingsTempStorageTest, Basic) {
45 EXPECT_GT(ref_map_.size(), 3u); // Number above 3 is many. 47 EXPECT_GT(ref_map_.size(), 3u); // Number above 3 is many.
46 typedef std::map<std::string, std::string>::iterator It; 48 typedef base::DictionaryValue::key_iterator It;
47 std::vector<It> a_list; 49 std::vector<It> a_list;
48 for (It it = ref_map_.begin(); it != ref_map_.end(); ++it) { 50 base::Value* value;
51 for (It it = ref_map_.begin_keys(); it != ref_map_.end_keys(); ++it) {
49 a_list.push_back(it); 52 a_list.push_back(it);
50 } 53 }
51 std::random_shuffle(a_list.begin(), a_list.end()); 54 std::random_shuffle(a_list.begin(), a_list.end());
52 std::vector<It> b_list(a_list); 55 std::vector<It> b_list(a_list);
53 std::copy(b_list.begin(), 56 std::copy(b_list.begin(),
54 b_list.begin() + b_list.size() / 2, 57 b_list.begin() + b_list.size() / 2,
55 std::back_inserter(a_list)); 58 std::back_inserter(a_list));
56 std::random_shuffle(a_list.begin(), a_list.end()); 59 std::random_shuffle(a_list.begin(), a_list.end());
57 for (size_t i = 0; i < a_list.size(); ++i) { 60 for (size_t i = 0; i < a_list.size(); ++i) {
58 EXPECT_TRUE(SignedSettingsTempStorage::Store(a_list[i]->first, 61 ref_map_.Get(*a_list[i], &value);
59 a_list[i]->second, 62 EXPECT_TRUE(SignedSettingsTempStorage::Store(*a_list[i],
63 *value,
60 local_state_.get())); 64 local_state_.get()));
61 } 65 }
62 for (int i = 0; i < 3; ++i) { 66 for (int i = 0; i < 3; ++i) {
63 std::copy(a_list.begin(), a_list.end(), std::back_inserter(b_list)); 67 std::copy(a_list.begin(), a_list.end(), std::back_inserter(b_list));
64 } 68 }
65 std::random_shuffle(b_list.begin(), b_list.end()); 69 std::random_shuffle(b_list.begin(), b_list.end());
66 std::string value;
67 for (size_t i = 0; i < b_list.size(); ++i) { 70 for (size_t i = 0; i < b_list.size(); ++i) {
68 EXPECT_TRUE(SignedSettingsTempStorage::Retrieve(b_list[i]->first, &value, 71 EXPECT_TRUE(SignedSettingsTempStorage::Retrieve(*b_list[i], &value,
69 local_state_.get())); 72 local_state_.get()));
70 EXPECT_EQ(b_list[i]->second, value); 73 base::Value* orignal_value;
74 ref_map_.Get(*b_list[i], &orignal_value);
75 EXPECT_TRUE(orignal_value->Equals(value));
71 EXPECT_FALSE(SignedSettingsTempStorage::Retrieve("non-existent tv-series", 76 EXPECT_FALSE(SignedSettingsTempStorage::Retrieve("non-existent tv-series",
72 &value, 77 &value,
73 local_state_.get())); 78 local_state_.get()));
74 } 79 }
75 } 80 }
76 81
77 } // namespace chromeos 82 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698