From af3d4809763ef308f08ced947a73b624729ac7ea Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Tue, 13 Oct 2015 13:24:50 +0200 Subject: BASELINE: Update Chromium to 47.0.2526.14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also adding in sources needed for spellchecking. Change-Id: Idd44170fa1616f26315188970a8d5ba7d472b18a Reviewed-by: Michael BrĂ¼ning --- chromium/net/android/BUILD.gn | 3 + chromium/net/android/gurl_utils.cc | 14 ++-- chromium/net/android/keystore_openssl.cc | 20 ++--- .../net/android/network_change_notifier_android.cc | 14 ++-- .../net/android/network_change_notifier_android.h | 7 +- .../network_change_notifier_android_unittest.cc | 22 ++++-- .../network_change_notifier_delegate_android.cc | 14 ++-- .../network_change_notifier_delegate_android.h | 7 +- chromium/net/android/network_library.cc | 13 ++++ chromium/net/android/network_library.h | 8 ++ chromium/net/android/traffic_stats.cc | 54 ++++++++++++++ chromium/net/android/traffic_stats.h | 58 +++++++++++++++ chromium/net/android/traffic_stats_unittest.cc | 87 ++++++++++++++++++++++ .../android/unittest_support/AndroidManifest.xml | 2 +- 14 files changed, 284 insertions(+), 39 deletions(-) create mode 100644 chromium/net/android/traffic_stats.cc create mode 100644 chromium/net/android/traffic_stats.h create mode 100644 chromium/net/android/traffic_stats_unittest.cc (limited to 'chromium/net/android') diff --git a/chromium/net/android/BUILD.gn b/chromium/net/android/BUILD.gn index 86b9c867054..0003962fb89 100644 --- a/chromium/net/android/BUILD.gn +++ b/chromium/net/android/BUILD.gn @@ -70,6 +70,7 @@ java_cpp_enum("net_android_java_enums_srcjar") { "../base/network_change_notifier.h", "cert_verify_result_android.h", "keystore.h", + "traffic_stats.cc", ] outputs = [ "org/chromium/net/CertificateMimeType.java", @@ -77,6 +78,7 @@ java_cpp_enum("net_android_java_enums_srcjar") { "org/chromium/net/ConnectionSubtype.java", "org/chromium/net/ConnectionType.java", "org/chromium/net/PrivateKeyType.java", + "org/chromium/net/TrafficStatsError.java", ] } @@ -87,6 +89,7 @@ junit_binary("net_junit_tests") { ":net_java", "//base:base_java", "//base:base_java_test_support", + "//base:base_junit_test_support", "//third_party/junit:hamcrest", ] } diff --git a/chromium/net/android/gurl_utils.cc b/chromium/net/android/gurl_utils.cc index c8cb1e4e998..5b2ff3f8ccc 100644 --- a/chromium/net/android/gurl_utils.cc +++ b/chromium/net/android/gurl_utils.cc @@ -10,18 +10,20 @@ namespace net { -jstring GetOrigin(JNIEnv* env, jclass clazz, jstring url) { +ScopedJavaLocalRef GetOrigin(JNIEnv* env, + const JavaParamRef& clazz, + const JavaParamRef& url) { GURL host(base::android::ConvertJavaStringToUTF16(env, url)); - return base::android::ConvertUTF8ToJavaString(env, - host.GetOrigin().spec()).Release(); + return base::android::ConvertUTF8ToJavaString(env, host.GetOrigin().spec()); } -jstring GetScheme(JNIEnv* env, jclass clazz, jstring url) { +ScopedJavaLocalRef GetScheme(JNIEnv* env, + const JavaParamRef& clazz, + const JavaParamRef& url) { GURL host(base::android::ConvertJavaStringToUTF16(env, url)); - return base::android::ConvertUTF8ToJavaString(env, - host.scheme()).Release(); + return base::android::ConvertUTF8ToJavaString(env, host.scheme()); } bool RegisterGURLUtils(JNIEnv* env) { diff --git a/chromium/net/android/keystore_openssl.cc b/chromium/net/android/keystore_openssl.cc index c9d30892e2f..fb0365c6a8d 100644 --- a/chromium/net/android/keystore_openssl.cc +++ b/chromium/net/android/keystore_openssl.cc @@ -176,7 +176,7 @@ int RsaMethodEncrypt(RSA* rsa, size_t in_len, int padding) { NOTIMPLEMENTED(); - OPENSSL_PUT_ERROR(RSA, encrypt, RSA_R_UNKNOWN_ALGORITHM_TYPE); + OPENSSL_PUT_ERROR(RSA, RSA_R_UNKNOWN_ALGORITHM_TYPE); return 0; } @@ -196,7 +196,7 @@ int RsaMethodSignRaw(RSA* rsa, // the same Android version as the "NONEwithRSA" // java.security.Signature algorithm, so the same version checks // for GetRsaLegacyKey should work. - OPENSSL_PUT_ERROR(RSA, sign_raw, RSA_R_UNKNOWN_PADDING_TYPE); + OPENSSL_PUT_ERROR(RSA, RSA_R_UNKNOWN_PADDING_TYPE); return 0; } @@ -204,7 +204,7 @@ int RsaMethodSignRaw(RSA* rsa, const KeyExData *ex_data = RsaGetExData(rsa); if (!ex_data || !ex_data->private_key) { LOG(WARNING) << "Null JNI reference passed to RsaMethodSignRaw!"; - OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); + OPENSSL_PUT_ERROR(RSA, ERR_R_INTERNAL_ERROR); return 0; } @@ -221,7 +221,7 @@ int RsaMethodSignRaw(RSA* rsa, // if there were some way to convince Java to do it. (Without going // through Java, it's difficult to get a handle on a system OpenSSL // function; dlopen loads a second copy.) - OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); + OPENSSL_PUT_ERROR(RSA, ERR_R_INTERNAL_ERROR); return 0; } *out_len = ret; @@ -234,7 +234,7 @@ int RsaMethodSignRaw(RSA* rsa, // PKCS#1 padding. if (!RawSignDigestWithPrivateKey(ex_data->private_key, from_piece, &result)) { LOG(WARNING) << "Could not sign message in RsaMethodSignRaw!"; - OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); + OPENSSL_PUT_ERROR(RSA, ERR_R_INTERNAL_ERROR); return 0; } @@ -242,12 +242,12 @@ int RsaMethodSignRaw(RSA* rsa, if (result.size() > expected_size) { LOG(ERROR) << "RSA Signature size mismatch, actual: " << result.size() << ", expected <= " << expected_size; - OPENSSL_PUT_ERROR(RSA, sign_raw, ERR_R_INTERNAL_ERROR); + OPENSSL_PUT_ERROR(RSA, ERR_R_INTERNAL_ERROR); return 0; } if (max_out < expected_size) { - OPENSSL_PUT_ERROR(RSA, sign_raw, RSA_R_DATA_TOO_LARGE); + OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE); return 0; } @@ -269,7 +269,7 @@ int RsaMethodDecrypt(RSA* rsa, size_t in_len, int padding) { NOTIMPLEMENTED(); - OPENSSL_PUT_ERROR(RSA, decrypt, RSA_R_UNKNOWN_ALGORITHM_TYPE); + OPENSSL_PUT_ERROR(RSA, RSA_R_UNKNOWN_ALGORITHM_TYPE); return 0; } @@ -281,7 +281,7 @@ int RsaMethodVerifyRaw(RSA* rsa, size_t in_len, int padding) { NOTIMPLEMENTED(); - OPENSSL_PUT_ERROR(RSA, verify_raw, RSA_R_UNKNOWN_ALGORITHM_TYPE); + OPENSSL_PUT_ERROR(RSA, RSA_R_UNKNOWN_ALGORITHM_TYPE); return 0; } @@ -485,7 +485,7 @@ int EcdsaMethodVerify(const uint8_t* digest, size_t sig_len, EC_KEY* ec_key) { NOTIMPLEMENTED(); - OPENSSL_PUT_ERROR(ECDSA, ECDSA_do_verify, ECDSA_R_NOT_IMPLEMENTED); + OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_NOT_IMPLEMENTED); return 0; } diff --git a/chromium/net/android/network_change_notifier_android.cc b/chromium/net/android/network_change_notifier_android.cc index 982923507d8..a967b85a35d 100644 --- a/chromium/net/android/network_change_notifier_android.cc +++ b/chromium/net/android/network_change_notifier_android.cc @@ -144,8 +144,11 @@ NetworkChangeNotifierAndroid::GetCurrentConnectionType() const { return delegate_->GetCurrentConnectionType(); } -double NetworkChangeNotifierAndroid::GetCurrentMaxBandwidth() const { - return delegate_->GetCurrentMaxBandwidth(); +void NetworkChangeNotifierAndroid::GetCurrentMaxBandwidthAndConnectionType( + double* max_bandwidth_mbps, + ConnectionType* connection_type) const { + delegate_->GetCurrentMaxBandwidthAndConnectionType(max_bandwidth_mbps, + connection_type); } void NetworkChangeNotifierAndroid::OnConnectionTypeChanged() { @@ -153,9 +156,10 @@ void NetworkChangeNotifierAndroid::OnConnectionTypeChanged() { } void NetworkChangeNotifierAndroid::OnMaxBandwidthChanged( - double max_bandwidth_mbps) { - NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange( - max_bandwidth_mbps); + double max_bandwidth_mbps, + ConnectionType type) { + NetworkChangeNotifier::NotifyObserversOfMaxBandwidthChange(max_bandwidth_mbps, + type); } // static diff --git a/chromium/net/android/network_change_notifier_android.h b/chromium/net/android/network_change_notifier_android.h index 1acb84042ce..61bec5368c3 100644 --- a/chromium/net/android/network_change_notifier_android.h +++ b/chromium/net/android/network_change_notifier_android.h @@ -49,11 +49,14 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierAndroid ConnectionType GetCurrentConnectionType() const override; // Requires ACCESS_WIFI_STATE permission in order to provide precise WiFi link // speed. - double GetCurrentMaxBandwidth() const override; + void GetCurrentMaxBandwidthAndConnectionType( + double* max_bandwidth_mbps, + ConnectionType* connection_type) const override; // NetworkChangeNotifierDelegateAndroid::Observer: void OnConnectionTypeChanged() override; - void OnMaxBandwidthChanged(double max_bandwidth_mbps) override; + void OnMaxBandwidthChanged(double max_bandwidth_mbps, + ConnectionType type) override; static bool Register(JNIEnv* env); diff --git a/chromium/net/android/network_change_notifier_android_unittest.cc b/chromium/net/android/network_change_notifier_android_unittest.cc index 933e0a35247..d3fe04d5786 100644 --- a/chromium/net/android/network_change_notifier_android_unittest.cc +++ b/chromium/net/android/network_change_notifier_android_unittest.cc @@ -28,7 +28,9 @@ class NetworkChangeNotifierDelegateAndroidObserver // NetworkChangeNotifierDelegateAndroid::Observer: void OnConnectionTypeChanged() override { type_notifications_count_++; } - void OnMaxBandwidthChanged(double max_bandwidth_mbps) override { + void OnMaxBandwidthChanged( + double max_bandwidth_mbps, + net::NetworkChangeNotifier::ConnectionType type) override { max_bandwidth_notifications_count_++; } @@ -248,14 +250,18 @@ TEST_F(NetworkChangeNotifierAndroidTest, TEST_F(NetworkChangeNotifierAndroidTest, MaxBandwidth) { SetOnline(); - EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, - notifier_->GetConnectionType()); - EXPECT_EQ(std::numeric_limits::infinity(), - notifier_->GetMaxBandwidth()); + double max_bandwidth_mbps = 0.0; + NetworkChangeNotifier::ConnectionType connection_type = + NetworkChangeNotifier::CONNECTION_NONE; + notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, + &connection_type); + EXPECT_EQ(NetworkChangeNotifier::CONNECTION_UNKNOWN, connection_type); + EXPECT_EQ(std::numeric_limits::infinity(), max_bandwidth_mbps); SetOffline(); - EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, - notifier_->GetConnectionType()); - EXPECT_EQ(0.0, notifier_->GetMaxBandwidth()); + notifier_->GetMaxBandwidthAndConnectionType(&max_bandwidth_mbps, + &connection_type); + EXPECT_EQ(NetworkChangeNotifier::CONNECTION_NONE, connection_type); + EXPECT_EQ(0.0, max_bandwidth_mbps); } TEST_F(NetworkChangeNotifierDelegateAndroidTest, diff --git a/chromium/net/android/network_change_notifier_delegate_android.cc b/chromium/net/android/network_change_notifier_delegate_android.cc index 856acfe7263..be4c6b18e11 100644 --- a/chromium/net/android/network_change_notifier_delegate_android.cc +++ b/chromium/net/android/network_change_notifier_delegate_android.cc @@ -45,7 +45,7 @@ NetworkChangeNotifier::ConnectionSubtype ConvertConnectionSubtype( } // namespace jdouble GetMaxBandwidthForConnectionSubtype(JNIEnv* env, - jclass caller, + const JavaParamRef& caller, jint subtype) { return NetworkChangeNotifierAndroid::GetMaxBandwidthForConnectionSubtype( ConvertConnectionSubtype(subtype)); @@ -84,9 +84,13 @@ NetworkChangeNotifierDelegateAndroid::GetCurrentConnectionType() const { return connection_type_; } -double NetworkChangeNotifierDelegateAndroid::GetCurrentMaxBandwidth() const { +void NetworkChangeNotifierDelegateAndroid:: + GetCurrentMaxBandwidthAndConnectionType( + double* max_bandwidth_mbps, + ConnectionType* connection_type) const { base::AutoLock auto_lock(connection_lock_); - return connection_max_bandwidth_; + *connection_type = connection_type_; + *max_bandwidth_mbps = connection_max_bandwidth_; } void NetworkChangeNotifierDelegateAndroid::NotifyConnectionTypeChanged( @@ -111,10 +115,10 @@ void NetworkChangeNotifierDelegateAndroid::NotifyMaxBandwidthChanged( jobject obj, jdouble new_max_bandwidth) { DCHECK(thread_checker_.CalledOnValidThread()); - DCHECK(new_max_bandwidth != GetCurrentMaxBandwidth()); + SetCurrentMaxBandwidth(new_max_bandwidth); observers_->Notify(FROM_HERE, &Observer::OnMaxBandwidthChanged, - new_max_bandwidth); + new_max_bandwidth, GetCurrentConnectionType()); } void NetworkChangeNotifierDelegateAndroid::AddObserver( diff --git a/chromium/net/android/network_change_notifier_delegate_android.h b/chromium/net/android/network_change_notifier_delegate_android.h index 93133f3c712..e1f874ab267 100644 --- a/chromium/net/android/network_change_notifier_delegate_android.h +++ b/chromium/net/android/network_change_notifier_delegate_android.h @@ -35,7 +35,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid { virtual void OnConnectionTypeChanged() = 0; // Updates the current max bandwidth. - virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0; + virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps, + ConnectionType connection_type) = 0; }; NetworkChangeNotifierDelegateAndroid(); @@ -67,7 +68,9 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierDelegateAndroid { ConnectionType GetCurrentConnectionType() const; // Can be called from any thread. - double GetCurrentMaxBandwidth() const; + void GetCurrentMaxBandwidthAndConnectionType( + double* max_bandwidth_mbps, + ConnectionType* connection_type) const; // Initializes JNI bindings. static bool Register(JNIEnv* env); diff --git a/chromium/net/android/network_library.cc b/chromium/net/android/network_library.cc index 83d43ff41b7..f4bda87f856 100644 --- a/chromium/net/android/network_library.cc +++ b/chromium/net/android/network_library.cc @@ -129,6 +129,19 @@ std::string GetTelephonyNetworkOperator() { base::android::GetApplicationContext())); } +std::string GetTelephonySimOperator() { + return base::android::ConvertJavaStringToUTF8( + Java_AndroidNetworkLibrary_getSimOperator( + base::android::AttachCurrentThread(), + base::android::GetApplicationContext())); +} + +bool GetIsRoaming() { + return Java_AndroidNetworkLibrary_getIsRoaming( + base::android::AttachCurrentThread(), + base::android::GetApplicationContext()); +} + bool RegisterNetworkLibrary(JNIEnv* env) { return RegisterNativesImpl(env); } diff --git a/chromium/net/android/network_library.h b/chromium/net/android/network_library.h index 3f1d44e16fb..5befcdf4683 100644 --- a/chromium/net/android/network_library.h +++ b/chromium/net/android/network_library.h @@ -73,6 +73,14 @@ NET_EXPORT std::string GetTelephonyNetworkCountryIso(); // the numeric name of the current registered operator. NET_EXPORT std::string GetTelephonyNetworkOperator(); +// Returns MCC+MNC (mobile country code + mobile network code) as +// the numeric name of the current SIM operator. +NET_EXPORT std::string GetTelephonySimOperator(); + +// Returns true if the device is roaming on the currently active network. When +// true, it suggests that use of data may incur extra costs. +NET_EXPORT bool GetIsRoaming(); + // Register JNI methods NET_EXPORT bool RegisterNetworkLibrary(JNIEnv* env); diff --git a/chromium/net/android/traffic_stats.cc b/chromium/net/android/traffic_stats.cc new file mode 100644 index 00000000000..4a953a6b880 --- /dev/null +++ b/chromium/net/android/traffic_stats.cc @@ -0,0 +1,54 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/android/traffic_stats.h" + +#include "jni/AndroidTrafficStats_jni.h" + +namespace net { + +namespace android { + +namespace traffic_stats { + +// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.net +enum TrafficStatsError { + // Value returned by AndroidTrafficStats APIs when a valid value is + // unavailable. + ERROR_NOT_SUPPORTED = 0, +}; + +bool GetTotalTxBytes(int64_t* bytes) { + JNIEnv* env = base::android::AttachCurrentThread(); + *bytes = Java_AndroidTrafficStats_getTotalTxBytes(env); + return *bytes != ERROR_NOT_SUPPORTED; +} + +bool GetTotalRxBytes(int64_t* bytes) { + JNIEnv* env = base::android::AttachCurrentThread(); + *bytes = Java_AndroidTrafficStats_getTotalRxBytes(env); + return *bytes != ERROR_NOT_SUPPORTED; +} + +bool GetCurrentUidTxBytes(int64_t* bytes) { + JNIEnv* env = base::android::AttachCurrentThread(); + *bytes = Java_AndroidTrafficStats_getCurrentUidTxBytes(env); + return *bytes != ERROR_NOT_SUPPORTED; +} + +bool GetCurrentUidRxBytes(int64_t* bytes) { + JNIEnv* env = base::android::AttachCurrentThread(); + *bytes = Java_AndroidTrafficStats_getCurrentUidRxBytes(env); + return *bytes != ERROR_NOT_SUPPORTED; +} + +bool Register(JNIEnv* env) { + return RegisterNativesImpl(env); +} + +} // namespace traffic_stats + +} // namespace android + +} // namespace net diff --git a/chromium/net/android/traffic_stats.h b/chromium/net/android/traffic_stats.h new file mode 100644 index 00000000000..f6aadadf8ad --- /dev/null +++ b/chromium/net/android/traffic_stats.h @@ -0,0 +1,58 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_ANDROID_TRAFFIC_STATS_H_ +#define NET_ANDROID_TRAFFIC_STATS_H_ + +// This file provides functions that interact with TrafficStats APIs that are +// provided on Android. + +#include +#include + +#include "net/base/net_export.h" + +namespace net { + +namespace android { + +namespace traffic_stats { + +// Returns true if the number of bytes transmitted since device boot is +// available and sets |*bytes| to that value. Counts packets across all network +// interfaces, and always increases monotonically since device boot. +// Statistics are measured at the network layer, so they include both TCP and +// UDP usage. |bytes| must not be nullptr. +NET_EXPORT bool GetTotalTxBytes(int64_t* bytes); + +// Returns true if the number of bytes received since device boot is +// available and sets |*bytes| to that value. Counts packets across all network +// interfaces, and always increases monotonically since device boot. +// Statistics are measured at the network layer, so they include both TCP and +// UDP usage. |bytes| must not be nullptr. +NET_EXPORT bool GetTotalRxBytes(int64_t* bytes); + +// Returns true if the number of bytes attributed to caller's UID since device +// boot are available and sets |*bytes| to that value. Counts packets across +// all network interfaces, and always increases monotonically since device +// boot. Statistics are measured at the network layer, so they include both TCP +// and UDP usage. |bytes| must not be nullptr. +NET_EXPORT bool GetCurrentUidTxBytes(int64_t* bytes); + +// Returns true if the number of bytes attributed to caller's UID since device +// boot are available and sets |*bytes| to that value. Counts packets across +// all network interfaces, and always increases monotonically since device +// boot. Statistics are measured at the network layer, so they include both TCP +// and UDP usage. |bytes| must not be nullptr. +NET_EXPORT bool GetCurrentUidRxBytes(int64_t* bytes); + +bool Register(JNIEnv* env); + +} // namespace traffic_stats + +} // namespace android + +} // namespace net + +#endif // NET_ANDROID_TRAFFIC_STATS_H_ diff --git a/chromium/net/android/traffic_stats_unittest.cc b/chromium/net/android/traffic_stats_unittest.cc new file mode 100644 index 00000000000..0d53c24658c --- /dev/null +++ b/chromium/net/android/traffic_stats_unittest.cc @@ -0,0 +1,87 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/android/traffic_stats.h" + +#include "base/run_loop.h" +#include "net/test/embedded_test_server/embedded_test_server.h" +#include "net/url_request/url_request_test_util.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "url/gurl.h" + +namespace net { + +namespace { + +TEST(TrafficStatsAndroidTest, BasicsTest) { + test_server::EmbeddedTestServer embedded_test_server; + embedded_test_server.ServeFilesFromDirectory( + base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); + ASSERT_TRUE(embedded_test_server.InitializeAndWaitUntilReady()); + + int64_t tx_bytes_before_request = -1; + int64_t rx_bytes_before_request = -1; + EXPECT_TRUE( + android::traffic_stats::GetTotalTxBytes(&tx_bytes_before_request)); + EXPECT_GE(tx_bytes_before_request, 0); + EXPECT_TRUE( + android::traffic_stats::GetTotalRxBytes(&rx_bytes_before_request)); + EXPECT_GE(rx_bytes_before_request, 0); + + TestDelegate test_delegate; + TestURLRequestContext context(false); + + scoped_ptr request( + context.CreateRequest(embedded_test_server.GetURL("/echo.html"), + DEFAULT_PRIORITY, &test_delegate)); + request->Start(); + base::RunLoop().Run(); + + // Bytes should increase because of the network traffic. + int64_t tx_bytes_after_request = -1; + int64_t rx_bytes_after_request = -1; + EXPECT_TRUE(android::traffic_stats::GetTotalTxBytes(&tx_bytes_after_request)); + DCHECK_GT(tx_bytes_after_request, tx_bytes_before_request); + EXPECT_TRUE(android::traffic_stats::GetTotalRxBytes(&rx_bytes_after_request)); + DCHECK_GT(rx_bytes_after_request, rx_bytes_before_request); +} + +TEST(TrafficStatsAndroidTest, UIDBasicsTest) { + test_server::EmbeddedTestServer embedded_test_server; + embedded_test_server.ServeFilesFromDirectory( + base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); + ASSERT_TRUE(embedded_test_server.InitializeAndWaitUntilReady()); + + int64_t tx_bytes_before_request = -1; + int64_t rx_bytes_before_request = -1; + EXPECT_TRUE( + android::traffic_stats::GetCurrentUidTxBytes(&tx_bytes_before_request)); + EXPECT_GE(tx_bytes_before_request, 0); + EXPECT_TRUE( + android::traffic_stats::GetCurrentUidRxBytes(&rx_bytes_before_request)); + EXPECT_GE(rx_bytes_before_request, 0); + + TestDelegate test_delegate; + TestURLRequestContext context(false); + + scoped_ptr request( + context.CreateRequest(embedded_test_server.GetURL("/echo.html"), + DEFAULT_PRIORITY, &test_delegate)); + request->Start(); + base::RunLoop().Run(); + + // Bytes should increase because of the network traffic. + int64_t tx_bytes_after_request = -1; + int64_t rx_bytes_after_request = -1; + EXPECT_TRUE( + android::traffic_stats::GetCurrentUidTxBytes(&tx_bytes_after_request)); + DCHECK_GT(tx_bytes_after_request, tx_bytes_before_request); + EXPECT_TRUE( + android::traffic_stats::GetCurrentUidRxBytes(&rx_bytes_after_request)); + DCHECK_GT(rx_bytes_after_request, rx_bytes_before_request); +} + +} // namespace + +} // namespace net diff --git a/chromium/net/android/unittest_support/AndroidManifest.xml b/chromium/net/android/unittest_support/AndroidManifest.xml index d7493debbc7..d538c5065a2 100644 --- a/chromium/net/android/unittest_support/AndroidManifest.xml +++ b/chromium/net/android/unittest_support/AndroidManifest.xml @@ -10,7 +10,7 @@ found in the LICENSE file. android:versionCode="1" android:versionName="1.0"> - + -- cgit v1.2.1