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

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"
5 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
6 9
7 #include "chrome/browser/importer/firefox_importer_utils.h"
8
9 struct GetPrefsJsValueCase { 10 struct GetPrefsJsValueCase {
10 std::string prefs_content; 11 std::string prefs_content;
11 std::string pref_name; 12 std::string pref_name;
12 std::string pref_value; 13 std::string pref_value;
13 } GetPrefsJsValueCases[] = { 14 } GetPrefsJsValueCases[] = {
14 // Basic case. Single pref, unquoted value. 15 // Basic case. Single pref, unquoted value.
15 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" }, 16 { "user_pref(\"foo.bar\", 1);", "foo.bar", "1" },
16 // Value is quoted. Quotes should be stripped. 17 // Value is quoted. Quotes should be stripped.
17 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" }, 18 { "user_pref(\"foo.bar\", \"1\");", "foo.bar", "1" },
18 // Value has parens. 19 // Value has parens.
(...skipping 14 matching lines...) Expand all
33 }; 34 };
34 35
35 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) { 36 TEST(FirefoxImporterUtilsTest, GetPrefsJsValue) {
36 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) { 37 for (size_t i = 0; i < arraysize(GetPrefsJsValueCases); ++i) {
37 EXPECT_EQ( 38 EXPECT_EQ(
38 GetPrefsJsValueCases[i].pref_value, 39 GetPrefsJsValueCases[i].pref_value,
39 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content, 40 GetPrefsJsValue(GetPrefsJsValueCases[i].prefs_content,
40 GetPrefsJsValueCases[i].pref_name)); 41 GetPrefsJsValueCases[i].pref_name));
41 } 42 }
42 } 43 }
44
45 struct GetFirefoxBrandingNameCase {
46 std::string app_ini_content;
47 std::string branding_name;
48 } GetFirefoxBrandingNameCases[] = {
49 // Basic case
50 { "[App]\n"
51 "Vendor=Mozilla\n"
52 "Name=CUSTOM_NAME\n"
53 "Version=10.0.6\n"
54 "BuildID=20120717115048\n"
55 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
56 "CUSTOM_NAME" },
57 // Whitespace
58 { " \t[App] \n"
59 "Vendor=Mozilla\n"
60 " Name=CUSTOM_NAME\t \r\n"
61 "Version=10.0.6\n",
62 "CUSTOM_NAME" },
63 // No Name setting
64 { "[App]\n"
65 "Vendor=Mozilla\n"
66 "Version=10.0.6\n"
67 "BuildID=20120717115048\n"
68 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
69 "" },
70 // No [App] section
71 { "[Foo]\n"
72 "Vendor=Mozilla\n"
73 "Name=Foo\n",
74 "" },
75 // Multiple Name settings in different sections
76 { "[Foo]\n"
77 "Vendor=Mozilla\n"
78 "Name=Foo\n"
79 "[App]\n"
80 "Profile=mozilla/firefox\n"
81 "Name=CUSTOM_NAME\n"
82 "[Bar]\n"
83 "Name=Bar\n"
84 "ID={ec8030f7-c20a-464f-9b0e-13a3a9e97384}",
85 "CUSTOM_NAME" },
86 // Empty file
87 { "", "" }
88 };
89
90 TEST(FirefoxImporterUtilsTest, GetFirefoxBrandingName) {
91 ScopedTempDir temp_dir;
92 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
93 const FilePath app_ini_file(temp_dir.path().Append("application.ini"));
94 for (size_t i = 0; i < arraysize(GetFirefoxBrandingNameCases); ++i) {
95 file_util::WriteFile(app_ini_file,
96 GetFirefoxBrandingNameCases[i].app_ini_content.c_str(),
97 GetFirefoxBrandingNameCases[i].app_ini_content.size());
98 EXPECT_EQ(GetFirefoxBrandingNameCases[i].branding_name,
99 GetFirefoxBrandingName(temp_dir.path()));
100 }
101 EXPECT_EQ("", GetFirefoxBrandingName(FilePath("/invalid/path")));
102 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698