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

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: Temporary - look at browser_list, browser_main_loop, content/p/b/browser_shutdown Created 9 years, 1 month 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
161 loop_.RunAllPending(); 155 loop_.RunAllPending();
162 } 156 }
163 157
164 virtual void TearDown() OVERRIDE { 158 virtual void TearDown() OVERRIDE {
165 loop_.RunAllPending(); 159 loop_.RunAllPending();
166 { 160
167 // chrome_browser_net::Predictor usually skips its shutdown routines on 161 // chrome_browser_net::Predictor usually skips its shutdown routines on
168 // unit_tests, but does the full thing when 162 // unit_tests, but does the full thing when
169 // g_browser_process->profile_manager() is valid during initialization. 163 // g_browser_process->profile_manager() is valid during initialization.
170 // Run a task on a temporary BrowserThread::IO that allows skipping 164 //
171 // these routines. 165 // Since the IO thread here is actually a TestIOThread that uses
172 io_thread_.set_message_loop(&loop_); 166 // loop_, this allows skipping these routines.
173 loop_.PostTask(FROM_HERE, 167 BrowserThread::PostTask(BrowserThread::IO,
174 base::Bind(&LoginUtilsTestBase::TearDownOnIO, 168 FROM_HERE,
175 base::Unretained(this))); 169 base::Bind(&LoginUtilsTestBase::TearDownOnIO,
176 loop_.RunAllPending(); 170 base::Unretained(this)));
177 io_thread_.set_message_loop(NULL); 171 loop_.RunAllPending();
178 }
179 172
180 // These trigger some tasks that have to run while BrowserThread::UI 173 // These trigger some tasks that have to run while BrowserThread::UI
181 // exists. 174 // exists.
182 connector_ = NULL; 175 connector_ = NULL;
183 browser_process_->SetBrowserPolicyConnector(NULL); 176 browser_process_->SetBrowserPolicyConnector(NULL);
184 browser_process_->SetProfileManager(NULL); 177 browser_process_->SetProfileManager(NULL);
185 loop_.RunAllPending(); 178 loop_.RunAllPending();
186 } 179 }
187 180
188 void TearDownOnIO() { 181 void TearDownOnIO() {
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 291
299 protected: 292 protected:
300 ScopedStubCrosEnabler stub_cros_enabler_; 293 ScopedStubCrosEnabler stub_cros_enabler_;
301 294
302 MessageLoop loop_; 295 MessageLoop loop_;
303 TestingBrowserProcess* browser_process_; 296 TestingBrowserProcess* browser_process_;
304 ScopedTestingLocalState local_state_; 297 ScopedTestingLocalState local_state_;
305 298
306 content::TestBrowserThread ui_thread_; 299 content::TestBrowserThread ui_thread_;
307 content::TestBrowserThread file_thread_; 300 content::TestBrowserThread file_thread_;
308 TestIOThread io_thread_; 301 content::TestBrowserThread io_thread_;
302 IOThread io_thread_state_;
309 303
310 MockDBusThreadManager dbus_thread_manager_; 304 MockDBusThreadManager dbus_thread_manager_;
311 TestURLFetcherFactory test_url_fetcher_factory_; 305 TestURLFetcherFactory test_url_fetcher_factory_;
312 306
313 policy::BrowserPolicyConnector* connector_; 307 policy::BrowserPolicyConnector* connector_;
314 MockCryptohomeLibrary* cryptohome_; 308 MockCryptohomeLibrary* cryptohome_;
315 Profile* prepared_profile_; 309 Profile* prepared_profile_;
316 310
317 private: 311 private:
318 ScopedTempDir scoped_temp_dir_; 312 ScopedTempDir scoped_temp_dir_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 } 443 }
450 444
451 INSTANTIATE_TEST_CASE_P( 445 INSTANTIATE_TEST_CASE_P(
452 LoginUtilsBlockingLoginTestInstance, 446 LoginUtilsBlockingLoginTestInstance,
453 LoginUtilsBlockingLoginTest, 447 LoginUtilsBlockingLoginTest,
454 testing::Values(0, 1, 2, 3, 4, 5)); 448 testing::Values(0, 1, 2, 3, 4, 5));
455 449
456 } // namespace 450 } // namespace
457 451
458 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698