OLD | NEW |
| (Empty) |
1 // Copyright 2013 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/chrome_notification_types.h" | |
6 #include "chrome/browser/chromeos/login/auth/user_context.h" | |
7 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | |
8 #include "chrome/browser/chromeos/login/users/user.h" | |
9 #include "chrome/browser/extensions/extension_apitest.h" | |
10 #include "chrome/browser/signin/signin_manager_factory.h" | |
11 #include "components/signin/core/browser/signin_manager.h" | |
12 #include "content/public/browser/notification_service.h" | |
13 #include "extensions/browser/api/test/test_api.h" | |
14 | |
15 namespace extensions { | |
16 | |
17 namespace { | |
18 | |
19 const char kAttemptClickAuthMessage[] = "attemptClickAuth"; | |
20 | |
21 } // namespace | |
22 | |
23 class ScreenlockPrivateApiTest : public ExtensionApiTest, | |
24 public content::NotificationObserver { | |
25 public: | |
26 ScreenlockPrivateApiTest() {} | |
27 | |
28 virtual ~ScreenlockPrivateApiTest() {} | |
29 | |
30 // ExtensionApiTest | |
31 virtual void SetUpOnMainThread() OVERRIDE { | |
32 SigninManagerFactory::GetForProfile(profile()) | |
33 ->SetAuthenticatedUsername("testuser@gmail.com"); | |
34 ExtensionApiTest::SetUpOnMainThread(); | |
35 } | |
36 | |
37 protected: | |
38 chromeos::ScreenLocker* GetScreenLocker() { | |
39 chromeos::ScreenLocker* locker = | |
40 chromeos::ScreenLocker::default_screen_locker(); | |
41 EXPECT_TRUE(locker); | |
42 return locker; | |
43 } | |
44 | |
45 // ExtensionApiTest override: | |
46 virtual void RunTestOnMainThreadLoop() OVERRIDE { | |
47 registrar_.Add(this, | |
48 chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE, | |
49 content::NotificationService::AllSources()); | |
50 ExtensionApiTest::RunTestOnMainThreadLoop(); | |
51 registrar_.RemoveAll(); | |
52 } | |
53 | |
54 // content::NotificationObserver override: | |
55 virtual void Observe(int type, | |
56 const content::NotificationSource& source, | |
57 const content::NotificationDetails& details) OVERRIDE { | |
58 const std::string& content = *content::Details<std::string>(details).ptr(); | |
59 if (content == kAttemptClickAuthMessage) { | |
60 chromeos::ScreenLocker* locker = GetScreenLocker(); | |
61 const chromeos::UserList& users = locker->users(); | |
62 EXPECT_GE(1u, users.size()); | |
63 GetScreenLocker()->Authenticate(chromeos::UserContext(users[0]->email())); | |
64 } | |
65 } | |
66 | |
67 content::NotificationRegistrar registrar_; | |
68 }; | |
69 | |
70 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, LockUnlock) { | |
71 ASSERT_TRUE(RunExtensionTest("screenlock_private/lock_unlock")) << message_; | |
72 } | |
73 | |
74 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) { | |
75 ASSERT_TRUE(RunExtensionTest("screenlock_private/auth_type")) << message_; | |
76 } | |
77 | |
78 } // namespace extensions | |
OLD | NEW |