OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/file_util.h" | |
6 #include "base/files/scoped_temp_dir.h" | |
7 #include "chrome/browser/importer/firefox_importer_utils.h" | |
8 #include "grit/generated_resources.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 | |
12 namespace { | |
13 | |
14 struct GetPrefsJsValueCase { | |
15 std::string prefs_content; | |
16 std::string pref_name; | |
17 std::string pref_value; | |
18 } GetPrefsJsValueCases[] = { | |
19 // Basic case. Single pref, unquoted value. | |
20 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" }, | |
21 // Value is quoted. Quotes should be stripped. | |
22 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" }, | |
23 // Value has parens. | |
24 { "user_pref(\"foo.bar\", \"Value (detail)\");", | |
25 "foo.bar", "Value (detail)" }, | |
26 // Multi-line case. | |
27 { "user_pref(\"foo.bar\", 1);\n" | |
28 "user_pref(\"foo.baz\", 2);\n" | |
29 "user_pref(\"foo.bag\", 3);", | |
30 "foo.baz", "2" }, | |
31 // Malformed content. | |
32 { "user_pref(\"foo.bar\", 1);\n" | |
33 "user_pref(\"foo.baz\", 2;\n" | |
34 "user_pref(\"foo.bag\", 3);", | |
35 "foo.baz", "" }, | |
36 // Malformed content. | |
37 { "uesr_pref(\"foo.bar\", 1);", "foo.bar", "" }, | |
38 }; | |
39 | |
40 struct GetFirefoxImporterNameCase { | |
41 std::string app_ini_content; | |
42 int resource_id; | |
43 } GetFirefoxImporterNameCases[] = { | |
44 // Basic case | |
45 { "[App]\n" | |
46 "Vendor=Mozilla\n" | |
47 "Name=iceweasel\n" | |
48 "Version=10.0.6\n" | |
49 "BuildID=20120717115048\n" | |
50 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}", | |
51 IDS_IMPORT_FROM_ICEWEASEL }, | |
52 // Whitespace | |
53 { " \t[App] \n" | |
54 "Vendor=Mozilla\n" | |
55 " Name=Firefox\t \r\n" | |
56 "Version=10.0.6\n", | |
57 IDS_IMPORT_FROM_FIREFOX }, | |
58 // No Name setting | |
59 { "[App]\n" | |
60 "Vendor=Mozilla\n" | |
61 "Version=10.0.6\n" | |
62 "BuildID=20120717115048\n" | |
63 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}", | |
64 IDS_IMPORT_FROM_FIREFOX }, | |
65 // No [App] section | |
66 { "[Foo]\n" | |
67 "Vendor=Mozilla\n" | |
68 "Name=Foo\n", | |
69 IDS_IMPORT_FROM_FIREFOX }, | |
70 // Multiple Name settings in different sections | |
71 { "[Foo]\n" | |
72 "Vendor=Mozilla\n" | |
73 "Name=Firefox\n" | |
74 "[App]\n" | |
75 "Profile=mozilla/firefox\n" | |
76 "Name=iceweasel\n" | |
77 "[Bar]\n" | |
78 "Name=Bar\n" | |
79 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}", | |
80 IDS_IMPORT_FROM_ICEWEASEL }, | |
81 // Case-insensitivity | |
82 { "[App]\n" | |
83 "Vendor=Mozilla\n" | |
84 "Name=IceWeasel\n" | |
85 "Version=10.0.6\n", | |
86 IDS_IMPORT_FROM_ICEWEASEL }, | |
87 // Empty file | |
88 { "", IDS_IMPORT_FROM_FIREFOX } | |
89 }; | |
90 | |
91 } // anonymous namespace | |
92 | |
93 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) { | |
94 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) { | |
95 EXPECT_EQ( | |
96 GetPrefsJsValueCases[i].pref_value, | |
97 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content, | |
98 GetPrefsJsValueCases[i].pref_name)); | |
99 } | |
100 } | |
101 | |
102 TEST(FirefoxImporterUtilsTest, GetFirefoxImporterName) { | |
103 base::ScopedTempDir temp_dir; | |
104 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
105 const base::FilePath app_ini_file( | |
106 temp_dir.path().AppendASCII("application.ini")); | |
107 for (size_t i = 0; i < arraysize(GetFirefoxImporterNameCases); ++i) { | |
108 file_util::WriteFile(app_ini_file, | |
109 GetFirefoxImporterNameCases[i].app_ini_content.c_str(), | |
110 GetFirefoxImporterNameCases[i].app_ini_content.size()); | |
111 EXPECT_EQ(GetFirefoxImporterName(temp_dir.path()), | |
112 l10n_util::GetStringUTF16(GetFirefoxImporterNameCases[i].resource_id)); | |
113 } | |
114 EXPECT_EQ(l10n_util::GetStringUTF16( | |
115 IDS_IMPORT_FROM_FIREFOX), | |
116 GetFirefoxImporterName(base::FilePath( | |
117 FILE_PATH_LITERAL("/invalid/path")))); | |
118 } | |
OLD | NEW |