OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/os_crypt/kwallet_dbus.h" | 5 #include "components/os_crypt/kwallet_dbus.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 return false; | 265 return false; |
266 | 266 |
267 bool b; | 267 bool b; |
268 EXPECT_TRUE(reader.PopBool(&b)); | 268 EXPECT_TRUE(reader.PopBool(&b)); |
269 if (bool_5 != b) | 269 if (bool_5 != b) |
270 return false; | 270 return false; |
271 | 271 |
272 return true; | 272 return true; |
273 } | 273 } |
274 | 274 |
275 MATCHER_P5(ArgumentsAreIntStringStringStringString, | |
276 int_1, | |
277 str_2, | |
278 str_3, | |
279 str_4, | |
280 str_5, | |
281 "") { | |
282 dbus::MessageReader reader(arg); | |
283 | |
284 int32_t i; | |
285 EXPECT_TRUE(reader.PopInt32(&i)); | |
286 if (i != int_1) | |
Lei Zhang
2016/07/20 01:08:26
You put int_1 on the right side, but moved str_N t
cfroussios
2016/07/20 15:22:47
Done.
| |
287 return false; | |
288 | |
289 std::string str; | |
290 EXPECT_TRUE(reader.PopString(&str)); | |
291 if (str_2 != str) | |
292 return false; | |
293 | |
294 EXPECT_TRUE(reader.PopString(&str)); | |
295 if (str_3 != str) | |
296 return false; | |
297 | |
298 EXPECT_TRUE(reader.PopString(&str)); | |
299 if (str_4 != str) | |
300 return false; | |
301 | |
302 EXPECT_TRUE(reader.PopString(&str)); | |
303 if (str_5 != str) | |
304 return false; | |
305 | |
306 return true; | |
307 } | |
308 | |
309 MATCHER_P3(ArgumentsAreIntBoolString, int_1, bool_2, str_3, "") { | |
310 dbus::MessageReader reader(arg); | |
311 | |
312 int32_t i; | |
313 EXPECT_TRUE(reader.PopInt32(&i)); | |
314 if (i != int_1) | |
315 return false; | |
316 | |
317 bool b; | |
318 EXPECT_TRUE(reader.PopBool(&b)); | |
319 if (b != bool_2) | |
320 return false; | |
321 | |
322 std::string str; | |
323 EXPECT_TRUE(reader.PopString(&str)); | |
324 if (str != str_3) | |
325 return false; | |
326 | |
327 return true; | |
328 } | |
329 | |
275 TEST_P(KWalletDBusTest, StartWalletd) { | 330 TEST_P(KWalletDBusTest, StartWalletd) { |
276 // The receiver of the message takes ownership of the response object. | 331 // The receiver of the message takes ownership of the response object. |
277 dbus::Response* response_success = RespondEmpty(); | 332 dbus::Response* response_success = RespondEmpty(); |
278 dbus::MessageWriter writer(response_success); | 333 dbus::MessageWriter writer(response_success); |
279 writer.AppendInt32(0); // return code | 334 writer.AppendInt32(0); // return code |
280 writer.AppendString("dbus_name"); | 335 writer.AppendString("dbus_name"); |
281 writer.AppendString(std::string()); // error message | 336 writer.AppendString(std::string()); // error message |
282 writer.AppendInt32(100); // pid | 337 writer.AppendInt32(100); // pid |
283 | 338 |
284 EXPECT_CALL( | 339 EXPECT_CALL( |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 EXPECT_CALL( | 741 EXPECT_CALL( |
687 *mock_kwallet_proxy_.get(), | 742 *mock_kwallet_proxy_.get(), |
688 MockCallMethodAndBlock(Calls(kKWalletInterface, "createFolder"), _)) | 743 MockCallMethodAndBlock(Calls(kKWalletInterface, "createFolder"), _)) |
689 .WillOnce(Return(nullptr)); | 744 .WillOnce(Return(nullptr)); |
690 | 745 |
691 bool created_folder = false; | 746 bool created_folder = false; |
692 EXPECT_EQ(KWalletDBus::Error::CANNOT_CONTACT, | 747 EXPECT_EQ(KWalletDBus::Error::CANNOT_CONTACT, |
693 kwallet_dbus_.CreateFolder(123, "folder", "app", &created_folder)); | 748 kwallet_dbus_.CreateFolder(123, "folder", "app", &created_folder)); |
694 } | 749 } |
695 | 750 |
751 TEST_P(KWalletDBusTest, WritePassword) { | |
752 EXPECT_CALL(*mock_kwallet_proxy_.get(), | |
753 MockCallMethodAndBlock( | |
754 AllOf(Calls(kKWalletInterface, "writePassword"), | |
755 ArgumentsAreIntStringStringStringString( | |
756 123, "folder", "key", "password", "app")), | |
757 _)) | |
758 .WillOnce(Return(RespondInt32(0))); | |
759 | |
760 bool write_success = false; | |
761 EXPECT_EQ(KWalletDBus::Error::SUCCESS, | |
762 kwallet_dbus_.WritePassword(123, "folder", "key", "password", "app", | |
763 &write_success)); | |
764 EXPECT_TRUE(write_success); | |
765 } | |
766 | |
767 TEST_P(KWalletDBusTest, WritePasswordRejected) { | |
768 EXPECT_CALL(*mock_kwallet_proxy_.get(), | |
769 MockCallMethodAndBlock( | |
770 AllOf(Calls(kKWalletInterface, "writePassword"), | |
771 ArgumentsAreIntStringStringStringString( | |
772 123, "folder", "key", "password", "app")), | |
773 _)) | |
774 .WillOnce(Return(RespondInt32(-1))); | |
775 | |
776 bool write_success = true; | |
777 EXPECT_EQ(KWalletDBus::Error::SUCCESS, | |
778 kwallet_dbus_.WritePassword(123, "folder", "key", "password", "app", | |
779 &write_success)); | |
780 EXPECT_FALSE(write_success); | |
781 } | |
782 | |
783 TEST_P(KWalletDBusTest, WritePasswordErrorRead) { | |
784 EXPECT_CALL( | |
785 *mock_kwallet_proxy_.get(), | |
786 MockCallMethodAndBlock(Calls(kKWalletInterface, "writePassword"), _)) | |
787 .WillOnce(Return(RespondEmpty())); | |
788 | |
789 bool write_success = false; | |
790 EXPECT_EQ(KWalletDBus::Error::CANNOT_READ, | |
791 kwallet_dbus_.WritePassword(123, "folder", "key", "password", "app", | |
792 &write_success)); | |
793 } | |
794 | |
795 TEST_P(KWalletDBusTest, WritePasswordErrorContact) { | |
796 EXPECT_CALL( | |
797 *mock_kwallet_proxy_.get(), | |
798 MockCallMethodAndBlock(Calls(kKWalletInterface, "writePassword"), _)) | |
799 .WillOnce(Return(nullptr)); | |
800 | |
801 bool write_success = false; | |
802 EXPECT_EQ(KWalletDBus::Error::CANNOT_CONTACT, | |
803 kwallet_dbus_.WritePassword(123, "folder", "key", "password", "app", | |
804 &write_success)); | |
805 } | |
806 | |
807 TEST_P(KWalletDBusTest, ReadPassword) { | |
808 EXPECT_CALL( | |
809 *mock_kwallet_proxy_.get(), | |
810 MockCallMethodAndBlock( | |
811 AllOf(Calls(kKWalletInterface, "readPassword"), | |
812 ArgumentsAreIntStringStringString(123, "folder", "key", "app")), | |
813 _)) | |
814 .WillOnce(Return(RespondString("password"))); | |
815 | |
816 std::string password; | |
817 EXPECT_EQ(KWalletDBus::Error::SUCCESS, | |
818 kwallet_dbus_.ReadPassword(123, "folder", "key", "app", &password)); | |
819 EXPECT_EQ("password", password); | |
Lei Zhang
2016/07/20 01:08:26
Can you use EXPECT_STREQ() here?
cfroussios
2016/07/20 15:22:47
EXPECT_STREQ is for C strings.
Lei Zhang
2016/07/20 19:15:07
It is indeed, and this is shorter than EXPECT_STRE
cfroussios
2016/07/21 11:49:46
Acknowledged.
| |
820 } | |
821 | |
822 TEST_P(KWalletDBusTest, ReadPasswordErrorRead) { | |
823 EXPECT_CALL( | |
824 *mock_kwallet_proxy_.get(), | |
825 MockCallMethodAndBlock(Calls(kKWalletInterface, "readPassword"), _)) | |
826 .WillOnce(Return(RespondEmpty())); | |
827 | |
828 std::string password; | |
829 EXPECT_EQ(KWalletDBus::Error::CANNOT_READ, | |
830 kwallet_dbus_.ReadPassword(123, "folder", "key", "app", &password)); | |
831 } | |
832 | |
833 TEST_P(KWalletDBusTest, ReadPasswordErrorContact) { | |
834 EXPECT_CALL( | |
835 *mock_kwallet_proxy_.get(), | |
836 MockCallMethodAndBlock(Calls(kKWalletInterface, "readPassword"), _)) | |
837 .WillOnce(Return(nullptr)); | |
838 | |
839 std::string password; | |
840 EXPECT_EQ(KWalletDBus::Error::CANNOT_CONTACT, | |
841 kwallet_dbus_.ReadPassword(123, "folder", "key", "app", &password)); | |
842 } | |
843 | |
844 TEST_P(KWalletDBusTest, CloseSuccess) { | |
845 EXPECT_CALL(*mock_kwallet_proxy_.get(), | |
846 MockCallMethodAndBlock( | |
847 AllOf(Calls(kKWalletInterface, "close"), | |
848 ArgumentsAreIntBoolString(123, false, "app")), | |
849 _)) | |
850 .WillOnce(Return(RespondInt32(0))); | |
851 | |
852 bool success = false; | |
853 EXPECT_EQ(KWalletDBus::Error::SUCCESS, | |
854 kwallet_dbus_.Close(123, false, "app", &success)); | |
855 EXPECT_EQ(true, success); | |
Lei Zhang
2016/07/20 01:08:26
EXPECT_TRUE(success)
cfroussios
2016/07/20 15:22:47
Done.
| |
856 } | |
857 | |
858 TEST_P(KWalletDBusTest, CloseUnsuccessful) { | |
859 EXPECT_CALL(*mock_kwallet_proxy_.get(), | |
860 MockCallMethodAndBlock( | |
861 AllOf(Calls(kKWalletInterface, "close"), | |
862 ArgumentsAreIntBoolString(123, false, "app")), | |
863 _)) | |
864 .WillOnce(Return(RespondInt32(1))); | |
865 | |
866 bool success = true; | |
867 EXPECT_EQ(KWalletDBus::Error::SUCCESS, | |
868 kwallet_dbus_.Close(123, false, "app", &success)); | |
869 EXPECT_EQ(false, success); | |
Lei Zhang
2016/07/20 01:08:26
EXPECT_FALSE
cfroussios
2016/07/20 15:22:47
Done.
| |
870 } | |
871 | |
872 TEST_P(KWalletDBusTest, CloseErrorRead) { | |
873 EXPECT_CALL(*mock_kwallet_proxy_.get(), | |
874 MockCallMethodAndBlock(Calls(kKWalletInterface, "close"), _)) | |
875 .WillOnce(Return(RespondEmpty())); | |
876 | |
877 bool success = true; | |
878 EXPECT_EQ(KWalletDBus::Error::CANNOT_READ, | |
879 kwallet_dbus_.Close(123, false, "app", &success)); | |
880 } | |
881 | |
882 TEST_P(KWalletDBusTest, CloseErrorContact) { | |
883 EXPECT_CALL(*mock_kwallet_proxy_.get(), | |
884 MockCallMethodAndBlock(Calls(kKWalletInterface, "close"), _)) | |
885 .WillOnce(Return(nullptr)); | |
886 | |
887 bool success = true; | |
888 EXPECT_EQ(KWalletDBus::Error::CANNOT_CONTACT, | |
889 kwallet_dbus_.Close(123, false, "app", &success)); | |
890 } | |
891 | |
696 } // namespace | 892 } // namespace |
OLD | NEW |