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.
5 #include "base/basictypes.h"
6 #include "base/command_line.h"
7 #include "base/compiler_specific.h"
8 #include "chrome/browser/chromeos/login/user_manager.h"
9 #include "chrome/browser/chromeos/profiles/profile_helper.h"
10 #include "chrome/browser/invalidation/invalidation_service_factory.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chromeos/chromeos_switches.h"
15 #include "components/invalidation/invalidation_service.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace invalidation {
20 class InvalidationServiceFactoryTestBase : public InProcessBrowserTest {
22 InvalidationServiceFactoryTestBase();
23 virtual ~InvalidationServiceFactoryTestBase();
25 InvalidationService* FindInvalidationServiceForProfile(Profile* profile);
28 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactoryTestBase);
31 InvalidationServiceFactoryTestBase::InvalidationServiceFactoryTestBase() {
34 InvalidationServiceFactoryTestBase::~InvalidationServiceFactoryTestBase() {
38 InvalidationServiceFactoryTestBase::FindInvalidationServiceForProfile(
40 return static_cast<InvalidationService*>(
41 InvalidationServiceFactory::GetInstance()->GetServiceForBrowserContext(
45 class InvalidationServiceFactoryLoginScreenBrowserTest
46 : public InvalidationServiceFactoryTestBase {
48 InvalidationServiceFactoryLoginScreenBrowserTest();
49 virtual ~InvalidationServiceFactoryLoginScreenBrowserTest();
51 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
54 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactoryLoginScreenBrowserTest);
57 InvalidationServiceFactoryLoginScreenBrowserTest::
58 InvalidationServiceFactoryLoginScreenBrowserTest() {
61 InvalidationServiceFactoryLoginScreenBrowserTest::
62 ~InvalidationServiceFactoryLoginScreenBrowserTest() {
65 void InvalidationServiceFactoryLoginScreenBrowserTest::SetUpCommandLine(
66 CommandLine* command_line) {
67 command_line->AppendSwitch(chromeos::switches::kLoginManager);
68 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
71 // Verify that no InvalidationService is instantiated for the login profile on
73 IN_PROC_BROWSER_TEST_F(InvalidationServiceFactoryLoginScreenBrowserTest,
74 NoInvalidationService) {
75 Profile* login_profile =
76 chromeos::ProfileHelper::GetSigninProfile()->GetOriginalProfile();
77 EXPECT_FALSE(FindInvalidationServiceForProfile(login_profile));
80 class InvalidationServiceFactoryGuestBrowserTest
81 : public InvalidationServiceFactoryTestBase {
83 InvalidationServiceFactoryGuestBrowserTest();
84 virtual ~InvalidationServiceFactoryGuestBrowserTest();
86 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
89 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceFactoryGuestBrowserTest);
92 InvalidationServiceFactoryGuestBrowserTest::
93 InvalidationServiceFactoryGuestBrowserTest() {
96 InvalidationServiceFactoryGuestBrowserTest::
97 ~InvalidationServiceFactoryGuestBrowserTest() {
100 void InvalidationServiceFactoryGuestBrowserTest::SetUpCommandLine(
101 CommandLine* command_line) {
102 command_line->AppendSwitch(chromeos::switches::kGuestSession);
103 command_line->AppendSwitch(::switches::kIncognito);
104 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
105 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser,
106 chromeos::UserManager::kGuestUserName);
109 // Verify that no InvalidationService is instantiated for the login profile or
110 // the guest profile while a guest session is in progress.
111 IN_PROC_BROWSER_TEST_F(InvalidationServiceFactoryGuestBrowserTest,
112 NoInvalidationService) {
113 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
114 EXPECT_TRUE(user_manager->IsLoggedInAsGuest());
115 Profile* guest_profile = user_manager->GetProfileByUser(
116 user_manager->GetActiveUser())->GetOriginalProfile();
117 Profile* login_profile =
118 chromeos::ProfileHelper::GetSigninProfile()->GetOriginalProfile();
119 EXPECT_FALSE(FindInvalidationServiceForProfile(guest_profile));
120 EXPECT_FALSE(FindInvalidationServiceForProfile(login_profile));
123 } // namespace invalidation