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

Side by Side Diff: chrome/browser/password_manager/chrome_password_manager_client_unittest.cc

Issue 231283003: Password manager: introduce logging for the internals page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments addressed 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/password_manager/chrome_password_manager_client.h" 5 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
6 6
7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
8 #include "components/autofill/content/common/autofill_messages.h"
8 #include "components/password_manager/core/browser/password_manager_logger.h" 9 #include "components/password_manager/core/browser/password_manager_logger.h"
9 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
10 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 #include "content/public/test/mock_render_process_host.h"
11 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 using content::BrowserContext; 16 using content::BrowserContext;
15 using content::WebContents; 17 using content::WebContents;
16 18
17 namespace { 19 namespace {
18 20
19 const char kTestText[] = "abcd1234"; 21 const char kTestText[] = "abcd1234";
20 22
21 class MockPasswordManagerLogger 23 class MockPasswordManagerLogger
22 : public password_manager::PasswordManagerLogger { 24 : public password_manager::PasswordManagerLogger {
23 public: 25 public:
24 MockPasswordManagerLogger() {} 26 MockPasswordManagerLogger() {}
25 27
26 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&)); 28 MOCK_METHOD1(LogSavePasswordProgress, void(const std::string&));
27 }; 29 };
28 30
29 } // namespace 31 } // namespace
30 32
31 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness { 33 class ChromePasswordManagerClientTest : public ChromeRenderViewHostTestHarness {
32 public: 34 public:
33 virtual void SetUp() OVERRIDE; 35 virtual void SetUp() OVERRIDE;
34 36
35 protected: 37 protected:
36 ChromePasswordManagerClient* GetClient(); 38 ChromePasswordManagerClient* GetClient();
37 39
38 testing::StrictMock<MockPasswordManagerLogger> logger; 40 // If the test IPC sink contains an AutofillMsg_ChangeLoggingState message,
41 // then copies its argument into |activation_flag| and returns true. Otherwise
42 // returns false.
43 bool WasLoggingActivationMessageSent(bool* activation_flag);
44
45 testing::StrictMock<MockPasswordManagerLogger> logger_;
39 }; 46 };
40 47
41 void ChromePasswordManagerClientTest::SetUp() { 48 void ChromePasswordManagerClientTest::SetUp() {
42 ChromeRenderViewHostTestHarness::SetUp(); 49 ChromeRenderViewHostTestHarness::SetUp();
43 ChromePasswordManagerClient::CreateForWebContentsWithAutofillManagerDelegate( 50 ChromePasswordManagerClient::CreateForWebContentsWithAutofillManagerDelegate(
44 web_contents(), NULL); 51 web_contents(), NULL);
45 } 52 }
46 53
47 ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() { 54 ChromePasswordManagerClient* ChromePasswordManagerClientTest::GetClient() {
48 return ChromePasswordManagerClient::FromWebContents(web_contents()); 55 return ChromePasswordManagerClient::FromWebContents(web_contents());
49 } 56 }
50 57
58 bool ChromePasswordManagerClientTest::WasLoggingActivationMessageSent(
59 bool* activation_flag) {
60 const uint32 kMsgID = AutofillMsg_ChangeLoggingState::ID;
61 const IPC::Message* message =
62 process()->sink().GetFirstMessageMatching(kMsgID);
63 if (!message)
64 return false;
65 Tuple1<bool> param;
66 AutofillMsg_ChangeLoggingState::Read(message, &param);
67 *activation_flag = param.a;
68 process()->sink().ClearMessages();
69 return true;
70 }
71
51 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoLogger) { 72 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNoLogger) {
52 ChromePasswordManagerClient* client = GetClient(); 73 ChromePasswordManagerClient* client = GetClient();
53 74
54 EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(0); 75 EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(0);
55 // Before attaching the logger, no text should be passed. 76 // Before attaching the logger, no text should be passed.
56 client->LogSavePasswordProgress(kTestText); 77 client->LogSavePasswordProgress(kTestText);
57 EXPECT_FALSE(client->IsLoggingActive()); 78 EXPECT_FALSE(client->IsLoggingActive());
58 } 79 }
59 80
60 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachLogger) { 81 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressAttachLogger) {
61 ChromePasswordManagerClient* client = GetClient(); 82 ChromePasswordManagerClient* client = GetClient();
62 83
63 // After attaching the logger, text should be passed. 84 // After attaching the logger, text should be passed.
64 client->SetLogger(&logger); 85 client->SetLogger(&logger_);
65 EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(1); 86 EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(1);
66 client->LogSavePasswordProgress(kTestText); 87 client->LogSavePasswordProgress(kTestText);
67 EXPECT_TRUE(client->IsLoggingActive()); 88 EXPECT_TRUE(client->IsLoggingActive());
68 } 89 }
69 90
70 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressDetachLogger) { 91 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressDetachLogger) {
71 ChromePasswordManagerClient* client = GetClient(); 92 ChromePasswordManagerClient* client = GetClient();
72 93
73 client->SetLogger(&logger); 94 client->SetLogger(&logger_);
74 // After detaching the logger, no text should be passed. 95 // After detaching the logger, no text should be passed.
75 client->SetLogger(NULL); 96 client->SetLogger(NULL);
76 EXPECT_CALL(logger, LogSavePasswordProgress(kTestText)).Times(0); 97 EXPECT_CALL(logger_, LogSavePasswordProgress(kTestText)).Times(0);
77 client->LogSavePasswordProgress(kTestText); 98 client->LogSavePasswordProgress(kTestText);
78 EXPECT_FALSE(client->IsLoggingActive()); 99 EXPECT_FALSE(client->IsLoggingActive());
79 } 100 }
101
102 TEST_F(ChromePasswordManagerClientTest, LogSavePasswordProgressNotifyRenderer) {
103 ChromePasswordManagerClient* client = GetClient();
104 bool logging_active = false;
105
106 // Initially, the logging should be off, so no IPC messages.
107 EXPECT_FALSE(WasLoggingActivationMessageSent(&logging_active));
108
109 client->SetLogger(&logger_);
110 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active));
111 EXPECT_TRUE(logging_active);
112
113 client->SetLogger(NULL);
114 EXPECT_TRUE(WasLoggingActivationMessageSent(&logging_active));
115 EXPECT_FALSE(logging_active);
116 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/chrome_password_manager_client.cc ('k') | chrome/browser/ui/login/login_prompt.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698