diff options
author | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-05 07:52:59 +0000 |
---|---|---|
committer | mgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-05 07:52:59 +0000 |
commit | 07753f0feaf23c21a62334f22b0cb05cac4b8d84 (patch) | |
tree | 96dfc0f8edb8d3d7c1ca4f2e4ce508f0c0517928 /chrome/browser/shell_integration_unittest.cc | |
parent | 853d93537201b82291f0d16a8124d940e5d3fff7 (diff) | |
download | chromium_src-07753f0feaf23c21a62334f22b0cb05cac4b8d84.zip chromium_src-07753f0feaf23c21a62334f22b0cb05cac4b8d84.tar.gz chromium_src-07753f0feaf23c21a62334f22b0cb05cac4b8d84.tar.bz2 |
App shortcut creation on Linux now removes localized versions of the Name key.
Previously, if the Chrome .desktop file had a localized string for the app name,
and the user was in a non-US locale, the localized string would be copied
(unmodified) to the app shortcut, and the app name would display as a localized
version "Google Chrome" or "Chromium Browser" instead of the actual app name.
BUG=173324
Review URL: https://chromiumcodereview.appspot.com/12114044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180634 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/shell_integration_unittest.cc')
-rw-r--r-- | chrome/browser/shell_integration_unittest.cc | 82 |
1 files changed, 67 insertions, 15 deletions
diff --git a/chrome/browser/shell_integration_unittest.cc b/chrome/browser/shell_integration_unittest.cc index 7179cbc..8dbb3e7 100644 --- a/chrome/browser/shell_integration_unittest.cc +++ b/chrome/browser/shell_integration_unittest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/shell_integration.h" +#include <cstdlib> #include <map> #include "base/file_path.h" @@ -65,6 +66,43 @@ class MockEnvironment : public base::Environment { DISALLOW_COPY_AND_ASSIGN(MockEnvironment); }; +// Allows you to change the real environment, but reverts changes upon +// destruction. +class ScopedEnvironment { + public: + ScopedEnvironment() {} + + ~ScopedEnvironment() { + for (std::map<std::string, std::string>::const_iterator + it = old_variables_.begin(); it != old_variables_.end(); ++it) { + if (it->second.empty()) { + unsetenv(it->first.c_str()); + } else { + setenv(it->first.c_str(), it->second.c_str(), 1); + } + } + } + + void Set(const std::string& name, const std::string& value) { + if (!ContainsKey(old_variables_, name)) { + const char* value = getenv(name.c_str()); + if (value != NULL) { + old_variables_[name] = value; + } else { + old_variables_[name] = std::string(); + } + } + setenv(name.c_str(), value.c_str(), 1); + } + + private: + // Map from name to original value, or the empty string if there was no + // previous value. + std::map<std::string, std::string> old_variables_; + + DISALLOW_COPY_AND_ASSIGN(ScopedEnvironment); +}; + } // namespace TEST(ShellIntegrationTest, GetDesktopShortcutTemplate) { @@ -179,6 +217,7 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "Version=1.0\n" "Encoding=UTF-8\n" "Name=Google Chrome\n" + "GenericName=Web Browser\n" "Comment=The web browser from Google\n" "Exec=/opt/google/chrome/google-chrome %U\n" "Terminal=false\n" @@ -204,8 +243,8 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "Type=Application\n" "Categories=Application;Network;WebBrowser;\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=gmail.com\n" #endif }, @@ -226,20 +265,26 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" "Icon=chrome-http__gmail.com\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=gmail.com\n" #endif }, - // Make sure i18n-ed comments are removed. + // Make sure i18n-ed names and other fields are removed. { "http://gmail.com", "GMail", "chrome-http__gmail.com", "[Desktop Entry]\n" "Name=Google Chrome\n" + "Name[en_AU]=Google Chrome\n" + "Name[pl]=Google Chrome\n" + "GenericName=Web Browser\n" + "GenericName[en_AU]=Web Browser\n" + "GenericName[pl]=Navegador Web\n" "Exec=/opt/google/chrome/google-chrome %U\n" + "Comment[en_AU]=Some comment.\n" "Comment[pl]=Jakis komentarz.\n", "#!/usr/bin/env xdg-open\n" @@ -248,8 +293,8 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" "Icon=chrome-http__gmail.com\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=gmail.com\n" #endif }, @@ -271,8 +316,8 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "Exec=/opt/google/chrome/google-chrome --app=http://gmail.com/\n" "Icon=/opt/google/chrome/product_logo_48.png\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=gmail.com\n" #endif }, @@ -293,8 +338,8 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "--app=http://evil.com/evil%20--join-the-b0tnet\n" "Icon=chrome-http__evil.com_evil\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=evil.com__evil%20--join-the-b0tnet\n" #endif }, @@ -317,8 +362,8 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "-rf%20\\\\$HOME%20%3Eownz0red\"\n" "Icon=chrome-http__evil.com_evil\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=evil.com__evil;%20rm%20-rf%20_;%20%22;%20" "rm%20-rf%20$HOME%20%3Eownz0red\n" #endif @@ -339,13 +384,20 @@ TEST(ShellIntegrationTest, GetDesktopFileContents) { "%60%20%3E/dev/null\n" "Icon=chrome-http__evil.com_evil\n" #if !defined(USE_AURA) - // Aura Chrome creates browser window in a single X11 window, so - // WMClass does not matter. + // Aura Chrome does not (yet) set WMClass, so we only expect + // StartupWMClass on non-Aura builds. "StartupWMClass=evil.com__evil%20%7C%20cat%20%60echo%20ownz0red" "%60%20%3E_dev_null\n" #endif }, }; + + // Set the language to en_AU. This causes glib to copy the en_AU localized + // strings into the shortcut file. (We want to test that they are removed.) + ScopedEnvironment env; + env.Set("LC_ALL", "en_AU.UTF-8"); + env.Set("LANGUAGE", "en_AU.UTF-8"); + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); i++) { SCOPED_TRACE(i); EXPECT_EQ( |