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

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

Powered by Google App Engine
This is Rietveld 408576698