OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "net/android/traffic_stats.h" | 5 #include "net/android/traffic_stats.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "net/test/embedded_test_server/embedded_test_server.h" | 8 #include "net/test/embedded_test_server/embedded_test_server.h" |
9 #include "net/url_request/url_request_test_util.h" | 9 #include "net/url_request/url_request_test_util.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 EXPECT_TRUE( | 25 EXPECT_TRUE( |
26 android::traffic_stats::GetTotalTxBytes(&tx_bytes_before_request)); | 26 android::traffic_stats::GetTotalTxBytes(&tx_bytes_before_request)); |
27 EXPECT_GE(tx_bytes_before_request, 0); | 27 EXPECT_GE(tx_bytes_before_request, 0); |
28 EXPECT_TRUE( | 28 EXPECT_TRUE( |
29 android::traffic_stats::GetTotalRxBytes(&rx_bytes_before_request)); | 29 android::traffic_stats::GetTotalRxBytes(&rx_bytes_before_request)); |
30 EXPECT_GE(rx_bytes_before_request, 0); | 30 EXPECT_GE(rx_bytes_before_request, 0); |
31 | 31 |
32 TestDelegate test_delegate; | 32 TestDelegate test_delegate; |
33 TestURLRequestContext context(false); | 33 TestURLRequestContext context(false); |
34 | 34 |
35 scoped_ptr<URLRequest> request( | 35 std::unique_ptr<URLRequest> request( |
36 context.CreateRequest(embedded_test_server.GetURL("/echo.html"), | 36 context.CreateRequest(embedded_test_server.GetURL("/echo.html"), |
37 DEFAULT_PRIORITY, &test_delegate)); | 37 DEFAULT_PRIORITY, &test_delegate)); |
38 request->Start(); | 38 request->Start(); |
39 base::RunLoop().Run(); | 39 base::RunLoop().Run(); |
40 | 40 |
41 // Bytes should increase because of the network traffic. | 41 // Bytes should increase because of the network traffic. |
42 int64_t tx_bytes_after_request = -1; | 42 int64_t tx_bytes_after_request = -1; |
43 int64_t rx_bytes_after_request = -1; | 43 int64_t rx_bytes_after_request = -1; |
44 EXPECT_TRUE(android::traffic_stats::GetTotalTxBytes(&tx_bytes_after_request)); | 44 EXPECT_TRUE(android::traffic_stats::GetTotalTxBytes(&tx_bytes_after_request)); |
45 EXPECT_GT(tx_bytes_after_request, tx_bytes_before_request); | 45 EXPECT_GT(tx_bytes_after_request, tx_bytes_before_request); |
(...skipping 12 matching lines...) Expand all Loading... |
58 EXPECT_TRUE( | 58 EXPECT_TRUE( |
59 android::traffic_stats::GetCurrentUidTxBytes(&tx_bytes_before_request)); | 59 android::traffic_stats::GetCurrentUidTxBytes(&tx_bytes_before_request)); |
60 EXPECT_GE(tx_bytes_before_request, 0); | 60 EXPECT_GE(tx_bytes_before_request, 0); |
61 EXPECT_TRUE( | 61 EXPECT_TRUE( |
62 android::traffic_stats::GetCurrentUidRxBytes(&rx_bytes_before_request)); | 62 android::traffic_stats::GetCurrentUidRxBytes(&rx_bytes_before_request)); |
63 EXPECT_GE(rx_bytes_before_request, 0); | 63 EXPECT_GE(rx_bytes_before_request, 0); |
64 | 64 |
65 TestDelegate test_delegate; | 65 TestDelegate test_delegate; |
66 TestURLRequestContext context(false); | 66 TestURLRequestContext context(false); |
67 | 67 |
68 scoped_ptr<URLRequest> request( | 68 std::unique_ptr<URLRequest> request( |
69 context.CreateRequest(embedded_test_server.GetURL("/echo.html"), | 69 context.CreateRequest(embedded_test_server.GetURL("/echo.html"), |
70 DEFAULT_PRIORITY, &test_delegate)); | 70 DEFAULT_PRIORITY, &test_delegate)); |
71 request->Start(); | 71 request->Start(); |
72 base::RunLoop().Run(); | 72 base::RunLoop().Run(); |
73 | 73 |
74 // Bytes should increase because of the network traffic. | 74 // Bytes should increase because of the network traffic. |
75 int64_t tx_bytes_after_request = -1; | 75 int64_t tx_bytes_after_request = -1; |
76 int64_t rx_bytes_after_request = -1; | 76 int64_t rx_bytes_after_request = -1; |
77 EXPECT_TRUE( | 77 EXPECT_TRUE( |
78 android::traffic_stats::GetCurrentUidTxBytes(&tx_bytes_after_request)); | 78 android::traffic_stats::GetCurrentUidTxBytes(&tx_bytes_after_request)); |
79 EXPECT_GT(tx_bytes_after_request, tx_bytes_before_request); | 79 EXPECT_GT(tx_bytes_after_request, tx_bytes_before_request); |
80 EXPECT_TRUE( | 80 EXPECT_TRUE( |
81 android::traffic_stats::GetCurrentUidRxBytes(&rx_bytes_after_request)); | 81 android::traffic_stats::GetCurrentUidRxBytes(&rx_bytes_after_request)); |
82 EXPECT_GT(rx_bytes_after_request, rx_bytes_before_request); | 82 EXPECT_GT(rx_bytes_after_request, rx_bytes_before_request); |
83 } | 83 } |
84 | 84 |
85 } // namespace | 85 } // namespace |
86 | 86 |
87 } // namespace net | 87 } // namespace net |
OLD | NEW |