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

Side by Side 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: Comments addressed Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/password_manager/password_manager_internals_service.h"
6
7 #include "chrome/test/base/testing_profile.h"
8 #include "components/keyed_service/content/browser_context_dependency_manager.h"
9 #include "components/password_manager/core/browser/password_manager_logger.h"
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 const char kTestText[] = "abcd1234";
16
17 class MockLogReceiver : public password_manager::PasswordManagerLogger {
18 public:
19 MockLogReceiver() {}
20
21 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&));
22 };
23
24 enum ProfileType { NORMAL_PROFILE, INCOGNITO_PROFILE };
25
26 scoped_ptr<TestingProfile> CreateProfile(ProfileType type) {
27 TestingProfile::Builder builder;
28 if (type == INCOGNITO_PROFILE)
29 builder.SetIncognito();
30 scoped_ptr<TestingProfile> profile(builder.Build());
31 #if !defined(NDEBUG)
32 // During the test cases, the profiles may get created on the same address. To
33 // avoid over-zealous asserts we need to mark the newly created one as "live".
34 // See declaration of MarkBrowserContextLiveForTesting for more details.
35 BrowserContextDependencyManager::GetInstance()
36 ->MarkBrowserContextLiveForTesting(profile.get());
37 #endif
38 return profile.Pass();
39 }
40
41 } // namespace
42
43 // When the profile is not incognito, it should be possible to activate the
44 // service.
45 TEST(PasswordManagerInternalsServiceTest, ServiceActiveNonIncognito) {
46 scoped_ptr<TestingProfile> profile(CreateProfile(NORMAL_PROFILE));
47 PasswordManagerInternalsService* service =
48 PasswordManagerInternalsService::Get(profile.get());
49 testing::StrictMock<MockLogReceiver> receiver;
50
51 ASSERT_TRUE(profile);
52 ASSERT_TRUE(service);
53 EXPECT_EQ(std::string(), service->RegisterReceiver(&receiver));
54
55 // TODO(vabr): Use a MockPasswordManagerClient to detect activity changes.
56 EXPECT_CALL(receiver, LogSavePasswordProgress(kTestText)).Times(1);
57 service->ProcessLog(kTestText);
58
59 service->UnregisterReceiver(&receiver);
60 }
61
62 // When the browser profile is incognito, it should not be possible to activate
63 // the service.
64 TEST(PasswordManagerInternalsServiceTest, ServiceNotActiveIncognito) {
65 scoped_ptr<TestingProfile> profile(CreateProfile(INCOGNITO_PROFILE));
66 ASSERT_TRUE(profile);
67 PasswordManagerInternalsService* service =
68 PasswordManagerInternalsService::Get(profile.get());
69 // BrowserContextKeyedBaseFactory::GetBrowserContextToUse should return NULL
70 // for |profile|, because |profile| is incognito. Therefore the returned
71 // |service| should also be NULL.
72 EXPECT_FALSE(service);
73 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698