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

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

Issue 10666010: Don't pass the connector check policy flag along. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
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 <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.h" 9 #include "base/message_loop.h"
10 #include "chrome/browser/browser_process_impl.h"
11 #include "chrome/browser/browser_shutdown.h"
12 #include "chrome/browser/chrome_browser_main.h"
13 #include "chrome/browser/intranet_redirect_detector.h"
14 #include "chrome/browser/managed_mode.h"
15 #include "chrome/browser/metrics/metrics_log.h"
16 #include "chrome/browser/metrics/metrics_service.h"
10 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 17 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
11 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 18 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
19 #include "chrome/browser/profiles/profile_info_cache.h"
20 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/browser/service/service_process_control.h" 21 #include "chrome/browser/service/service_process_control.h"
13 #include "chrome/browser/ui/startup/startup_browser_creator.h" 22 #include "chrome/browser/ui/startup/startup_browser_creator.h"
23 #include "chrome/browser/ui/webui/flags_ui.h"
14 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/cloud_print/cloud_print_proxy_info.h" 25 #include "chrome/common/cloud_print/cloud_print_proxy_info.h"
16 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
17 #include "chrome/common/service_messages.h" 27 #include "chrome/common/service_messages.h"
18 #include "chrome/test/base/testing_browser_process.h" 28 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_pref_service.h" 29 #include "chrome/test/base/testing_pref_service.h"
20 #include "chrome/test/base/testing_profile.h" 30 #include "chrome/test/base/testing_profile.h"
21 #include "chrome/test/base/testing_profile_manager.h" 31 #include "chrome/test/base/testing_profile_manager.h"
32 #include "content/public/browser/browser_main_parts.h"
22 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/content_browser_client.h"
35 #include "content/public/common/content_client.h"
36 #include "content/public/common/main_function_params.h"
37 #include "content/public/common/result_codes.h"
23 #include "content/public/test/test_browser_thread.h" 38 #include "content/public/test/test_browser_thread.h"
24 #include "testing/gmock/include/gmock/gmock.h" 39 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
26 41
27 using ::testing::Assign; 42 using ::testing::Assign;
28 using ::testing::AtMost; 43 using ::testing::AtMost;
29 using ::testing::DeleteArg; 44 using ::testing::DeleteArg;
30 using ::testing::DoAll; 45 using ::testing::DoAll;
31 using ::testing::Invoke; 46 using ::testing::Invoke;
32 using ::testing::Property; 47 using ::testing::Property;
33 using ::testing::Return; 48 using ::testing::Return;
49 using ::testing::ReturnNull;
34 using ::testing::ReturnPointee; 50 using ::testing::ReturnPointee;
35 using ::testing::WithArgs; 51 using ::testing::WithArgs;
36 using ::testing::WithoutArgs; 52 using ::testing::WithoutArgs;
37 using ::testing::_; 53 using ::testing::_;
38 54
39 class MockServiceProcessControl : public ServiceProcessControl { 55 class MockServiceProcessControl : public ServiceProcessControl {
40 public: 56 public:
41 static std::string EnabledUserId(); 57 static std::string EnabledUserId();
42 58
43 MockServiceProcessControl() : connected_(false) { } 59 MockServiceProcessControl() : connected_(false) { }
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 458
443 CloudPrintProxyServiceFactory::GetInstance()-> 459 CloudPrintProxyServiceFactory::GetInstance()->
444 SetTestingFactory(&profile_, TestCloudPrintProxyServiceFactory); 460 SetTestingFactory(&profile_, TestCloudPrintProxyServiceFactory);
445 461
446 CommandLine command_line(CommandLine::NO_PROGRAM); 462 CommandLine command_line(CommandLine::NO_PROGRAM);
447 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy); 463 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy);
448 464
449 EXPECT_FALSE(LaunchBrowser(command_line, &profile_)); 465 EXPECT_FALSE(LaunchBrowser(command_line, &profile_));
450 MessageLoop::current()->RunAllPending(); 466 MessageLoop::current()->RunAllPending();
451 } 467 }
468
469 ProfileKeyedService* TestCloudPrintProxyServiceFactoryNoExpectations(
470 Profile* profile) {
471 TestCloudPrintProxyService* service = new TestCloudPrintProxyService(profile);
472
473 service->Initialize();
474 MessageLoop::current()->RunAllPending();
475 return service;
476 }
477
478 class MockBrowserProcessImpl : public BrowserProcessImpl {
479 public:
480 explicit MockBrowserProcessImpl(const CommandLine& command_line,
481 BrowserProcess* original_browser_process)
482 : BrowserProcessImpl(command_line) { }
483
484 MOCK_METHOD0(PreMainMessageLoopRun, void());
485 MOCK_METHOD0(metrics_service, MetricsService*());
486 MOCK_METHOD0(watchdog_thread, WatchDogThread*());
487 MOCK_METHOD0(profile_manager, ProfileManager*());
488 MOCK_METHOD0(local_state, PrefService*());
489 MOCK_METHOD0(notification_ui_manager, NotificationUIManager*());
490 MOCK_METHOD0(component_updater, ComponentUpdateService*());
491 };
492
493 class MockProcessSingleton : public ProcessSingleton {
494 public:
495 explicit MockProcessSingleton(const FilePath& user_data_dir)
496 : ProcessSingleton(user_data_dir) { }
497
498 MOCK_METHOD1(NotifyOtherProcessOrCreate,
499 NotifyResult(const NotificationCallback&));
500 };
501
502 class MockProfileManager : public ProfileManagerWithoutInit {
503 public:
504 explicit MockProfileManager(const FilePath& user_data_dir)
505 : ProfileManagerWithoutInit(user_data_dir) { }
506
507 MOCK_METHOD1(GetDefaultProfile, Profile*(const FilePath&));
508 MOCK_METHOD1(GetLastUsedProfile, Profile*(const FilePath&));
509 };
510
511 TEST_F(CloudPrintProxyPolicyTest, CheckCommandLineCrossTalk) {
Paweł Hajdan Jr. 2012/06/23 07:23:37 Aren't you mocking too much here? Would it make se
Scott Byer 2012/06/27 19:29:06 Yes, yes I am. I started in and ended up "pot comm
512 base::ShadowingAtExitManager at_exit_manager;
513 TestCloudPrintProxyService service(&profile_);
514
515 // Otherwise, other unit tests that start up sub-processes can leave a global
516 // variable (g_url_requests_started) set, which trips up the enforcing cookie
517 // routine during startup.
518 ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ = true;
519
520 CloudPrintProxyServiceFactory::GetInstance()->
521 SetTestingFactory(&profile_,
522 TestCloudPrintProxyServiceFactoryNoExpectations);
523
524 CommandLine command_line(CommandLine::NO_PROGRAM);
525 command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy);
526 command_line.AppendSwitch(switches::kDisableInternalFlash);
527
528 BrowserProcess* original_browser_process = g_browser_process;
529
530 {
Paweł Hajdan Jr. 2012/06/23 07:23:37 nit: When you use braces, indent the following lin
531 scoped_ptr<MockProfileManager> mock_profile_manager(
532 new MockProfileManager(FilePath()));
533
534 EXPECT_CALL(*mock_profile_manager, GetDefaultProfile(_)).
535 WillRepeatedly(Return(&profile_));
536 EXPECT_CALL(*mock_profile_manager, GetLastUsedProfile(_)).
537 WillRepeatedly(Return(&profile_));
538
539 content::MainFunctionParams parameters(command_line);
540
541 TestingPrefService* prefs = profile_.GetTestingPrefService();
542 browser_shutdown::RegisterPrefs(prefs);
543 ManagedMode::RegisterPrefs(prefs);
544 ProfileInfoCache::RegisterPrefs(prefs);
545 IntranetRedirectDetector::RegisterPrefs(prefs);
546 MetricsService::RegisterPrefs(prefs);
547 MetricsLog::RegisterPrefs(prefs);
548 FlagsUI::RegisterPrefs(prefs);
549
550 MockBrowserProcessImpl* mock_browser_process(
551 new MockBrowserProcessImpl(command_line, g_browser_process));
552 mock_browser_process->SetApplicationLocale("en_US");
553
554 EXPECT_CALL(*mock_browser_process, PreMainMessageLoopRun()).Times(1);
555 EXPECT_CALL(*mock_browser_process, metrics_service()).
556 WillRepeatedly(ReturnNull());
557 EXPECT_CALL(*mock_browser_process, watchdog_thread()).
558 WillRepeatedly(ReturnNull());
559 EXPECT_CALL(*mock_browser_process, profile_manager()).
560 WillRepeatedly(Return(mock_profile_manager.get()));
561 EXPECT_CALL(*mock_browser_process, local_state()).
562 WillRepeatedly(Return(prefs));
563 EXPECT_CALL(*mock_browser_process, notification_ui_manager()).
564 WillRepeatedly(ReturnNull());
565 EXPECT_CALL(*mock_browser_process, component_updater()).
566 WillRepeatedly(ReturnNull());
567
568 scoped_ptr<ChromeBrowserMainParts> parts(
569 reinterpret_cast<ChromeBrowserMainParts*>(
570 content::GetContentClient()->browser()->
571 CreateBrowserMainParts(parameters)));
572
573 MockProcessSingleton* mock_process_singleton(
574 new MockProcessSingleton(FilePath()));
575
576 EXPECT_CALL(*mock_process_singleton, NotifyOtherProcessOrCreate(_)).Times(0);
577
578 parts->process_singleton_.reset(mock_process_singleton);
579 parts->browser_process_.reset(mock_browser_process);
580 parts->browser_creator_.reset(new StartupBrowserCreator());
581 parts->local_state_ = prefs;
582
583 int result = parts->PreMainMessageLoopRunImpl();
584 EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, result);
585 EXPECT_EQ(ProcessSingleton::PROCESS_NONE, parts->notify_result_);
586
587 parts->PostMainMessageLoopRun();
588
589 // Clear out a global variable.
590 mock_browser_process->SetApplicationLocale("");
591 }
592
593 EXPECT_EQ(NULL, g_browser_process);
594 g_browser_process = original_browser_process;
Paweł Hajdan Jr. 2012/06/23 07:23:37 We have AutoReset or something for that.
595 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698