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

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

Issue 8477004: Have content/ create and destroy its own threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix official build, avoid DCHECK in official Linux/ChromeOS builds. Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 12 matching lines...) Expand all
23 #include "chrome/browser/policy/browser_policy_connector.h" 23 #include "chrome/browser/policy/browser_policy_connector.h"
24 #include "chrome/browser/policy/proto/device_management_backend.pb.h" 24 #include "chrome/browser/policy/proto/device_management_backend.pb.h"
25 #include "chrome/browser/profiles/profile_manager.h" 25 #include "chrome/browser/profiles/profile_manager.h"
26 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/net/gaia/gaia_urls.h" 28 #include "chrome/common/net/gaia/gaia_urls.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "chrome/common/net/gaia/gaia_auth_consumer.h" 30 #include "chrome/common/net/gaia/gaia_auth_consumer.h"
31 #include "chrome/test/base/testing_browser_process.h" 31 #include "chrome/test/base/testing_browser_process.h"
32 #include "chrome/test/base/testing_pref_service.h" 32 #include "chrome/test/base/testing_pref_service.h"
33 #include "content/public/browser/browser_thread.h"
33 #include "content/public/common/url_fetcher_delegate.h" 34 #include "content/public/common/url_fetcher_delegate.h"
34 #include "content/test/test_browser_thread.h" 35 #include "content/test/test_browser_thread.h"
35 #include "content/test/test_url_fetcher_factory.h" 36 #include "content/test/test_url_fetcher_factory.h"
36 #include "net/url_request/url_request.h" 37 #include "net/url_request/url_request.h"
37 #include "net/url_request/url_request_status.h" 38 #include "net/url_request/url_request_status.h"
38 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
40 41
41 namespace chromeos { 42 namespace chromeos {
42 43
43 namespace { 44 namespace {
44 45
45 namespace em = enterprise_management; 46 namespace em = enterprise_management;
46 47
47 using ::testing::DoAll; 48 using ::testing::DoAll;
48 using ::testing::Return; 49 using ::testing::Return;
49 using ::testing::SetArgPointee; 50 using ::testing::SetArgPointee;
50 using ::testing::_; 51 using ::testing::_;
52 using content::BrowserThread;
51 53
52 const char kTrue[] = "true"; 54 const char kTrue[] = "true";
53 const char kDomain[] = "domain.com"; 55 const char kDomain[] = "domain.com";
54 const char kUsername[] = "user@domain.com"; 56 const char kUsername[] = "user@domain.com";
55 const char kUsernameOtherDomain[] = "user@other.com"; 57 const char kUsernameOtherDomain[] = "user@other.com";
56 const char kAttributeOwned[] = "enterprise.owned"; 58 const char kAttributeOwned[] = "enterprise.owned";
57 const char kAttributeOwner[] = "enterprise.user"; 59 const char kAttributeOwner[] = "enterprise.user";
58 60
59 const char kOAuthTokenCookie[] = "oauth_token=1234"; 61 const char kOAuthTokenCookie[] = "oauth_token=1234";
60 const char kOAuthGetAccessTokenData[] = 62 const char kOAuthGetAccessTokenData[] =
61 "oauth_token=1234&oauth_token_secret=1234"; 63 "oauth_token=1234&oauth_token_secret=1234";
62 const char kOAuthServiceTokenData[] = 64 const char kOAuthServiceTokenData[] =
63 "wrap_access_token=1234&wrap_access_token_expires_in=123456789"; 65 "wrap_access_token=1234&wrap_access_token_expires_in=123456789";
64 66
65 const char kDMServer[] = "http://server/device_management"; 67 const char kDMServer[] = "http://server/device_management";
66 const char kDMRegisterRequest[] = 68 const char kDMRegisterRequest[] =
67 "http://server/device_management?request=register"; 69 "http://server/device_management?request=register";
68 const char kDMPolicyRequest[] = 70 const char kDMPolicyRequest[] =
69 "http://server/device_management?request=policy"; 71 "http://server/device_management?request=policy";
70 72
71 const char kDMToken[] = "1234"; 73 const char kDMToken[] = "1234";
72 74
73 ACTION_P(MockSessionManagerClientPolicyCallback, policy) { 75 ACTION_P(MockSessionManagerClientPolicyCallback, policy) {
74 arg0.Run(policy); 76 arg0.Run(policy);
75 } 77 }
76 78
77 // Subclass IOThread to expose set_message_loop.
78 class TestIOThread : public IOThread {
79 public:
80 explicit TestIOThread(PrefService* local_state)
81 : IOThread(local_state, NULL, NULL) {}
82
83 using IOThread::set_message_loop;
84 };
85
86 template<typename TESTBASE> 79 template<typename TESTBASE>
87 class LoginUtilsTestBase : public TESTBASE, 80 class LoginUtilsTestBase : public TESTBASE,
88 public LoginUtils::Delegate, 81 public LoginUtils::Delegate,
89 public LoginStatusConsumer { 82 public LoginStatusConsumer {
90 public: 83 public:
84 // Initialization here is important. The UI thread gets the test's
85 // message loop, as does the file thread (which never actually gets
86 // started - so this is a way to fake multiple threads on a single
87 // test thread). The IO thread does not get the message loop set,
88 // and is never started. This is necessary so that we skip various
89 // bits of initialization that get posted to the IO thread. We do
90 // however, at one point in the test, temporarily set the message
91 // loop for the IO thread.
91 LoginUtilsTestBase() 92 LoginUtilsTestBase()
92 : loop_(MessageLoop::TYPE_IO), 93 : loop_(MessageLoop::TYPE_IO),
93 browser_process_( 94 browser_process_(
94 static_cast<TestingBrowserProcess*>(g_browser_process)), 95 static_cast<TestingBrowserProcess*>(g_browser_process)),
95 local_state_(browser_process_), 96 local_state_(browser_process_),
96 ui_thread_(content::BrowserThread::UI, &loop_), 97 ui_thread_(content::BrowserThread::UI, &loop_),
97 file_thread_(content::BrowserThread::FILE, &loop_), 98 file_thread_(content::BrowserThread::FILE, &loop_),
98 io_thread_(local_state_.Get()), 99 io_thread_(content::BrowserThread::IO),
100 io_thread_state_(local_state_.Get(), NULL, NULL),
99 prepared_profile_(NULL) {} 101 prepared_profile_(NULL) {}
100 102
101 virtual void SetUp() OVERRIDE { 103 virtual void SetUp() OVERRIDE {
102 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 104 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
103 // BrowserPolicyConnector makes the UserPolicyCache read relative to this 105 // BrowserPolicyConnector makes the UserPolicyCache read relative to this
104 // path. Make sure it's in a clean state. 106 // path. Make sure it's in a clean state.
105 PathService::Override(chrome::DIR_USER_DATA, scoped_temp_dir_.path()); 107 PathService::Override(chrome::DIR_USER_DATA, scoped_temp_dir_.path());
106 108
107 CommandLine* command_line = CommandLine::ForCurrentProcess(); 109 CommandLine* command_line = CommandLine::ForCurrentProcess();
108 command_line->AppendSwitch(switches::kEnableDevicePolicy); 110 command_line->AppendSwitch(switches::kEnableDevicePolicy);
109 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, kDMServer); 111 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, kDMServer);
110 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 112 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
111 113
112 local_state_.Get()->RegisterStringPref(prefs::kApplicationLocale, ""); 114 local_state_.Get()->RegisterStringPref(prefs::kApplicationLocale, "");
113 115
114 browser_process_->SetIOThread(&io_thread_); 116 browser_process_->SetIOThread(&io_thread_state_);
115 117
116 DBusThreadManager::InitializeForTesting(&dbus_thread_manager_); 118 DBusThreadManager::InitializeForTesting(&dbus_thread_manager_);
117 119
118 MockSessionManagerClient* session_managed_client = 120 MockSessionManagerClient* session_managed_client =
119 dbus_thread_manager_.mock_session_manager_client(); 121 dbus_thread_manager_.mock_session_manager_client();
120 EXPECT_CALL(*session_managed_client, RetrievePolicy(_)) 122 EXPECT_CALL(*session_managed_client, RetrievePolicy(_))
121 .WillRepeatedly(MockSessionManagerClientPolicyCallback("")); 123 .WillRepeatedly(MockSessionManagerClientPolicyCallback(""));
122 124
123 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); 125 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi();
124 ASSERT_TRUE(test_api); 126 ASSERT_TRUE(test_api);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 164 }
163 165
164 virtual void TearDown() OVERRIDE { 166 virtual void TearDown() OVERRIDE {
165 loop_.RunAllPending(); 167 loop_.RunAllPending();
166 { 168 {
167 // chrome_browser_net::Predictor usually skips its shutdown routines on 169 // chrome_browser_net::Predictor usually skips its shutdown routines on
168 // unit_tests, but does the full thing when 170 // unit_tests, but does the full thing when
169 // g_browser_process->profile_manager() is valid during initialization. 171 // g_browser_process->profile_manager() is valid during initialization.
170 // Run a task on a temporary BrowserThread::IO that allows skipping 172 // Run a task on a temporary BrowserThread::IO that allows skipping
171 // these routines. 173 // these routines.
172 io_thread_.set_message_loop(&loop_); 174 //
175 // It is important to not have a fake message loop on the IO
176 // thread for the whole test, see comment on LoginUtilsTestBase
177 // constructor for details.
178 io_thread_.DeprecatedSetMessageLoop(&loop_);
173 loop_.PostTask(FROM_HERE, 179 loop_.PostTask(FROM_HERE,
174 base::Bind(&LoginUtilsTestBase::TearDownOnIO, 180 base::Bind(&LoginUtilsTestBase::TearDownOnIO,
175 base::Unretained(this))); 181 base::Unretained(this)));
176 loop_.RunAllPending(); 182 loop_.RunAllPending();
177 io_thread_.set_message_loop(NULL); 183 io_thread_.DeprecatedSetMessageLoop(NULL);
178 } 184 }
179 185
180 // These trigger some tasks that have to run while BrowserThread::UI 186 // These trigger some tasks that have to run while BrowserThread::UI
181 // exists. 187 // exists.
182 connector_ = NULL; 188 connector_ = NULL;
183 browser_process_->SetBrowserPolicyConnector(NULL); 189 browser_process_->SetBrowserPolicyConnector(NULL);
184 browser_process_->SetProfileManager(NULL); 190 browser_process_->SetProfileManager(NULL);
185 loop_.RunAllPending(); 191 loop_.RunAllPending();
186 } 192 }
187 193
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 304
299 protected: 305 protected:
300 ScopedStubCrosEnabler stub_cros_enabler_; 306 ScopedStubCrosEnabler stub_cros_enabler_;
301 307
302 MessageLoop loop_; 308 MessageLoop loop_;
303 TestingBrowserProcess* browser_process_; 309 TestingBrowserProcess* browser_process_;
304 ScopedTestingLocalState local_state_; 310 ScopedTestingLocalState local_state_;
305 311
306 content::TestBrowserThread ui_thread_; 312 content::TestBrowserThread ui_thread_;
307 content::TestBrowserThread file_thread_; 313 content::TestBrowserThread file_thread_;
308 TestIOThread io_thread_; 314 content::TestBrowserThread io_thread_;
315 IOThread io_thread_state_;
309 316
310 MockDBusThreadManager dbus_thread_manager_; 317 MockDBusThreadManager dbus_thread_manager_;
311 TestURLFetcherFactory test_url_fetcher_factory_; 318 TestURLFetcherFactory test_url_fetcher_factory_;
312 319
313 policy::BrowserPolicyConnector* connector_; 320 policy::BrowserPolicyConnector* connector_;
314 MockCryptohomeLibrary* cryptohome_; 321 MockCryptohomeLibrary* cryptohome_;
315 Profile* prepared_profile_; 322 Profile* prepared_profile_;
316 323
317 private: 324 private:
318 ScopedTempDir scoped_temp_dir_; 325 ScopedTempDir scoped_temp_dir_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 456 }
450 457
451 INSTANTIATE_TEST_CASE_P( 458 INSTANTIATE_TEST_CASE_P(
452 LoginUtilsBlockingLoginTestInstance, 459 LoginUtilsBlockingLoginTestInstance,
453 LoginUtilsBlockingLoginTest, 460 LoginUtilsBlockingLoginTest,
454 testing::Values(0, 1, 2, 3, 4, 5)); 461 testing::Values(0, 1, 2, 3, 4, 5));
455 462
456 } // namespace 463 } // namespace
457 464
458 } 465 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/input_method/xkeyboard.cc ('k') | chrome/browser/chromeos/login/webui_screen_locker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698