Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/chromeos/login/test/oobe_base_test.cc

Issue 1054403002: Basic tests for new webview based signin flow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reuse OobeBaseTest Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/path_service.h" 10 #include "base/path_service.h"
10 #include "chrome/browser/chrome_notification_types.h" 11 #include "chrome/browser/chrome_notification_types.h"
11 #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"
12 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h" 14 #include "chrome/browser/chromeos/net/network_portal_detector_test_impl.h"
13 #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"
17 #include "chrome/common/chrome_constants.h"
14 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/pref_names.h"
16 #include "chromeos/chromeos_switches.h" 21 #include "chromeos/chromeos_switches.h"
17 #include "chromeos/dbus/fake_shill_manager_client.h" 22 #include "chromeos/dbus/fake_shill_manager_client.h"
18 #include "components/user_manager/fake_user_manager.h" 23 #include "components/user_manager/fake_user_manager.h"
19 #include "content/public/browser/notification_observer.h" 24 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
23 #include "google_apis/gaia/gaia_switches.h" 28 #include "google_apis/gaia/gaia_switches.h"
24 #include "net/dns/mock_host_resolver.h" 29 #include "net/dns/mock_host_resolver.h"
25 #include "net/test/embedded_test_server/http_request.h" 30 #include "net/test/embedded_test_server/http_request.h"
26 #include "net/test/embedded_test_server/http_response.h" 31 #include "net/test/embedded_test_server/http_response.h"
27 32
28 namespace chromeos { 33 namespace chromeos {
29 34
30 OobeBaseTest::OobeBaseTest() 35 OobeBaseTest::OobeBaseTest()
31 : fake_gaia_(new FakeGaia()), 36 : fake_gaia_(new FakeGaia()),
32 network_portal_detector_(NULL), 37 network_portal_detector_(NULL),
33 needs_background_networking_(false) { 38 needs_background_networking_(false),
39 gaia_frame_parent_("signin-frame"),
40 use_webview_(false) {
34 set_exit_when_last_browser_closes(false); 41 set_exit_when_last_browser_closes(false);
35 set_chromeos_user_ = false; 42 set_chromeos_user_ = false;
36 } 43 }
37 44
38 OobeBaseTest::~OobeBaseTest() { 45 OobeBaseTest::~OobeBaseTest() {
39 } 46 }
40 47
41 void OobeBaseTest::SetUp() { 48 void OobeBaseTest::SetUp() {
42 base::FilePath test_data_dir; 49 base::FilePath test_data_dir;
43 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); 50 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
44 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); 51 embedded_test_server()->ServeFilesFromDirectory(test_data_dir);
52
45 embedded_test_server()->RegisterRequestHandler( 53 embedded_test_server()->RegisterRequestHandler(
46 base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get()))); 54 base::Bind(&FakeGaia::HandleRequest, base::Unretained(fake_gaia_.get())));
55
47 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 56 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
57
58 // Start https wrapper here so that the URLs can be pointed at it in
59 // SetUpCommandLine().
60 InitHttpsForwarders();
61
48 // Stop IO thread here because no threads are allowed while 62 // Stop IO thread here because no threads are allowed while
49 // spawning sandbox host process. See crbug.com/322732. 63 // spawning sandbox host process. See crbug.com/322732.
50 embedded_test_server()->StopThread(); 64 embedded_test_server()->StopThread();
51 65
52 ExtensionApiTest::SetUp(); 66 ExtensionApiTest::SetUp();
53 } 67 }
54 68
69 bool OobeBaseTest::SetUpUserDataDirectory() {
70 if (use_webview_) {
71 // Fake Dev channel to enable webview signin.
72 scoped_channel_.reset(
73 new extensions::ScopedCurrentChannel(chrome::VersionInfo::CHANNEL_DEV));
74
75 base::FilePath user_data_dir;
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.
81 // Otherwise, we break PRE tests that leave state in it.
82 if (!base::PathExists(local_state_path)) {
83 base::DictionaryValue local_state_dict;
84 local_state_dict.SetBoolean(prefs::kWebviewSigninEnabled, true);
85 // OobeCompleted to skip controller-pairing-screen which still uses
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);
89
90 CHECK(JSONFileValueSerializer(local_state_path)
91 .Serialize(local_state_dict));
92 }
93 }
94
95 return ExtensionApiTest::SetUpUserDataDirectory();
96 }
97
55 void OobeBaseTest::SetUpInProcessBrowserTestFixture() { 98 void OobeBaseTest::SetUpInProcessBrowserTestFixture() {
56 host_resolver()->AddRule("*", "127.0.0.1"); 99 host_resolver()->AddRule("*", "127.0.0.1");
57 network_portal_detector_ = new NetworkPortalDetectorTestImpl(); 100 network_portal_detector_ = new NetworkPortalDetectorTestImpl();
58 NetworkPortalDetector::InitializeForTesting(network_portal_detector_); 101 NetworkPortalDetector::InitializeForTesting(network_portal_detector_);
59 network_portal_detector_->SetDefaultNetworkForTesting( 102 network_portal_detector_->SetDefaultNetworkForTesting(
60 FakeShillManagerClient::kFakeEthernetNetworkGuid); 103 FakeShillManagerClient::kFakeEthernetNetworkGuid);
61 104
62 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); 105 ExtensionApiTest::SetUpInProcessBrowserTestFixture();
63 } 106 }
64 107
65 void OobeBaseTest::SetUpOnMainThread() { 108 void OobeBaseTest::SetUpOnMainThread() {
66 // 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.
67 embedded_test_server()->RestartThreadAndListen(); 110 embedded_test_server()->RestartThreadAndListen();
68 111
112 login_screen_load_observer_.reset(new content::WindowedNotificationObserver(
113 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
114 content::NotificationService::AllSources()));
115
69 ExtensionApiTest::SetUpOnMainThread(); 116 ExtensionApiTest::SetUpOnMainThread();
70 } 117 }
71 118
72 void OobeBaseTest::TearDownOnMainThread() { 119 void OobeBaseTest::TearDownOnMainThread() {
73 // If the login display is still showing, exit gracefully. 120 // If the login display is still showing, exit gracefully.
74 if (LoginDisplayHostImpl::default_host()) { 121 if (LoginDisplayHostImpl::default_host()) {
75 base::MessageLoop::current()->PostTask(FROM_HERE, 122 base::MessageLoop::current()->PostTask(FROM_HERE,
76 base::Bind(&chrome::AttemptExit)); 123 base::Bind(&chrome::AttemptExit));
77 content::RunMessageLoop(); 124 content::RunMessageLoop();
78 } 125 }
79 126
80 ExtensionApiTest::TearDownOnMainThread(); 127 ExtensionApiTest::TearDownOnMainThread();
81 } 128 }
82 129
83 void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) { 130 void OobeBaseTest::SetUpCommandLine(base::CommandLine* command_line) {
84 ExtensionApiTest::SetUpCommandLine(command_line); 131 ExtensionApiTest::SetUpCommandLine(command_line);
132
85 command_line->AppendSwitch(chromeos::switches::kLoginManager); 133 command_line->AppendSwitch(chromeos::switches::kLoginManager);
86 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); 134 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
87 if (!needs_background_networking_) 135 if (!needs_background_networking_)
88 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking); 136 command_line->AppendSwitch(::switches::kDisableBackgroundNetworking);
89 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 137 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
90 138
91 // Create gaia and webstore URL from test server url but using different 139 GURL gaia_url = gaia_https_forwarder_->GetURL("");
92 // host names. This is to avoid gaia response being tagged as from
93 // webstore in chrome_resource_dispatcher_host_delegate.cc.
94 const GURL& server_url = embedded_test_server()->base_url();
95
96 GURL::Replacements replace_gaia_host;
97 replace_gaia_host.SetHostStr("gaia");
98 GURL gaia_url = server_url.ReplaceComponents(replace_gaia_host);
99 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec()); 140 command_line->AppendSwitchASCII(::switches::kGaiaUrl, gaia_url.spec());
100 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec()); 141 command_line->AppendSwitchASCII(::switches::kLsoUrl, gaia_url.spec());
101 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl, 142 command_line->AppendSwitchASCII(::switches::kGoogleApisUrl,
102 gaia_url.spec()); 143 gaia_url.spec());
144
103 fake_gaia_->Initialize(); 145 fake_gaia_->Initialize();
146 fake_gaia_->set_issue_oauth_code_cookie(use_webview_);
147 }
148
149 void OobeBaseTest::InitHttpsForwarders() {
150 // Create gaia and webstore URL from test server url but using different
151 // host names. This is to avoid gaia response being tagged as from
152 // webstore in chrome_resource_dispatcher_host_delegate.cc.
153 gaia_https_forwarder_.reset(
154 new HTTPSForwarder(embedded_test_server()->base_url()));
155 ASSERT_TRUE(gaia_https_forwarder_->Start());
104 } 156 }
105 157
106 void OobeBaseTest::SimulateNetworkOffline() { 158 void OobeBaseTest::SimulateNetworkOffline() {
107 NetworkPortalDetector::CaptivePortalState offline_state; 159 NetworkPortalDetector::CaptivePortalState offline_state;
108 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE; 160 offline_state.status = NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE;
109 network_portal_detector_->SetDetectionResultsForTesting( 161 network_portal_detector_->SetDetectionResultsForTesting(
110 FakeShillManagerClient::kFakeEthernetNetworkGuid, 162 FakeShillManagerClient::kFakeEthernetNetworkGuid,
111 offline_state); 163 offline_state);
112 network_portal_detector_->NotifyObserversForTesting(); 164 network_portal_detector_->NotifyObserversForTesting();
113 } 165 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 213 }
162 214
163 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() { 215 WebUILoginDisplay* OobeBaseTest::GetLoginDisplay() {
164 ExistingUserController* controller = 216 ExistingUserController* controller =
165 ExistingUserController::current_controller(); 217 ExistingUserController::current_controller();
166 CHECK(controller); 218 CHECK(controller);
167 return static_cast<WebUILoginDisplay*>( 219 return static_cast<WebUILoginDisplay*>(
168 controller->login_display()); 220 controller->login_display());
169 } 221 }
170 222
223 void OobeBaseTest::WaitForSigninScreen() {
224 WizardController* wizard_controller = WizardController::default_controller();
225 if (wizard_controller) {
226 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
227 }
228 WizardController::SkipPostLoginScreensForTesting();
229
230 login_screen_load_observer_->Wait();
231 }
232
233 void OobeBaseTest::ExecuteJsInSigninFrame(const std::string& js) {
234 content::RenderFrameHost* frame = InlineLoginUI::GetAuthIframe(
Nikita (slow) 2015/04/07 12:37:48 Please rename to InlineLoginUI::GetAuthFrame() sin
Dmitry Polukhin 2015/04/07 13:24:40 Done.
235 GetLoginUI()->GetWebContents(), GURL(), gaia_frame_parent_);
236 ASSERT_TRUE(content::ExecuteScript(frame, js));
237 }
238
239 void OobeBaseTest::SetSignFormField(const std::string& field_id,
240 const std::string& field_value) {
241 std::string js =
242 "(function(){"
243 "document.getElementById('$FieldId').value = '$FieldValue';"
244 "var e = new Event('input');"
245 "document.getElementById('$FieldId').dispatchEvent(e);"
246 "})();";
247 ReplaceSubstringsAfterOffset(&js, 0, "$FieldId", field_id);
248 ReplaceSubstringsAfterOffset(&js, 0, "$FieldValue", field_value);
249 ExecuteJsInSigninFrame(js);
250 }
251
171 } // namespace chromeos 252 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698