OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Cookie API implementation unit tests. | 5 // Cookie API implementation unit tests. |
6 | 6 |
7 // MockWin32 can't be included after ChromeFrameHost because of an include | 7 // MockWin32 can't be included after ChromeFrameHost because of an include |
8 // incompatibility with atlwin.h. | 8 // incompatibility with atlwin.h. |
9 #include "ceee/testing/utils/mock_win32.h" // NOLINT | 9 #include "ceee/testing/utils/mock_win32.h" // NOLINT |
10 | 10 |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
949 PostError(StrEq("Not implemented."))).Times(1); | 949 PostError(StrEq("Not implemented."))).Times(1); |
950 invocation.Execute(args, kRequestId); | 950 invocation.Execute(args, kRequestId); |
951 } | 951 } |
952 | 952 |
953 TEST_F(CookieApiTests, CookieChangedEventHandler) { | 953 TEST_F(CookieApiTests, CookieChangedEventHandler) { |
954 testing::LogDisabler no_dchecks; | 954 testing::LogDisabler no_dchecks; |
955 MockCookieChanged cookie_changed; | 955 MockCookieChanged cookie_changed; |
956 std::string converted_args; | 956 std::string converted_args; |
957 // Empty args. | 957 // Empty args. |
958 std::string input_args = ""; | 958 std::string input_args = ""; |
959 EXPECT_EQ(false, | 959 EXPECT_FALSE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
960 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
961 // Invalid args. | 960 // Invalid args. |
962 input_args = "[false, {hello]"; | 961 input_args = "[false, {hello]"; |
963 EXPECT_EQ(false, | 962 EXPECT_FALSE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
964 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
965 input_args = "[3]"; | 963 input_args = "[3]"; |
966 EXPECT_EQ(false, | 964 EXPECT_FALSE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
967 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
968 // Valid args. | 965 // Valid args. |
969 input_args = "[{\"removed\": false, \"cookie\": {\"storeId\": \"1\"}}]"; | 966 input_args = "[{\"removed\": false, \"cookie\": {\"storeId\": \"1\"}}]"; |
970 | 967 |
971 // Invalid store ID. | 968 // Invalid store ID. |
972 cookie_changed.AllocateApiResult(); | 969 cookie_changed.AllocateApiResult(); |
973 EXPECT_CALL(*cookie_changed.api_result_, | 970 EXPECT_CALL(*cookie_changed.api_result_, |
974 GetAnyWindowInStore(StrEq("1"), true, _, _)) | 971 GetAnyWindowInStore(StrEq("1"), true, _, _)) |
975 .WillOnce(Return(false)); | 972 .WillOnce(Return(false)); |
976 EXPECT_EQ(false, | 973 EXPECT_FALSE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
977 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
978 | 974 |
979 // Cookie store access errors. | 975 // Cookie store access errors. |
980 cookie_changed.AllocateApiResult(); | 976 cookie_changed.AllocateApiResult(); |
981 EXPECT_CALL(*cookie_changed.api_result_, | 977 EXPECT_CALL(*cookie_changed.api_result_, |
982 GetAnyWindowInStore(StrEq("1"), true, _, _)) | 978 GetAnyWindowInStore(StrEq("1"), true, _, _)) |
983 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), | 979 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), |
984 SetArgumentPointee<3>(false), | 980 SetArgumentPointee<3>(false), |
985 Return(true))); | 981 Return(true))); |
986 EXPECT_CALL(*cookie_changed.api_result_, | 982 EXPECT_CALL(*cookie_changed.api_result_, |
987 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(E_FAIL)); | 983 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(E_FAIL)); |
988 EXPECT_EQ(false, | 984 EXPECT_FALSE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
989 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
990 | 985 |
991 cookie_changed.AllocateApiResult(); | 986 cookie_changed.AllocateApiResult(); |
992 EXPECT_CALL(*cookie_changed.api_result_, | 987 EXPECT_CALL(*cookie_changed.api_result_, |
993 GetAnyWindowInStore(StrEq("1"), true, _, _)) | 988 GetAnyWindowInStore(StrEq("1"), true, _, _)) |
994 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), | 989 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), |
995 SetArgumentPointee<3>(false), | 990 SetArgumentPointee<3>(false), |
996 Return(true))); | 991 Return(true))); |
997 EXPECT_CALL(*cookie_changed.api_result_, | 992 EXPECT_CALL(*cookie_changed.api_result_, |
998 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(S_FALSE)); | 993 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(S_FALSE)); |
999 EXPECT_CALL(*cookie_changed.api_result_, | 994 EXPECT_CALL(*cookie_changed.api_result_, |
1000 RegisterCookieStore(HWND(5))).WillOnce(Return(E_FAIL)); | 995 RegisterCookieStore(HWND(5))).WillOnce(Return(E_FAIL)); |
1001 EXPECT_EQ(false, | 996 EXPECT_FALSE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
1002 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
1003 | 997 |
1004 // Registered cookie store. | 998 // Registered cookie store. |
1005 cookie_changed.AllocateApiResult(); | 999 cookie_changed.AllocateApiResult(); |
1006 EXPECT_CALL(*cookie_changed.api_result_, | 1000 EXPECT_CALL(*cookie_changed.api_result_, |
1007 GetAnyWindowInStore(StrEq("1"), true, _, _)) | 1001 GetAnyWindowInStore(StrEq("1"), true, _, _)) |
1008 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), | 1002 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), |
1009 SetArgumentPointee<3>(false), | 1003 SetArgumentPointee<3>(false), |
1010 Return(true))); | 1004 Return(true))); |
1011 EXPECT_CALL(*cookie_changed.api_result_, | 1005 EXPECT_CALL(*cookie_changed.api_result_, |
1012 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(S_OK)); | 1006 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(S_OK)); |
1013 EXPECT_EQ(true, | 1007 EXPECT_TRUE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
1014 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
1015 | 1008 |
1016 // Unregistered cookie store. | 1009 // Unregistered cookie store. |
1017 cookie_changed.AllocateApiResult(); | 1010 cookie_changed.AllocateApiResult(); |
1018 EXPECT_CALL(*cookie_changed.api_result_, | 1011 EXPECT_CALL(*cookie_changed.api_result_, |
1019 GetAnyWindowInStore(StrEq("1"), true, _, _)) | 1012 GetAnyWindowInStore(StrEq("1"), true, _, _)) |
1020 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), | 1013 .WillOnce(DoAll(SetArgumentPointee<2>(HWND(5)), |
1021 SetArgumentPointee<3>(false), | 1014 SetArgumentPointee<3>(false), |
1022 Return(true))); | 1015 Return(true))); |
1023 EXPECT_CALL(*cookie_changed.api_result_, | 1016 EXPECT_CALL(*cookie_changed.api_result_, |
1024 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(S_FALSE)); | 1017 CookieStoreIsRegistered(HWND(5))).WillOnce(Return(S_FALSE)); |
1025 EXPECT_CALL(*cookie_changed.api_result_, | 1018 EXPECT_CALL(*cookie_changed.api_result_, |
1026 RegisterCookieStore(HWND(5))).WillOnce(Return(S_OK)); | 1019 RegisterCookieStore(HWND(5))).WillOnce(Return(S_OK)); |
1027 EXPECT_EQ(true, | 1020 EXPECT_TRUE(cookie_changed.EventHandlerImpl(input_args, &converted_args)); |
1028 cookie_changed.EventHandlerImpl(input_args, &converted_args)); | |
1029 } | 1021 } |
1030 | 1022 |
1031 } // namespace | 1023 } // namespace |
OLD | NEW |