OLD | NEW |
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 "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" | 5 #include "components/autofill/content/renderer/renderer_save_password_progress_l
ogger.h" |
6 | 6 |
7 #include "components/autofill/content/common/autofill_messages.h" | 7 #include "components/autofill/content/common/autofill_messages.h" |
8 #include "ipc/ipc_test_sink.h" | 8 #include "ipc/ipc_test_sink.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace autofill { | 11 namespace autofill { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const char kTestText[] = "test"; | |
16 | |
17 class TestLogger : public RendererSavePasswordProgressLogger { | 15 class TestLogger : public RendererSavePasswordProgressLogger { |
18 public: | 16 public: |
19 TestLogger() : RendererSavePasswordProgressLogger(&sink_, 0) {} | 17 TestLogger() : RendererSavePasswordProgressLogger(&sink_, 0) {} |
20 | 18 |
21 using RendererSavePasswordProgressLogger::SendLog; | 19 using RendererSavePasswordProgressLogger::SendLog; |
22 | 20 |
23 // Searches for an |AutofillHostMsg_RecordSavePasswordProgress| message in the | 21 // Searches for an |AutofillHostMsg_RecordSavePasswordProgress| message in the |
24 // queue of sent IPC messages. If none is present, returns false. Otherwise, | 22 // queue of sent IPC messages. If none is present, returns false. Otherwise, |
25 // extracts the first |AutofillHostMsg_RecordSavePasswordProgress| message, | 23 // extracts the first |AutofillHostMsg_RecordSavePasswordProgress| message, |
26 // fills the output parameter with the value of the message's parameter, and | 24 // fills the output parameter with the value of the message's parameter, and |
27 // clears the queue of sent messages. | 25 // clears the queue of sent messages. |
28 bool GetLogMessage(std::string* log) { | 26 bool GetLogMessage( |
| 27 std::vector<SavePasswordProgressLogger::StructuredLog>* logs) { |
29 const uint32 kMsgID = AutofillHostMsg_RecordSavePasswordProgress::ID; | 28 const uint32 kMsgID = AutofillHostMsg_RecordSavePasswordProgress::ID; |
30 const IPC::Message* message = sink_.GetFirstMessageMatching(kMsgID); | 29 const IPC::Message* message = sink_.GetFirstMessageMatching(kMsgID); |
31 if (!message) | 30 if (!message) |
32 return false; | 31 return false; |
33 Tuple1<std::string> param; | 32 Tuple1<std::vector<SavePasswordProgressLogger::StructuredLog> > param; |
34 AutofillHostMsg_RecordSavePasswordProgress::Read(message, ¶m); | 33 AutofillHostMsg_RecordSavePasswordProgress::Read(message, ¶m); |
35 *log = param.a; | 34 *logs = param.a; |
36 sink_.ClearMessages(); | 35 sink_.ClearMessages(); |
37 return true; | 36 return true; |
38 } | 37 } |
39 | 38 |
40 private: | 39 private: |
41 IPC::TestSink sink_; | 40 IPC::TestSink sink_; |
42 }; | 41 }; |
43 | 42 |
44 } // namespace | 43 } // namespace |
45 | 44 |
46 TEST(RendererSavePasswordProgressLoggerTest, SendLog) { | 45 TEST(RendererSavePasswordProgressLoggerTest, SendLog) { |
47 TestLogger logger; | 46 TestLogger logger; |
48 logger.SendLog(kTestText); | 47 std::vector<SavePasswordProgressLogger::StructuredLog> logs; |
49 std::string sent_log; | 48 logs.push_back(SavePasswordProgressLogger::StructuredLog( |
50 EXPECT_TRUE(logger.GetLogMessage(&sent_log)); | 49 SavePasswordProgressLogger::STRING_MESSAGE)); |
51 EXPECT_EQ(kTestText, sent_log); | 50 logger.SendLog(logs); |
| 51 std::vector<SavePasswordProgressLogger::StructuredLog> sent_logs; |
| 52 EXPECT_TRUE(logger.GetLogMessage(&sent_logs)); |
| 53 EXPECT_EQ(logs, sent_logs); |
52 } | 54 } |
53 | 55 |
54 } // namespace autofill | 56 } // namespace autofill |
OLD | NEW |