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 "base/file_util.h" | |
6 #include "base/scoped_temp_dir.h" | |
7 #include "chrome/browser/importer/firefox_importer_utils.h" | |
8 #include "grit/generated_resources.h" | |
5 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
6 | 10 #include "ui/base/l10n/l10n_util.h" |
7 #include "chrome/browser/importer/firefox_importer_utils.h" | |
8 | 11 |
9 struct GetPrefsJsValueCase { | 12 struct GetPrefsJsValueCase { |
10 std::string prefs_content; | 13 std::string prefs_content; |
11 std::string pref_name; | 14 std::string pref_name; |
12 std::string pref_value; | 15 std::string pref_value; |
13 } GetPrefsJsValueCases[] = { | 16 } GetPrefsJsValueCases[] = { |
14 // Basic case. Single pref, unquoted value. | 17 // Basic case. Single pref, unquoted value. |
15 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" }, | 18 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" }, |
16 // Value is quoted. Quotes should be stripped. | 19 // Value is quoted. Quotes should be stripped. |
17 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" }, | 20 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" }, |
(...skipping 15 matching lines...) Expand all Loading... | |
33 }; | 36 }; |
34 | 37 |
35 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) { | 38 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) { |
36 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) { | 39 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) { |
37 EXPECT_EQ( | 40 EXPECT_EQ( |
38 GetPrefsJsValueCases[i].pref_value, | 41 GetPrefsJsValueCases[i].pref_value, |
39 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content, | 42 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content, |
40 GetPrefsJsValueCases[i].pref_name)); | 43 GetPrefsJsValueCases[i].pref_name)); |
41 } | 44 } |
42 } | 45 } |
46 | |
47 struct GetFirefoxImporterNameCase { | |
48 std::string app_ini_content; | |
49 int resource_id; | |
50 } GetFirefoxImporterNameCases[] = { | |
51 // Basic case | |
52 { "[App]\n" | |
53 "Vendor=Mozilla\n" | |
54 "Name=Iceweasel\n" | |
55 "Version=10.0.6\n" | |
56 "BuildID=20120717115048\n" | |
57 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}", | |
58 IDS_IMPORT_FROM_ICEWEASEL }, | |
59 // Whitespace | |
60 { " \t[App] \n" | |
61 "Vendor=Mozilla\n" | |
62 " Name=Firefox\t \r\n" | |
63 "Version=10.0.6\n", | |
64 IDS_IMPORT_FROM_FIREFOX }, | |
65 // No Name setting | |
66 { "[App]\n" | |
67 "Vendor=Mozilla\n" | |
68 "Version=10.0.6\n" | |
69 "BuildID=20120717115048\n" | |
70 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}", | |
71 IDS_IMPORT_FROM_FIREFOX }, | |
72 // No [App] section | |
73 { "[Foo]\n" | |
74 "Vendor=Mozilla\n" | |
75 "Name=Foo\n", | |
76 IDS_IMPORT_FROM_FIREFOX }, | |
77 // Multiple Name settings in different sections | |
78 { "[Foo]\n" | |
79 "Vendor=Mozilla\n" | |
80 "Name=Firefox\n" | |
81 "[App]\n" | |
82 "Profile=mozilla/firefox\n" | |
83 "Name=iceweasel\n" | |
Ilya Sherman
2012/08/07 21:52:21
nit: Perhaps add a separate test case for case-ins
cristian.patrasciuc
2012/08/08 15:20:52
Done.
| |
84 "[Bar]\n" | |
85 "Name=Bar\n" | |
86 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}", | |
87 IDS_IMPORT_FROM_ICEWEASEL }, | |
88 // Empty file | |
89 { "", IDS_IMPORT_FROM_FIREFOX } | |
90 }; | |
Ilya Sherman
2012/08/07 21:52:21
nit: Please move this definition either into the t
cristian.patrasciuc
2012/08/08 15:20:52
Done. I also moved the other definition inside the
| |
91 | |
92 TEST(FirefoxImporterUtilsTest, GetFirefoxImporterName) { | |
93 ScopedTempDir temp_dir; | |
94 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
95 const FilePath app_ini_file(temp_dir.path().Append("application.ini")); | |
96 for (size_t i = 0; i < arraysize(GetFirefoxImporterNameCases); ++i) { | |
97 file_util::WriteFile(app_ini_file, | |
98 GetFirefoxImporterNameCases[i].app_ini_content.c_str(), | |
99 GetFirefoxImporterNameCases[i].app_ini_content.size()); | |
100 EXPECT_EQ(GetFirefoxImporterName(temp_dir.path()), | |
101 l10n_util::GetStringUTF16(GetFirefoxImporterNameCases[i].resource_id)); | |
102 } | |
103 EXPECT_EQ(GetFirefoxImporterName(FilePath("/invalid/path")), | |
104 l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX)); | |
105 } | |
OLD | NEW |