Prevent chrome://net-internals/#export from flickering
[chromium-blink-merge.git] / chrome / browser / invalidation / profile_invalidation_provider_factory_browsertest.cc
blobd0cb2259c3d6ed2e03e3d90d38e83a180ecffc57
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/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"
20 namespace invalidation {
22 class ProfileInvalidationProviderFactoryTestBase : public InProcessBrowserTest {
23 protected:
24 ProfileInvalidationProviderFactoryTestBase();
25 ~ProfileInvalidationProviderFactoryTestBase() override;
27 bool CanConstructProfileInvalidationProvider(Profile* profile);
29 private:
30 DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactoryTestBase);
33 ProfileInvalidationProviderFactoryTestBase::
34 ProfileInvalidationProviderFactoryTestBase() {
37 ProfileInvalidationProviderFactoryTestBase::
38 ~ProfileInvalidationProviderFactoryTestBase() {
41 bool
42 ProfileInvalidationProviderFactoryTestBase::
43 CanConstructProfileInvalidationProvider(Profile* profile) {
44 return static_cast<bool>(
45 ProfileInvalidationProviderFactory::GetInstance()->
46 GetServiceForBrowserContext(profile, false));
49 class ProfileInvalidationProviderFactoryLoginScreenBrowserTest
50 : public ProfileInvalidationProviderFactoryTestBase {
51 protected:
52 ProfileInvalidationProviderFactoryLoginScreenBrowserTest();
53 ~ProfileInvalidationProviderFactoryLoginScreenBrowserTest() override;
55 void SetUpCommandLine(base::CommandLine* command_line) override;
57 private:
58 DISALLOW_COPY_AND_ASSIGN(
59 ProfileInvalidationProviderFactoryLoginScreenBrowserTest);
62 ProfileInvalidationProviderFactoryLoginScreenBrowserTest::
63 ProfileInvalidationProviderFactoryLoginScreenBrowserTest() {
66 ProfileInvalidationProviderFactoryLoginScreenBrowserTest::
67 ~ProfileInvalidationProviderFactoryLoginScreenBrowserTest() {
70 void ProfileInvalidationProviderFactoryLoginScreenBrowserTest::SetUpCommandLine(
71 base::CommandLine* command_line) {
72 command_line->AppendSwitch(chromeos::switches::kLoginManager);
73 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user");
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));
85 class ProfileInvalidationProviderFactoryGuestBrowserTest
86 : public ProfileInvalidationProviderFactoryTestBase {
87 protected:
88 ProfileInvalidationProviderFactoryGuestBrowserTest();
89 ~ProfileInvalidationProviderFactoryGuestBrowserTest() override;
91 void SetUpCommandLine(base::CommandLine* command_line) override;
93 private:
94 DISALLOW_COPY_AND_ASSIGN(ProfileInvalidationProviderFactoryGuestBrowserTest);
97 ProfileInvalidationProviderFactoryGuestBrowserTest::
98 ProfileInvalidationProviderFactoryGuestBrowserTest() {
101 ProfileInvalidationProviderFactoryGuestBrowserTest::
102 ~ProfileInvalidationProviderFactoryGuestBrowserTest() {
105 void ProfileInvalidationProviderFactoryGuestBrowserTest::SetUpCommandLine(
106 base::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);
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));
130 } // namespace invalidation