Description[Cronet] Test the libcronet that's shipped, not libcronet_test
The motivation is two-fold:
1. It's always best to test what you ship.
2. This facilitates testing an implementation (libcronet) loaded by other means, rather than forcing testing to replace the implementation in an artificial manner (e.g. substituting libcronet_test for libcronet).
Previously libcronet_test contained both Cronet and the tests, so it could be tested without libcronet. Now libcronet contains Cronet and the tests are contained within libcronet_test. During testing libcronet and libcronet_test are loaded. This presents some complications because libcronet exposes no symbols so direct native testing is not possible (there are no symbols to call), but this is easily addressed: Most testing just involves actuating the Cronet API (we've good encapsulation boundaries) and what native components need to be accessed can be accessed through a couple simple @hide JNI APIs, namely CronetUrlRequestContext.getUrlRequestContextAdapter and CronetUrlRequest.getUrlRequestAdapterForTesting.
There are a few static data items that cannot be directly manipulated within libcronet and required some additional changes for testing:
1. URLRequestFilter - A few tests registered URLRequest interceptors with URLRequestFilter. This was remedied by inserting a URLRequestInterceptingJobFactory into the URLRequestContext under test. The URLRequestInterceptingJobFactory delegates to libcronet_test's URLRequestFilter so interceptors work like normal.
2. NetworkChangeNotifier - I rewrote NetworkChangeNotifierTest to perform a more comprehensive system integration test that did not require direct native manipulation, and instead used pre-existing Java testing APIs.
3. MessageLoop and ThreadTaskRunnerHandle - When libcronet_test code (e.g. URLRequestInterceptors) are run on libcronet's network threads they cannot access MessageLoop::current() and ThreadTaskRunnerHandle::Get() as they're static and, like all static data, are not shared between libcronet and libcronet_test. To remedy this I simply instantiate a MessageLoop in libcronet_test via CronetTestUtil.PrepareNetworkThread(), and set it to use libcronet's SingleThreadTaskRunner.
TestUploadDataStreamHandler was also slightly modified to run on a thread from libcronet rather than create its own thread. This way there was a MessageLoop and ThreadTaskRunnerHandle already accessible to libcronet native code.
BUG=629299
Committed: https://crrev.com/fd031f17d903f22300f08f46610e1f6418275708
Cr-Commit-Position: refs/heads/master@{#433525}
Patch Set 1 #Patch Set 2 : fix deps #Patch Set 3 : fix build file #Patch Set 4 : fix #Patch Set 5 : fixes #Patch Set 6 : fix jni load #Patch Set 7 : lots of fixes #Patch Set 8 : get working #Patch Set 9 : almost fix testDestroyNativeStreamBeforeReadComplete #Patch Set 10 : get all test passing #Patch Set 11 : fix build #Patch Set 12 : more fix #Patch Set 13 : cleanup #Patch Set 14 : more cleanup #Patch Set 15 : more cleanup #Patch Set 16 : more comments #Patch Set 17 : fix perf test #
Total comments: 13
Patch Set 18 : Clean up phase 1 of 2: use network thread directly #Patch Set 19 : cleanup (still more to come) #Patch Set 20 : cleanup (still more to come) #Patch Set 21 : Clean up phase 2 of 2: remove staticness (still more cleanup to come) #Patch Set 22 : some comments #Patch Set 23 : fixes #
Total comments: 16
Patch Set 24 : address Helen's comments #
Total comments: 12
Patch Set 25 : address Helen's comments #Patch Set 26 : address two remaining comments #
Total comments: 21
Patch Set 27 : rebase #Patch Set 28 : fix rebase #Patch Set 29 : address Misha's comments #Patch Set 30 : fix shutdown race #Messages
Total messages: 40 (12 generated)
|