OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/test/oobe_base_test.h" | 5 #include "chrome/browser/chromeos/login/test/oobe_base_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" | 8 #include "base/json/json_file_value_serializer.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 12 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
13 #include "chrome/browser/chromeos/login/test/https_forwarder.h" | 13 #include "chrome/browser/chromeos/login/test/https_forwarder.h" |
14 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" | 14 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" |
15 #include "chrome/browser/lifetime/application_lifetime.h" | 15 #include "chrome/browser/lifetime/application_lifetime.h" |
16 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" | 16 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
17 #include "chrome/common/chrome_constants.h" | 17 #include "chrome/common/chrome_constants.h" |
18 #include "chrome/common/chrome_paths.h" | 18 #include "chrome/common/chrome_paths.h" |
19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
21 #include "chromeos/chromeos_switches.h" | 21 #include "chromeos/chromeos_switches.h" |
22 #include "chromeos/dbus/fake_shill_manager_client.h" | 22 #include "chromeos/dbus/fake_shill_manager_client.h" |
23 #include "components/policy/core/common/policy_switches.h" | |
24 #include "components/user_manager/fake_user_manager.h" | 23 #include "components/user_manager/fake_user_manager.h" |
25 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
26 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
27 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
28 #include "content/public/test/browser_test_utils.h" | 27 #include "content/public/test/browser_test_utils.h" |
29 #include "google_apis/gaia/gaia_switches.h" | 28 #include "google_apis/gaia/gaia_switches.h" |
30 #include "net/dns/mock_host_resolver.h" | 29 #include "net/dns/mock_host_resolver.h" |
31 #include "net/test/embedded_test_server/http_request.h" | 30 #include "net/test/embedded_test_server/http_request.h" |
32 #include "net/test/embedded_test_server/http_response.h" | 31 #include "net/test/embedded_test_server/http_response.h" |
33 | 32 |
34 namespace chromeos { | 33 namespace chromeos { |
35 | 34 |
36 // static | |
37 const char OobeBaseTest::kFakeUserEmail[] = "fake-email@gmail.com"; | |
38 const char OobeBaseTest::kFakeUserPassword[] = "fake-password"; | |
39 const char OobeBaseTest::kFakeSIDCookie[] = "fake-SID-cookie"; | |
40 const char OobeBaseTest::kFakeLSIDCookie[] = "fake-LSID-cookie"; | |
41 | |
42 OobeBaseTest::OobeBaseTest() | 35 OobeBaseTest::OobeBaseTest() |
43 : fake_gaia_(new FakeGaia()), | 36 : fake_gaia_(new FakeGaia()), |
44 network_portal_detector_(NULL), | 37 network_portal_detector_(NULL), |
45 needs_background_networking_(false), | 38 needs_background_networking_(false), |
46 gaia_frame_parent_("signin-frame"), | 39 gaia_frame_parent_("signin-frame"), |
47 use_webview_(false), | 40 use_webview_(false) { |
48 initialize_fake_merge_session_(true) { | |
49 set_exit_when_last_browser_closes(false); | 41 set_exit_when_last_browser_closes(false); |
50 set_chromeos_user_ = false; | 42 set_chromeos_user_ = false; |
51 } | 43 } |
52 | 44 |
53 OobeBaseTest::~OobeBaseTest() { | 45 OobeBaseTest::~OobeBaseTest() { |
54 } | 46 } |
55 | 47 |
56 void OobeBaseTest::SetUp() { | 48 void OobeBaseTest::SetUp() { |
57 base::FilePath test_data_dir; | 49 base::FilePath test_data_dir; |
58 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 50 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
59 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 51 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
60 | 52 |
61 RegisterAdditionalRequestHandlers(); | |
62 | |
63 embedded_test_server()->RegisterRequestHandler( | 53 embedded_test_server()->RegisterRequestHandler( |
64 base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get()))); | 54 base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get()))); |
65 | 55 |
66 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 56 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
67 | 57 |
68 // Start https wrapper here so that the URLs can be pointed at it in | 58 // Start https wrapper here so that the URLs can be pointed at it in |
69 // SetUpCommandLine(). | 59 // SetUpCommandLine(). |
70 InitHttpsForwarders(); | 60 InitHttpsForwarders(); |
71 | 61 |
72 // Stop IO thread here because no threads are allowed while | 62 // Stop IO thread here because no threads are allowed while |
73 // spawning sandbox host process. See crbug.com/322732. | 63 // spawning sandbox host process. See crbug.com/322732. |
74 embedded_test_server()->StopThread(); | 64 embedded_test_server()->StopThread(); |
75 | 65 |
76 ExtensionApiTest::SetUp(); | 66 ExtensionApiTest::SetUp(); |
77 } | 67 } |
78 | 68 |
79 bool OobeBaseTest::SetUpUserDataDirectory() { | 69 bool OobeBaseTest::SetUpUserDataDirectory() { |
80 base::FilePath user_data_dir; | 70 if (use_webview_) { |
81 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 71 // Fake Dev channel to enable webview signin. |
82 base::FilePath local_state_path = | 72 scoped_channel_.reset( |
83 user_data_dir.Append(chrome::kLocalStateFilename); | 73 new extensions::ScopedCurrentChannel(chrome::VersionInfo::CHANNEL_DEV)); |
84 | 74 |
85 if (!use_webview()) { | 75 base::FilePath user_data_dir; |
86 // Set webview disabled flag only when local state file does not exist. | 76 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
| 77 base::FilePath local_state_path = |
| 78 user_data_dir.Append(chrome::kLocalStateFilename); |
| 79 |
| 80 // Set webview enabled flag only when local state file does not exist. |
87 // Otherwise, we break PRE tests that leave state in it. | 81 // Otherwise, we break PRE tests that leave state in it. |
88 if (!base::PathExists(local_state_path)) { | 82 if (!base::PathExists(local_state_path)) { |
89 base::DictionaryValue local_state_dict; | 83 base::DictionaryValue local_state_dict; |
90 | 84 local_state_dict.SetBoolean(prefs::kWebviewSigninEnabled, true); |
91 // TODO(nkostylev): Fix tests that fail with webview signin. | 85 // OobeCompleted to skip controller-pairing-screen which still uses |
92 local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); | 86 // iframe and ends up in a JS error in oobe page init. |
| 87 // See http://crbug.com/467147 |
| 88 local_state_dict.SetBoolean(prefs::kOobeComplete, true); |
93 | 89 |
94 CHECK(JSONFileValueSerializer(local_state_path) | 90 CHECK(JSONFileValueSerializer(local_state_path) |
95 .Serialize(local_state_dict)); | 91 .Serialize(local_state_dict)); |
96 } | 92 } |
97 } | 93 } |
98 | 94 |
99 return ExtensionApiTest::SetUpUserDataDirectory(); | 95 return ExtensionApiTest::SetUpUserDataDirectory(); |
100 } | 96 } |
101 | 97 |
102 void OobeBaseTest::SetUpInProcessBrowserTestFixture() { | 98 void OobeBaseTest::SetUpInProcessBrowserTestFixture() { |
103 host_resolver()->AddRule("*", "127.0.0.1"); | 99 host_resolver()->AddRule("*", "127.0.0.1"); |
104 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); | 100 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); |
105 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); | 101 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); |
106 network_portal_detector_->SetDefaultNetworkForTesting( | 102 network_portal_detector_->SetDefaultNetworkForTesting( |
107 FakeShillManagerClient::kFakeEthernetNetworkGuid); | 103 FakeShillManagerClient::kFakeEthernetNetworkGuid); |
108 | 104 |
109 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 105 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
110 } | 106 } |
111 | 107 |
112 void OobeBaseTest::SetUpOnMainThread() { | 108 void OobeBaseTest::SetUpOnMainThread() { |
113 if (initialize_fake_merge_session()) { | |
114 fake_gaia_->SetFakeMergeSessionParams(kFakeUserEmail, kFakeSIDCookie, | |
115 kFakeLSIDCookie); | |
116 } | |
117 | |
118 // Restart the thread as the sandbox host process has already been spawned. | 109 // Restart the thread as the sandbox host process has already been spawned. |
119 embedded_test_server()->RestartThreadAndListen(); | 110 embedded_test_server()->RestartThreadAndListen(); |
120 | 111 |
121 login_screen_load_observer_.reset(new content::WindowedNotificationObserver( | 112 login_screen_load_observer_.reset(new content::WindowedNotificationObserver( |
122 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, | 113 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
123 content::NotificationService::AllSources())); | 114 content::NotificationService::AllSources())); |
124 | 115 |
125 ExtensionApiTest::SetUpOnMainThread(); | 116 ExtensionApiTest::SetUpOnMainThread(); |
126 } | 117 } |
127 | 118 |
128 void OobeBaseTest::TearDownOnMainThread() { | 119 void OobeBaseTest::TearDownOnMainThread() { |
129 // If the login display is still showing, exit gracefully. | 120 // If the login display is still showing, exit gracefully. |
130 if (LoginDisplayHostImpl::default_host()) { | 121 if (LoginDisplayHostImpl::default_host()) { |
131 base::MessageLoop::current()->PostTask(FROM_HERE, | 122 base::MessageLoop::current()->PostTask(FROM_HERE, |
132 base::Bind(&chrome::AttemptExit)); | 123 base::Bind(&chrome::AttemptExit)); |
133 content::RunMessageLoop(); | 124 content::RunMessageLoop(); |
134 } | 125 } |
135 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | |
136 | 126 |
137 ExtensionApiTest::TearDownOnMainThread(); | 127 ExtensionApiTest::TearDownOnMainThread(); |
138 } | 128 } |
139 | 129 |
140 void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { | 130 void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { |
141 ExtensionApiTest::SetUpCommandLine(command_line); | 131 ExtensionApiTest::SetUpCommandLine(command_line); |
142 | 132 |
143 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 133 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
144 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 134 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
145 if (!needs_background_networking_) | 135 if (!needs_background_networking_) |
146 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); | 136 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); |
147 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | 137 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); |
148 | 138 |
149 GURL gaia_url = gaia_https_forwarder_->GetURL(std::string()); | 139 GURL gaia_url = gaia_https_forwarder_->GetURL(""); |
150 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); | 140 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); |
151 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); | 141 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); |
152 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, | 142 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, |
153 gaia_url.spec()); | 143 gaia_url.spec()); |
154 | 144 |
155 fake_gaia_->Initialize(); | 145 fake_gaia_->Initialize(); |
156 fake_gaia_->set_issue_oauth_code_cookie(use_webview()); | 146 fake_gaia_->set_issue_oauth_code_cookie(use_webview_); |
157 } | 147 } |
158 | 148 |
159 void OobeBaseTest::InitHttpsForwarders() { | 149 void OobeBaseTest::InitHttpsForwarders() { |
160 gaia_https_forwarder_.reset( | 150 gaia_https_forwarder_.reset( |
161 new HTTPSForwarder(embedded_test_server()->base_url())); | 151 new HTTPSForwarder(embedded_test_server()->base_url())); |
162 ASSERT_TRUE(gaia_https_forwarder_->Start()); | 152 ASSERT_TRUE(gaia_https_forwarder_->Start()); |
163 } | 153 } |
164 | 154 |
165 void OobeBaseTest::RegisterAdditionalRequestHandlers() { | |
166 } | |
167 | |
168 void OobeBaseTest::SimulateNetworkOffline() { | 155 void OobeBaseTest::SimulateNetworkOffline() { |
169 NetworkPortalDetector::CaptivePortalState offline_state; | 156 NetworkPortalDetector::CaptivePortalState offline_state; |
170 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; | 157 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; |
171 network_portal_detector_->SetDetectionResultsForTesting( | 158 network_portal_detector_->SetDetectionResultsForTesting( |
172 FakeShillManagerClient::kFakeEthernetNetworkGuid, | 159 FakeShillManagerClient::kFakeEthernetNetworkGuid, |
173 offline_state); | 160 offline_state); |
174 network_portal_detector_->NotifyObserversForTesting(); | 161 network_portal_detector_->NotifyObserversForTesting(); |
175 } | 162 } |
176 | 163 |
177 base::Closure OobeBaseTest::SimulateNetworkOfflineClosure() { | 164 base::Closure OobeBaseTest::SimulateNetworkOfflineClosure() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 210 } |
224 | 211 |
225 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { | 212 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { |
226 ExistingUserController* controller = | 213 ExistingUserController* controller = |
227 ExistingUserController::current_controller(); | 214 ExistingUserController::current_controller(); |
228 CHECK(controller); | 215 CHECK(controller); |
229 return static_cast<WebUILoginDisplay*>( | 216 return static_cast<WebUILoginDisplay*>( |
230 controller->login_display()); | 217 controller->login_display()); |
231 } | 218 } |
232 | 219 |
233 void OobeBaseTest::WaitForGaiaPageLoad() { | |
234 WaitForSigninScreen(); | |
235 | |
236 if (!use_webview()) | |
237 return; | |
238 | |
239 ASSERT_TRUE(content::ExecuteScript( | |
240 GetLoginUI()->GetWebContents(), | |
241 "$('gaia-signin').gaiaAuthHost_.addEventListener('ready'," | |
242 "function() {" | |
243 "window.domAutomationController.setAutomationId(0);" | |
244 "window.domAutomationController.send('GaiaReady');" | |
245 "});")); | |
246 | |
247 content::DOMMessageQueue message_queue; | |
248 std::string message; | |
249 do { | |
250 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
251 } while (message != "\"GaiaReady\""); | |
252 } | |
253 | |
254 void OobeBaseTest::WaitForSigninScreen() { | 220 void OobeBaseTest::WaitForSigninScreen() { |
255 WizardController* wizard_controller = WizardController::default_controller(); | 221 WizardController* wizard_controller = WizardController::default_controller(); |
256 if (wizard_controller) | 222 if (wizard_controller) { |
257 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); | 223 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
258 | 224 } |
259 WizardController::SkipPostLoginScreensForTesting(); | 225 WizardController::SkipPostLoginScreensForTesting(); |
260 | 226 |
261 login_screen_load_observer_->Wait(); | 227 login_screen_load_observer_->Wait(); |
262 } | 228 } |
263 | 229 |
264 void OobeBaseTest::ExecuteJsInSigninFrame(const std::string& js) { | 230 void OobeBaseTest::ExecuteJsInSigninFrame(const std::string& js) { |
265 content::RenderFrameHost* frame = InlineLoginUI::GetAuthFrame( | 231 content::RenderFrameHost* frame = InlineLoginUI::GetAuthFrame( |
266 GetLoginUI()->GetWebContents(), GURL(), gaia_frame_parent_); | 232 GetLoginUI()->GetWebContents(), GURL(), gaia_frame_parent_); |
267 ASSERT_TRUE(content::ExecuteScript(frame, js)); | 233 ASSERT_TRUE(content::ExecuteScript(frame, js)); |
268 } | 234 } |
269 | 235 |
270 void OobeBaseTest::SetSignFormField(const std::string& field_id, | 236 void OobeBaseTest::SetSignFormField(const std::string& field_id, |
271 const std::string& field_value) { | 237 const std::string& field_value) { |
272 std::string js = | 238 std::string js = |
273 "(function(){" | 239 "(function(){" |
274 "document.getElementById('$FieldId').value = '$FieldValue';" | 240 "document.getElementById('$FieldId').value = '$FieldValue';" |
275 "var e = new Event('input');" | 241 "var e = new Event('input');" |
276 "document.getElementById('$FieldId').dispatchEvent(e);" | 242 "document.getElementById('$FieldId').dispatchEvent(e);" |
277 "})();"; | 243 "})();"; |
278 ReplaceSubstringsAfterOffset(&js, 0, "$FieldId", field_id); | 244 ReplaceSubstringsAfterOffset(&js, 0, "$FieldId", field_id); |
279 ReplaceSubstringsAfterOffset(&js, 0, "$FieldValue", field_value); | 245 ReplaceSubstringsAfterOffset(&js, 0, "$FieldValue", field_value); |
280 ExecuteJsInSigninFrame(js); | 246 ExecuteJsInSigninFrame(js); |
281 } | 247 } |
282 | 248 |
283 } // namespace chromeos | 249 } // namespace chromeos |
OLD | NEW |