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