| OLD | NEW |
| 1 // Copyright (c) 2009 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_LINUX) | 21 #if defined(OS_LINUX) |
| 22 #include "base/linux_util.h" | 22 #include "base/env_var.h" |
| 23 #endif // defined(OS_LINUX) | 23 #endif // defined(OS_LINUX) |
| 24 | 24 |
| 25 #define FPL FILE_PATH_LITERAL | 25 #define FPL FILE_PATH_LITERAL |
| 26 | 26 |
| 27 #if defined(OS_LINUX) | 27 #if defined(OS_LINUX) |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // Provides mock environment variables values based on a stored map. | 30 // Provides mock environment variables values based on a stored map. |
| 31 class MockEnvironmentVariableGetter : public base::EnvironmentVariableGetter { | 31 class MockEnvVarGetter : public base::EnvVarGetter { |
| 32 public: | 32 public: |
| 33 MockEnvironmentVariableGetter() { | 33 MockEnvVarGetter() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 void Set(const std::string& name, const std::string& value) { | 36 void Set(const std::string& name, const std::string& value) { |
| 37 variables_[name] = value; | 37 variables_[name] = value; |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual bool Getenv(const char* variable_name, std::string* result) { | 40 virtual bool GetEnv(const char* variable_name, std::string* result) { |
| 41 if (ContainsKey(variables_, variable_name)) { | 41 if (ContainsKey(variables_, variable_name)) { |
| 42 *result = variables_[variable_name]; | 42 *result = variables_[variable_name]; |
| 43 return true; | 43 return true; |
| 44 } | 44 } |
| 45 | 45 |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 std::map<std::string, std::string> variables_; | 50 std::map<std::string, std::string> variables_; |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(MockEnvironmentVariableGetter); | 52 DISALLOW_COPY_AND_ASSIGN(MockEnvVarGetter); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { | 57 TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { |
| 58 #if defined(GOOGLE_CHROME_BUILD) | 58 #if defined(GOOGLE_CHROME_BUILD) |
| 59 const char kTemplateFilename[] = "google-chrome.desktop"; | 59 const char kTemplateFilename[] = "google-chrome.desktop"; |
| 60 #else // CHROMIUM_BUILD | 60 #else // CHROMIUM_BUILD |
| 61 const char kTemplateFilename[] = "chromium-browser.desktop"; | 61 const char kTemplateFilename[] = "chromium-browser.desktop"; |
| 62 #endif | 62 #endif |
| 63 | 63 |
| 64 const char kTestData1[] = "a magical testing string"; | 64 const char kTestData1[] = "a magical testing string"; |
| 65 const char kTestData2[] = "a different testing string"; | 65 const char kTestData2[] = "a different testing string"; |
| 66 | 66 |
| 67 MessageLoop message_loop; | 67 MessageLoop message_loop; |
| 68 ChromeThread file_thread(ChromeThread::FILE, &message_loop); | 68 ChromeThread file_thread(ChromeThread::FILE, &message_loop); |
| 69 | 69 |
| 70 { | 70 { |
| 71 ScopedTempDir temp_dir; | 71 ScopedTempDir temp_dir; |
| 72 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 72 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 73 | 73 |
| 74 MockEnvironmentVariableGetter env_getter; | 74 MockEnvVarGetter env_getter; |
| 75 env_getter.Set("XDG_DATA_HOME", temp_dir.path().value()); | 75 env_getter.Set("XDG_DATA_HOME", temp_dir.path().value()); |
| 76 ASSERT_TRUE(file_util::WriteFile( | 76 ASSERT_TRUE(file_util::WriteFile( |
| 77 temp_dir.path().AppendASCII(kTemplateFilename), | 77 temp_dir.path().AppendASCII(kTemplateFilename), |
| 78 kTestData1, strlen(kTestData1))); | 78 kTestData1, strlen(kTestData1))); |
| 79 std::string contents; | 79 std::string contents; |
| 80 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, | 80 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, |
| 81 &contents)); | 81 &contents)); |
| 82 EXPECT_EQ(kTestData1, contents); | 82 EXPECT_EQ(kTestData1, contents); |
| 83 } | 83 } |
| 84 | 84 |
| 85 { | 85 { |
| 86 ScopedTempDir temp_dir; | 86 ScopedTempDir temp_dir; |
| 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 87 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 88 | 88 |
| 89 MockEnvironmentVariableGetter env_getter; | 89 MockEnvVarGetter env_getter; |
| 90 env_getter.Set("XDG_DATA_DIRS", temp_dir.path().value()); | 90 env_getter.Set("XDG_DATA_DIRS", temp_dir.path().value()); |
| 91 ASSERT_TRUE(file_util::CreateDirectory( | 91 ASSERT_TRUE(file_util::CreateDirectory( |
| 92 temp_dir.path().AppendASCII("applications"))); | 92 temp_dir.path().AppendASCII("applications"))); |
| 93 ASSERT_TRUE(file_util::WriteFile( | 93 ASSERT_TRUE(file_util::WriteFile( |
| 94 temp_dir.path().AppendASCII("applications") | 94 temp_dir.path().AppendASCII("applications") |
| 95 .AppendASCII(kTemplateFilename), | 95 .AppendASCII(kTemplateFilename), |
| 96 kTestData2, strlen(kTestData2))); | 96 kTestData2, strlen(kTestData2))); |
| 97 std::string contents; | 97 std::string contents; |
| 98 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, | 98 ASSERT_TRUE(ShellIntegration::GetDesktopShortcutTemplate(&env_getter, |
| 99 &contents)); | 99 &contents)); |
| 100 EXPECT_EQ(kTestData2, contents); | 100 EXPECT_EQ(kTestData2, contents); |
| 101 } | 101 } |
| 102 | 102 |
| 103 { | 103 { |
| 104 ScopedTempDir temp_dir; | 104 ScopedTempDir temp_dir; |
| 105 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 105 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 106 | 106 |
| 107 MockEnvironmentVariableGetter env_getter; | 107 MockEnvVarGetter env_getter; |
| 108 env_getter.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + | 108 env_getter.Set("XDG_DATA_DIRS", temp_dir.path().value() + ":" + |
| 109 temp_dir.path().AppendASCII("applications").value()); | 109 temp_dir.path().AppendASCII("applications").value()); |
| 110 ASSERT_TRUE(file_util::CreateDirectory( | 110 ASSERT_TRUE(file_util::CreateDirectory( |
| 111 temp_dir.path().AppendASCII("applications"))); | 111 temp_dir.path().AppendASCII("applications"))); |
| 112 ASSERT_TRUE(file_util::WriteFile( | 112 ASSERT_TRUE(file_util::WriteFile( |
| 113 temp_dir.path().AppendASCII(kTemplateFilename), | 113 temp_dir.path().AppendASCII(kTemplateFilename), |
| 114 kTestData1, strlen(kTestData1))); | 114 kTestData1, strlen(kTestData1))); |
| 115 ASSERT_TRUE(file_util::WriteFile( | 115 ASSERT_TRUE(file_util::WriteFile( |
| 116 temp_dir.path().AppendASCII("applications") | 116 temp_dir.path().AppendASCII("applications") |
| 117 .AppendASCII(kTemplateFilename), | 117 .AppendASCII(kTemplateFilename), |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 // Non-default profile path should get chrome::kBrowserAppID joined with | 299 // Non-default profile path should get chrome::kBrowserAppID joined with |
| 300 // profile info. | 300 // profile info. |
| 301 FilePath profile_path(FILE_PATH_LITERAL("root")); | 301 FilePath profile_path(FILE_PATH_LITERAL("root")); |
| 302 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); | 302 profile_path = profile_path.Append(FILE_PATH_LITERAL("udd")); |
| 303 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); | 303 profile_path = profile_path.Append(FILE_PATH_LITERAL("User Data - Test")); |
| 304 EXPECT_EQ(std::wstring(chrome::kBrowserAppID) + L".udd.UserDataTest", | 304 EXPECT_EQ(std::wstring(chrome::kBrowserAppID) + L".udd.UserDataTest", |
| 305 ShellIntegration::GetChromiumAppId(profile_path)); | 305 ShellIntegration::GetChromiumAppId(profile_path)); |
| 306 } | 306 } |
| 307 #endif | 307 #endif |
| OLD | NEW |