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
3 // found in the LICENSE file.
5 #include "net/android/traffic_stats.h"
7 #include "base/run_loop.h"
8 #include "net/test/embedded_test_server/embedded_test_server.h"
9 #include "net/url_request/url_request_test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
17 TEST(TrafficStatsAndroidTest
, BasicsTest
) {
18 test_server::EmbeddedTestServer embedded_test_server
;
19 embedded_test_server
.ServeFilesFromDirectory(
20 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
21 ASSERT_TRUE(embedded_test_server
.InitializeAndWaitUntilReady());
23 int64_t bytes_before_request
= -1;
24 EXPECT_TRUE(android::traffic_stats::GetTotalTxBytes(&bytes_before_request
));
25 EXPECT_GE(bytes_before_request
, 0);
27 TestDelegate test_delegate
;
28 TestURLRequestContext
context(false);
30 scoped_ptr
<URLRequest
> request(
31 context
.CreateRequest(embedded_test_server
.GetURL("/echo.html"),
32 DEFAULT_PRIORITY
, &test_delegate
));
34 base::RunLoop().Run();
36 // Bytes should increase because of the network traffic.
37 int64_t bytes_after_request
;
38 EXPECT_TRUE(android::traffic_stats::GetTotalTxBytes(&bytes_after_request
));
39 DCHECK_GT(bytes_after_request
, bytes_before_request
);