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

Side by Side Diff: chrome/browser/importer/firefox_importer_utils_unittest.cc

Issue 10830098: Get the Firefox branding name dynamically (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 4 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) 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"
10 #include "ui/base/l10n/l10n_util.h"
6 11
7 #include "chrome/browser/importer/firefox_importer_utils.h" 12 namespace {
8 13
9 struct GetPrefsJsValueCase { 14 struct GetPrefsJsValueCase {
10 std::string prefs_content; 15 std::string prefs_content;
11 std::string pref_name; 16 std::string pref_name;
12 std::string pref_value; 17 std::string pref_value;
13 } GetPrefsJsValueCases[] = { 18 } GetPrefsJsValueCases[] = {
14 // Basic case. Single pref, unquoted value. 19 // Basic case. Single pref, unquoted value.
15 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" }, 20 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" },
16 // Value is quoted. Quotes should be stripped. 21 // Value is quoted. Quotes should be stripped.
17 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" }, 22 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" },
18 // Value has parens. 23 // Value has parens.
19 { "user_pref(\"foo.bar\", \"Value (detail)\");", 24 { "user_pref(\"foo.bar\", \"Value (detail)\");",
20 "foo.bar", "Value (detail)" }, 25 "foo.bar", "Value (detail)" },
21 // Multi-line case. 26 // Multi-line case.
22 { "user_pref(\"foo.bar\", 1);\n" 27 { "user_pref(\"foo.bar\", 1);\n"
23 "user_pref(\"foo.baz\", 2);\n" 28 "user_pref(\"foo.baz\", 2);\n"
24 "user_pref(\"foo.bag\", 3);", 29 "user_pref(\"foo.bag\", 3);",
25 "foo.baz", "2" }, 30 "foo.baz", "2" },
26 // Malformed content. 31 // Malformed content.
27 { "user_pref(\"foo.bar\", 1);\n" 32 { "user_pref(\"foo.bar\", 1);\n"
28 "user_pref(\"foo.baz\", 2;\n" 33 "user_pref(\"foo.baz\", 2;\n"
29 "user_pref(\"foo.bag\", 3);", 34 "user_pref(\"foo.bag\", 3);",
30 "foo.baz", "" }, 35 "foo.baz", "" },
31 // Malformed content. 36 // Malformed content.
32 { "uesr_pref(\"foo.bar\", 1);", "foo.bar", "" }, 37 { "uesr_pref(\"foo.bar\", 1);", "foo.bar", "" },
33 }; 38 };
34 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
35 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) { 93 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) {
36 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) { 94 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) {
37 EXPECT_EQ( 95 EXPECT_EQ(
38 GetPrefsJsValueCases[i].pref_value, 96 GetPrefsJsValueCases[i].pref_value,
39 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content, 97 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content,
40 GetPrefsJsValueCases[i].pref_name)); 98 GetPrefsJsValueCases[i].pref_name));
41 } 99 }
42 } 100 }
101
102 TEST(FirefoxImporterUtilsTest, GetFirefoxImporterName) {
103 ScopedTempDir temp_dir;
104 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
105 const FilePath app_ini_file(temp_dir.path().AppendASCII("application.ini"));
106 for (size_t i = 0; i < arraysize(GetFirefoxImporterNameCases); ++i) {
107 file_util::WriteFile(app_ini_file,
108 GetFirefoxImporterNameCases[i].app_ini_content.c_str(),
109 GetFirefoxImporterNameCases[i].app_ini_content.size());
110 EXPECT_EQ(GetFirefoxImporterName(temp_dir.path()),
111 l10n_util::GetStringUTF16(GetFirefoxImporterNameCases[i].resource_id));
112 }
113 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_IMPORT_FROM_FIREFOX),
114 GetFirefoxImporterName(FilePath(FILE_PATH_LITERAL("/invalid/path"))));
115 }
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils.cc ('k') | chrome/browser/importer/importer_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698