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

Side by Side Diff: chrome/browser/json_pref_store_unittest.cc

Issue 1692011: Implementation of managed policy: Policy Abstraction (Closed)
Patch Set: check no changes Created 10 years, 7 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
« no previous file with comments | « chrome/browser/json_pref_store.h ('k') | chrome/browser/pref_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "app/test/data/resource.h" 5 #include "app/test/data/resource.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 FilePath data_dir_; 44 FilePath data_dir_;
45 }; 45 };
46 46
47 // Test fallback behavior for a nonexistent file. 47 // Test fallback behavior for a nonexistent file.
48 TEST_F(JsonPrefStoreTest, NonExistentFile) { 48 TEST_F(JsonPrefStoreTest, NonExistentFile) {
49 FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); 49 FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
50 ASSERT_FALSE(file_util::PathExists(bogus_input_file)); 50 ASSERT_FALSE(file_util::PathExists(bogus_input_file));
51 JsonPrefStore pref_store(bogus_input_file); 51 JsonPrefStore pref_store(bogus_input_file);
52 EXPECT_EQ(PrefStore::PREF_READ_ERROR_NO_FILE, pref_store.ReadPrefs()); 52 EXPECT_EQ(PrefStore::PREF_READ_ERROR_NO_FILE, pref_store.ReadPrefs());
53 EXPECT_FALSE(pref_store.ReadOnly()); 53 EXPECT_FALSE(pref_store.ReadOnly());
54 EXPECT_TRUE(pref_store.Prefs()->empty()); 54 EXPECT_TRUE(pref_store.prefs()->empty());
55 } 55 }
56 56
57 // Test fallback behavior for an invalid file. 57 // Test fallback behavior for an invalid file.
58 TEST_F(JsonPrefStoreTest, InvalidFile) { 58 TEST_F(JsonPrefStoreTest, InvalidFile) {
59 FilePath invalid_file_original = data_dir_.AppendASCII("invalid.json"); 59 FilePath invalid_file_original = data_dir_.AppendASCII("invalid.json");
60 FilePath invalid_file = test_dir_.AppendASCII("invalid.json"); 60 FilePath invalid_file = test_dir_.AppendASCII("invalid.json");
61 ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file)); 61 ASSERT_TRUE(file_util::CopyFile(invalid_file_original, invalid_file));
62 JsonPrefStore pref_store(invalid_file); 62 JsonPrefStore pref_store(invalid_file);
63 EXPECT_EQ(PrefStore::PREF_READ_ERROR_JSON_PARSE, pref_store.ReadPrefs()); 63 EXPECT_EQ(PrefStore::PREF_READ_ERROR_JSON_PARSE, pref_store.ReadPrefs());
64 EXPECT_FALSE(pref_store.ReadOnly()); 64 EXPECT_FALSE(pref_store.ReadOnly());
65 EXPECT_TRUE(pref_store.Prefs()->empty()); 65 EXPECT_TRUE(pref_store.prefs()->empty());
66 66
67 // The file should have been moved aside. 67 // The file should have been moved aside.
68 EXPECT_FALSE(file_util::PathExists(invalid_file)); 68 EXPECT_FALSE(file_util::PathExists(invalid_file));
69 FilePath moved_aside = test_dir_.AppendASCII("invalid.bad"); 69 FilePath moved_aside = test_dir_.AppendASCII("invalid.bad");
70 EXPECT_TRUE(file_util::PathExists(moved_aside)); 70 EXPECT_TRUE(file_util::PathExists(moved_aside));
71 EXPECT_TRUE(file_util::TextContentsEqual(invalid_file_original, 71 EXPECT_TRUE(file_util::TextContentsEqual(invalid_file_original,
72 moved_aside)); 72 moved_aside));
73 } 73 }
74 74
75 TEST_F(JsonPrefStoreTest, Basic) { 75 TEST_F(JsonPrefStoreTest, Basic) {
76 ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"), 76 ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"),
77 test_dir_.AppendASCII("write.json"))); 77 test_dir_.AppendASCII("write.json")));
78 78
79 // Test that the persistent value can be loaded. 79 // Test that the persistent value can be loaded.
80 FilePath input_file = test_dir_.AppendASCII("write.json"); 80 FilePath input_file = test_dir_.AppendASCII("write.json");
81 ASSERT_TRUE(file_util::PathExists(input_file)); 81 ASSERT_TRUE(file_util::PathExists(input_file));
82 JsonPrefStore pref_store(input_file); 82 JsonPrefStore pref_store(input_file);
83 ASSERT_EQ(PrefStore::PREF_READ_ERROR_NONE, pref_store.ReadPrefs()); 83 ASSERT_EQ(PrefStore::PREF_READ_ERROR_NONE, pref_store.ReadPrefs());
84 ASSERT_FALSE(pref_store.ReadOnly()); 84 ASSERT_FALSE(pref_store.ReadOnly());
85 DictionaryValue* prefs = pref_store.Prefs(); 85 DictionaryValue* prefs = pref_store.prefs();
86 86
87 // The JSON file looks like this: 87 // The JSON file looks like this:
88 // { 88 // {
89 // "homepage": "http://www.cnn.com", 89 // "homepage": "http://www.cnn.com",
90 // "some_directory": "/usr/local/", 90 // "some_directory": "/usr/local/",
91 // "tabs": { 91 // "tabs": {
92 // "new_windows_in_tabs": true, 92 // "new_windows_in_tabs": true,
93 // "max_tabs": 20 93 // "max_tabs": 20
94 // } 94 // }
95 // } 95 // }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 MessageLoop message_loop; 139 MessageLoop message_loop;
140 ChromeThread file_thread(ChromeThread::FILE, &message_loop); 140 ChromeThread file_thread(ChromeThread::FILE, &message_loop);
141 FilePath output_file = input_file; 141 FilePath output_file = input_file;
142 FilePath golden_output_file = data_dir_.AppendASCII("write.golden.json"); 142 FilePath golden_output_file = data_dir_.AppendASCII("write.golden.json");
143 ASSERT_TRUE(file_util::PathExists(golden_output_file)); 143 ASSERT_TRUE(file_util::PathExists(golden_output_file));
144 ASSERT_TRUE(pref_store.WritePrefs()); 144 ASSERT_TRUE(pref_store.WritePrefs());
145 MessageLoop::current()->RunAllPending(); 145 MessageLoop::current()->RunAllPending();
146 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); 146 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file));
147 ASSERT_TRUE(file_util::Delete(output_file, false)); 147 ASSERT_TRUE(file_util::Delete(output_file, false));
148 } 148 }
OLDNEW
« no previous file with comments | « chrome/browser/json_pref_store.h ('k') | chrome/browser/pref_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698