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.
4 
5 #include "cronet_url_request_context_config_test.h"
6 
7 #include <jni.h>
8 
9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
11 #include "base/android/scoped_java_ref.h"
12 #include "base/check_op.h"
13 #include "components/cronet/android/cronet_tests_jni_headers/CronetUrlRequestContextTest_jni.h"
14 #include "components/cronet/url_request_context_config.h"
15 #include "components/cronet/version.h"
16 
17 using base::android::JavaParamRef;
18 
19 namespace cronet {
20 
21 // Verifies that all the configuration options set by
22 // CronetUrlRequestContextTest.testCronetEngineBuilderConfig
23 // made it from the CronetEngine.Builder to the URLRequestContextConfig.
JNI_CronetUrlRequestContextTest_VerifyUrlRequestContextConfig(JNIEnv * env,jlong jurl_request_context_config,const JavaParamRef<jstring> & jstorage_path)24 static void JNI_CronetUrlRequestContextTest_VerifyUrlRequestContextConfig(
25     JNIEnv* env,
26     jlong jurl_request_context_config,
27     const JavaParamRef<jstring>& jstorage_path) {
28   URLRequestContextConfig* config =
29       reinterpret_cast<URLRequestContextConfig*>(jurl_request_context_config);
30   CHECK_EQ(config->enable_spdy, false);
31   CHECK_EQ(config->enable_quic, true);
32   CHECK_EQ(config->bypass_public_key_pinning_for_local_trust_anchors, false);
33   CHECK_EQ(config->quic_hints.size(), 1u);
34   CHECK_EQ((*config->quic_hints.begin())->host, "example.com");
35   CHECK_EQ((*config->quic_hints.begin())->port, 12);
36   CHECK_EQ((*config->quic_hints.begin())->alternate_port, 34);
37   CHECK_NE(config->quic_user_agent_id.find("Cronet/" CRONET_VERSION),
38            std::string::npos);
39   CHECK_EQ(config->load_disable_cache, false);
40   CHECK_EQ(config->http_cache, URLRequestContextConfig::HttpCacheType::MEMORY);
41   CHECK_EQ(config->http_cache_max_size, 54321);
42   CHECK_EQ(config->user_agent, "efgh");
43   CHECK(!config->effective_experimental_options);
44   CHECK_EQ(config->storage_path,
45            base::android::ConvertJavaStringToUTF8(env, jstorage_path));
46 }
47 
48 // Verify that QUIC can be turned off in CronetEngine.Builder.
49 // Note that the config expectation is hard coded here because it's very hard to
50 // create an expected config in the JAVA package.
51 static void
JNI_CronetUrlRequestContextTest_VerifyUrlRequestContextQuicOffConfig(JNIEnv * env,jlong jurl_request_context_config,const JavaParamRef<jstring> & jstorage_path)52 JNI_CronetUrlRequestContextTest_VerifyUrlRequestContextQuicOffConfig(
53     JNIEnv* env,
54     jlong jurl_request_context_config,
55     const JavaParamRef<jstring>& jstorage_path) {
56   URLRequestContextConfig* config =
57       reinterpret_cast<URLRequestContextConfig*>(jurl_request_context_config);
58   CHECK_EQ(config->enable_spdy, false);
59   CHECK_EQ(config->enable_quic, false);
60   CHECK_EQ(config->bypass_public_key_pinning_for_local_trust_anchors, false);
61   CHECK_EQ(config->load_disable_cache, false);
62   CHECK_EQ(config->http_cache, URLRequestContextConfig::HttpCacheType::MEMORY);
63   CHECK_EQ(config->http_cache_max_size, 54321);
64   CHECK_EQ(config->user_agent, "efgh");
65   CHECK(!config->effective_experimental_options);
66   CHECK_EQ(config->storage_path,
67            base::android::ConvertJavaStringToUTF8(env, jstorage_path));
68 }
69 
70 }  // namespace cronet
71