| 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" |
| 11 #include "content/public/test/test_browser_thread_bundle.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 using password_manager::PasswordManagerInternalsService; | 15 using password_manager::PasswordManagerInternalsService; |
| 15 using password_manager::PasswordManagerInternalsServiceFactory; | 16 using password_manager::PasswordManagerInternalsServiceFactory; |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kTestText[] = "abcd1234"; | 20 const char kTestText[] = "abcd1234"; |
| 20 | 21 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 if (type == INCOGNITO_PROFILE) { | 40 if (type == INCOGNITO_PROFILE) { |
| 40 BrowserContextDependencyManager::GetInstance() | 41 BrowserContextDependencyManager::GetInstance() |
| 41 ->MarkBrowserContextLiveForTesting(profile->GetOffTheRecordProfile()); | 42 ->MarkBrowserContextLiveForTesting(profile->GetOffTheRecordProfile()); |
| 42 } | 43 } |
| 43 #endif | 44 #endif |
| 44 return profile.Pass(); | 45 return profile.Pass(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 } // namespace | 48 } // namespace |
| 48 | 49 |
| 50 class PasswordManagerInternalsServiceTest : public testing::Test { |
| 51 content::TestBrowserThreadBundle thread_bundle_; |
| 52 }; |
| 53 |
| 49 // 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 |
| 50 // service. | 55 // service. |
| 51 TEST(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) { | 56 TEST_F(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) { |
| 52 scoped_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE)); | 57 scoped_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE)); |
| 53 PasswordManagerInternalsService* service = | 58 PasswordManagerInternalsService* service = |
| 54 PasswordManagerInternalsServiceFactory::GetForBrowserContext( | 59 PasswordManagerInternalsServiceFactory::GetForBrowserContext( |
| 55 profile.get()); | 60 profile.get()); |
| 56 testing::StrictMock<MockLogReceiver> receiver; | 61 testing::StrictMock<MockLogReceiver> receiver; |
| 57 | 62 |
| 58 ASSERT_TRUE(profile); | 63 ASSERT_TRUE(profile); |
| 59 ASSERT_TRUE(service); | 64 ASSERT_TRUE(service); |
| 60 EXPECT_EQ(std::string(), service->RegisterReceiver(&receiver)); | 65 EXPECT_EQ(std::string(), service->RegisterReceiver(&receiver)); |
| 61 | 66 |
| 62 // TODO(vabr): Use a MockPasswordManagerClient to detect activity changes. | 67 // TODO(vabr): Use a MockPasswordManagerClient to detect activity changes. |
| 63 EXPECT_CALL(receiver, LogSavePasswordProgress(kTestText)).Times(1); | 68 EXPECT_CALL(receiver, LogSavePasswordProgress(kTestText)).Times(1); |
| 64 service->ProcessLog(kTestText); | 69 service->ProcessLog(kTestText); |
| 65 | 70 |
| 66 service->UnregisterReceiver(&receiver); | 71 service->UnregisterReceiver(&receiver); |
| 67 } | 72 } |
| 68 | 73 |
| 69 // 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 |
| 70 // the service. | 75 // the service. |
| 71 TEST(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) { | 76 TEST_F(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) { |
| 72 scoped_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE)); | 77 scoped_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE)); |
| 73 ASSERT_TRUE(profile); | 78 ASSERT_TRUE(profile); |
| 74 | 79 |
| 75 Profile* incognito_profile = profile->GetOffTheRecordProfile(); | 80 Profile* incognito_profile = profile->GetOffTheRecordProfile(); |
| 76 PasswordManagerInternalsService* service = | 81 PasswordManagerInternalsService* service = |
| 77 PasswordManagerInternalsServiceFactory::GetForBrowserContext( | 82 PasswordManagerInternalsServiceFactory::GetForBrowserContext( |
| 78 incognito_profile); | 83 incognito_profile); |
| 79 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL | 84 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL |
| 80 // for |profile|, because |profile| is incognito. Therefore the returned | 85 // for |profile|, because |profile| is incognito. Therefore the returned |
| 81 // |service| should also be NULL. | 86 // |service| should also be NULL. |
| 82 EXPECT_FALSE(service); | 87 EXPECT_FALSE(service); |
| 83 } | 88 } |
| OLD | NEW |