1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/basictypes.h" 6 #include "base/command_line.h" 7 #include "base/compiler_specific.h" 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" 9 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" 10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/common/chrome_switches.h" 12 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chromeos/chromeos_switches.h" 14 #include "chromeos/login/user_names.h" 15 #include "components/invalidation/invalidation_service.h" 16 #include "components/invalidation/profile_invalidation_provider.h" 17 #include "components/user_manager/user_manager.h" 18 #include "testing/gtest/include/gtest/gtest.h" 19 20 namespace invalidation { 21 22 class ProfileInvalidationProviderFactoryTestBase : public InProcessBrowserTest { 23 protected: 24 ProfileInvalidationProviderFactoryTestBase(); 25 virtual ~ProfileInvalidationProviderFactoryTestBase(); 26 27 bool CanConstructProfileInvalidationProvider(Profile* profile); 28 29 private: 30 DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactoryTestBase); 31 }; 32 33 ProfileInvalidationProviderFactoryTestBase:: 34 ProfileInvalidationProviderFactoryTestBase() { 35 } 36 37 ProfileInvalidationProviderFactoryTestBase:: 38 ~ProfileInvalidationProviderFactoryTestBase() { 39 } 40 41 bool 42 ProfileInvalidationProviderFactoryTestBase:: 43 CanConstructProfileInvalidationProvider(Profile* profile) { 44 return static_cast<bool>( 45 ProfileInvalidationProviderFactory::GetInstance()-> 46 GetServiceForBrowserContext(profile, false)); 47 } 48 49 class ProfileInvalidationProviderFactoryLoginScreenBrowserTest 50 : public ProfileInvalidationProviderFactoryTestBase { 51 protected: 52 ProfileInvalidationProviderFactoryLoginScreenBrowserTest(); 53 virtual ~ProfileInvalidationProviderFactoryLoginScreenBrowserTest(); 54 55 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 56 57 private: 58 DISALLOW_COPY_AND_ASSIGN( 59 ProfileInvalidationProviderFactoryLoginScreenBrowserTest); 60 }; 61 62 ProfileInvalidationProviderFactoryLoginScreenBrowserTest:: 63 ProfileInvalidationProviderFactoryLoginScreenBrowserTest() { 64 } 65 66 ProfileInvalidationProviderFactoryLoginScreenBrowserTest:: 67 ~ProfileInvalidationProviderFactoryLoginScreenBrowserTest() { 68 } 69 70 void ProfileInvalidationProviderFactoryLoginScreenBrowserTest::SetUpCommandLine( 71 CommandLine* command_line) { 72 command_line->AppendSwitch(chromeos::switches::kLoginManager); 73 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 74 } 75 76 // Verify that no InvalidationService is instantiated for the login profile on 77 // the login screen. 78 IN_PROC_BROWSER_TEST_F(ProfileInvalidationProviderFactoryLoginScreenBrowserTest, 79 NoInvalidationService) { 80 Profile* login_profile = 81 chromeos::ProfileHelper::GetSigninProfile()->GetOriginalProfile(); 82 EXPECT_FALSE(CanConstructProfileInvalidationProvider(login_profile)); 83 } 84 85 class ProfileInvalidationProviderFactoryGuestBrowserTest 86 : public ProfileInvalidationProviderFactoryTestBase { 87 protected: 88 ProfileInvalidationProviderFactoryGuestBrowserTest(); 89 virtual ~ProfileInvalidationProviderFactoryGuestBrowserTest(); 90 91 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 92 93 private: 94 DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactoryGuestBrowserTest); 95 }; 96 97 ProfileInvalidationProviderFactoryGuestBrowserTest:: 98 ProfileInvalidationProviderFactoryGuestBrowserTest() { 99 } 100 101 ProfileInvalidationProviderFactoryGuestBrowserTest:: 102 ~ProfileInvalidationProviderFactoryGuestBrowserTest() { 103 } 104 105 void ProfileInvalidationProviderFactoryGuestBrowserTest::SetUpCommandLine( 106 CommandLine* command_line) { 107 command_line->AppendSwitch(chromeos::switches::kGuestSession); 108 command_line->AppendSwitch(::switches::kIncognito); 109 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); 110 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser, 111 chromeos::login::kGuestUserName); 112 } 113 114 // Verify that no InvalidationService is instantiated for the login profile or 115 // the guest profile while a guest session is in progress. 116 IN_PROC_BROWSER_TEST_F(ProfileInvalidationProviderFactoryGuestBrowserTest, 117 NoInvalidationService) { 118 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); 119 EXPECT_TRUE(user_manager->IsLoggedInAsGuest()); 120 Profile* guest_profile = 121 chromeos::ProfileHelper::Get() 122 ->GetProfileByUserUnsafe(user_manager->GetActiveUser()) 123 ->GetOriginalProfile(); 124 Profile* login_profile = 125 chromeos::ProfileHelper::GetSigninProfile()->GetOriginalProfile(); 126 EXPECT_FALSE(CanConstructProfileInvalidationProvider(guest_profile)); 127 EXPECT_FALSE(CanConstructProfileInvalidationProvider(login_profile)); 128 } 129 130 } // namespace invalidation 131