OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 " \"error_detail\":\"error_detail\"," | 274 " \"error_detail\":\"error_detail\"," |
275 " \"message_for_user\":" | 275 " \"message_for_user\":" |
276 " {" | 276 " {" |
277 " \"text\":\"text\"," | 277 " \"text\":\"text\"," |
278 " \"subtext\":\"subtext\"," | 278 " \"subtext\":\"subtext\"," |
279 " \"details\":\"details\"" | 279 " \"details\":\"details\"" |
280 " }" | 280 " }" |
281 " }" | 281 " }" |
282 "}"; | 282 "}"; |
283 | 283 |
| 284 const char kErrorResponseSpendingLimitExceeded[] = |
| 285 "{" |
| 286 " \"error_type\":\"APPLICATION_ERROR\"," |
| 287 " \"error_detail\":\"error_detail\"," |
| 288 " \"application_error\":\"application_error\"," |
| 289 " \"debug_data\":" |
| 290 " {" |
| 291 " \"debug_message\":\"debug_message\"," |
| 292 " \"stack_trace\":\"stack_trace\"" |
| 293 " }," |
| 294 " \"application_error_data\":\"application_error_data\"," |
| 295 " \"wallet_error\":" |
| 296 " {" |
| 297 " \"error_type\":\"SPENDING_LIMIT_EXCEEDED\"," |
| 298 " \"error_detail\":\"error_detail\"," |
| 299 " \"message_for_user\":" |
| 300 " {" |
| 301 " \"text\":\"text\"," |
| 302 " \"subtext\":\"subtext\"," |
| 303 " \"details\":\"details\"" |
| 304 " }" |
| 305 " }" |
| 306 "}"; |
| 307 |
284 const char kErrorTypeMissingInResponse[] = | 308 const char kErrorTypeMissingInResponse[] = |
285 "{" | 309 "{" |
286 " \"error_type\":\"Not APPLICATION_ERROR\"," | 310 " \"error_type\":\"Not APPLICATION_ERROR\"," |
287 " \"error_detail\":\"error_detail\"," | 311 " \"error_detail\":\"error_detail\"," |
288 " \"application_error\":\"application_error\"," | 312 " \"application_error\":\"application_error\"," |
289 " \"debug_data\":" | 313 " \"debug_data\":" |
290 " {" | 314 " {" |
291 " \"debug_message\":\"debug_message\"," | 315 " \"debug_message\":\"debug_message\"," |
292 " \"stack_trace\":\"stack_trace\"" | 316 " \"stack_trace\":\"stack_trace\"" |
293 " }," | 317 " }," |
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 | 1772 |
1749 wallet_client_->GetWalletItems(base::string16(), base::string16()); | 1773 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
1750 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | 1774 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
1751 | 1775 |
1752 VerifyAndFinishRequest(net::HTTP_OK, | 1776 VerifyAndFinishRequest(net::HTTP_OK, |
1753 kGetWalletItemsValidRequest, | 1777 kGetWalletItemsValidRequest, |
1754 kGetWalletItemsValidResponse); | 1778 kGetWalletItemsValidResponse); |
1755 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1779 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1756 } | 1780 } |
1757 | 1781 |
1758 TEST_F(WalletClientTest, ErrorResponse) { | 1782 // 500 (INTERNAL_SERVER_ERROR) - response json is parsed. |
| 1783 TEST_F(WalletClientTest, ErrorResponse500) { |
1759 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1784 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1760 delegate_.ExpectBaselineMetrics(); | 1785 delegate_.ExpectBaselineMetrics(); |
1761 wallet_client_->GetWalletItems(base::string16(), base::string16()); | 1786 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
1762 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | 1787 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
1763 testing::Mock::VerifyAndClear(delegate_.metric_logger()); | 1788 testing::Mock::VerifyAndClear(delegate_.metric_logger()); |
1764 | 1789 |
1765 EXPECT_CALL(delegate_, OnWalletError( | 1790 EXPECT_CALL(delegate_, OnWalletError( |
1766 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | 1791 WalletClient::SERVICE_UNAVAILABLE)).Times(1); |
1767 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1792 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
1768 1); | 1793 1); |
1769 delegate_.ExpectWalletErrorMetric( | 1794 delegate_.ExpectWalletErrorMetric( |
1770 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); | 1795 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); |
1771 | 1796 |
1772 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | 1797 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, |
1773 kGetWalletItemsValidRequest, | 1798 kGetWalletItemsValidRequest, |
1774 kErrorResponse); | 1799 kErrorResponse); |
1775 } | 1800 } |
1776 | 1801 |
| 1802 // 403 (FORBIDDEN) - response json is parsed. |
| 1803 TEST_F(WalletClientTest, ErrorResponse403) { |
| 1804 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1805 delegate_.ExpectBaselineMetrics(); |
| 1806 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
| 1807 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
| 1808 testing::Mock::VerifyAndClear(delegate_.metric_logger()); |
| 1809 |
| 1810 EXPECT_CALL(delegate_, OnWalletError(WalletClient::SPENDING_LIMIT_EXCEEDED)) |
| 1811 .Times(1); |
| 1812 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
| 1813 1); |
| 1814 delegate_.ExpectWalletErrorMetric( |
| 1815 AutofillMetrics::WALLET_SPENDING_LIMIT_EXCEEDED); |
| 1816 |
| 1817 VerifyAndFinishRequest(net::HTTP_FORBIDDEN, |
| 1818 kGetWalletItemsValidRequest, |
| 1819 kErrorResponseSpendingLimitExceeded); |
| 1820 } |
| 1821 |
| 1822 // 400 (BAD_REQUEST) - response json is ignored. |
| 1823 TEST_F(WalletClientTest, ErrorResponse400) { |
| 1824 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1825 delegate_.ExpectBaselineMetrics(); |
| 1826 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
| 1827 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
| 1828 testing::Mock::VerifyAndClear(delegate_.metric_logger()); |
| 1829 |
| 1830 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); |
| 1831 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
| 1832 1); |
| 1833 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_BAD_REQUEST); |
| 1834 |
| 1835 VerifyAndFinishRequest( |
| 1836 net::HTTP_BAD_REQUEST, kGetWalletItemsValidRequest, kErrorResponse); |
| 1837 } |
| 1838 |
| 1839 // Anything else - response json is ignored. |
| 1840 TEST_F(WalletClientTest, ErrorResponseOther) { |
| 1841 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1842 delegate_.ExpectBaselineMetrics(); |
| 1843 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
| 1844 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
| 1845 testing::Mock::VerifyAndClear(delegate_.metric_logger()); |
| 1846 |
| 1847 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); |
| 1848 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
| 1849 1); |
| 1850 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); |
| 1851 |
| 1852 VerifyAndFinishRequest( |
| 1853 net::HTTP_NOT_FOUND, kGetWalletItemsValidRequest, kErrorResponse); |
| 1854 } |
| 1855 |
1777 TEST_F(WalletClientTest, CancelRequest) { | 1856 TEST_F(WalletClientTest, CancelRequest) { |
1778 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1857 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1779 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1858 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
1780 0); | 1859 0); |
1781 delegate_.ExpectBaselineMetrics(); | 1860 delegate_.ExpectBaselineMetrics(); |
1782 | 1861 |
1783 wallet_client_->GetWalletItems(base::string16(), base::string16()); | 1862 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
1784 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | 1863 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
1785 wallet_client_->CancelRequest(); | 1864 wallet_client_->CancelRequest(); |
1786 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1865 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1787 } | 1866 } |
1788 | 1867 |
1789 } // namespace wallet | 1868 } // namespace wallet |
1790 } // namespace autofill | 1869 } // namespace autofill |
OLD | NEW |