kiosk_mode_idle_logout_unittest.cc revision 9ab5563a3196760eb381d102cbb2bc0f7abc6a50
1// Copyright (c) 2012 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.
4
5#include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_idle_logout.h"
6
7#include "ash/shell.h"
8#include "ash/test/ash_test_base.h"
9#include "ash/wm/user_activity_detector.h"
10#include "base/bind.h"
11#include "base/memory/scoped_ptr.h"
12#include "base/message_loop/message_loop.h"
13#include "base/synchronization/waitable_event.h"
14#include "chrome/browser/chrome_notification_types.h"
15#include "chrome/browser/chromeos/login/user_manager.h"
16#include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
17#include "content/public/browser/browser_thread.h"
18#include "content/public/browser/notification_registrar.h"
19#include "content/public/browser/notification_service.h"
20#include "content/public/test/test_browser_thread.h"
21#include "testing/gtest/include/gtest/gtest.h"
22
23using content::BrowserThread;
24
25namespace chromeos {
26
27class KioskModeIdleLogoutTest : public ash::test::AshTestBase {
28 public:
29  KioskModeIdleLogoutTest()
30      : ui_thread_(BrowserThread::UI, message_loop()),
31        idle_logout_(NULL) {
32  }
33
34  virtual void SetUp() OVERRIDE {
35    AshTestBase::SetUp();
36    idle_logout_ = new KioskModeIdleLogout();
37  }
38
39  virtual void TearDown() OVERRIDE {
40    delete idle_logout_;
41    AshTestBase::TearDown();
42  }
43
44  bool LoginUserObserverRegistered() {
45    return idle_logout_->registrar_.IsRegistered(
46        idle_logout_,
47        chrome::NOTIFICATION_LOGIN_USER_CHANGED,
48        content::NotificationService::AllSources());
49  }
50
51  bool UserActivityObserverRegistered() {
52    return ash::Shell::GetInstance()->user_activity_detector()->HasObserver(
53        idle_logout_);
54  }
55
56  content::TestBrowserThread ui_thread_;
57
58  ScopedDeviceSettingsTestHelper device_settings_test_helper_;
59
60  KioskModeIdleLogout* idle_logout_;
61  content::NotificationRegistrar registrar_;
62};
63
64// http://crbug.com/177918
65TEST_F(KioskModeIdleLogoutTest, DISABLED_CheckObserversBeforeUserLogin) {
66  EXPECT_TRUE(LoginUserObserverRegistered());
67  EXPECT_FALSE(UserActivityObserverRegistered());
68}
69
70// http://crbug.com/177918
71TEST_F(KioskModeIdleLogoutTest, DISABLED_CheckObserversAfterUserLogin) {
72  content::NotificationService::current()->Notify(
73      chrome::NOTIFICATION_LOGIN_USER_CHANGED,
74      content::Source<UserManager>(UserManager::Get()),
75      // Ideally this should be the user logged in, but since we won't really be
76      // checking for the current logged in user in our observer anyway, giving
77      // NoDetails here is fine.
78      content::NotificationService::NoDetails());
79
80  RunAllPendingInMessageLoop();
81  EXPECT_FALSE(LoginUserObserverRegistered());
82  EXPECT_TRUE(UserActivityObserverRegistered());
83}
84
85}  // namespace chromeos
86