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

Side by Side Diff: chrome/browser/chromeos/login/login_utils_browsertest.cc

Issue 10581012: Move test_url_fetcher_factory.* from content/ to net/url_request (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove export annotations Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_utils.h" 5 #include "chrome/browser/chromeos/login/login_utils.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 18 matching lines...) Expand all
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 30 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
31 #include "chrome/common/net/gaia/gaia_urls.h" 31 #include "chrome/common/net/gaia/gaia_urls.h"
32 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
33 #include "chrome/test/base/testing_browser_process.h" 33 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_pref_service.h" 34 #include "chrome/test/base/testing_pref_service.h"
35 #include "chromeos/dbus/mock_dbus_thread_manager.h" 35 #include "chromeos/dbus/mock_dbus_thread_manager.h"
36 #include "chromeos/dbus/mock_session_manager_client.h" 36 #include "chromeos/dbus/mock_session_manager_client.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/test/test_browser_thread.h" 38 #include "content/public/test/test_browser_thread.h"
39 #include "content/public/test/test_url_fetcher_factory.h" 39 #include "net/url_request/test_url_fetcher_factory.h"
40 #include "net/url_request/url_fetcher_delegate.h" 40 #include "net/url_request/url_fetcher_delegate.h"
41 #include "net/url_request/url_request.h" 41 #include "net/url_request/url_request.h"
42 #include "net/url_request/url_request_status.h" 42 #include "net/url_request/url_request_status.h"
43 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
44 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
45 45
46 namespace chromeos { 46 namespace chromeos {
47 47
48 namespace { 48 namespace {
49 49
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 LoginUtils::Get()->CreateAuthenticator(this); 307 LoginUtils::Get()->CreateAuthenticator(this);
308 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(), 308 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(),
309 username, 309 username,
310 "password"); 310 "password");
311 311
312 LoginUtils::Get()->PrepareProfile(username, std::string(), "password", 312 LoginUtils::Get()->PrepareProfile(username, std::string(), "password",
313 false, true, false, this); 313 false, true, false, this);
314 RunAllPending(); 314 RunAllPending();
315 } 315 }
316 316
317 TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) { 317 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) {
318 TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); 318 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0);
319 EXPECT_TRUE(fetcher); 319 EXPECT_TRUE(fetcher);
320 EXPECT_TRUE(fetcher->delegate()); 320 EXPECT_TRUE(fetcher->delegate());
321 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(), 321 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(),
322 expected_url, 322 expected_url,
323 true)); 323 true));
324 fetcher->set_url(fetcher->GetOriginalURL()); 324 fetcher->set_url(fetcher->GetOriginalURL());
325 fetcher->set_response_code(200); 325 fetcher->set_response_code(200);
326 fetcher->set_status(net::URLRequestStatus()); 326 fetcher->set_status(net::URLRequestStatus());
327 return fetcher; 327 return fetcher;
328 } 328 }
329 329
330 TestURLFetcher* PrepareDMServiceFetcher( 330 net::TestURLFetcher* PrepareDMServiceFetcher(
331 const std::string& expected_url, 331 const std::string& expected_url,
332 const em::DeviceManagementResponse& response) { 332 const em::DeviceManagementResponse& response) {
333 TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); 333 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0);
334 EXPECT_TRUE(fetcher); 334 EXPECT_TRUE(fetcher);
335 EXPECT_TRUE(fetcher->delegate()); 335 EXPECT_TRUE(fetcher->delegate());
336 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(), 336 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(),
337 expected_url, 337 expected_url,
338 true)); 338 true));
339 fetcher->set_url(fetcher->GetOriginalURL()); 339 fetcher->set_url(fetcher->GetOriginalURL());
340 fetcher->set_response_code(200); 340 fetcher->set_response_code(200);
341 fetcher->set_status(net::URLRequestStatus()); 341 fetcher->set_status(net::URLRequestStatus());
342 std::string data; 342 std::string data;
343 EXPECT_TRUE(response.SerializeToString(&data)); 343 EXPECT_TRUE(response.SerializeToString(&data));
344 fetcher->SetResponseString(data); 344 fetcher->SetResponseString(data);
345 return fetcher; 345 return fetcher;
346 } 346 }
347 347
348 TestURLFetcher* PrepareDMRegisterFetcher() { 348 net::TestURLFetcher* PrepareDMRegisterFetcher() {
349 em::DeviceManagementResponse response; 349 em::DeviceManagementResponse response;
350 em::DeviceRegisterResponse* register_response = 350 em::DeviceRegisterResponse* register_response =
351 response.mutable_register_response(); 351 response.mutable_register_response();
352 register_response->set_device_management_token(kDMToken); 352 register_response->set_device_management_token(kDMToken);
353 register_response->set_enrollment_type( 353 register_response->set_enrollment_type(
354 em::DeviceRegisterResponse::ENTERPRISE); 354 em::DeviceRegisterResponse::ENTERPRISE);
355 return PrepareDMServiceFetcher(kDMRegisterRequest, response); 355 return PrepareDMServiceFetcher(kDMRegisterRequest, response);
356 } 356 }
357 357
358 TestURLFetcher* PrepareDMPolicyFetcher() { 358 net::TestURLFetcher* PrepareDMPolicyFetcher() {
359 em::DeviceManagementResponse response; 359 em::DeviceManagementResponse response;
360 response.mutable_policy_response()->add_response(); 360 response.mutable_policy_response()->add_response();
361 return PrepareDMServiceFetcher(kDMPolicyRequest, response); 361 return PrepareDMServiceFetcher(kDMPolicyRequest, response);
362 } 362 }
363 363
364 protected: 364 protected:
365 ScopedStubCrosEnabler stub_cros_enabler_; 365 ScopedStubCrosEnabler stub_cros_enabler_;
366 366
367 MessageLoop loop_; 367 MessageLoop loop_;
368 TestingBrowserProcess* browser_process_; 368 TestingBrowserProcess* browser_process_;
369 ScopedTestingLocalState local_state_; 369 ScopedTestingLocalState local_state_;
370 370
371 content::TestBrowserThread ui_thread_; 371 content::TestBrowserThread ui_thread_;
372 content::TestBrowserThread db_thread_; 372 content::TestBrowserThread db_thread_;
373 content::TestBrowserThread file_thread_; 373 content::TestBrowserThread file_thread_;
374 content::TestBrowserThread io_thread_; 374 content::TestBrowserThread io_thread_;
375 scoped_ptr<IOThread> io_thread_state_; 375 scoped_ptr<IOThread> io_thread_state_;
376 376
377 MockDBusThreadManager mock_dbus_thread_manager_; 377 MockDBusThreadManager mock_dbus_thread_manager_;
378 input_method::MockInputMethodManager mock_input_method_manager_; 378 input_method::MockInputMethodManager mock_input_method_manager_;
379 TestURLFetcherFactory test_url_fetcher_factory_; 379 net::TestURLFetcherFactory test_url_fetcher_factory_;
380 380
381 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; 381 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
382 382
383 policy::BrowserPolicyConnector* connector_; 383 policy::BrowserPolicyConnector* connector_;
384 MockCryptohomeLibrary* cryptohome_; 384 MockCryptohomeLibrary* cryptohome_;
385 Profile* prepared_profile_; 385 Profile* prepared_profile_;
386 386
387 private: 387 private:
388 ScopedTempDir scoped_temp_dir_; 388 ScopedTempDir scoped_temp_dir_;
389 389
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 EXPECT_FALSE(prepared_profile_); 455 EXPECT_FALSE(prepared_profile_);
456 456
457 // Login with a user of the enterprise domain waits for policy. 457 // Login with a user of the enterprise domain waits for policy.
458 PrepareProfile(kUsername); 458 PrepareProfile(kUsername);
459 459
460 EXPECT_FALSE(prepared_profile_); 460 EXPECT_FALSE(prepared_profile_);
461 ASSERT_TRUE(user_manager->IsUserLoggedIn() && 461 ASSERT_TRUE(user_manager->IsUserLoggedIn() &&
462 !user_manager->IsLoggedInAsStub()); 462 !user_manager->IsLoggedInAsStub());
463 463
464 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 464 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
465 TestURLFetcher* fetcher; 465 net::TestURLFetcher* fetcher;
466 466
467 // |steps| is the test parameter, and is the number of successful fetches. 467 // |steps| is the test parameter, and is the number of successful fetches.
468 // The first incomplete fetch will fail. In any case, the profile creation 468 // The first incomplete fetch will fail. In any case, the profile creation
469 // should resume. 469 // should resume.
470 int steps = GetParam(); 470 int steps = GetParam();
471 471
472 do { 472 do {
473 if (steps < 1) break; 473 if (steps < 1) break;
474 474
475 // Fake OAuth token retrieval: 475 // Fake OAuth token retrieval:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 507
508 fetcher = PrepareDMPolicyFetcher(); 508 fetcher = PrepareDMPolicyFetcher();
509 fetcher->delegate()->OnURLFetchComplete(fetcher); 509 fetcher->delegate()->OnURLFetchComplete(fetcher);
510 } while (0); 510 } while (0);
511 511
512 if (steps < 5) { 512 if (steps < 5) {
513 // Verify that the profile hasn't been created yet. 513 // Verify that the profile hasn't been created yet.
514 EXPECT_FALSE(prepared_profile_); 514 EXPECT_FALSE(prepared_profile_);
515 515
516 // Make the current fetcher fail. 516 // Make the current fetcher fail.
517 TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); 517 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0);
518 EXPECT_TRUE(fetcher); 518 EXPECT_TRUE(fetcher);
519 EXPECT_TRUE(fetcher->delegate()); 519 EXPECT_TRUE(fetcher->delegate());
520 fetcher->set_url(fetcher->GetOriginalURL()); 520 fetcher->set_url(fetcher->GetOriginalURL());
521 fetcher->set_response_code(500); 521 fetcher->set_response_code(500);
522 fetcher->delegate()->OnURLFetchComplete(fetcher); 522 fetcher->delegate()->OnURLFetchComplete(fetcher);
523 } 523 }
524 524
525 // The profile is finally ready: 525 // The profile is finally ready:
526 EXPECT_TRUE(prepared_profile_); 526 EXPECT_TRUE(prepared_profile_);
527 } 527 }
528 528
529 INSTANTIATE_TEST_CASE_P( 529 INSTANTIATE_TEST_CASE_P(
530 LoginUtilsBlockingLoginTestInstance, 530 LoginUtilsBlockingLoginTestInstance,
531 LoginUtilsBlockingLoginTest, 531 LoginUtilsBlockingLoginTest,
532 testing::Values(0, 1, 2, 3, 4, 5)); 532 testing::Values(0, 1, 2, 3, 4, 5));
533 533
534 } // namespace 534 } // namespace
535 535
536 } 536 }
OLDNEW
« no previous file with comments | « chrome/browser/captive_portal/captive_portal_service_unittest.cc ('k') | chrome/browser/chromeos/login/mock_url_fetchers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698