OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 EXPECT_FALSE(mock_control.IsConnected()); | 234 EXPECT_FALSE(mock_control.IsConnected()); |
235 } | 235 } |
236 | 236 |
237 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabled) { | 237 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabled) { |
238 TestCloudPrintProxyService service(&profile_); | 238 TestCloudPrintProxyService service(&profile_); |
239 | 239 |
240 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 240 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
241 MockServiceProcessControl::kServiceStateDisabled, false); | 241 MockServiceProcessControl::kServiceStateDisabled, false); |
242 | 242 |
243 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 243 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
244 prefs->SetUserPref(prefs::kCloudPrintEmail, | 244 prefs->SetUserPref( |
245 base::Value::CreateStringValue( | 245 prefs::kCloudPrintEmail, |
246 MockServiceProcessControl::EnabledUserId())); | 246 new base::StringValue(MockServiceProcessControl::EnabledUserId())); |
247 | 247 |
248 service.Initialize(); | 248 service.Initialize(); |
249 | 249 |
250 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 250 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
251 } | 251 } |
252 | 252 |
253 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabled) { | 253 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabled) { |
254 TestCloudPrintProxyService service(&profile_); | 254 TestCloudPrintProxyService service(&profile_); |
255 | 255 |
256 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 256 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
257 MockServiceProcessControl::kServiceStateEnabled, false); | 257 MockServiceProcessControl::kServiceStateEnabled, false); |
258 | 258 |
259 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 259 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
260 prefs->SetUserPref(prefs::kCloudPrintEmail, | 260 prefs->SetUserPref(prefs::kCloudPrintEmail, |
261 base::Value::CreateStringValue(std::string())); | 261 new base::StringValue(std::string())); |
262 | 262 |
263 service.Initialize(); | 263 service.Initialize(); |
264 service.RefreshStatusFromService(); | 264 service.RefreshStatusFromService(); |
265 | 265 |
266 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), | 266 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), |
267 prefs->GetString(prefs::kCloudPrintEmail)); | 267 prefs->GetString(prefs::kCloudPrintEmail)); |
268 } | 268 } |
269 | 269 |
270 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyDisabled) { | 270 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyDisabled) { |
271 TestCloudPrintProxyService service(&profile_); | 271 TestCloudPrintProxyService service(&profile_); |
272 | 272 |
273 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 273 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
274 MockServiceProcessControl::kServiceStateDisabled, false); | 274 MockServiceProcessControl::kServiceStateDisabled, false); |
275 | 275 |
276 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 276 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
277 prefs->SetUserPref(prefs::kCloudPrintEmail, | 277 prefs->SetUserPref(prefs::kCloudPrintEmail, |
278 base::Value::CreateStringValue(std::string())); | 278 new base::StringValue(std::string())); |
279 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 279 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
280 new base::FundamentalValue(false)); | 280 new base::FundamentalValue(false)); |
281 | 281 |
282 service.Initialize(); | 282 service.Initialize(); |
283 | 283 |
284 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 284 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
285 } | 285 } |
286 | 286 |
287 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyEnabled) { | 287 TEST_F(CloudPrintProxyPolicyTest, StartWithPolicySetProxyEnabled) { |
288 TestCloudPrintProxyService service(&profile_); | 288 TestCloudPrintProxyService service(&profile_); |
289 | 289 |
290 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 290 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
291 MockServiceProcessControl::kServiceStateEnabled, false); | 291 MockServiceProcessControl::kServiceStateEnabled, false); |
292 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); | 292 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); |
293 | 293 |
294 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 294 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
295 prefs->SetUserPref(prefs::kCloudPrintEmail, | 295 prefs->SetUserPref(prefs::kCloudPrintEmail, |
296 base::Value::CreateStringValue(std::string())); | 296 new base::StringValue(std::string())); |
297 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 297 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
298 new base::FundamentalValue(false)); | 298 new base::FundamentalValue(false)); |
299 | 299 |
300 service.Initialize(); | 300 service.Initialize(); |
301 | 301 |
302 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 302 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
303 } | 303 } |
304 | 304 |
305 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenSetPolicy) { | 305 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenSetPolicy) { |
306 TestCloudPrintProxyService service(&profile_); | 306 TestCloudPrintProxyService service(&profile_); |
307 | 307 |
308 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 308 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
309 MockServiceProcessControl::kServiceStateDisabled, false); | 309 MockServiceProcessControl::kServiceStateDisabled, false); |
310 | 310 |
311 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 311 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
312 prefs->SetUserPref(prefs::kCloudPrintEmail, | 312 prefs->SetUserPref( |
313 base::Value::CreateStringValue( | 313 prefs::kCloudPrintEmail, |
314 MockServiceProcessControl::EnabledUserId())); | 314 new base::StringValue(MockServiceProcessControl::EnabledUserId())); |
315 | 315 |
316 service.Initialize(); | 316 service.Initialize(); |
317 | 317 |
318 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 318 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
319 | 319 |
320 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 320 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
321 new base::FundamentalValue(false)); | 321 new base::FundamentalValue(false)); |
322 | 322 |
323 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 323 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
324 } | 324 } |
325 | 325 |
326 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabledThenSetPolicy) { | 326 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyEnabledThenSetPolicy) { |
327 TestCloudPrintProxyService service(&profile_); | 327 TestCloudPrintProxyService service(&profile_); |
328 | 328 |
329 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 329 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
330 MockServiceProcessControl::kServiceStateEnabled, false); | 330 MockServiceProcessControl::kServiceStateEnabled, false); |
331 | 331 |
332 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 332 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
333 prefs->SetUserPref(prefs::kCloudPrintEmail, | 333 prefs->SetUserPref(prefs::kCloudPrintEmail, |
334 base::Value::CreateStringValue(std::string())); | 334 new base::StringValue(std::string())); |
335 | 335 |
336 service.Initialize(); | 336 service.Initialize(); |
337 service.RefreshStatusFromService(); | 337 service.RefreshStatusFromService(); |
338 | 338 |
339 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), | 339 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), |
340 prefs->GetString(prefs::kCloudPrintEmail)); | 340 prefs->GetString(prefs::kCloudPrintEmail)); |
341 | 341 |
342 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); | 342 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); |
343 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 343 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
344 new base::FundamentalValue(false)); | 344 new base::FundamentalValue(false)); |
345 | 345 |
346 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 346 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
347 } | 347 } |
348 | 348 |
349 TEST_F(CloudPrintProxyPolicyTest, | 349 TEST_F(CloudPrintProxyPolicyTest, |
350 StartWithPolicySetProxyDisabledThenClearPolicy) { | 350 StartWithPolicySetProxyDisabledThenClearPolicy) { |
351 TestCloudPrintProxyService service(&profile_); | 351 TestCloudPrintProxyService service(&profile_); |
352 | 352 |
353 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 353 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
354 MockServiceProcessControl::kServiceStateDisabled, false); | 354 MockServiceProcessControl::kServiceStateDisabled, false); |
355 | 355 |
356 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 356 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
357 prefs->SetUserPref(prefs::kCloudPrintEmail, | 357 prefs->SetUserPref(prefs::kCloudPrintEmail, |
358 base::Value::CreateStringValue(std::string())); | 358 new base::StringValue(std::string())); |
359 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 359 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
360 new base::FundamentalValue(false)); | 360 new base::FundamentalValue(false)); |
361 | 361 |
362 service.Initialize(); | 362 service.Initialize(); |
363 | 363 |
364 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 364 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
365 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); | 365 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); |
366 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 366 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
367 } | 367 } |
368 | 368 |
369 TEST_F(CloudPrintProxyPolicyTest, | 369 TEST_F(CloudPrintProxyPolicyTest, |
370 StartWithPolicySetProxyEnabledThenClearPolicy) { | 370 StartWithPolicySetProxyEnabledThenClearPolicy) { |
371 TestCloudPrintProxyService service(&profile_); | 371 TestCloudPrintProxyService service(&profile_); |
372 | 372 |
373 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 373 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
374 MockServiceProcessControl::kServiceStateEnabled, false); | 374 MockServiceProcessControl::kServiceStateEnabled, false); |
375 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); | 375 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); |
376 | 376 |
377 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 377 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
378 prefs->SetUserPref(prefs::kCloudPrintEmail, | 378 prefs->SetUserPref(prefs::kCloudPrintEmail, |
379 base::Value::CreateStringValue(std::string())); | 379 new base::StringValue(std::string())); |
380 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 380 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
381 new base::FundamentalValue(false)); | 381 new base::FundamentalValue(false)); |
382 | 382 |
383 service.Initialize(); | 383 service.Initialize(); |
384 | 384 |
385 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 385 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
386 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); | 386 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); |
387 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 387 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
388 } | 388 } |
389 | 389 |
390 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenEnable) { | 390 TEST_F(CloudPrintProxyPolicyTest, StartWithNoPolicyProxyDisabledThenEnable) { |
391 TestCloudPrintProxyService service(&profile_); | 391 TestCloudPrintProxyService service(&profile_); |
392 | 392 |
393 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 393 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
394 MockServiceProcessControl::kServiceStateDisabled, false); | 394 MockServiceProcessControl::kServiceStateDisabled, false); |
395 | 395 |
396 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 396 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
397 prefs->SetUserPref(prefs::kCloudPrintEmail, | 397 prefs->SetUserPref( |
398 base::Value::CreateStringValue( | 398 prefs::kCloudPrintEmail, |
399 MockServiceProcessControl::EnabledUserId())); | 399 new base::StringValue(MockServiceProcessControl::EnabledUserId())); |
400 | 400 |
401 service.Initialize(); | 401 service.Initialize(); |
402 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 402 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
403 | 403 |
404 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); | 404 service.GetMockServiceProcessControl()->SetWillBeEnabledExpectations(); |
405 service.EnableForUser(); | 405 service.EnableForUser(); |
406 | 406 |
407 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), | 407 EXPECT_EQ(MockServiceProcessControl::EnabledUserId(), |
408 prefs->GetString(prefs::kCloudPrintEmail)); | 408 prefs->GetString(prefs::kCloudPrintEmail)); |
409 } | 409 } |
410 | 410 |
411 TEST_F(CloudPrintProxyPolicyTest, | 411 TEST_F(CloudPrintProxyPolicyTest, |
412 StartWithPolicySetProxyEnabledThenClearPolicyAndEnable) { | 412 StartWithPolicySetProxyEnabledThenClearPolicyAndEnable) { |
413 TestCloudPrintProxyService service(&profile_); | 413 TestCloudPrintProxyService service(&profile_); |
414 | 414 |
415 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( | 415 service.GetMockServiceProcessControl()->SetConnectSuccessMockExpectations( |
416 MockServiceProcessControl::kServiceStateEnabled, false); | 416 MockServiceProcessControl::kServiceStateEnabled, false); |
417 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); | 417 service.GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); |
418 | 418 |
419 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 419 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
420 prefs->SetUserPref(prefs::kCloudPrintEmail, | 420 prefs->SetUserPref(prefs::kCloudPrintEmail, |
421 base::Value::CreateStringValue(std::string())); | 421 new base::StringValue(std::string())); |
422 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 422 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
423 new base::FundamentalValue(false)); | 423 new base::FundamentalValue(false)); |
424 | 424 |
425 service.Initialize(); | 425 service.Initialize(); |
426 | 426 |
427 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 427 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
428 service.EnableForUser(); | 428 service.EnableForUser(); |
429 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); | 429 EXPECT_EQ(std::string(), prefs->GetString(prefs::kCloudPrintEmail)); |
430 | 430 |
431 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); | 431 prefs->RemoveManagedPref(prefs::kCloudPrintProxyEnabled); |
(...skipping 15 matching lines...) Expand all Loading... |
447 MockServiceProcessControl::kServiceStateEnabled, true); | 447 MockServiceProcessControl::kServiceStateEnabled, true); |
448 service->GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); | 448 service->GetMockServiceProcessControl()->SetWillBeDisabledExpectations(); |
449 | 449 |
450 service->Initialize(); | 450 service->Initialize(); |
451 return service; | 451 return service; |
452 } | 452 } |
453 | 453 |
454 TEST_F(CloudPrintProxyPolicyTest, StartupBrowserCreatorWithCommandLine) { | 454 TEST_F(CloudPrintProxyPolicyTest, StartupBrowserCreatorWithCommandLine) { |
455 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); | 455 TestingPrefServiceSyncable* prefs = profile_.GetTestingPrefService(); |
456 prefs->SetUserPref(prefs::kCloudPrintEmail, | 456 prefs->SetUserPref(prefs::kCloudPrintEmail, |
457 base::Value::CreateStringValue(std::string())); | 457 new base::StringValue(std::string())); |
458 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, | 458 prefs->SetManagedPref(prefs::kCloudPrintProxyEnabled, |
459 new base::FundamentalValue(false)); | 459 new base::FundamentalValue(false)); |
460 | 460 |
461 CloudPrintProxyServiceFactory::GetInstance()-> | 461 CloudPrintProxyServiceFactory::GetInstance()-> |
462 SetTestingFactory(&profile_, TestCloudPrintProxyServiceFactory); | 462 SetTestingFactory(&profile_, TestCloudPrintProxyServiceFactory); |
463 | 463 |
464 CommandLine command_line(CommandLine::NO_PROGRAM); | 464 CommandLine command_line(CommandLine::NO_PROGRAM); |
465 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); | 465 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); |
466 | 466 |
467 EXPECT_FALSE(LaunchBrowser(command_line, &profile_)); | 467 EXPECT_FALSE(LaunchBrowser(command_line, &profile_)); |
468 base::RunLoop().RunUntilIdle(); | 468 base::RunLoop().RunUntilIdle(); |
469 } | 469 } |
OLD | NEW |