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.
5 #include "base/strings/string16.h"
6 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/signin/easy_unlock_service.h"
9 #include "chrome/browser/signin/signin_manager_factory.h"
10 #include "components/signin/core/browser/signin_manager.h"
11 #include "components/signin/core/common/profile_management_switches.h"
12 #include "content/public/browser/notification_service.h"
13 #include "extensions/browser/api/test/test_api.h"
14 #include "extensions/browser/notification_types.h"
15 #include "extensions/common/switches.h"
17 namespace extensions {
21 const char kAttemptClickAuthMessage[] = "attemptClickAuth";
22 const char kTestExtensionId[] = "lkegkdgachcnekllcdfkijonogckdnjo";
23 const char kTestUser[] = "testuser@gmail.com";
27 class ScreenlockPrivateApiTest : public ExtensionApiTest,
28 public content::NotificationObserver {
30 ScreenlockPrivateApiTest() {}
32 virtual ~ScreenlockPrivateApiTest() {}
35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36 ExtensionApiTest::SetUpCommandLine(command_line);
37 command_line->AppendSwitchASCII(
38 extensions::switches::kWhitelistedExtensionID, kTestExtensionId);
40 #if !defined(OS_CHROMEOS)
41 // New profile management needs to be on for non-ChromeOS lock.
42 ::switches::EnableNewProfileManagementForTesting(command_line);
46 virtual void SetUpOnMainThread() OVERRIDE {
47 SigninManagerFactory::GetForProfile(profile())
48 ->SetAuthenticatedUsername(kTestUser);
49 ExtensionApiTest::SetUpOnMainThread();
53 // ExtensionApiTest override:
54 virtual void RunTestOnMainThreadLoop() OVERRIDE {
56 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE,
57 content::NotificationService::AllSources());
58 ExtensionApiTest::RunTestOnMainThreadLoop();
59 registrar_.RemoveAll();
62 // content::NotificationObserver override:
63 virtual void Observe(int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) OVERRIDE {
66 const std::string& content = *content::Details<std::string>(details).ptr();
67 if (content == kAttemptClickAuthMessage) {
68 ScreenlockBridge::Get()->lock_handler()->SetAuthType(
70 ScreenlockBridge::LockHandler::USER_CLICK,
72 EasyUnlockService::Get(profile())->AttemptAuth(kTestUser);
76 // Loads |extension_name| as appropriate for the platform and waits for a
77 // pass / fail notification.
78 void RunTest(const std::string& extension_name) {
79 #if defined(OS_CHROMEOS)
80 ASSERT_TRUE(RunComponentExtensionTest(extension_name)) << message_;
82 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
87 content::NotificationRegistrar registrar_;
89 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateApiTest);
92 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, LockUnlock) {
93 RunTest("screenlock_private/lock_unlock");
96 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) {
97 RunTest("screenlock_private/auth_type");
100 } // namespace extensions