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

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: Temporarily disable CF net tests, add probable fix for them, update suppression. 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:
91 LoginUtilsTestBase() 84 LoginUtilsTestBase()
92 : loop_(MessageLoop::TYPE_IO), 85 : loop_(MessageLoop::TYPE_IO),
93 browser_process_( 86 browser_process_(
94 static_cast<TestingBrowserProcess*>(g_browser_process)), 87 static_cast<TestingBrowserProcess*>(g_browser_process)),
95 local_state_(browser_process_), 88 local_state_(browser_process_),
96 ui_thread_(content::BrowserThread::UI, &loop_), 89 ui_thread_(content::BrowserThread::UI, &loop_),
97 file_thread_(content::BrowserThread::FILE, &loop_), 90 file_thread_(content::BrowserThread::FILE, &loop_),
98 io_thread_(local_state_.Get()), 91 io_thread_(content::BrowserThread::IO, &loop_),
92 io_thread_state_(local_state_.Get(), NULL, NULL),
99 prepared_profile_(NULL) {} 93 prepared_profile_(NULL) {}
100 94
101 virtual void SetUp() OVERRIDE { 95 virtual void SetUp() OVERRIDE {
102 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 96 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
103 // BrowserPolicyConnector makes the UserPolicyCache read relative to this 97 // BrowserPolicyConnector makes the UserPolicyCache read relative to this
104 // path. Make sure it's in a clean state. 98 // path. Make sure it's in a clean state.
105 PathService::Override(chrome::DIR_USER_DATA, scoped_temp_dir_.path()); 99 PathService::Override(chrome::DIR_USER_DATA, scoped_temp_dir_.path());
106 100
107 CommandLine* command_line = CommandLine::ForCurrentProcess(); 101 CommandLine* command_line = CommandLine::ForCurrentProcess();
108 command_line->AppendSwitch(switches::kEnableDevicePolicy); 102 command_line->AppendSwitch(switches::kEnableDevicePolicy);
109 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, kDMServer); 103 command_line->AppendSwitchASCII(switches::kDeviceManagementUrl, kDMServer);
110 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 104 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
111 105
112 local_state_.Get()->RegisterStringPref(prefs::kApplicationLocale, ""); 106 local_state_.Get()->RegisterStringPref(prefs::kApplicationLocale, "");
113 107
114 browser_process_->SetIOThread(&io_thread_); 108 browser_process_->SetIOThread(&io_thread_state_);
115 109
116 DBusThreadManager::InitializeForTesting(&dbus_thread_manager_); 110 DBusThreadManager::InitializeForTesting(&dbus_thread_manager_);
117 111
118 MockSessionManagerClient* session_managed_client = 112 MockSessionManagerClient* session_managed_client =
119 dbus_thread_manager_.mock_session_manager_client(); 113 dbus_thread_manager_.mock_session_manager_client();
120 EXPECT_CALL(*session_managed_client, RetrievePolicy(_)) 114 EXPECT_CALL(*session_managed_client, RetrievePolicy(_))
121 .WillRepeatedly(MockSessionManagerClientPolicyCallback("")); 115 .WillRepeatedly(MockSessionManagerClientPolicyCallback(""));
122 116
123 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi(); 117 CrosLibrary::TestApi* test_api = CrosLibrary::Get()->GetTestApi();
124 ASSERT_TRUE(test_api); 118 ASSERT_TRUE(test_api);
(...skipping 26 matching lines...) Expand all
151 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwner, _)) 145 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttributeOwner, _))
152 .WillRepeatedly(DoAll(SetArgPointee<1>(kUsername), 146 .WillRepeatedly(DoAll(SetArgPointee<1>(kUsername),
153 Return(true))); 147 Return(true)));
154 test_api->SetCryptohomeLibrary(cryptohome_, true); 148 test_api->SetCryptohomeLibrary(cryptohome_, true);
155 149
156 browser_process_->SetProfileManager( 150 browser_process_->SetProfileManager(
157 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); 151 new ProfileManagerWithoutInit(scoped_temp_dir_.path()));
158 connector_ = browser_process_->browser_policy_connector(); 152 connector_ = browser_process_->browser_policy_connector();
159 connector_->Init(); 153 connector_->Init();
160 154
155 file_thread_.Start();
156 io_thread_.StartIOThread();
157
161 loop_.RunAllPending(); 158 loop_.RunAllPending();
162 } 159 }
163 160
164 virtual void TearDown() OVERRIDE { 161 virtual void TearDown() OVERRIDE {
165 loop_.RunAllPending(); 162 loop_.RunAllPending();
166 { 163
167 // chrome_browser_net::Predictor usually skips its shutdown routines on 164 // chrome_browser_net::Predictor usually skips its shutdown routines on
168 // unit_tests, but does the full thing when 165 // unit_tests, but does the full thing when
169 // g_browser_process->profile_manager() is valid during initialization. 166 // g_browser_process->profile_manager() is valid during initialization.
170 // Run a task on a temporary BrowserThread::IO that allows skipping 167 //
171 // these routines. 168 // Since the IO thread here is actually a TestIOThread that uses
172 io_thread_.set_message_loop(&loop_); 169 // loop_, this allows skipping these routines.
173 loop_.PostTask(FROM_HERE, 170 BrowserThread::PostTask(BrowserThread::IO,
174 base::Bind(&LoginUtilsTestBase::TearDownOnIO, 171 FROM_HERE,
175 base::Unretained(this))); 172 base::Bind(&LoginUtilsTestBase::TearDownOnIO,
176 loop_.RunAllPending(); 173 base::Unretained(this)));
177 io_thread_.set_message_loop(NULL); 174 loop_.RunAllPending();
178 }
179 175
180 // These trigger some tasks that have to run while BrowserThread::UI 176 // These trigger some tasks that have to run while BrowserThread::UI
181 // exists. 177 // exists.
182 connector_ = NULL; 178 connector_ = NULL;
183 browser_process_->SetBrowserPolicyConnector(NULL); 179 browser_process_->SetBrowserPolicyConnector(NULL);
184 browser_process_->SetProfileManager(NULL); 180 browser_process_->SetProfileManager(NULL);
185 loop_.RunAllPending(); 181 loop_.RunAllPending();
186 } 182 }
187 183
188 void TearDownOnIO() { 184 void TearDownOnIO() {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 294
299 protected: 295 protected:
300 ScopedStubCrosEnabler stub_cros_enabler_; 296 ScopedStubCrosEnabler stub_cros_enabler_;
301 297
302 MessageLoop loop_; 298 MessageLoop loop_;
303 TestingBrowserProcess* browser_process_; 299 TestingBrowserProcess* browser_process_;
304 ScopedTestingLocalState local_state_; 300 ScopedTestingLocalState local_state_;
305 301
306 content::TestBrowserThread ui_thread_; 302 content::TestBrowserThread ui_thread_;
307 content::TestBrowserThread file_thread_; 303 content::TestBrowserThread file_thread_;
308 TestIOThread io_thread_; 304 content::TestBrowserThread io_thread_;
305 IOThread io_thread_state_;
309 306
310 MockDBusThreadManager dbus_thread_manager_; 307 MockDBusThreadManager dbus_thread_manager_;
311 TestURLFetcherFactory test_url_fetcher_factory_; 308 TestURLFetcherFactory test_url_fetcher_factory_;
312 309
313 policy::BrowserPolicyConnector* connector_; 310 policy::BrowserPolicyConnector* connector_;
314 MockCryptohomeLibrary* cryptohome_; 311 MockCryptohomeLibrary* cryptohome_;
315 Profile* prepared_profile_; 312 Profile* prepared_profile_;
316 313
317 private: 314 private:
318 ScopedTempDir scoped_temp_dir_; 315 ScopedTempDir scoped_temp_dir_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 446 }
450 447
451 INSTANTIATE_TEST_CASE_P( 448 INSTANTIATE_TEST_CASE_P(
452 LoginUtilsBlockingLoginTestInstance, 449 LoginUtilsBlockingLoginTestInstance,
453 LoginUtilsBlockingLoginTest, 450 LoginUtilsBlockingLoginTest,
454 testing::Values(0, 1, 2, 3, 4, 5)); 451 testing::Values(0, 1, 2, 3, 4, 5));
455 452
456 } // namespace 453 } // namespace
457 454
458 } 455 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698