Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / extensions / api / screenlock_private / screenlock_private_apitest.cc
blobd498c04e0bbb20990a5b036dedd0a007b48e5789
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 "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/extensions/api/screenlock_private/screenlock_private_api.h"
9 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/browser/profiles/profile_info_cache.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/signin/easy_unlock_service.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "components/proximity_auth/screenlock_bridge.h"
15 #include "components/signin/core/browser/signin_manager.h"
16 #include "components/signin/core/common/profile_management_switches.h"
17 #include "content/public/browser/notification_service.h"
18 #include "extensions/browser/api/test/test_api.h"
19 #include "extensions/browser/notification_types.h"
20 #include "extensions/common/switches.h"
22 namespace extensions {
24 namespace {
26 const char kTestGaiaId[] = "gaia-id-testuser@gmail.com";
27 const char kAttemptClickAuthMessage[] = "attemptClickAuth";
28 const char kTestExtensionId[] = "lkegkdgachcnekllcdfkijonogckdnjo";
29 const char kTestUser[] = "testuser@gmail.com";
31 } // namespace
33 class ScreenlockPrivateApiTest : public ExtensionApiTest,
34 public content::NotificationObserver {
35 public:
36 ScreenlockPrivateApiTest() {}
38 ~ScreenlockPrivateApiTest() override {}
40 // ExtensionApiTest
41 void SetUpCommandLine(base::CommandLine* command_line) override {
42 ExtensionApiTest::SetUpCommandLine(command_line);
43 command_line->AppendSwitchASCII(
44 extensions::switches::kWhitelistedExtensionID, kTestExtensionId);
46 #if !defined(OS_CHROMEOS)
47 // New profile management needs to be on for non-ChromeOS lock.
48 ::switches::EnableNewProfileManagementForTesting(command_line);
49 #endif
52 void SetUpOnMainThread() override {
53 SigninManagerFactory::GetForProfile(profile())
54 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
55 ProfileInfoCache& info_cache =
56 g_browser_process->profile_manager()->GetProfileInfoCache();
57 size_t index = info_cache.GetIndexOfProfileWithPath(profile()->GetPath());
58 ASSERT_NE(std::string::npos, index);
59 info_cache.SetAuthInfoOfProfileAtIndex(index, kTestGaiaId,
60 base::UTF8ToUTF16(kTestUser));
61 ExtensionApiTest::SetUpOnMainThread();
64 protected:
65 // ExtensionApiTest override:
66 void RunTestOnMainThreadLoop() override {
67 registrar_.Add(this,
68 extensions::NOTIFICATION_EXTENSION_TEST_MESSAGE,
69 content::NotificationService::AllSources());
70 ExtensionApiTest::RunTestOnMainThreadLoop();
71 registrar_.RemoveAll();
74 // content::NotificationObserver override:
75 void Observe(int type,
76 const content::NotificationSource& source,
77 const content::NotificationDetails& details) override {
78 const std::string& content = *content::Details<std::string>(details).ptr();
79 if (content == kAttemptClickAuthMessage) {
80 proximity_auth::ScreenlockBridge::Get()->lock_handler()->SetAuthType(
81 kTestUser, proximity_auth::ScreenlockBridge::LockHandler::USER_CLICK,
82 base::string16());
83 EasyUnlockService::Get(profile())->AttemptAuth(kTestUser);
87 // Loads |extension_name| and waits for a pass / fail notification.
88 void RunTest(const std::string& extension_name) {
89 ASSERT_TRUE(RunComponentExtensionTest(extension_name)) << message_;
92 private:
93 content::NotificationRegistrar registrar_;
95 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateApiTest);
98 // Locking is currently implemented only on ChromeOS.
99 #if defined(OS_CHROMEOS)
101 // Time out under MSan. http://crbug.com/478091
102 // Flaky under LSan on ChromeOS. http://crbug.com/482002
103 #if defined(MEMORY_SANITIZER) || defined(LEAK_SANITIZER) && defined(OS_CHROMEOS)
104 #define MAYBE_LockUnlock DISABLED_LockUnlock
105 #define MAYBE_AuthType DISABLED_AuthType
106 #else
107 #define MAYBE_LockUnlock LockUnlock
108 #define MAYBE_AuthType AuthType
109 #endif
111 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, MAYBE_LockUnlock) {
112 RunTest("screenlock_private/lock_unlock");
115 IN_PROC_BROWSER_TEST_F(ScreenlockPrivateApiTest, MAYBE_AuthType) {
116 RunTest("screenlock_private/auth_type");
119 #endif // defined(OS_CHROMEOS)
121 } // namespace extensions