Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Side by Side Diff: components/cronet/android/test/test_upload_data_stream_handler.h

Issue 2406273002: [Cronet] Test the libcronet that's shipped, not libcronet_test (Closed)
Patch Set: address two remaining comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ 5 #ifndef COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_
6 #define COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ 6 #define COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread.h" 15 #include "base/single_thread_task_runner.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/upload_data_stream.h" 17 #include "net/base/upload_data_stream.h"
18 18
19 namespace cronet { 19 namespace cronet {
20 20
21 /** 21 /**
22 * This class allows a net::UploadDataStream to be driven directly from 22 * This class allows a net::UploadDataStream to be driven directly from
23 * Java, for use in tests. 23 * Java, for use in tests.
24 */ 24 */
25 class TestUploadDataStreamHandler { 25 class TestUploadDataStreamHandler {
26 public: 26 public:
27 TestUploadDataStreamHandler( 27 TestUploadDataStreamHandler(
28 std::unique_ptr<net::UploadDataStream> upload_data_stream, 28 std::unique_ptr<net::UploadDataStream> upload_data_stream,
29 JNIEnv* env, 29 JNIEnv* env,
30 jobject jtest_upload_data_stream_handler); 30 jobject jtest_upload_data_stream_handler,
31 jlong jcontext_adapter);
31 32
32 ~TestUploadDataStreamHandler(); 33 ~TestUploadDataStreamHandler();
33 34
34 // Destroys |network_thread_| created by this class. 35 // Destroys |network_thread_| created by this class.
35 void Destroy(JNIEnv* env, 36 void Destroy(JNIEnv* env,
36 const base::android::JavaParamRef<jobject>& jcaller); 37 const base::android::JavaParamRef<jobject>& jcaller);
37 38
38 // Posts a task to |network_thread_| to call the corresponding method of 39 // Posts a task to |network_thread_| to call the corresponding method of
39 // net::UploadDataStream on |upload_data_stream_|. 40 // net::UploadDataStream on |upload_data_stream_|.
40 41
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // when init or reset is called again. Created on a Java thread, but is only 80 // when init or reset is called again. Created on a Java thread, but is only
80 // accessed from |network_thread_|. 81 // accessed from |network_thread_|.
81 bool read_callback_invoked_; 82 bool read_callback_invoked_;
82 // Indicates the number of bytes read. It is reset to 0 when init, reset, or 83 // Indicates the number of bytes read. It is reset to 0 when init, reset, or
83 // read is called again. Created on a Java thread, but is only accessed from 84 // read is called again. Created on a Java thread, but is only accessed from
84 // |network_thread_|. 85 // |network_thread_|.
85 int bytes_read_; 86 int bytes_read_;
86 87
87 // Created and destroyed on the same Java thread. This is where methods of 88 // Created and destroyed on the same Java thread. This is where methods of
88 // net::UploadDataStream run on. 89 // net::UploadDataStream run on.
89 std::unique_ptr<base::Thread> network_thread_; 90 scoped_refptr<base::SingleThreadTaskRunner> network_thread_;
90 // Created on a Java thread. Accessed only on |network_thread_|. 91 // Created on a Java thread. Accessed only on |network_thread_|.
91 std::unique_ptr<net::UploadDataStream> upload_data_stream_; 92 std::unique_ptr<net::UploadDataStream> upload_data_stream_;
92 // Created and accessed only on |network_thread_|. 93 // Created and accessed only on |network_thread_|.
93 scoped_refptr<net::IOBufferWithSize> read_buffer_; 94 scoped_refptr<net::IOBufferWithSize> read_buffer_;
94 // A Java reference pointer for calling methods on the Java 95 // A Java reference pointer for calling methods on the Java
95 // TestUploadDataStreamHandler object. Initialized during construction. 96 // TestUploadDataStreamHandler object. Initialized during construction.
96 base::android::ScopedJavaGlobalRef<jobject> jtest_upload_data_stream_handler_; 97 base::android::ScopedJavaGlobalRef<jobject> jtest_upload_data_stream_handler_;
97 98
98 DISALLOW_COPY_AND_ASSIGN(TestUploadDataStreamHandler); 99 DISALLOW_COPY_AND_ASSIGN(TestUploadDataStreamHandler);
99 }; 100 };
100 101
101 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env); 102 bool TestUploadDataStreamHandlerRegisterJni(JNIEnv* env);
102 103
103 } // namespace cronet 104 } // namespace cronet
104 105
105 #endif // COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_ 106 #endif // COMPONENTS_CRONET_ANDROID_TEST_TEST_UPLOAD_DATA_STREAM_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698