1 // Copyright 2015 The Chromium Authors
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_EQ(config->load_disable_cache, false);
38   CHECK_EQ(config->http_cache, URLRequestContextConfig::HttpCacheType::MEMORY);
39   CHECK_EQ(config->http_cache_max_size, 54321);
40   CHECK_EQ(config->user_agent, "efgh");
41   CHECK(config->effective_experimental_options.empty());
42   CHECK_EQ(config->storage_path,
43            base::android::ConvertJavaStringToUTF8(env, jstorage_path));
44 }
45 
46 // Verify that QUIC can be turned off in CronetEngine.Builder.
47 // Note that the config expectation is hard coded here because it's very hard to
48 // create an expected config in the JAVA package.
49 static void
JNI_CronetUrlRequestContextTest_VerifyUrlRequestContextQuicOffConfig(JNIEnv * env,jlong jurl_request_context_config,const JavaParamRef<jstring> & jstorage_path)50 JNI_CronetUrlRequestContextTest_VerifyUrlRequestContextQuicOffConfig(
51     JNIEnv* env,
52     jlong jurl_request_context_config,
53     const JavaParamRef<jstring>& jstorage_path) {
54   URLRequestContextConfig* config =
55       reinterpret_cast<URLRequestContextConfig*>(jurl_request_context_config);
56   CHECK_EQ(config->enable_spdy, false);
57   CHECK_EQ(config->enable_quic, false);
58   CHECK_EQ(config->bypass_public_key_pinning_for_local_trust_anchors, false);
59   CHECK_EQ(config->load_disable_cache, false);
60   CHECK_EQ(config->http_cache, URLRequestContextConfig::HttpCacheType::MEMORY);
61   CHECK_EQ(config->http_cache_max_size, 54321);
62   CHECK_EQ(config->user_agent, "efgh");
63   CHECK(config->effective_experimental_options.empty());
64   CHECK_EQ(config->storage_path,
65            base::android::ConvertJavaStringToUTF8(env, jstorage_path));
66 }
67 
68 }  // namespace cronet
69