Add devil dir to telemetry isolate files for GN builds of gpu_tests.
[chromium-blink-merge.git] / base / nix / xdg_util_unittest.cc
blob136eb5d745d7df331ce5fc88b010bef263fc5709
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
3 // found in the LICENSE file.
5 #include "base/nix/xdg_util.h"
7 #include "base/environment.h"
8 #include "testing/gmock/include/gmock/gmock.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 using ::testing::_;
12 using ::testing::Return;
13 using ::testing::SetArgumentPointee;
14 using ::testing::StrEq;
16 namespace base {
17 namespace nix {
19 namespace {
21 class MockEnvironment : public Environment {
22 public:
23 MOCK_METHOD2(GetVar, bool(const char*, std::string* result));
24 MOCK_METHOD2(SetVar, bool(const char*, const std::string& new_value));
25 MOCK_METHOD1(UnSetVar, bool(const char*));
28 // Needs to be const char* to make gmock happy.
29 const char* const kDesktopGnome = "gnome";
30 const char* const kDesktopGnomeFallback = "gnome-fallback";
31 const char* const kDesktopMATE = "mate";
32 const char* const kDesktopKDE4 = "kde4";
33 const char* const kDesktopKDE = "kde";
34 const char* const kDesktopXFCE = "xfce";
35 const char* const kXdgDesktopGNOME = "GNOME";
36 const char* const kXdgDesktopKDE = "KDE";
37 const char* const kXdgDesktopUnity = "Unity";
39 const char kDesktopSession[] = "DESKTOP_SESSION";
40 const char kXdgDesktop[] = "XDG_CURRENT_DESKTOP";
42 } // namespace
44 TEST(XDGUtilTest, GetDesktopEnvironmentGnome) {
45 MockEnvironment getter;
46 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
47 EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
48 .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopGnome), Return(true)));
50 EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
53 TEST(XDGUtilTest, GetDesktopEnvironmentMATE) {
54 MockEnvironment getter;
55 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
56 EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
57 .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopMATE), Return(true)));
59 EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
62 TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) {
63 MockEnvironment getter;
64 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
65 EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
66 .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopKDE4), Return(true)));
68 EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4, GetDesktopEnvironment(&getter));
71 TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) {
72 MockEnvironment getter;
73 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
74 EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
75 .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopKDE), Return(true)));
77 EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE3, GetDesktopEnvironment(&getter));
80 TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) {
81 MockEnvironment getter;
82 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
83 EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
84 .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopXFCE), Return(true)));
86 EXPECT_EQ(DESKTOP_ENVIRONMENT_XFCE, GetDesktopEnvironment(&getter));
89 TEST(XDGUtilTest, GetXdgDesktopGnome) {
90 MockEnvironment getter;
91 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
92 EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
93 .WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopGNOME), Return(true)));
95 EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
98 TEST(XDGUtilTest, GetXdgDesktopGnomeFallback) {
99 MockEnvironment getter;
100 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
101 EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
102 .WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopUnity), Return(true)));
103 EXPECT_CALL(getter, GetVar(StrEq(kDesktopSession), _))
104 .WillOnce(DoAll(SetArgumentPointee<1>(kDesktopGnomeFallback),
105 Return(true)));
107 EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME, GetDesktopEnvironment(&getter));
110 TEST(XDGUtilTest, GetXdgDesktopKDE4) {
111 MockEnvironment getter;
112 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
113 EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
114 .WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopKDE), Return(true)));
116 EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4, GetDesktopEnvironment(&getter));
119 TEST(XDGUtilTest, GetXdgDesktopUnity) {
120 MockEnvironment getter;
121 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
122 EXPECT_CALL(getter, GetVar(StrEq(kXdgDesktop), _))
123 .WillOnce(DoAll(SetArgumentPointee<1>(kXdgDesktopUnity), Return(true)));
125 EXPECT_EQ(DESKTOP_ENVIRONMENT_UNITY, GetDesktopEnvironment(&getter));
128 } // namespace nix
129 } // namespace base