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

Side by Side Diff: chrome/browser/shell_integration_unittest.cc

Issue 3052034: base: Rename EnvVarGetter to Environment. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: review Created 10 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
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 "chrome/browser/shell_integration.h" 5 #include "chrome/browser/shell_integration.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/scoped_temp_dir.h" 12 #include "base/scoped_temp_dir.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/chrome_thread.h" 15 #include "chrome/browser/chrome_thread.h"
16 #include "chrome/common/chrome_constants.h" 16 #include "chrome/common/chrome_constants.h"
17 #include "chrome/common/chrome_paths_internal.h" 17 #include "chrome/common/chrome_paths_internal.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 #if defined(OS_WIN) 21 #if defined(OS_WIN)
22 #include "chrome/installer/util/browser_distribution.h" 22 #include "chrome/installer/util/browser_distribution.h"
23 #elif defined(OS_LINUX) 23 #elif defined(OS_LINUX)
24 #include "base/env_var.h" 24 #include "base/environment.h"
25 #endif // defined(OS_LINUX) 25 #endif // defined(OS_LINUX)
26 26
27 #define FPL FILE_PATH_LITERAL 27 #define FPL FILE_PATH_LITERAL
28 28
29 #if defined(OS_LINUX) 29 #if defined(OS_LINUX)
30 namespace { 30 namespace {
31 31
32 // Provides mock environment variables values based on a stored map. 32 // Provides mock environment variables values based on a stored map.
33 class MockEnvVarGetter : public base::EnvVarGetter { 33 class MockEnvironment : public base::Environment {
34 public: 34 public:
35 MockEnvVarGetter() {} 35 MockEnvironment() {}
36 36
37 void Set(const std::string& name, const std::string& value) { 37 void Set(const std::string& name, const std::string& value) {
38 variables_[name] = value; 38 variables_[name] = value;
39 } 39 }
40 40
41 virtual bool GetEnv(const char* variable_name, std::string* result) { 41 virtual bool GetEnv(const char* variable_name, std::string* result) {
42 if (ContainsKey(variables_, variable_name)) { 42 if (ContainsKey(variables_, variable_name)) {
43 *result = variables_[variable_name]; 43 *result = variables_[variable_name];
44 return true; 44 return true;
45 } 45 }
46 46
47 return false; 47 return false;
48 } 48 }
49 49
50 virtual bool SetEnv(const char* variable_name, const std::string& new_value) { 50 virtual bool SetEnv(const char* variable_name, const std::string& new_value) {
51 ADD_FAILURE(); 51 ADD_FAILURE();
52 return false; 52 return false;
53 } 53 }
54 54
55 virtual bool UnSetEnv(const char* variable_name) { 55 virtual bool UnSetEnv(const char* variable_name) {
56 ADD_FAILURE(); 56 ADD_FAILURE();
57 return false; 57 return false;
58 } 58 }
59 59
60 private: 60 private:
61 std::map<std::string, std::string> variables_; 61 std::map<std::string, std::string> variables_;
62 62
63 DISALLOW_COPY_AND_ASSIGN(MockEnvVarGetter); 63 DISALLOW_COPY_AND_ASSIGN(MockEnvironment);
64 }; 64 };
65 65
66 } // namespace 66 } // namespace
67 67
68 TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { 68 TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) {
69 #if defined(GOOGLE_CHROME_BUILD) 69 #if defined(GOOGLE_CHROME_BUILD)
70 const char kTemplateFilename[] = "google-chrome.desktop"; 70 const char kTemplateFilename[] = "google-chrome.desktop";
71 #else // CHROMIUM_BUILD 71 #else // CHROMIUM_BUILD
72 const char kTemplateFilename[] = "chromium-browser.desktop"; 72 const char kTemplateFilename[] = "chromium-browser.desktop";
73 #endif 73 #endif
74 74
75 const char kTestData1[] = "a magical testing string"; 75 const char kTestData1[] = "a magical testing string";
76 const char kTestData2[] = "a different testing string"; 76 const char kTestData2[] = "a different testing string";
77 77
78 MessageLoop message_loop; 78 MessageLoop message_loop;
79 ChromeThread file_thread(ChromeThread::FILE, &message_loop); 79 ChromeThread file_thread(ChromeThread::FILE, &message_loop);
80 80
81 { 81 {
82 ScopedTempDir temp_dir; 82 ScopedTempDir temp_dir;
83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
84 84
85 MockEnvVarGetter env_getter; 85 MockEnvironment env;
86 env_getter.Set("XDG_DATA_HOME", temp_dir.path().value()); 86 env.Set("XDG_DATA_HOME", temp_dir.path().value());
87 ASSERT_TRUE(file_util::WriteFile( 87 ASSERT_TRUE(file_util::WriteFile(
88 temp_dir.path().AppendASCII(kTemplateFilename), 88 temp_dir.path().AppendASCII(kTemplateFilename),
89 kTestData1, strlen(kTestData1))); 89 kTestData1, strlen(kTestData1)));
90 std::string contents; 90 std::string contents;
91 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, 91 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
92 &contents)); 92 &contents));
93 EXPECT_EQ(kTestData1, contents); 93 EXPECT_EQ(kTestData1, contents);
94 } 94 }
95 95
96 { 96 {
97 ScopedTempDir temp_dir; 97 ScopedTempDir temp_dir;
98 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 98 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
99 99
100 MockEnvVarGetter env_getter; 100 MockEnvironment env;
101 env_getter.Set("XDG_DATA_DIRS", temp_dir.path().value()); 101 env.Set("XDG_DATA_DIRS", temp_dir.path().value());
102 ASSERT_TRUE(file_util::CreateDirectory( 102 ASSERT_TRUE(file_util::CreateDirectory(
103 temp_dir.path().AppendASCII("applications"))); 103 temp_dir.path().AppendASCII("applications")));
104 ASSERT_TRUE(file_util::WriteFile( 104 ASSERT_TRUE(file_util::WriteFile(
105 temp_dir.path().AppendASCII("applications") 105 temp_dir.path().AppendASCII("applications")
106 .AppendASCII(kTemplateFilename), 106 .AppendASCII(kTemplateFilename),
107 kTestData2, strlen(kTestData2))); 107 kTestData2, strlen(kTestData2)));
108 std::string contents; 108 std::string contents;
109 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, 109 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
110 &contents)); 110 &contents));
111 EXPECT_EQ(kTestData2, contents); 111 EXPECT_EQ(kTestData2, contents);
112 } 112 }
113 113
114 { 114 {
115 ScopedTempDir temp_dir; 115 ScopedTempDir temp_dir;
116 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 116 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
117 117
118 MockEnvVarGetter env_getter; 118 MockEnvironment env;
119 env_getter.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + 119 env.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" +
120 temp_dir.path().AppendASCII("applications").value()); 120 temp_dir.path().AppendASCII("applications").value());
121 ASSERT_TRUE(file_util::CreateDirectory( 121 ASSERT_TRUE(file_util::CreateDirectory(
122 temp_dir.path().AppendASCII("applications"))); 122 temp_dir.path().AppendASCII("applications")));
123 ASSERT_TRUE(file_util::WriteFile( 123 ASSERT_TRUE(file_util::WriteFile(
124 temp_dir.path().AppendASCII(kTemplateFilename), 124 temp_dir.path().AppendASCII(kTemplateFilename),
125 kTestData1, strlen(kTestData1))); 125 kTestData1, strlen(kTestData1)));
126 ASSERT_TRUE(file_util::WriteFile( 126 ASSERT_TRUE(file_util::WriteFile(
127 temp_dir.path().AppendASCII("applications") 127 temp_dir.path().AppendASCII("applications")
128 .AppendASCII(kTemplateFilename), 128 .AppendASCII(kTemplateFilename),
129 kTestData2, strlen(kTestData2))); 129 kTestData2, strlen(kTestData2)));
130 std::string contents; 130 std::string contents;
131 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, 131 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env,
132 &contents)); 132 &contents));
133 EXPECT_EQ(kTestData1, contents); 133 EXPECT_EQ(kTestData1, contents);
134 } 134 }
135 } 135 }
136 136
137 TEST(ShellIntegrationTest, GetDesktopShortcutFilename) { 137 TEST(ShellIntegrationTest, GetDesktopShortcutFilename) {
138 const struct { 138 const struct {
139 const FilePath::CharType* path; 139 const FilePath::CharType* path;
140 const char* url; 140 const char* url;
141 } test_cases[] = { 141 } test_cases[] = {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // Non-default profile path should get chrome::kBrowserAppID joined with 309 // Non-default profile path should get chrome::kBrowserAppID joined with
310 // profile info. 310 // profile info.
311 FilePath profile_path(FILE_PATH_LITERAL("root")); 311 FilePath profile_path(FILE_PATH_LITERAL("root"));
312 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); 312 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd"));
313 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); 313 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test"));
314 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId() + 314 EXPECT_EQ(BrowserDistribution::GetDistribution()->GetBrowserAppId() +
315 L".udd.UserDataTest", 315 L".udd.UserDataTest",
316 ShellIntegration::GetChromiumAppId(profile_path)); 316 ShellIntegration::GetChromiumAppId(profile_path));
317 } 317 }
318 #endif 318 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698