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