| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chrome_notification_types.h" | 5 #include "chrome/browser/chrome_notification_types.h" |
| 6 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" | 6 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_ap
i.h" |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "chrome/browser/signin/signin_manager_factory.h" | 8 #include "chrome/browser/signin/signin_manager_factory.h" |
| 9 #include "components/signin/core/browser/signin_manager.h" | 9 #include "components/signin/core/browser/signin_manager.h" |
| 10 #include "components/signin/core/common/profile_management_switches.h" | 10 #include "components/signin/core/common/profile_management_switches.h" |
| 11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 12 #include "extensions/browser/api/test/test_api.h" | 12 #include "extensions/browser/api/test/test_api.h" |
| 13 #include "extensions/common/switches.h" |
| 13 | 14 |
| 14 namespace extensions { | 15 namespace extensions { |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 19 const char kAttemptClickAuthMessage[] = "attemptClickAuth"; |
| 20 const char kTestExtensionId[] = "lkegkdgachcnekllcdfkijonogckdnjo"; |
| 18 const char kTestUser[] = "testuser@gmail.com"; | 21 const char kTestUser[] = "testuser@gmail.com"; |
| 19 const char kAttemptClickAuthMessage[] = "attemptClickAuth"; | |
| 20 | 22 |
| 21 } // namespace | 23 } // namespace |
| 22 | 24 |
| 23 class ScreenlockPrivateApiTest : public ExtensionApiTest, | 25 class ScreenlockPrivateApiTest : public ExtensionApiTest, |
| 24 public content::NotificationObserver { | 26 public content::NotificationObserver { |
| 25 public: | 27 public: |
| 26 ScreenlockPrivateApiTest() {} | 28 ScreenlockPrivateApiTest() {} |
| 27 | 29 |
| 28 virtual ~ScreenlockPrivateApiTest() {} | 30 virtual ~ScreenlockPrivateApiTest() {} |
| 29 | 31 |
| 30 // ExtensionApiTest | 32 // ExtensionApiTest |
| 31 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 32 ExtensionApiTest::SetUpCommandLine(command_line); | 34 ExtensionApiTest::SetUpCommandLine(command_line); |
| 35 command_line->AppendSwitchASCII( |
| 36 extensions::switches::kWhitelistedExtensionID, kTestExtensionId); |
| 33 | 37 |
| 34 #if !defined(OS_CHROMEOS) | 38 #if !defined(OS_CHROMEOS) |
| 35 // New profile management needs to be on for non-ChromeOS lock. | 39 // New profile management needs to be on for non-ChromeOS lock. |
| 36 switches::EnableNewProfileManagementForTesting(command_line); | 40 ::switches::EnableNewProfileManagementForTesting(command_line); |
| 37 #endif | 41 #endif |
| 38 } | 42 } |
| 39 | 43 |
| 40 virtual void SetUpOnMainThread() OVERRIDE { | 44 virtual void SetUpOnMainThread() OVERRIDE { |
| 41 SigninManagerFactory::GetForProfile(profile()) | 45 SigninManagerFactory::GetForProfile(profile()) |
| 42 ->SetAuthenticatedUsername(kTestUser); | 46 ->SetAuthenticatedUsername(kTestUser); |
| 43 ExtensionApiTest::SetUpOnMainThread(); | 47 ExtensionApiTest::SetUpOnMainThread(); |
| 44 } | 48 } |
| 45 | 49 |
| 46 protected: | 50 protected: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 60 const std::string& content = *content::Details<std::string>(details).ptr(); | 64 const std::string& content = *content::Details<std::string>(details).ptr(); |
| 61 if (content == kAttemptClickAuthMessage) { | 65 if (content == kAttemptClickAuthMessage) { |
| 62 extensions::ScreenlockPrivateEventRouter* router = | 66 extensions::ScreenlockPrivateEventRouter* router = |
| 63 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( | 67 extensions::ScreenlockPrivateEventRouter::GetFactoryInstance()->Get( |
| 64 profile()); | 68 profile()); |
| 65 router->OnAuthAttempted( | 69 router->OnAuthAttempted( |
| 66 ScreenlockBridge::Get()->lock_handler()->GetAuthType(kTestUser), ""); | 70 ScreenlockBridge::Get()->lock_handler()->GetAuthType(kTestUser), ""); |
| 67 } | 71 } |
| 68 } | 72 } |
| 69 | 73 |
| 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_; |
| 79 #else |
| 80 ASSERT_TRUE(RunExtensionTest(extension_name)) << message_; |
| 81 #endif |
| 82 } |
| 83 |
| 70 private: | 84 private: |
| 71 content::NotificationRegistrar registrar_; | 85 content::NotificationRegistrar registrar_; |
| 72 | 86 |
| 73 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateApiTest); | 87 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateApiTest); |
| 74 }; | 88 }; |
| 75 | 89 |
| 76 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, LockUnlock) { | 90 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, LockUnlock) { |
| 77 ASSERT_TRUE(RunExtensionTest("screenlock_private/lock_unlock")) << message_; | 91 RunTest("screenlock_private/lock_unlock"); |
| 78 } | 92 } |
| 79 | 93 |
| 80 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) { | 94 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, AuthType) { |
| 81 ASSERT_TRUE(RunExtensionTest("screenlock_private/auth_type")) << message_; | 95 RunTest("screenlock_private/auth_type"); |
| 82 } | 96 } |
| 83 | 97 |
| 84 } // namespace extensions | 98 } // namespace extensions |
| OLD | NEW |