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" | |
23 #include "components/user_manager/fake_user_manager.h" | 24 #include "components/user_manager/fake_user_manager.h" |
24 #include "content/public/browser/notification_observer.h" | 25 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 26 #include "content/public/browser/notification_registrar.h" |
26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
27 #include "content/public/test/browser_test_utils.h" | 28 #include "content/public/test/browser_test_utils.h" |
28 #include "google_apis/gaia/gaia_switches.h" | 29 #include "google_apis/gaia/gaia_switches.h" |
29 #include "net/dns/mock_host_resolver.h" | 30 #include "net/dns/mock_host_resolver.h" |
30 #include "net/test/embedded_test_server/http_request.h" | 31 #include "net/test/embedded_test_server/http_request.h" |
31 #include "net/test/embedded_test_server/http_response.h" | 32 #include "net/test/embedded_test_server/http_response.h" |
32 | 33 |
(...skipping 10 matching lines...) Expand all Loading... | |
43 } | 44 } |
44 | 45 |
45 OobeBaseTest::~OobeBaseTest() { | 46 OobeBaseTest::~OobeBaseTest() { |
46 } | 47 } |
47 | 48 |
48 void OobeBaseTest::SetUp() { | 49 void OobeBaseTest::SetUp() { |
49 base::FilePath test_data_dir; | 50 base::FilePath test_data_dir; |
50 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 51 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
51 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 52 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
52 | 53 |
54 RegisterAdditionalRequestHandlers(); | |
55 | |
53 embedded_test_server()->RegisterRequestHandler( | 56 embedded_test_server()->RegisterRequestHandler( |
54 base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get()))); | 57 base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get()))); |
55 | 58 |
56 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 59 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
57 | 60 |
58 // Start https wrapper here so that the URLs can be pointed at it in | 61 // Start https wrapper here so that the URLs can be pointed at it in |
59 // SetUpCommandLine(). | 62 // SetUpCommandLine(). |
60 InitHttpsForwarders(); | 63 InitHttpsForwarders(); |
61 | 64 |
62 // Stop IO thread here because no threads are allowed while | 65 // Stop IO thread here because no threads are allowed while |
63 // spawning sandbox host process. See crbug.com/322732. | 66 // spawning sandbox host process. See crbug.com/322732. |
64 embedded_test_server()->StopThread(); | 67 embedded_test_server()->StopThread(); |
65 | 68 |
66 ExtensionApiTest::SetUp(); | 69 ExtensionApiTest::SetUp(); |
67 } | 70 } |
68 | 71 |
69 bool OobeBaseTest::SetUpUserDataDirectory() { | 72 bool OobeBaseTest::SetUpUserDataDirectory() { |
70 if (use_webview_) { | 73 base::FilePath user_data_dir; |
71 // Fake Dev channel to enable webview signin. | 74 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); |
72 scoped_channel_.reset( | 75 base::FilePath local_state_path = |
73 new extensions::ScopedCurrentChannel(chrome::VersionInfo::CHANNEL_DEV)); | 76 user_data_dir.Append(chrome::kLocalStateFilename); |
74 | 77 |
75 base::FilePath user_data_dir; | 78 if (!use_webview_) { |
76 CHECK(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | 79 // Set webview disabled flag only when local state file does not exist. |
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. | |
81 // Otherwise, we break PRE tests that leave state in it. | 80 // Otherwise, we break PRE tests that leave state in it. |
82 if (!base::PathExists(local_state_path)) { | 81 if (!base::PathExists(local_state_path)) { |
83 base::DictionaryValue local_state_dict; | 82 base::DictionaryValue local_state_dict; |
84 local_state_dict.SetBoolean(prefs::kWebviewSigninEnabled, true); | 83 |
85 // OobeCompleted to skip controller-pairing-screen which still uses | 84 // TODO(nkostylev): Fix tests that fail with webview signin. |
86 // iframe and ends up in a JS error in oobe page init. | 85 local_state_dict.SetBoolean(prefs::kWebviewSigninDisabled, true); |
87 // See http://crbug.com/467147 | |
88 local_state_dict.SetBoolean(prefs::kOobeComplete, true); | |
89 | 86 |
90 CHECK(JSONFileValueSerializer(local_state_path) | 87 CHECK(JSONFileValueSerializer(local_state_path) |
91 .Serialize(local_state_dict)); | 88 .Serialize(local_state_dict)); |
92 } | 89 } |
93 } | 90 } |
94 | 91 |
95 return ExtensionApiTest::SetUpUserDataDirectory(); | 92 return ExtensionApiTest::SetUpUserDataDirectory(); |
96 } | 93 } |
97 | 94 |
98 void OobeBaseTest::SetUpInProcessBrowserTestFixture() { | 95 void OobeBaseTest::SetUpInProcessBrowserTestFixture() { |
(...skipping 17 matching lines...) Expand all Loading... | |
116 ExtensionApiTest::SetUpOnMainThread(); | 113 ExtensionApiTest::SetUpOnMainThread(); |
117 } | 114 } |
118 | 115 |
119 void OobeBaseTest::TearDownOnMainThread() { | 116 void OobeBaseTest::TearDownOnMainThread() { |
120 // If the login display is still showing, exit gracefully. | 117 // If the login display is still showing, exit gracefully. |
121 if (LoginDisplayHostImpl::default_host()) { | 118 if (LoginDisplayHostImpl::default_host()) { |
122 base::MessageLoop::current()->PostTask(FROM_HERE, | 119 base::MessageLoop::current()->PostTask(FROM_HERE, |
123 base::Bind(&chrome::AttemptExit)); | 120 base::Bind(&chrome::AttemptExit)); |
124 content::RunMessageLoop(); | 121 content::RunMessageLoop(); |
125 } | 122 } |
123 EXPECT_TRUE(embedded_test_server()->ShutdownAndWaitUntilComplete()); | |
126 | 124 |
127 ExtensionApiTest::TearDownOnMainThread(); | 125 ExtensionApiTest::TearDownOnMainThread(); |
128 } | 126 } |
129 | 127 |
130 void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { | 128 void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { |
131 ExtensionApiTest::SetUpCommandLine(command_line); | 129 ExtensionApiTest::SetUpCommandLine(command_line); |
132 | 130 |
133 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 131 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
134 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 132 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
135 if (!needs_background_networking_) | 133 if (!needs_background_networking_) |
136 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); | 134 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); |
137 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); | 135 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); |
138 | 136 |
139 GURL gaia_url = gaia_https_forwarder_->GetURL(""); | 137 GURL gaia_url = gaia_https_forwarder_->GetURL(std::string()); |
140 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); | 138 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); |
141 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); | 139 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); |
142 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, | 140 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, |
143 gaia_url.spec()); | 141 gaia_url.spec()); |
142 command_line->AppendSwitchASCII( | |
143 policy::switches::kDeviceManagementUrl, | |
144 embedded_test_server()->GetURL("/device_management").spec()); | |
144 | 145 |
145 fake_gaia_->Initialize(); | 146 fake_gaia_->Initialize(); |
146 fake_gaia_->set_issue_oauth_code_cookie(use_webview_); | 147 fake_gaia_->set_issue_oauth_code_cookie(use_webview_); |
147 } | 148 } |
148 | 149 |
149 void OobeBaseTest::InitHttpsForwarders() { | 150 void OobeBaseTest::InitHttpsForwarders() { |
150 gaia_https_forwarder_.reset( | 151 gaia_https_forwarder_.reset( |
151 new HTTPSForwarder(embedded_test_server()->base_url())); | 152 new HTTPSForwarder(embedded_test_server()->base_url())); |
152 ASSERT_TRUE(gaia_https_forwarder_->Start()); | 153 ASSERT_TRUE(gaia_https_forwarder_->Start()); |
153 } | 154 } |
154 | 155 |
156 void OobeBaseTest::RegisterAdditionalRequestHandlers() { | |
157 } | |
158 | |
155 void OobeBaseTest::SimulateNetworkOffline() { | 159 void OobeBaseTest::SimulateNetworkOffline() { |
156 NetworkPortalDetector::CaptivePortalState offline_state; | 160 NetworkPortalDetector::CaptivePortalState offline_state; |
157 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; | 161 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; |
158 network_portal_detector_->SetDetectionResultsForTesting( | 162 network_portal_detector_->SetDetectionResultsForTesting( |
159 FakeShillManagerClient::kFakeEthernetNetworkGuid, | 163 FakeShillManagerClient::kFakeEthernetNetworkGuid, |
160 offline_state); | 164 offline_state); |
161 network_portal_detector_->NotifyObserversForTesting(); | 165 network_portal_detector_->NotifyObserversForTesting(); |
162 } | 166 } |
163 | 167 |
164 base::Closure OobeBaseTest::SimulateNetworkOfflineClosure() { | 168 base::Closure OobeBaseTest::SimulateNetworkOfflineClosure() { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 } | 214 } |
211 | 215 |
212 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { | 216 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { |
213 ExistingUserController* controller = | 217 ExistingUserController* controller = |
214 ExistingUserController::current_controller(); | 218 ExistingUserController::current_controller(); |
215 CHECK(controller); | 219 CHECK(controller); |
216 return static_cast<WebUILoginDisplay*>( | 220 return static_cast<WebUILoginDisplay*>( |
217 controller->login_display()); | 221 controller->login_display()); |
218 } | 222 } |
219 | 223 |
224 void OobeBaseTest::WaitForGaiaPageLoad() { | |
225 WaitForSigninScreen(); | |
226 | |
227 if (!use_webview_) | |
228 return; | |
229 | |
230 ASSERT_TRUE(content::ExecuteScript( | |
231 GetLoginUI()->GetWebContents(), | |
232 "$('gaia-signin').gaiaAuthHost_.addEventListener('ready'," | |
233 "function() {" | |
234 "window.domAutomationController.setAutomationId(0);" | |
235 "window.domAutomationController.send('GaiaReady');" | |
236 "});")); | |
237 | |
238 content::DOMMessageQueue message_queue; | |
239 std::string message; | |
240 ASSERT_TRUE(message_queue.WaitForMessage(&message)); | |
dzhioev (left Google)
2015/04/15 17:36:25
Please check message's value in loop, until you re
Nikita (slow)
2015/04/15 18:35:42
Done.
| |
241 EXPECT_EQ("\"GaiaReady\"", message); | |
242 } | |
243 | |
220 void OobeBaseTest::WaitForSigninScreen() { | 244 void OobeBaseTest::WaitForSigninScreen() { |
221 WizardController* wizard_controller = WizardController::default_controller(); | 245 WizardController* wizard_controller = WizardController::default_controller(); |
222 if (wizard_controller) { | 246 if (wizard_controller) |
223 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); | 247 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
224 } | 248 |
225 WizardController::SkipPostLoginScreensForTesting(); | 249 WizardController::SkipPostLoginScreensForTesting(); |
226 | 250 |
227 login_screen_load_observer_->Wait(); | 251 login_screen_load_observer_->Wait(); |
228 } | 252 } |
229 | 253 |
230 void OobeBaseTest::ExecuteJsInSigninFrame(const std::string& js) { | 254 void OobeBaseTest::ExecuteJsInSigninFrame(const std::string& js) { |
231 content::RenderFrameHost* frame = InlineLoginUI::GetAuthFrame( | 255 content::RenderFrameHost* frame = InlineLoginUI::GetAuthFrame( |
232 GetLoginUI()->GetWebContents(), GURL(), gaia_frame_parent_); | 256 GetLoginUI()->GetWebContents(), GURL(), gaia_frame_parent_); |
233 ASSERT_TRUE(content::ExecuteScript(frame, js)); | 257 ASSERT_TRUE(content::ExecuteScript(frame, js)); |
234 } | 258 } |
235 | 259 |
236 void OobeBaseTest::SetSignFormField(const std::string& field_id, | 260 void OobeBaseTest::SetSignFormField(const std::string& field_id, |
237 const std::string& field_value) { | 261 const std::string& field_value) { |
238 std::string js = | 262 std::string js = |
239 "(function(){" | 263 "(function(){" |
240 "document.getElementById('$FieldId').value = '$FieldValue';" | 264 "document.getElementById('$FieldId').value = '$FieldValue';" |
241 "var e = new Event('input');" | 265 "var e = new Event('input');" |
242 "document.getElementById('$FieldId').dispatchEvent(e);" | 266 "document.getElementById('$FieldId').dispatchEvent(e);" |
243 "})();"; | 267 "})();"; |
244 ReplaceSubstringsAfterOffset(&js, 0, "$FieldId", field_id); | 268 ReplaceSubstringsAfterOffset(&js, 0, "$FieldId", field_id); |
245 ReplaceSubstringsAfterOffset(&js, 0, "$FieldValue", field_value); | 269 ReplaceSubstringsAfterOffset(&js, 0, "$FieldValue", field_value); |
246 ExecuteJsInSigninFrame(js); | 270 ExecuteJsInSigninFrame(js); |
247 } | 271 } |
248 | 272 |
249 } // namespace chromeos | 273 } // namespace chromeos |
OLD | NEW |