• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/extensions/api/screenlock_private/screenlock_private_api.h"
7 #include "chrome/browser/extensions/extension_apitest.h"
8 #include "chrome/browser/signin/signin_manager_factory.h"
9 #include "components/signin/core/browser/signin_manager.h"
10 #include "components/signin/core/common/profile_management_switches.h"
11 #include "content/public/browser/notification_service.h"
12 #include "extensions/browser/api/test/test_api.h"
13 
14 namespace extensions {
15 
16 namespace {
17 
18 const char kTestUser[] = "testuser@gmail.com";
19 const char kAttemptClickAuthMessage[] = "attemptClickAuth";
20 
21 }  // namespace
22 
23 class ScreenlockPrivateApiTest : public ExtensionApiTest,
24                                  public content::NotificationObserver {
25  public:
ScreenlockPrivateApiTest()26   ScreenlockPrivateApiTest() {}
27 
~ScreenlockPrivateApiTest()28   virtual ~ScreenlockPrivateApiTest() {}
29 
30   // ExtensionApiTest
SetUpCommandLine(CommandLine * command_line)31   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
32     ExtensionApiTest::SetUpCommandLine(command_line);
33 
34 #if !defined(OS_CHROMEOS)
35     // New profile management needs to be on for non-ChromeOS lock.
36     switches::EnableNewProfileManagementForTesting(command_line);
37 #endif
38   }
39 
SetUpOnMainThread()40   virtual void SetUpOnMainThread() OVERRIDE {
41     SigninManagerFactory::GetForProfile(profile())
42         ->SetAuthenticatedUsername(kTestUser);
43     ExtensionApiTest::SetUpOnMainThread();
44   }
45 
46  protected:
47   // ExtensionApiTest override:
RunTestOnMainThreadLoop()48   virtual void RunTestOnMainThreadLoop() OVERRIDE {
49     registrar_.Add(this,
50                    chrome::NOTIFICATION_EXTENSION_TEST_MESSAGE,
51                    content::NotificationService::AllSources());
52     ExtensionApiTest::RunTestOnMainThreadLoop();
53     registrar_.RemoveAll();
54   }
55 
56   // content::NotificationObserver override:
Observe(int type,const content::NotificationSource & source,const content::NotificationDetails & details)57   virtual void Observe(int type,
58                        const content::NotificationSource& source,
59                        const content::NotificationDetails& details) OVERRIDE {
60     const std::string& content = *content::Details<std::string>(details).ptr();
61     if (content == kAttemptClickAuthMessage) {
62       extensions::ScreenlockPrivateEventRouter* router =
63           extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get(
64               profile());
65       router->OnAuthAttempted(
66           ScreenlockBridge::Get()->lock_handler()->GetAuthType(kTestUser), "");
67     }
68   }
69 
70  private:
71   content::NotificationRegistrar registrar_;
72 
73   DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateApiTest);
74 };
75 
IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest,LockUnlock)76 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, LockUnlock) {
77   ASSERT_TRUE(RunExtensionTest("screenlock_private/lock_unlock")) << message_;
78 }
79 
IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest,AuthType)80 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) {
81   ASSERT_TRUE(RunExtensionTest("screenlock_private/auth_type")) << message_;
82 }
83 
84 }  // namespace extensions
85