9b84163cda0920e900462307580a24450498ef6a
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / kiosk_mode / kiosk_mode_idle_logout_unittest.cc
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/notification_registrar.h"
18 #include "content/public/browser/notification_service.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace chromeos {
22
23 class KioskModeIdleLogoutTest : public ash::test::AshTestBase {
24  public:
25   KioskModeIdleLogoutTest()
26       : idle_logout_(NULL) {
27   }
28
29   virtual void SetUp() OVERRIDE {
30     AshTestBase::SetUp();
31     idle_logout_ = new KioskModeIdleLogout();
32   }
33
34   virtual void TearDown() OVERRIDE {
35     delete idle_logout_;
36     AshTestBase::TearDown();
37   }
38
39   bool LoginUserObserverRegistered() {
40     return idle_logout_->registrar_.IsRegistered(
41         idle_logout_,
42         chrome::NOTIFICATION_LOGIN_USER_CHANGED,
43         content::NotificationService::AllSources());
44   }
45
46   bool UserActivityObserverRegistered() {
47     return ash::Shell::GetInstance()->user_activity_detector()->HasObserver(
48         idle_logout_);
49   }
50
51   ScopedDeviceSettingsTestHelper device_settings_test_helper_;
52
53   KioskModeIdleLogout* idle_logout_;
54   content::NotificationRegistrar registrar_;
55 };
56
57 // http://crbug.com/177918
58 TEST_F(KioskModeIdleLogoutTest, DISABLED_CheckObserversBeforeUserLogin) {
59   EXPECT_TRUE(LoginUserObserverRegistered());
60   EXPECT_FALSE(UserActivityObserverRegistered());
61 }
62
63 // http://crbug.com/177918
64 TEST_F(KioskModeIdleLogoutTest, DISABLED_CheckObserversAfterUserLogin) {
65   content::NotificationService::current()->Notify(
66       chrome::NOTIFICATION_LOGIN_USER_CHANGED,
67       content::Source<UserManager>(UserManager::Get()),
68       // Ideally this should be the user logged in, but since we won't really be
69       // checking for the current logged in user in our observer anyway, giving
70       // NoDetails here is fine.
71       content::NotificationService::NoDetails());
72
73   RunAllPendingInMessageLoop();
74   EXPECT_FALSE(LoginUserObserverRegistered());
75   EXPECT_TRUE(UserActivityObserverRegistered());
76 }
77
78 }  // namespace chromeos