Chromium Code Reviews| 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( | |
| 1811 WalletClient::SPENDING_LIMIT_EXCEEDED)).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( | |
| 1831 WalletClient::BAD_REQUEST)).Times(1); | |
| 1832 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | |
| 1833 1); | |
| 1834 delegate_.ExpectWalletErrorMetric( | |
| 1835 AutofillMetrics::WALLET_BAD_REQUEST); | |
| 1836 | |
| 1837 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, | |
| 1838 kGetWalletItemsValidRequest, | |
| 1839 kErrorResponse); | |
| 1840 } | |
| 1841 | |
| 1842 // Anything else - response json is ignored. | |
| 1843 TEST_F(WalletClientTest, ErrorResponseOther) { | |
| 1844 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1845 delegate_.ExpectBaselineMetrics(); | |
| 1846 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1847 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1848 testing::Mock::VerifyAndClear(delegate_.metric_logger()); | |
|
Dan Beam
2014/09/04 01:04:19
seems like a lot of copy pasta...
Evan Stade
2014/09/04 18:16:19
Acknowledged.
| |
| 1849 | |
| 1850 EXPECT_CALL(delegate_, OnWalletError( | |
| 1851 WalletClient::NETWORK_ERROR)).Times(1); | |
| 1852 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | |
| 1853 1); | |
| 1854 delegate_.ExpectWalletErrorMetric(AutofillMetrics::WALLET_NETWORK_ERROR); | |
| 1855 | |
| 1856 VerifyAndFinishRequest(net::HTTP_NOT_FOUND, | |
| 1857 kGetWalletItemsValidRequest, | |
| 1858 kErrorResponse); | |
| 1859 } | |
| 1860 | |
| 1777 TEST_F(WalletClientTest, CancelRequest) { | 1861 TEST_F(WalletClientTest, CancelRequest) { |
| 1778 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1862 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1779 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1863 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
| 1780 0); | 1864 0); |
| 1781 delegate_.ExpectBaselineMetrics(); | 1865 delegate_.ExpectBaselineMetrics(); |
| 1782 | 1866 |
| 1783 wallet_client_->GetWalletItems(base::string16(), base::string16()); | 1867 wallet_client_->GetWalletItems(base::string16(), base::string16()); |
| 1784 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | 1868 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
| 1785 wallet_client_->CancelRequest(); | 1869 wallet_client_->CancelRequest(); |
| 1786 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1870 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1787 } | 1871 } |
| 1788 | 1872 |
| 1789 } // namespace wallet | 1873 } // namespace wallet |
| 1790 } // namespace autofill | 1874 } // namespace autofill |
| OLD | NEW |