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/chromeos/login/login_manager_test.h" | 5 #include "chrome/browser/chromeos/login/login_manager_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_file_value_serializer.h" | |
9 #include "base/path_service.h" | |
10 #include "base/prefs/scoped_user_pref_update.h" | 8 #include "base/prefs/scoped_user_pref_update.h" |
11 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 11 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
14 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 12 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
15 #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" | 13 #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" |
16 #include "chrome/browser/chromeos/login/startup_utils.h" | |
17 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 14 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
18 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" | 15 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" |
19 #include "chrome/common/chrome_constants.h" | |
20 #include "chrome/common/chrome_paths.h" | |
21 #include "chrome/common/pref_names.h" | |
22 #include "chromeos/chromeos_switches.h" | 16 #include "chromeos/chromeos_switches.h" |
23 #include "chromeos/login/auth/key.h" | 17 #include "chromeos/login/auth/key.h" |
24 #include "chromeos/login/auth/user_context.h" | 18 #include "chromeos/login/auth/user_context.h" |
25 #include "components/user_manager/user.h" | 19 #include "components/user_manager/user.h" |
26 #include "components/user_manager/user_manager.h" | 20 #include "components/user_manager/user_manager.h" |
27 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
29 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
30 #include "content/public/test/test_utils.h" | 24 #include "content/public/test/test_utils.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
32 | 26 |
33 namespace chromeos { | 27 namespace chromeos { |
34 | 28 |
35 LoginManagerTest::LoginManagerTest(bool should_launch_browser) | 29 LoginManagerTest::LoginManagerTest(bool should_launch_browser) |
36 : use_webview_(false), | 30 : should_launch_browser_(should_launch_browser), |
37 should_launch_browser_(should_launch_browser), | |
38 web_contents_(NULL) { | 31 web_contents_(NULL) { |
39 set_exit_when_last_browser_closes(false); | 32 set_exit_when_last_browser_closes(false); |
40 } | 33 } |
41 | 34 |
42 void LoginManagerTest::TearDownOnMainThread() { | 35 void LoginManagerTest::TearDownOnMainThread() { |
43 MixinBasedBrowserTest::TearDownOnMainThread(); | 36 MixinBasedBrowserTest::TearDownOnMainThread(); |
44 if (LoginDisplayHostImpl::default_host()) | 37 if (LoginDisplayHostImpl::default_host()) |
45 LoginDisplayHostImpl::default_host()->Finalize(); | 38 LoginDisplayHostImpl::default_host()->Finalize(); |
46 base::MessageLoop::current()->RunUntilIdle(); | 39 base::MessageLoop::current()->RunUntilIdle(); |
47 } | 40 } |
(...skipping 13 matching lines...) Expand all Loading... |
61 content::WindowedNotificationObserver( | 54 content::WindowedNotificationObserver( |
62 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 55 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
63 content::NotificationService::AllSources()).Wait(); | 56 content::NotificationService::AllSources()).Wait(); |
64 InitializeWebContents(); | 57 InitializeWebContents(); |
65 test::UserSessionManagerTestApi session_manager_test_api( | 58 test::UserSessionManagerTestApi session_manager_test_api( |
66 UserSessionManager::GetInstance()); | 59 UserSessionManager::GetInstance()); |
67 session_manager_test_api.SetShouldLaunchBrowserInTests( | 60 session_manager_test_api.SetShouldLaunchBrowserInTests( |
68 should_launch_browser_); | 61 should_launch_browser_); |
69 } | 62 } |
70 | 63 |
71 bool LoginManagerTest::SetUpUserDataDirectory() { | |
72 base::FilePath user_data_dir; | |
73 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | |
74 base::FilePath local_state_path = | |
75 user_data_dir.Append(chrome::kLocalStateFilename); | |
76 | |
77 if (!use_webview()) { | |
78 // Set webview disabled flag only when local state file does not exist. | |
79 // Otherwise, we break PRE tests that leave state in it. | |
80 if (!base::PathExists(local_state_path)) { | |
81 base::DictionaryValue local_state_dict; | |
82 | |
83 // TODO(nkostylev): Fix tests that fail with webview signin. | |
84 local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); | |
85 | |
86 CHECK(JSONFileValueSerializer(local_state_path) | |
87 .Serialize(local_state_dict)); | |
88 } | |
89 } | |
90 | |
91 return MixinBasedBrowserTest::SetUpUserDataDirectory(); | |
92 } | |
93 | |
94 void LoginManagerTest::RegisterUser(const std::string& user_id) { | 64 void LoginManagerTest::RegisterUser(const std::string& user_id) { |
95 ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers"); | 65 ListPrefUpdate users_pref(g_browser_process->local_state(), "LoggedInUsers"); |
96 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); | 66 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); |
97 } | 67 } |
98 | 68 |
99 void LoginManagerTest::SetExpectedCredentials(const UserContext& user_context) { | 69 void LoginManagerTest::SetExpectedCredentials(const UserContext& user_context) { |
100 test::UserSessionManagerTestApi session_manager_test_api( | 70 test::UserSessionManagerTestApi session_manager_test_api( |
101 UserSessionManager::GetInstance()); | 71 UserSessionManager::GetInstance()); |
102 session_manager_test_api.InjectStubUserContext(user_context); | 72 session_manager_test_api.InjectStubUserContext(user_context); |
103 } | 73 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 EXPECT_TRUE(host != NULL); | 127 EXPECT_TRUE(host != NULL); |
158 | 128 |
159 content::WebContents* web_contents = | 129 content::WebContents* web_contents = |
160 host->GetWebUILoginView()->GetWebContents(); | 130 host->GetWebUILoginView()->GetWebContents(); |
161 EXPECT_TRUE(web_contents != NULL); | 131 EXPECT_TRUE(web_contents != NULL); |
162 set_web_contents(web_contents); | 132 set_web_contents(web_contents); |
163 js_checker_.set_web_contents(web_contents); | 133 js_checker_.set_web_contents(web_contents); |
164 } | 134 } |
165 | 135 |
166 } // namespace chromeos | 136 } // namespace chromeos |
OLD | NEW |