| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 class MockLogReceiver : public password_manager::LogReceiver { | 22 class MockLogReceiver : public password_manager::LogReceiver { |
| 23 public: | 23 public: |
| 24 MockLogReceiver() {} | 24 MockLogReceiver() {} |
| 25 | 25 |
| 26 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); | 26 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 enum ProfileType { NORMAL_PROFILE, INCOGNITO_PROFILE }; | 29 enum ProfileType { NORMAL_PROFILE, INCOGNITO_PROFILE }; |
| 30 | 30 |
| 31 scoped_ptr<TestingProfile> CreateProfile(ProfileType type) { | 31 std::unique_ptr<TestingProfile> CreateProfile(ProfileType type) { |
| 32 TestingProfile::Builder builder; | 32 TestingProfile::Builder builder; |
| 33 scoped_ptr<TestingProfile> profile(builder.Build()); | 33 std::unique_ptr<TestingProfile> profile(builder.Build()); |
| 34 #if !defined(NDEBUG) | 34 #if !defined(NDEBUG) |
| 35 // During the test cases, the profiles may get created on the same address. To | 35 // During the test cases, the profiles may get created on the same address. To |
| 36 // avoid over-zealous asserts we need to mark the newly created one as "live". | 36 // avoid over-zealous asserts we need to mark the newly created one as "live". |
| 37 // See declaration of MarkBrowserContextLiveForTesting for more details. | 37 // See declaration of MarkBrowserContextLiveForTesting for more details. |
| 38 BrowserContextDependencyManager::GetInstance() | 38 BrowserContextDependencyManager::GetInstance() |
| 39 ->MarkBrowserContextLiveForTesting(profile.get()); | 39 ->MarkBrowserContextLiveForTesting(profile.get()); |
| 40 if (type == INCOGNITO_PROFILE) { | 40 if (type == INCOGNITO_PROFILE) { |
| 41 BrowserContextDependencyManager::GetInstance() | 41 BrowserContextDependencyManager::GetInstance() |
| 42 ->MarkBrowserContextLiveForTesting(profile->GetOffTheRecordProfile()); | 42 ->MarkBrowserContextLiveForTesting(profile->GetOffTheRecordProfile()); |
| 43 } | 43 } |
| 44 #endif | 44 #endif |
| 45 return profile; | 45 return profile; |
| 46 } | 46 } |
| 47 | 47 |
| 48 } // namespace | 48 } // namespace |
| 49 | 49 |
| 50 class PasswordManagerInternalsServiceTest : public testing::Test { | 50 class PasswordManagerInternalsServiceTest : public testing::Test { |
| 51 content::TestBrowserThreadBundle thread_bundle_; | 51 content::TestBrowserThreadBundle thread_bundle_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 // When the profile is not incognito, it should be possible to activate the | 54 // When the profile is not incognito, it should be possible to activate the |
| 55 // service. | 55 // service. |
| 56 TEST_F(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) { | 56 TEST_F(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) { |
| 57 scoped_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE)); | 57 std::unique_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE)); |
| 58 PasswordManagerInternalsService* service = | 58 PasswordManagerInternalsService* service = |
| 59 PasswordManagerInternalsServiceFactory::GetForBrowserContext( | 59 PasswordManagerInternalsServiceFactory::GetForBrowserContext( |
| 60 profile.get()); | 60 profile.get()); |
| 61 testing::StrictMock<MockLogReceiver> receiver; | 61 testing::StrictMock<MockLogReceiver> receiver; |
| 62 | 62 |
| 63 ASSERT_TRUE(profile); | 63 ASSERT_TRUE(profile); |
| 64 ASSERT_TRUE(service); | 64 ASSERT_TRUE(service); |
| 65 EXPECT_EQ(std::string(), service->RegisterReceiver(&receiver)); | 65 EXPECT_EQ(std::string(), service->RegisterReceiver(&receiver)); |
| 66 | 66 |
| 67 // TODO(vabr): Use a MockPasswordManagerClient to detect activity changes. | 67 // TODO(vabr): Use a MockPasswordManagerClient to detect activity changes. |
| 68 EXPECT_CALL(receiver, LogSavePasswordProgress(kTestText)).Times(1); | 68 EXPECT_CALL(receiver, LogSavePasswordProgress(kTestText)).Times(1); |
| 69 service->ProcessLog(kTestText); | 69 service->ProcessLog(kTestText); |
| 70 | 70 |
| 71 service->UnregisterReceiver(&receiver); | 71 service->UnregisterReceiver(&receiver); |
| 72 } | 72 } |
| 73 | 73 |
| 74 // When the browser profile is incognito, it should not be possible to activate | 74 // When the browser profile is incognito, it should not be possible to activate |
| 75 // the service. | 75 // the service. |
| 76 TEST_F(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) { | 76 TEST_F(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) { |
| 77 scoped_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE)); | 77 std::unique_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE)); |
| 78 ASSERT_TRUE(profile); | 78 ASSERT_TRUE(profile); |
| 79 | 79 |
| 80 Profile* incognito_profile = profile->GetOffTheRecordProfile(); | 80 Profile* incognito_profile = profile->GetOffTheRecordProfile(); |
| 81 PasswordManagerInternalsService* service = | 81 PasswordManagerInternalsService* service = |
| 82 PasswordManagerInternalsServiceFactory::GetForBrowserContext( | 82 PasswordManagerInternalsServiceFactory::GetForBrowserContext( |
| 83 incognito_profile); | 83 incognito_profile); |
| 84 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL | 84 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL |
| 85 // for |profile|, because |profile| is incognito. Therefore the returned | 85 // for |profile|, because |profile| is incognito. Therefore the returned |
| 86 // |service| should also be NULL. | 86 // |service| should also be NULL. |
| 87 EXPECT_FALSE(service); | 87 EXPECT_FALSE(service); |
| 88 } | 88 } |
| OLD | NEW |