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

Side by Side Diff: chrome/browser/password_manager/password_manager_internals_service_unittest.cc

Issue 556173002: Ensure incognito TestingProfiles are incognito for their whole lifetime. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: respond to comments Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "components/password_manager/core/browser/password_manager_internals_se rvice.h" 5 #include "components/password_manager/core/browser/password_manager_internals_se rvice.h"
6 6
7 #include "chrome/test/base/testing_profile.h" 7 #include "chrome/test/base/testing_profile.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h" 8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h" 9 #include "components/password_manager/content/browser/password_manager_internals _service_factory.h"
10 #include "components/password_manager/core/browser/log_receiver.h" 10 #include "components/password_manager/core/browser/log_receiver.h"
(...skipping 11 matching lines...) Expand all
22 public: 22 public:
23 MockLogReceiver() {} 23 MockLogReceiver() {}
24 24
25 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); 25 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&));
26 }; 26 };
27 27
28 enum ProfileType { NORMAL_PROFILE, INCOGNITO_PROFILE }; 28 enum ProfileType { NORMAL_PROFILE, INCOGNITO_PROFILE };
29 29
30 scoped_ptr<TestingProfile> CreateProfile(ProfileType type) { 30 scoped_ptr<TestingProfile> CreateProfile(ProfileType type) {
31 TestingProfile::Builder builder; 31 TestingProfile::Builder builder;
32 if (type == INCOGNITO_PROFILE)
33 builder.SetIncognito();
34 scoped_ptr<TestingProfile> profile(builder.Build()); 32 scoped_ptr<TestingProfile> profile(builder.Build());
35 #if !defined(NDEBUG) 33 #if !defined(NDEBUG)
36 // During the test cases, the profiles may get created on the same address. To 34 // During the test cases, the profiles may get created on the same address. To
37 // avoid over-zealous asserts we need to mark the newly created one as "live". 35 // avoid over-zealous asserts we need to mark the newly created one as "live".
38 // See declaration of MarkBrowserContextLiveForTesting for more details. 36 // See declaration of MarkBrowserContextLiveForTesting for more details.
39 BrowserContextDependencyManager::GetInstance() 37 BrowserContextDependencyManager::GetInstance()
40 ->MarkBrowserContextLiveForTesting(profile.get()); 38 ->MarkBrowserContextLiveForTesting(profile.get());
39 if (type == INCOGNITO_PROFILE) {
40 BrowserContextDependencyManager::GetInstance()
41 ->MarkBrowserContextLiveForTesting(profile->GetOffTheRecordProfile());
42 }
41 #endif 43 #endif
42 return profile.Pass(); 44 return profile.Pass();
43 } 45 }
44 46
45 } // namespace 47 } // namespace
46 48
47 // When the profile is not incognito, it should be possible to activate the 49 // When the profile is not incognito, it should be possible to activate the
48 // service. 50 // service.
49 TEST(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) { 51 TEST(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) {
50 scoped_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE)); 52 scoped_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE));
(...skipping 11 matching lines...) Expand all
62 service->ProcessLog(kTestText); 64 service->ProcessLog(kTestText);
63 65
64 service->UnregisterReceiver(&receiver); 66 service->UnregisterReceiver(&receiver);
65 } 67 }
66 68
67 // When the browser profile is incognito, it should not be possible to activate 69 // When the browser profile is incognito, it should not be possible to activate
68 // the service. 70 // the service.
69 TEST(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) { 71 TEST(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) {
70 scoped_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE)); 72 scoped_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE));
71 ASSERT_TRUE(profile); 73 ASSERT_TRUE(profile);
74
75 Profile* incognito_profile = profile->GetOffTheRecordProfile();
72 PasswordManagerInternalsService* service = 76 PasswordManagerInternalsService* service =
73 PasswordManagerInternalsServiceFactory::GetForBrowserContext( 77 PasswordManagerInternalsServiceFactory::GetForBrowserContext(
74 profile.get()); 78 incognito_profile);
75 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL 79 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL
76 // for |profile|, because |profile| is incognito. Therefore the returned 80 // for |profile|, because |profile| is incognito. Therefore the returned
77 // |service| should also be NULL. 81 // |service| should also be NULL.
78 EXPECT_FALSE(service); 82 EXPECT_FALSE(service);
79 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698