Index: chrome/browser/password_manager/password_manager_internals_service_unittest.cc |
diff --git a/chrome/browser/password_manager/password_manager_internals_service_unittest.cc b/chrome/browser/password_manager/password_manager_internals_service_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a5ece89b14626a66faca632a3452a272e3d19c18 |
--- /dev/null |
+++ b/chrome/browser/password_manager/password_manager_internals_service_unittest.cc |
@@ -0,0 +1,71 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/password_manager/password_manager_internals_service.h" |
+ |
+#include "chrome/test/base/testing_profile.h" |
+#include "components/keyed_service/content/browser_context_dependency_manager.h" |
+#include "components/password_manager/core/browser/password_manager_logger.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+const char kTestText[] = "abcd1234"; |
+ |
+class MockLogReceiver : public password_manager::PasswordManagerLogger { |
+ public: |
+ MockLogReceiver() {} |
+ |
+ MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); |
+}; |
+ |
+enum ProfileType { NORMAL_PROFILE, OTR_PROFILE }; |
Ilya Sherman
2014/05/02 23:38:38
nit: "OTR" -> "INCOGNITO"
vabr (Chromium)
2014/05/06 13:16:30
Done.
|
+ |
+scoped_ptr<TestingProfile> CreateProfile(ProfileType type) { |
+ TestingProfile::Builder builder; |
+ if (type == OTR_PROFILE) |
+ builder.SetIncognito(); |
+ scoped_ptr<TestingProfile> context(builder.Build()); |
Ilya Sherman
2014/05/02 23:38:38
nit: "context" -> "profile"
vabr (Chromium)
2014/05/06 13:16:30
Done.
|
+ // During the test cases, the contexts may get created on the same address. To |
+ // avoid over-zealous asserts we need to mark the newly created one as "live". |
+ // See declaration of MarkBrowserContextLiveForTesting for more details. |
+ BrowserContextDependencyManager::GetInstance() |
+ ->MarkBrowserContextLiveForTesting(context.get()); |
vabr (Chromium)
2014/05/02 15:33:10
TODO(vabr): Need to put this inside #if !defined(N
|
+ return context.Pass(); |
+} |
+ |
+} // namespace |
+ |
+// When the browser context is not off-the-record, it should be possible to |
+// activate the service. |
+TEST(PasswordManagerInternalsServiceTest, ServiceActiveNoOTR) { |
Ilya Sherman
2014/05/02 23:38:38
nit: "OTR" -> "Incognito" throughout. Likewise, "
vabr (Chromium)
2014/05/06 13:16:30
Thanks, Ilya, I did not know that OTR is deprecate
|
+ scoped_ptr<TestingProfile> context(CreateProfile(NORMAL_PROFILE)); |
Ilya Sherman
2014/05/02 23:38:38
nit: Please be consistent about "profile" or "cont
vabr (Chromium)
2014/05/06 13:16:30
That's a fair point. I'll switch to "profile" comp
|
+ PasswordManagerInternalsService* service = |
+ PasswordManagerInternalsService::Get(context.get()); |
+ testing::StrictMock<MockLogReceiver> receiver; |
+ |
+ ASSERT_TRUE(context); |
+ ASSERT_TRUE(service); |
+ ASSERT_TRUE(service->RegisterReceiver(&receiver)); |
+ |
+ // TODO(vabr): Use a MockPasswordManagerClient to detect activity changes. |
+ EXPECT_CALL(receiver, LogSavePasswordProgress(kTestText)).Times(1); |
+ service->ProcessLog(kTestText); |
+ |
+ ASSERT_TRUE(service->UnregisterReceiver(&receiver)); |
+} |
+ |
+// When the browser context is off-the-record, it should not be possible to |
+// activate the service. |
+TEST(PasswordManagerInternalsServiceTest, ServiceNotActiveOTR) { |
+ scoped_ptr<TestingProfile> context(CreateProfile(OTR_PROFILE)); |
+ ASSERT_TRUE(context); |
+ PasswordManagerInternalsService* service = |
+ PasswordManagerInternalsService::Get(context.get()); |
+ // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL |
+ // for |context|, because |context| is OTR. Therefore the returned |service| |
+ // should also be NULL. |
+ EXPECT_FALSE(service); |
+} |