OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit tests for master preferences related methods. | 5 // Unit tests for master preferences related methods. |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/common/chrome_paths.h" | 12 #include "chrome/common/chrome_paths.h" |
13 #include "chrome/installer/util/master_preferences.h" | 13 #include "chrome/installer/util/master_preferences.h" |
14 #include "chrome/installer/util/master_preferences_constants.h" | 14 #include "chrome/installer/util/master_preferences_constants.h" |
15 #include "chrome/installer/util/util_constants.h" | 15 #include "chrome/installer/util/util_constants.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 class MasterPreferencesTest : public testing::Test { | 19 class MasterPreferencesTest : public testing::Test { |
20 protected: | 20 protected: |
21 virtual void SetUp() { | 21 virtual void SetUp() { |
22 ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_)); | 22 ASSERT_TRUE(file_util::CreateTemporaryFile(&prefs_file_)); |
23 } | 23 } |
24 | 24 |
25 virtual void TearDown() { | 25 virtual void TearDown() { |
26 EXPECT_TRUE(file_util::Delete(prefs_file_, false)); | 26 EXPECT_TRUE(base::Delete(prefs_file_, false)); |
27 } | 27 } |
28 | 28 |
29 const base::FilePath& prefs_file() const { return prefs_file_; } | 29 const base::FilePath& prefs_file() const { return prefs_file_; } |
30 | 30 |
31 private: | 31 private: |
32 base::FilePath prefs_file_; | 32 base::FilePath prefs_file_; |
33 }; | 33 }; |
34 | 34 |
35 // Used to specify an expected value for a set boolean preference variable. | 35 // Used to specify an expected value for a set boolean preference variable. |
36 struct ExpectedBooleans { | 36 struct ExpectedBooleans { |
37 const char* name; | 37 const char* name; |
38 bool expected_value; | 38 bool expected_value; |
39 }; | 39 }; |
40 | 40 |
41 } // namespace | 41 } // namespace |
42 | 42 |
43 TEST_F(MasterPreferencesTest, NoFileToParse) { | 43 TEST_F(MasterPreferencesTest, NoFileToParse) { |
44 EXPECT_TRUE(file_util::Delete(prefs_file(), false)); | 44 EXPECT_TRUE(base::Delete(prefs_file(), false)); |
45 installer::MasterPreferences prefs(prefs_file()); | 45 installer::MasterPreferences prefs(prefs_file()); |
46 EXPECT_FALSE(prefs.read_from_file()); | 46 EXPECT_FALSE(prefs.read_from_file()); |
47 } | 47 } |
48 | 48 |
49 TEST_F(MasterPreferencesTest, ParseDistroParams) { | 49 TEST_F(MasterPreferencesTest, ParseDistroParams) { |
50 const char text[] = | 50 const char text[] = |
51 "{ \n" | 51 "{ \n" |
52 " \"distribution\": { \n" | 52 " \"distribution\": { \n" |
53 " \"show_welcome_page\": true,\n" | 53 " \"show_welcome_page\": true,\n" |
54 " \"import_search_engine\": true,\n" | 54 " \"import_search_engine\": true,\n" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 }; | 268 }; |
269 | 269 |
270 // Now check that prefs got merged correctly. | 270 // Now check that prefs got merged correctly. |
271 bool value = false; | 271 bool value = false; |
272 for (int i = 0; i < arraysize(expected_bool); ++i) { | 272 for (int i = 0; i < arraysize(expected_bool); ++i) { |
273 EXPECT_TRUE(prefs.GetBool(expected_bool[i].name, &value)); | 273 EXPECT_TRUE(prefs.GetBool(expected_bool[i].name, &value)); |
274 EXPECT_EQ(value, expected_bool[i].expected_value) << expected_bool[i].name; | 274 EXPECT_EQ(value, expected_bool[i].expected_value) << expected_bool[i].name; |
275 } | 275 } |
276 | 276 |
277 // Delete temporary prefs file. | 277 // Delete temporary prefs file. |
278 EXPECT_TRUE(file_util::Delete(prefs_file, false)); | 278 EXPECT_TRUE(base::Delete(prefs_file, false)); |
279 | 279 |
280 // Check that if master prefs doesn't exist, we can still parse the common | 280 // Check that if master prefs doesn't exist, we can still parse the common |
281 // prefs. | 281 // prefs. |
282 cmd_str = L"setup.exe --do-not-launch-chrome"; | 282 cmd_str = L"setup.exe --do-not-launch-chrome"; |
283 cmd_line.ParseFromString(cmd_str); | 283 cmd_line.ParseFromString(cmd_str); |
284 installer::MasterPreferences prefs2(cmd_line); | 284 installer::MasterPreferences prefs2(cmd_line); |
285 ExpectedBooleans expected_bool2[] = { | 285 ExpectedBooleans expected_bool2[] = { |
286 { installer::master_preferences::kDoNotLaunchChrome, true }, | 286 { installer::master_preferences::kDoNotLaunchChrome, true }, |
287 }; | 287 }; |
288 | 288 |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 prefs.GetBool( | 426 prefs.GetBool( |
427 installer::master_preferences::kDoNotCreateQuickLaunchShortcut, | 427 installer::master_preferences::kDoNotCreateQuickLaunchShortcut, |
428 &do_not_create_quick_launch_shortcut); | 428 &do_not_create_quick_launch_shortcut); |
429 prefs.GetBool( | 429 prefs.GetBool( |
430 installer::master_preferences::kDoNotCreateTaskbarShortcut, | 430 installer::master_preferences::kDoNotCreateTaskbarShortcut, |
431 &do_not_create_taskbar_shortcut); | 431 &do_not_create_taskbar_shortcut); |
432 EXPECT_FALSE(do_not_create_desktop_shortcut); | 432 EXPECT_FALSE(do_not_create_desktop_shortcut); |
433 EXPECT_FALSE(do_not_create_quick_launch_shortcut); | 433 EXPECT_FALSE(do_not_create_quick_launch_shortcut); |
434 EXPECT_FALSE(do_not_create_taskbar_shortcut); | 434 EXPECT_FALSE(do_not_create_taskbar_shortcut); |
435 } | 435 } |
OLD | NEW |