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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/printing/cloud_print/cloud_print_proxy_service_unittest.cc
diff --git a/chrome/browser/printing/cloud_print/cloud_print_proxy_service_unittest.cc b/chrome/browser/printing/cloud_print/cloud_print_proxy_service_unittest.cc
index 8f6ea5225d706e15e180b8c14e197241257e68cb..0c1462352d63c56c488971d91ff4c09182d82a14 100644
--- a/chrome/browser/printing/cloud_print/cloud_print_proxy_service_unittest.cc
+++ b/chrome/browser/printing/cloud_print/cloud_print_proxy_service_unittest.cc
@@ -7,10 +7,20 @@
#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "chrome/browser/browser_process_impl.h"
+#include "chrome/browser/browser_shutdown.h"
+#include "chrome/browser/chrome_browser_main.h"
+#include "chrome/browser/intranet_redirect_detector.h"
+#include "chrome/browser/managed_mode.h"
+#include "chrome/browser/metrics/metrics_log.h"
+#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory.h"
+#include "chrome/browser/profiles/profile_info_cache.h"
+#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/service/service_process_control.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
+#include "chrome/browser/ui/webui/flags_ui.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/cloud_print/cloud_print_proxy_info.h"
#include "chrome/common/pref_names.h"
@@ -19,7 +29,12 @@
#include "chrome/test/base/testing_pref_service.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
+#include "content/public/browser/browser_main_parts.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/content_browser_client.h"
+#include "content/public/common/content_client.h"
+#include "content/public/common/main_function_params.h"
+#include "content/public/common/result_codes.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -31,6 +46,7 @@ using ::testing::DoAll;
using ::testing::Invoke;
using ::testing::Property;
using ::testing::Return;
+using ::testing::ReturnNull;
using ::testing::ReturnPointee;
using ::testing::WithArgs;
using ::testing::WithoutArgs;
@@ -449,3 +465,131 @@ TEST_F(CloudPrintProxyPolicyTest, StartupBrowserCreatorWithCommandLine) {
EXPECT_FALSE(LaunchBrowser(command_line, &profile_));
MessageLoop::current()->RunAllPending();
}
+
+ProfileKeyedService* TestCloudPrintProxyServiceFactoryNoExpectations(
+ Profile* profile) {
+ TestCloudPrintProxyService* service = new TestCloudPrintProxyService(profile);
+
+ service->Initialize();
+ MessageLoop::current()->RunAllPending();
+ return service;
+}
+
+class MockBrowserProcessImpl : public BrowserProcessImpl {
+ public:
+ explicit MockBrowserProcessImpl(const CommandLine& command_line,
+ BrowserProcess* original_browser_process)
+ : BrowserProcessImpl(command_line) { }
+
+ MOCK_METHOD0(PreMainMessageLoopRun, void());
+ MOCK_METHOD0(metrics_service, MetricsService*());
+ MOCK_METHOD0(watchdog_thread, WatchDogThread*());
+ MOCK_METHOD0(profile_manager, ProfileManager*());
+ MOCK_METHOD0(local_state, PrefService*());
+ MOCK_METHOD0(notification_ui_manager, NotificationUIManager*());
+ MOCK_METHOD0(component_updater, ComponentUpdateService*());
+};
+
+class MockProcessSingleton : public ProcessSingleton {
+ public:
+ explicit MockProcessSingleton(const FilePath& user_data_dir)
+ : ProcessSingleton(user_data_dir) { }
+
+ MOCK_METHOD1(NotifyOtherProcessOrCreate,
+ NotifyResult(const NotificationCallback&));
+};
+
+class MockProfileManager : public ProfileManagerWithoutInit {
+ public:
+ explicit MockProfileManager(const FilePath& user_data_dir)
+ : ProfileManagerWithoutInit(user_data_dir) { }
+
+ MOCK_METHOD1(GetDefaultProfile, Profile*(const FilePath&));
+ MOCK_METHOD1(GetLastUsedProfile, Profile*(const FilePath&));
+};
+
+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
+ base::ShadowingAtExitManager at_exit_manager;
+ TestCloudPrintProxyService service(&profile_);
+
+ // Otherwise, other unit tests that start up sub-processes can leave a global
+ // variable (g_url_requests_started) set, which trips up the enforcing cookie
+ // routine during startup.
+ ChromeBrowserMainParts::disable_enforcing_cookie_policies_for_tests_ = true;
+
+ CloudPrintProxyServiceFactory::GetInstance()->
+ SetTestingFactory(&profile_,
+ TestCloudPrintProxyServiceFactoryNoExpectations);
+
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ command_line.AppendSwitch(switches::kCheckCloudPrintConnectorPolicy);
+ command_line.AppendSwitch(switches::kDisableInternalFlash);
+
+ BrowserProcess* original_browser_process = g_browser_process;
+
+ {
Paweł Hajdan Jr. 2012/06/23 07:23:37 nit: When you use braces, indent the following lin
+ scoped_ptr<MockProfileManager> mock_profile_manager(
+ new MockProfileManager(FilePath()));
+
+ EXPECT_CALL(*mock_profile_manager, GetDefaultProfile(_)).
+ WillRepeatedly(Return(&profile_));
+ EXPECT_CALL(*mock_profile_manager, GetLastUsedProfile(_)).
+ WillRepeatedly(Return(&profile_));
+
+ content::MainFunctionParams parameters(command_line);
+
+ TestingPrefService* prefs = profile_.GetTestingPrefService();
+ browser_shutdown::RegisterPrefs(prefs);
+ ManagedMode::RegisterPrefs(prefs);
+ ProfileInfoCache::RegisterPrefs(prefs);
+ IntranetRedirectDetector::RegisterPrefs(prefs);
+ MetricsService::RegisterPrefs(prefs);
+ MetricsLog::RegisterPrefs(prefs);
+ FlagsUI::RegisterPrefs(prefs);
+
+ MockBrowserProcessImpl* mock_browser_process(
+ new MockBrowserProcessImpl(command_line, g_browser_process));
+ mock_browser_process->SetApplicationLocale("en_US");
+
+ EXPECT_CALL(*mock_browser_process, PreMainMessageLoopRun()).Times(1);
+ EXPECT_CALL(*mock_browser_process, metrics_service()).
+ WillRepeatedly(ReturnNull());
+ EXPECT_CALL(*mock_browser_process, watchdog_thread()).
+ WillRepeatedly(ReturnNull());
+ EXPECT_CALL(*mock_browser_process, profile_manager()).
+ WillRepeatedly(Return(mock_profile_manager.get()));
+ EXPECT_CALL(*mock_browser_process, local_state()).
+ WillRepeatedly(Return(prefs));
+ EXPECT_CALL(*mock_browser_process, notification_ui_manager()).
+ WillRepeatedly(ReturnNull());
+ EXPECT_CALL(*mock_browser_process, component_updater()).
+ WillRepeatedly(ReturnNull());
+
+ scoped_ptr<ChromeBrowserMainParts> parts(
+ reinterpret_cast<ChromeBrowserMainParts*>(
+ content::GetContentClient()->browser()->
+ CreateBrowserMainParts(parameters)));
+
+ MockProcessSingleton* mock_process_singleton(
+ new MockProcessSingleton(FilePath()));
+
+ EXPECT_CALL(*mock_process_singleton, NotifyOtherProcessOrCreate(_)).Times(0);
+
+ parts->process_singleton_.reset(mock_process_singleton);
+ parts->browser_process_.reset(mock_browser_process);
+ parts->browser_creator_.reset(new StartupBrowserCreator());
+ parts->local_state_ = prefs;
+
+ int result = parts->PreMainMessageLoopRunImpl();
+ EXPECT_EQ(content::RESULT_CODE_NORMAL_EXIT, result);
+ EXPECT_EQ(ProcessSingleton::PROCESS_NONE, parts->notify_result_);
+
+ parts->PostMainMessageLoopRun();
+
+ // Clear out a global variable.
+ mock_browser_process->SetApplicationLocale("");
+ }
+
+ EXPECT_EQ(NULL, g_browser_process);
+ g_browser_process = original_browser_process;
Paweł Hajdan Jr. 2012/06/23 07:23:37 We have AutoReset or something for that.
+}

Powered by Google App Engine
This is Rietveld 408576698