summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--base/base.gyp3
-rw-r--r--base/linux_util.cc10
-rw-r--r--base/linux_util.h3
-rw-r--r--base/linux_util_unittest.cc69
4 files changed, 79 insertions, 6 deletions
diff --git a/base/base.gyp b/base/base.gyp
index bccac47..938b05c 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -170,6 +170,9 @@
'file_version_info_unittest.cc',
'worker_pool_linux_unittest.cc',
],
+ 'sources': [
+ 'linux_util_unittest.cc',
+ ],
'dependencies': [
'../build/linux/system.gyp:gtk',
'../build/linux/system.gyp:nss',
diff --git a/base/linux_util.cc b/base/linux_util.cc
index b552b93..6197bc3 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -229,18 +229,18 @@ FilePath GetXDGUserDirectory(EnvVarGetter* env, const char* dir_name,
DesktopEnvironment GetDesktopEnvironment(EnvVarGetter* env) {
std::string desktop_session;
if (env->GetEnv("DESKTOP_SESSION", &desktop_session)) {
- if (desktop_session == "gnome")
+ if (desktop_session == "gnome") {
return DESKTOP_ENVIRONMENT_GNOME;
- else if (desktop_session == "kde4")
+ } else if (desktop_session == "kde4") {
return DESKTOP_ENVIRONMENT_KDE4;
- else if (desktop_session == "kde") {
+ } else if (desktop_session == "kde") {
// This may mean KDE4 on newer systems, so we have to check.
if (env->HasEnv("KDE_SESSION_VERSION"))
return DESKTOP_ENVIRONMENT_KDE4;
return DESKTOP_ENVIRONMENT_KDE3;
- }
- else if (desktop_session == "xfce4")
+ } else if (desktop_session.find("xfce") != std::string::npos) {
return DESKTOP_ENVIRONMENT_XFCE;
+ }
}
// Fall back on some older environment variables.
diff --git a/base/linux_util.h b/base/linux_util.h
index 370a65e..1458cfb 100644
--- a/base/linux_util.h
+++ b/base/linux_util.h
@@ -10,11 +10,12 @@
#include <string>
-class EnvVarGetter;
class FilePath;
namespace base {
+class EnvVarGetter;
+
static const char kFindInodeSwitch[] = "--find-inode";
// Makes a copy of |pixels| with the ordering changed from BGRA to RGBA.
diff --git a/base/linux_util_unittest.cc b/base/linux_util_unittest.cc
new file mode 100644
index 0000000..d904080
--- /dev/null
+++ b/base/linux_util_unittest.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/linux_util.h"
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+#include "base/env_var.h"
+
+using ::testing::_;
+using ::testing::Return;
+using ::testing::SetArgumentPointee;
+using ::testing::StrEq;
+
+class MockEnvVarGetter : public base::EnvVarGetter {
+ public:
+ MOCK_METHOD2(GetEnv, bool(const char*, std::string* result));
+};
+
+namespace {
+
+const char* kGnome = "gnome";
+const char* kKDE4 = "kde4";
+const char* kKDE = "kde";
+const char* kXFCE = "xfce";
+
+} // namespace
+
+TEST(LinuxUtilTest, GetDesktopEnvironmentGnome) {
+ MockEnvVarGetter getter;
+ EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
+ EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(kGnome), Return(true)));
+
+ EXPECT_EQ(base::DESKTOP_ENVIRONMENT_GNOME,
+ base::GetDesktopEnvironment(&getter));
+}
+
+TEST(LinuxUtilTest, GetDesktopEnvironmentKDE4) {
+ MockEnvVarGetter getter;
+ EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
+ EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(kKDE4), Return(true)));
+
+ EXPECT_EQ(base::DESKTOP_ENVIRONMENT_KDE4,
+ base::GetDesktopEnvironment(&getter));
+}
+
+TEST(LinuxUtilTest, GetDesktopEnvironmentKDE3) {
+ MockEnvVarGetter getter;
+ EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
+ EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(kKDE), Return(true)));
+
+ EXPECT_EQ(base::DESKTOP_ENVIRONMENT_KDE3,
+ base::GetDesktopEnvironment(&getter));
+}
+
+TEST(LinuxUtilTest, GetDesktopEnvironmentXFCE) {
+ MockEnvVarGetter getter;
+ EXPECT_CALL(getter, GetEnv(_, _)).WillRepeatedly(Return(false));
+ EXPECT_CALL(getter, GetEnv(StrEq("DESKTOP_SESSION"), _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(kXFCE), Return(true)));
+
+ EXPECT_EQ(base::DESKTOP_ENVIRONMENT_XFCE,
+ base::GetDesktopEnvironment(&getter));
+}