Add DriveAppRegistryObserver.
[chromium-blink-merge.git] / base / nix / xdg_util_unittest.cc
blob2fc9d4c5c474d1af2e7ede464e71960e2af15f32
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 const char* kGnome = "gnome";
29 const char* kKDE4 = "kde4";
30 const char* kKDE = "kde";
31 const char* kXFCE = "xfce";
33 } // namespace
35 TEST(XDGUtilTest, GetDesktopEnvironmentGnome) {
36 MockEnvironment getter;
37 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
38 EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
39 .WillOnce(DoAll(SetArgumentPointee<1>(kGnome), Return(true)));
41 EXPECT_EQ(DESKTOP_ENVIRONMENT_GNOME,
42 GetDesktopEnvironment(&getter));
45 TEST(XDGUtilTest, GetDesktopEnvironmentKDE4) {
46 MockEnvironment getter;
47 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
48 EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
49 .WillOnce(DoAll(SetArgumentPointee<1>(kKDE4), Return(true)));
51 EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE4,
52 GetDesktopEnvironment(&getter));
55 TEST(XDGUtilTest, GetDesktopEnvironmentKDE3) {
56 MockEnvironment getter;
57 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
58 EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
59 .WillOnce(DoAll(SetArgumentPointee<1>(kKDE), Return(true)));
61 EXPECT_EQ(DESKTOP_ENVIRONMENT_KDE3,
62 GetDesktopEnvironment(&getter));
65 TEST(XDGUtilTest, GetDesktopEnvironmentXFCE) {
66 MockEnvironment getter;
67 EXPECT_CALL(getter, GetVar(_, _)).WillRepeatedly(Return(false));
68 EXPECT_CALL(getter, GetVar(StrEq("DESKTOP_SESSION"), _))
69 .WillOnce(DoAll(SetArgumentPointee<1>(kXFCE), Return(true)));
71 EXPECT_EQ(DESKTOP_ENVIRONMENT_XFCE,
72 GetDesktopEnvironment(&getter));
75 } // namespace nix
76 } // namespace base