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

Side by Side Diff: chrome/browser/printing/cloud_print/cloud_print_proxy_service_unittest.cc

Issue 2782553004: Move TestingPrefService to use unique_ptr<Value> (Closed)
Patch Set: comments Created 3 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 (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/printing/cloud_print/cloud_print_proxy_service.h" 5 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/run_loop.h" 16 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 19 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
19 #include "chrome/browser/service_process/service_process_control.h" 20 #include "chrome/browser/service_process/service_process_control.h"
20 #include "chrome/browser/ui/startup/startup_browser_creator.h" 21 #include "chrome/browser/ui/startup/startup_browser_creator.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" 23 #include "chrome/common/cloud_print/cloud_print_proxy_info.h"
23 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 238 }
238 239
239 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabled) { 240 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabled) {
240 TestCloudPrintProxyService service(&profile_); 241 TestCloudPrintProxyService service(&profile_);
241 242
242 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 243 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
243 MockServiceProcessControl::kServiceStateDisabled, false); 244 MockServiceProcessControl::kServiceStateDisabled, false);
244 245
245 sync_preferences::TestingPrefServiceSyncable* prefs = 246 sync_preferences::TestingPrefServiceSyncable* prefs =
246 profile_.GetTestingPrefService(); 247 profile_.GetTestingPrefService();
247 prefs->SetUserPref( 248 prefs->SetUserPref(prefs::kCloudPrintEmail,
248 prefs::kCloudPrintEmail, 249 base::MakeUnique<base::Value>(
249 new base::Value(MockServiceProcessControl::EnabledUserId())); 250 MockServiceProcessControl::EnabledUserId()));
250 251
251 service.Initialize(); 252 service.Initialize();
252 253
253 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 254 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
254 } 255 }
255 256
256 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabled) { 257 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabled) {
257 TestCloudPrintProxyService service(&profile_); 258 TestCloudPrintProxyService service(&profile_);
258 259
259 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 260 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
260 MockServiceProcessControl::kServiceStateEnabled, false); 261 MockServiceProcessControl::kServiceStateEnabled, false);
261 262
262 sync_preferences::TestingPrefServiceSyncable* prefs = 263 sync_preferences::TestingPrefServiceSyncable* prefs =
263 profile_.GetTestingPrefService(); 264 profile_.GetTestingPrefService();
264 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 265 prefs->SetUserPref(prefs::kCloudPrintEmail,
266 base::MakeUnique<base::Value>(std::string()));
265 267
266 service.Initialize(); 268 service.Initialize();
267 service.RefreshStatusFromService(); 269 service.RefreshStatusFromService();
268 270
269 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), 271 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(),
270 prefs->GetString(prefs::kCloudPrintEmail)); 272 prefs->GetString(prefs::kCloudPrintEmail));
271 } 273 }
272 274
273 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyDisabled) { 275 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyDisabled) {
274 TestCloudPrintProxyService service(&profile_); 276 TestCloudPrintProxyService service(&profile_);
275 277
276 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 278 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
277 MockServiceProcessControl::kServiceStateDisabled, false); 279 MockServiceProcessControl::kServiceStateDisabled, false);
278 280
279 sync_preferences::TestingPrefServiceSyncable* prefs = 281 sync_preferences::TestingPrefServiceSyncable* prefs =
280 profile_.GetTestingPrefService(); 282 profile_.GetTestingPrefService();
281 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 283 prefs->SetUserPref(prefs::kCloudPrintEmail,
282 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 284 base::MakeUnique<base::Value>(std::string()));
285 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
286 base::MakeUnique<base::Value>(false));
283 287
284 service.Initialize(); 288 service.Initialize();
285 289
286 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 290 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
287 } 291 }
288 292
289 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyEnabled) { 293 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyEnabled) {
290 TestCloudPrintProxyService service(&profile_); 294 TestCloudPrintProxyService service(&profile_);
291 295
292 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 296 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
293 MockServiceProcessControl::kServiceStateEnabled, false); 297 MockServiceProcessControl::kServiceStateEnabled, false);
294 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); 298 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations();
295 299
296 sync_preferences::TestingPrefServiceSyncable* prefs = 300 sync_preferences::TestingPrefServiceSyncable* prefs =
297 profile_.GetTestingPrefService(); 301 profile_.GetTestingPrefService();
298 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 302 prefs->SetUserPref(prefs::kCloudPrintEmail,
299 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 303 base::MakeUnique<base::Value>(std::string()));
304 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
305 base::MakeUnique<base::Value>(false));
300 306
301 service.Initialize(); 307 service.Initialize();
302 308
303 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 309 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
304 } 310 }
305 311
306 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenSetPolicy) { 312 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenSetPolicy) {
307 TestCloudPrintProxyService service(&profile_); 313 TestCloudPrintProxyService service(&profile_);
308 314
309 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 315 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
310 MockServiceProcessControl::kServiceStateDisabled, false); 316 MockServiceProcessControl::kServiceStateDisabled, false);
311 317
312 sync_preferences::TestingPrefServiceSyncable* prefs = 318 sync_preferences::TestingPrefServiceSyncable* prefs =
313 profile_.GetTestingPrefService(); 319 profile_.GetTestingPrefService();
314 prefs->SetUserPref( 320 prefs->SetUserPref(prefs::kCloudPrintEmail,
315 prefs::kCloudPrintEmail, 321 base::MakeUnique<base::Value>(
316 new base::Value(MockServiceProcessControl::EnabledUserId())); 322 MockServiceProcessControl::EnabledUserId()));
317 323
318 service.Initialize(); 324 service.Initialize();
319 325
320 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 326 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
321 327
322 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 328 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
329 base::MakeUnique<base::Value>(false));
323 330
324 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 331 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
325 } 332 }
326 333
327 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabledThenSetPolicy) { 334 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabledThenSetPolicy) {
328 TestCloudPrintProxyService service(&profile_); 335 TestCloudPrintProxyService service(&profile_);
329 336
330 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 337 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
331 MockServiceProcessControl::kServiceStateEnabled, false); 338 MockServiceProcessControl::kServiceStateEnabled, false);
332 339
333 sync_preferences::TestingPrefServiceSyncable* prefs = 340 sync_preferences::TestingPrefServiceSyncable* prefs =
334 profile_.GetTestingPrefService(); 341 profile_.GetTestingPrefService();
335 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 342 prefs->SetUserPref(prefs::kCloudPrintEmail,
343 base::MakeUnique<base::Value>(std::string()));
336 344
337 service.Initialize(); 345 service.Initialize();
338 service.RefreshStatusFromService(); 346 service.RefreshStatusFromService();
339 347
340 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), 348 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(),
341 prefs->GetString(prefs::kCloudPrintEmail)); 349 prefs->GetString(prefs::kCloudPrintEmail));
342 350
343 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); 351 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations();
344 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 352 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
353 base::MakeUnique<base::Value>(false));
345 354
346 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 355 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
347 } 356 }
348 357
349 TEST_F(CloudPrintProxyPolicyTest, 358 TEST_F(CloudPrintProxyPolicyTest,
350 StartWithPolicySetProxyDisabledThenClearPolicy) { 359 StartWithPolicySetProxyDisabledThenClearPolicy) {
351 TestCloudPrintProxyService service(&profile_); 360 TestCloudPrintProxyService service(&profile_);
352 361
353 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 362 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
354 MockServiceProcessControl::kServiceStateDisabled, false); 363 MockServiceProcessControl::kServiceStateDisabled, false);
355 364
356 sync_preferences::TestingPrefServiceSyncable* prefs = 365 sync_preferences::TestingPrefServiceSyncable* prefs =
357 profile_.GetTestingPrefService(); 366 profile_.GetTestingPrefService();
358 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 367 prefs->SetUserPref(prefs::kCloudPrintEmail,
359 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 368 base::MakeUnique<base::Value>(std::string()));
369 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
370 base::MakeUnique<base::Value>(false));
360 371
361 service.Initialize(); 372 service.Initialize();
362 373
363 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 374 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
364 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); 375 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled);
365 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 376 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
366 } 377 }
367 378
368 TEST_F(CloudPrintProxyPolicyTest, 379 TEST_F(CloudPrintProxyPolicyTest,
369 StartWithPolicySetProxyEnabledThenClearPolicy) { 380 StartWithPolicySetProxyEnabledThenClearPolicy) {
370 TestCloudPrintProxyService service(&profile_); 381 TestCloudPrintProxyService service(&profile_);
371 382
372 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 383 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
373 MockServiceProcessControl::kServiceStateEnabled, false); 384 MockServiceProcessControl::kServiceStateEnabled, false);
374 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); 385 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations();
375 386
376 sync_preferences::TestingPrefServiceSyncable* prefs = 387 sync_preferences::TestingPrefServiceSyncable* prefs =
377 profile_.GetTestingPrefService(); 388 profile_.GetTestingPrefService();
378 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 389 prefs->SetUserPref(prefs::kCloudPrintEmail,
379 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 390 base::MakeUnique<base::Value>(std::string()));
391 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
392 base::MakeUnique<base::Value>(false));
380 393
381 service.Initialize(); 394 service.Initialize();
382 395
383 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 396 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
384 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); 397 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled);
385 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 398 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
386 } 399 }
387 400
388 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenEnable) { 401 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenEnable) {
389 TestCloudPrintProxyService service(&profile_); 402 TestCloudPrintProxyService service(&profile_);
390 403
391 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 404 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
392 MockServiceProcessControl::kServiceStateDisabled, false); 405 MockServiceProcessControl::kServiceStateDisabled, false);
393 406
394 sync_preferences::TestingPrefServiceSyncable* prefs = 407 sync_preferences::TestingPrefServiceSyncable* prefs =
395 profile_.GetTestingPrefService(); 408 profile_.GetTestingPrefService();
396 prefs->SetUserPref( 409 prefs->SetUserPref(prefs::kCloudPrintEmail,
397 prefs::kCloudPrintEmail, 410 base::MakeUnique<base::Value>(
398 new base::Value(MockServiceProcessControl::EnabledUserId())); 411 MockServiceProcessControl::EnabledUserId()));
399 412
400 service.Initialize(); 413 service.Initialize();
401 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 414 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
402 415
403 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); 416 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations();
404 service.EnableForUser(); 417 service.EnableForUser();
405 418
406 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), 419 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(),
407 prefs->GetString(prefs::kCloudPrintEmail)); 420 prefs->GetString(prefs::kCloudPrintEmail));
408 } 421 }
409 422
410 TEST_F(CloudPrintProxyPolicyTest, 423 TEST_F(CloudPrintProxyPolicyTest,
411 StartWithPolicySetProxyEnabledThenClearPolicyAndEnable) { 424 StartWithPolicySetProxyEnabledThenClearPolicyAndEnable) {
412 TestCloudPrintProxyService service(&profile_); 425 TestCloudPrintProxyService service(&profile_);
413 426
414 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( 427 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations(
415 MockServiceProcessControl::kServiceStateEnabled, false); 428 MockServiceProcessControl::kServiceStateEnabled, false);
416 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); 429 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations();
417 430
418 sync_preferences::TestingPrefServiceSyncable* prefs = 431 sync_preferences::TestingPrefServiceSyncable* prefs =
419 profile_.GetTestingPrefService(); 432 profile_.GetTestingPrefService();
420 prefs->SetUserPref(prefs::kCloudPrintEmail, new base::Value(std::string())); 433 prefs->SetUserPref(prefs::kCloudPrintEmail,
421 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, new base::Value(false)); 434 base::MakeUnique<base::Value>(std::string()));
435 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled,
436 base::MakeUnique<base::Value>(false));
422 437
423 service.Initialize(); 438 service.Initialize();
424 439
425 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 440 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
426 service.EnableForUser(); 441 service.EnableForUser();
427 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 442 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
428 443
429 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); 444 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled);
430 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); 445 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail));
431 446
432 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); 447 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations();
433 service.EnableForUser(); 448 service.EnableForUser();
434 449
435 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), 450 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(),
436 prefs->GetString(prefs::kCloudPrintEmail)); 451 prefs->GetString(prefs::kCloudPrintEmail));
437 } 452 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/session_startup_pref_unittest.cc ('k') | chrome/browser/profiles/profile_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698