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 "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
6 #include "chrome/browser/extensions/extension_apitest.h"
7 #include "chrome/browser/signin/signin_manager_factory.h"
8 #include "components/signin/core/browser/signin_manager.h"
9 #include "components/signin/core/common/profile_management_switches.h"
10 #include "content/public/browser/notification_service.h"
11 #include "extensions/browser/api/test/test_api.h"
12 #include "extensions/browser/notification_types.h"
13 #include "extensions/common/switches.h"
15 namespace extensions {
19 const char kAttemptClickAuthMessage[] = "attemptClickAuth";
20 const char kTestExtensionId[] = "lkegkdgachcnekllcdfkijonogckdnjo";
21 const char kTestUser[] = "testuser@gmail.com";
25 class ScreenlockPrivateApiTest : public ExtensionApiTest,
26 public content::NotificationObserver {
28 ScreenlockPrivateApiTest() {}
30 virtual ~ScreenlockPrivateApiTest() {}
33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
34 ExtensionApiTest::SetUpCommandLine(command_line);
35 command_line->AppendSwitchASCII(
36 extensions::switches::kWhitelistedExtensionID, kTestExtensionId);
38 #if !defined(OS_CHROMEOS)
39 // New profile management needs to be on for non-ChromeOS lock.
40 ::switches::EnableNewProfileManagementForTesting(command_line);
44 virtual void SetUpOnMainThread() OVERRIDE {
45 SigninManagerFactory::GetForProfile(profile())
46 ->SetAuthenticatedUsername(kTestUser);
47 ExtensionApiTest::SetUpOnMainThread();
51 // ExtensionApiTest override:
52 virtual void RunTestOnMainThreadLoop() OVERRIDE {
54 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE,
55 content::NotificationService::AllSources());
56 ExtensionApiTest::RunTestOnMainThreadLoop();
57 registrar_.RemoveAll();
60 // content::NotificationObserver override:
61 virtual void Observe(int type,
62 const content::NotificationSource& source,
63 const content::NotificationDetails& details) OVERRIDE {
64 const std::string& content = *content::Details<std::string>(details).ptr();
65 if (content == kAttemptClickAuthMessage) {
66 extensions::ScreenlockPrivateEventRouter* router =
67 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
69 router->OnAuthAttempted(
70 ScreenlockBridge::Get()->lock_handler()->GetAuthType(kTestUser), "");
74 // Loads |extension_name| as appropriate for the platform and waits for a
75 // pass / fail notification.
76 void RunTest(const std::string& extension_name) {
77 #if defined(OS_CHROMEOS)
78 ASSERT_TRUE(RunComponentExtensionTest(extension_name)) << message_;
80 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_;
85 content::NotificationRegistrar registrar_;
87 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateApiTest);
90 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, LockUnlock) {
91 RunTest("screenlock_private/lock_unlock");
94 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) {
95 RunTest("screenlock_private/auth_type");
98 } // namespace extensions