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

Unified Diff: chrome/browser/password_manager/password_manager_internals_service_unittest.cc

Issue 262583007: Password manager internals page service: introduction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add client registration, remove IsActive Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
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);
+}

Powered by Google App Engine
This is Rietveld 408576698