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

Side by Side Diff: chrome/browser/chromeos/policy/blocking_login_browsertest.cc

Issue 1107873002: Test BlockingLoginTestInstance with enabled webview (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments resolved 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 *out = result; 71 *out = result;
72 loop->Quit(); 72 loop->Quit();
73 } 73 }
74 74
75 } // namespace 75 } // namespace
76 76
77 struct BlockingLoginTestParam { 77 struct BlockingLoginTestParam {
78 const int steps; 78 const int steps;
79 const char* username; 79 const char* username;
80 const bool enroll_device; 80 const bool enroll_device;
81 const bool use_webview;
81 }; 82 };
82 83
83 class BlockingLoginTest 84 class BlockingLoginTest
84 : public OobeBaseTest, 85 : public OobeBaseTest,
85 public content::NotificationObserver, 86 public content::NotificationObserver,
86 public testing::WithParamInterface<BlockingLoginTestParam> { 87 public testing::WithParamInterface<BlockingLoginTestParam> {
87 public: 88 public:
88 BlockingLoginTest() : profile_added_(NULL) { 89 BlockingLoginTest() : profile_added_(NULL) {
89 // TODO(nkostylev): Fix this test for webview. http://crbug.com/477402 90 // TODO(nkostylev): Fix this test for webview. http://crbug.com/477402
90 set_use_webview(false); 91 set_use_webview(GetParam().use_webview);
91 } 92 }
92 93
93 void SetUpCommandLine(base::CommandLine* command_line) override { 94 void SetUpCommandLine(base::CommandLine* command_line) override {
94 OobeBaseTest::SetUpCommandLine(command_line); 95 OobeBaseTest::SetUpCommandLine(command_line);
95 96
96 command_line->AppendSwitchASCII(::switches::kAuthExtensionPath,
97 "gaia_auth");
98 command_line->AppendSwitchASCII( 97 command_line->AppendSwitchASCII(
99 policy::switches::kDeviceManagementUrl, 98 policy::switches::kDeviceManagementUrl,
100 embedded_test_server()->GetURL("/device_management").spec()); 99 embedded_test_server()->GetURL("/device_management").spec());
101 } 100 }
102 101
103 void SetUpOnMainThread() override { 102 void SetUpOnMainThread() override {
104 registrar_.Add(this, 103 registrar_.Add(this,
105 chrome::NOTIFICATION_PROFILE_ADDED, 104 chrome::NOTIFICATION_PROFILE_ADDED,
106 content::NotificationService::AllSources()); 105 content::NotificationService::AllSources());
107 106
(...skipping 17 matching lines...) Expand all
125 124
126 void RunUntilIdle() { 125 void RunUntilIdle() {
127 base::RunLoop().RunUntilIdle(); 126 base::RunLoop().RunUntilIdle();
128 } 127 }
129 128
130 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector() { 129 policy::BrowserPolicyConnectorChromeOS* browser_policy_connector() {
131 return g_browser_process->platform_part() 130 return g_browser_process->platform_part()
132 ->browser_policy_connector_chromeos(); 131 ->browser_policy_connector_chromeos();
133 } 132 }
134 133
135 void SkipToSigninScreen() {
136 WizardController::SkipPostLoginScreensForTesting();
137 WizardController* wizard_controller =
138 WizardController::default_controller();
139 ASSERT_TRUE(wizard_controller);
140 wizard_controller->SkipToLoginForTesting(LoginScreenContext());
141
142 content::WindowedNotificationObserver(
143 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
144 content::NotificationService::AllSources()).Wait();
145 RunUntilIdle();
146 }
147
148 void EnrollDevice(const std::string& username) { 134 void EnrollDevice(const std::string& username) {
149 base::RunLoop loop; 135 base::RunLoop loop;
150 policy::EnterpriseInstallAttributes::LockResult result; 136 policy::EnterpriseInstallAttributes::LockResult result;
151 browser_policy_connector()->GetInstallAttributes()->LockDevice( 137 browser_policy_connector()->GetInstallAttributes()->LockDevice(
152 username, policy::DEVICE_MODE_ENTERPRISE, "100200300", 138 username, policy::DEVICE_MODE_ENTERPRISE, "100200300",
153 base::Bind(&CopyLockResult, &loop, &result)); 139 base::Bind(&CopyLockResult, &loop, &result));
154 loop.Run(); 140 loop.Run();
155 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, result); 141 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, result);
156 RunUntilIdle(); 142 RunUntilIdle();
157 } 143 }
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 EXPECT_EQ(kDomain, browser_policy_connector()->GetEnterpriseDomain()); 247 EXPECT_EQ(kDomain, browser_policy_connector()->GetEnterpriseDomain());
262 EXPECT_FALSE(profile_added_); 248 EXPECT_FALSE(profile_added_);
263 EXPECT_EQ(policy::USER_AFFILIATION_MANAGED, 249 EXPECT_EQ(policy::USER_AFFILIATION_MANAGED,
264 browser_policy_connector()->GetUserAffiliation(kUsername)); 250 browser_policy_connector()->GetUserAffiliation(kUsername));
265 RunUntilIdle(); 251 RunUntilIdle();
266 EXPECT_FALSE(user_manager->IsKnownUser(kUsername)); 252 EXPECT_FALSE(user_manager->IsKnownUser(kUsername));
267 } 253 }
268 254
269 // Skip the OOBE, go to the sign-in screen, and wait for the login screen to 255 // Skip the OOBE, go to the sign-in screen, and wait for the login screen to
270 // become visible. 256 // become visible.
271 SkipToSigninScreen(); 257 WaitForSigninScreen();
272 EXPECT_FALSE(profile_added_); 258 EXPECT_FALSE(profile_added_);
273 259
274 // Prepare the fake HTTP responses. 260 // Prepare the fake HTTP responses.
275 if (GetParam().steps < 5) { 261 if (GetParam().steps < 5) {
276 // If this instance is not going to complete the entire flow successfully 262 // If this instance is not going to complete the entire flow successfully
277 // then the last step will fail. 263 // then the last step will fail.
278 264
279 // This response body is important to make the gaia fetcher skip its delayed 265 // This response body is important to make the gaia fetcher skip its delayed
280 // retry behavior, which makes testing harder. If this is sent to the policy 266 // retry behavior, which makes testing harder. If this is sent to the policy
281 // fetchers then it will make them fail too. 267 // fetchers then it will make them fail too.
282 PushResponse(net::HTTP_UNAUTHORIZED).set_content("Error=AccountDeleted"); 268 PushResponse(net::HTTP_UNAUTHORIZED).set_content("Error=AccountDeleted");
283 } 269 }
284 270
285 // Push a response for each step that is going to succeed, in reverse order. 271 // Push a response for each step that is going to succeed, in reverse order.
286 switch (GetParam().steps) { 272 switch (GetParam().steps) {
287 default: 273 default:
288 ADD_FAILURE() << "Invalid step number: " << GetParam().steps; 274 ADD_FAILURE() << "Invalid step number: " << GetParam().steps;
289 return; 275 return;
290 276
291 case 5: 277 case 5:
292 PushResponse(net::HTTP_OK).set_content(GetPolicyResponse()); 278 PushResponse(net::HTTP_OK).set_content(GetPolicyResponse());
293 279
294 case 4: 280 case 4:
295 PushResponse(net::HTTP_OK).set_content(GetRegisterResponse()); 281 PushResponse(net::HTTP_OK).set_content(GetRegisterResponse());
296 282
297 case 3: 283 case 3:
298 PushResponse(net::HTTP_OK).set_content(kOAuth2AccessTokenData); 284 if (!GetParam().use_webview)
285 PushResponse(net::HTTP_OK).set_content(kOAuth2AccessTokenData);
299 286
300 case 2: 287 case 2:
301 PushResponse(net::HTTP_OK).set_content(kOAuth2TokenPairData); 288 if (!GetParam().use_webview)
289 PushResponse(net::HTTP_OK).set_content(kOAuth2TokenPairData);
302 290
303 case 1: 291 case 1:
304 PushResponse(net::HTTP_OK) 292 PushResponse(net::HTTP_OK)
305 .AddCustomHeader("Set-Cookie", kOAuthCodeCookie); 293 .AddCustomHeader("Set-Cookie", kOAuthCodeCookie);
306 break; 294 break;
307 295
308 case 0: 296 case 0:
309 break; 297 break;
310 } 298 }
311 299
312 // Login now. This verifies that logging in with the canned responses (which 300 // Login now. This verifies that logging in with the canned responses (which
313 // may include failures) won't be blocked due to the potential failures. 301 // may include failures) won't be blocked due to the potential failures.
314 EXPECT_FALSE(profile_added_); 302 EXPECT_FALSE(profile_added_);
315 Login(GetParam().username); 303 Login(GetParam().username);
316 EXPECT_TRUE(profile_added_); 304 EXPECT_TRUE(profile_added_);
317 ASSERT_TRUE(user_manager->IsUserLoggedIn()); 305 ASSERT_TRUE(user_manager->IsUserLoggedIn());
318 EXPECT_TRUE(user_manager->IsCurrentUserNew()); 306 EXPECT_TRUE(user_manager->IsCurrentUserNew());
319 } 307 }
320 308
321 const BlockingLoginTestParam kBlockinLoginTestCases[] = { 309 const BlockingLoginTestParam kBlockinLoginTestCases[] = {
322 { 0, kUsername, true }, 310 {0, kUsername, true, false},
323 { 1, kUsername, true }, 311 {1, kUsername, true, false},
324 { 2, kUsername, true }, 312 {2, kUsername, true, false},
325 { 3, kUsername, true }, 313 {3, kUsername, true, false},
326 { 4, kUsername, true }, 314 {4, kUsername, true, false},
327 { 5, kUsername, true }, 315 {5, kUsername, true, false},
328 { 0, kUsername, false }, 316 {0, kUsername, false, false},
329 { 1, kUsername, false }, 317 {1, kUsername, false, false},
330 { 2, kUsername, false }, 318 {2, kUsername, false, false},
331 { 3, kUsername, false }, 319 {3, kUsername, false, false},
332 { 4, kUsername, false }, 320 {4, kUsername, false, false},
333 { 5, kUsername, false }, 321 {5, kUsername, false, false},
334 { 0, kUsernameOtherDomain, true }, 322 {0, kUsernameOtherDomain, true, false},
335 { 1, kUsernameOtherDomain, true }, 323 {1, kUsernameOtherDomain, true, false},
336 { 2, kUsernameOtherDomain, true }, 324 {2, kUsernameOtherDomain, true, false},
337 { 3, kUsernameOtherDomain, true }, 325 {3, kUsernameOtherDomain, true, false},
338 { 4, kUsernameOtherDomain, true }, 326 {4, kUsernameOtherDomain, true, false},
339 { 5, kUsernameOtherDomain, true }, 327 {5, kUsernameOtherDomain, true, false},
328
329 {0, kUsername, true, true},
330 {1, kUsername, true, true},
331 {2, kUsername, true, true},
332 {3, kUsername, true, true},
333 {4, kUsername, true, true},
334 {5, kUsername, true, true},
335 {0, kUsername, false, true},
336 {1, kUsername, false, true},
337 {2, kUsername, false, true},
338 {3, kUsername, false, true},
339 {4, kUsername, false, true},
340 {5, kUsername, false, true},
341 {0, kUsernameOtherDomain, true, true},
342 {1, kUsernameOtherDomain, true, true},
343 {2, kUsernameOtherDomain, true, true},
344 {3, kUsernameOtherDomain, true, true},
345 {4, kUsernameOtherDomain, true, true},
346 {5, kUsernameOtherDomain, true, true},
340 }; 347 };
341 348
342 INSTANTIATE_TEST_CASE_P(BlockingLoginTestInstance, 349 INSTANTIATE_TEST_CASE_P(BlockingLoginTestInstance,
343 BlockingLoginTest, 350 BlockingLoginTest,
344 testing::ValuesIn(kBlockinLoginTestCases)); 351 testing::ValuesIn(kBlockinLoginTestCases));
345 352
346 } // namespace chromeos 353 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698