| OLD | NEW |
| 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 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
| 8 import android.test.suitebuilder.annotation.SmallTest; | 8 import android.test.suitebuilder.annotation.SmallTest; |
| 9 | 9 |
| 10 import org.chromium.base.test.util.Feature; | 10 import org.chromium.base.test.util.Feature; |
| 11 import org.chromium.net.CronetTestBase.OnlyRunNativeCronet; |
| 11 | 12 |
| 12 import java.io.BufferedReader; | 13 import java.io.BufferedReader; |
| 13 import java.io.FileReader; | 14 import java.io.FileReader; |
| 14 import java.io.IOException; | 15 import java.io.IOException; |
| 15 import java.util.ArrayList; | 16 import java.util.ArrayList; |
| 16 import java.util.Arrays; | 17 import java.util.Arrays; |
| 17 import java.util.HashMap; | 18 import java.util.HashMap; |
| 18 import java.util.List; | 19 import java.util.List; |
| 19 import java.util.Map; | 20 import java.util.Map; |
| 20 | 21 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 58 |
| 58 @Override | 59 @Override |
| 59 protected void tearDown() throws Exception { | 60 protected void tearDown() throws Exception { |
| 60 NativeTestServer.shutdownNativeTestServer(); | 61 NativeTestServer.shutdownNativeTestServer(); |
| 61 super.tearDown(); | 62 super.tearDown(); |
| 62 } | 63 } |
| 63 | 64 |
| 64 @SmallTest | 65 @SmallTest |
| 65 @Feature({"Cronet"}) | 66 @Feature({"Cronet"}) |
| 66 @SuppressWarnings("deprecation") | 67 @SuppressWarnings("deprecation") |
| 68 @OnlyRunNativeCronet |
| 67 public void testSdchEnabled_LegacyApi() throws Exception { | 69 public void testSdchEnabled_LegacyApi() throws Exception { |
| 68 setUp(Sdch.ENABLED, Api.LEGACY); | 70 setUp(Sdch.ENABLED, Api.LEGACY); |
| 69 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test"; | 71 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test"; |
| 70 long contextAdapter = | 72 long contextAdapter = |
| 71 getContextAdapter((ChromiumUrlRequestFactory) mTestFramework.mRe
questFactory); | 73 getContextAdapter((ChromiumUrlRequestFactory) mTestFramework.mRe
questFactory); |
| 72 DictionaryAddedObserver observer = | 74 DictionaryAddedObserver observer = |
| 73 new DictionaryAddedObserver(targetUrl, contextAdapter, true /**
Legacy Api */); | 75 new DictionaryAddedObserver(targetUrl, contextAdapter, true /**
Legacy Api */); |
| 74 | 76 |
| 75 // Make a request to /sdch/index which advertises the dictionary. | 77 // Make a request to /sdch/index which advertises the dictionary. |
| 76 TestHttpUrlRequestListener listener1 = | 78 TestHttpUrlRequestListener listener1 = |
| 77 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, | 79 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, |
| 78 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"
); | 80 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"
); |
| 79 assertEquals(200, listener1.mHttpStatusCode); | 81 assertEquals(200, listener1.mHttpStatusCode); |
| 80 assertEquals("This is an index page.\n", listener1.mResponseAsString); | 82 assertEquals("This is an index page.\n", listener1.mResponseAsString); |
| 81 assertEquals(Arrays.asList("/sdch/dict/LeQxM80O"), | 83 assertEquals(Arrays.asList("/sdch/dict/LeQxM80O"), |
| 82 listener1.mResponseHeaders.get("Get-Dictionary")); | 84 listener1.mResponseHeaders.get("Get-Dictionary")); |
| 83 | 85 |
| 84 observer.waitForDictionaryAdded(); | 86 observer.waitForDictionaryAdded(); |
| 85 | 87 |
| 86 // Make a request to fetch encoded response at /sdch/test. | 88 // Make a request to fetch encoded response at /sdch/test. |
| 87 TestHttpUrlRequestListener listener2 = | 89 TestHttpUrlRequestListener listener2 = |
| 88 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, targetUrl); | 90 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, targetUrl); |
| 89 assertEquals(200, listener2.mHttpStatusCode); | 91 assertEquals(200, listener2.mHttpStatusCode); |
| 90 assertEquals("The quick brown fox jumps over the lazy dog.\n", listener2
.mResponseAsString); | 92 assertEquals("The quick brown fox jumps over the lazy dog.\n", listener2
.mResponseAsString); |
| 91 } | 93 } |
| 92 | 94 |
| 93 @SmallTest | 95 @SmallTest |
| 94 @Feature({"Cronet"}) | 96 @Feature({"Cronet"}) |
| 95 @SuppressWarnings("deprecation") | 97 @SuppressWarnings("deprecation") |
| 98 @OnlyRunNativeCronet |
| 96 public void testSdchDisabled_LegacyApi() throws Exception { | 99 public void testSdchDisabled_LegacyApi() throws Exception { |
| 97 setUp(Sdch.DISABLED, Api.LEGACY); | 100 setUp(Sdch.DISABLED, Api.LEGACY); |
| 98 // Make a request to /sdch/index. | 101 // Make a request to /sdch/index. |
| 99 // Since Sdch is not enabled, no dictionary should be advertised. | 102 // Since Sdch is not enabled, no dictionary should be advertised. |
| 100 TestHttpUrlRequestListener listener = | 103 TestHttpUrlRequestListener listener = |
| 101 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, | 104 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, |
| 102 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"
); | 105 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"
); |
| 103 assertEquals(200, listener.mHttpStatusCode); | 106 assertEquals(200, listener.mHttpStatusCode); |
| 104 assertEquals("This is an index page.\n", listener.mResponseAsString); | 107 assertEquals("This is an index page.\n", listener.mResponseAsString); |
| 105 assertEquals(null, listener.mResponseHeaders.get("Get-Dictionary")); | 108 assertEquals(null, listener.mResponseHeaders.get("Get-Dictionary")); |
| 106 } | 109 } |
| 107 | 110 |
| 108 @SmallTest | 111 @SmallTest |
| 109 @Feature({"Cronet"}) | 112 @Feature({"Cronet"}) |
| 110 @SuppressWarnings("deprecation") | 113 @SuppressWarnings("deprecation") |
| 114 @OnlyRunNativeCronet |
| 111 public void testDictionaryNotFound_LegacyApi() throws Exception { | 115 public void testDictionaryNotFound_LegacyApi() throws Exception { |
| 112 setUp(Sdch.ENABLED, Api.LEGACY); | 116 setUp(Sdch.ENABLED, Api.LEGACY); |
| 113 // Make a request to /sdch/index which advertises a bad dictionary that | 117 // Make a request to /sdch/index which advertises a bad dictionary that |
| 114 // does not exist. | 118 // does not exist. |
| 115 TestHttpUrlRequestListener listener1 = | 119 TestHttpUrlRequestListener listener1 = |
| 116 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, | 120 startAndWaitForComplete_LegacyApi(mTestFramework.mRequestFactory
, |
| 117 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound"
); | 121 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound"
); |
| 118 assertEquals(200, listener1.mHttpStatusCode); | 122 assertEquals(200, listener1.mHttpStatusCode); |
| 119 assertEquals("This is an index page.\n", listener1.mResponseAsString); | 123 assertEquals("This is an index page.\n", listener1.mResponseAsString); |
| 120 assertEquals(Arrays.asList("/sdch/dict/NotFound"), | 124 assertEquals(Arrays.asList("/sdch/dict/NotFound"), |
| 121 listener1.mResponseHeaders.get("Get-Dictionary")); | 125 listener1.mResponseHeaders.get("Get-Dictionary")); |
| 122 | 126 |
| 123 // Make a request to fetch /sdch/test, and make sure request succeeds. | 127 // Make a request to fetch /sdch/test, and make sure request succeeds. |
| 124 TestHttpUrlRequestListener listener2 = startAndWaitForComplete_LegacyApi
( | 128 TestHttpUrlRequestListener listener2 = startAndWaitForComplete_LegacyApi
( |
| 125 mTestFramework.mRequestFactory, NativeTestServer.getSdchURL() +
"/sdch/test"); | 129 mTestFramework.mRequestFactory, NativeTestServer.getSdchURL() +
"/sdch/test"); |
| 126 assertEquals(200, listener2.mHttpStatusCode); | 130 assertEquals(200, listener2.mHttpStatusCode); |
| 127 assertEquals("Sdch is not used.\n", listener2.mResponseAsString); | 131 assertEquals("Sdch is not used.\n", listener2.mResponseAsString); |
| 128 } | 132 } |
| 129 | 133 |
| 130 @SmallTest | 134 @SmallTest |
| 131 @Feature({"Cronet"}) | 135 @Feature({"Cronet"}) |
| 136 @OnlyRunNativeCronet |
| 132 public void testSdchEnabled() throws Exception { | 137 public void testSdchEnabled() throws Exception { |
| 133 setUp(Sdch.ENABLED, Api.ASYNC); | 138 setUp(Sdch.ENABLED, Api.ASYNC); |
| 134 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test"; | 139 String targetUrl = NativeTestServer.getSdchURL() + "/sdch/test"; |
| 135 long contextAdapter = | 140 long contextAdapter = |
| 136 getContextAdapter((CronetUrlRequestContext) mTestFramework.mCron
etEngine); | 141 getContextAdapter((CronetUrlRequestContext) mTestFramework.mCron
etEngine); |
| 137 DictionaryAddedObserver observer = | 142 DictionaryAddedObserver observer = |
| 138 new DictionaryAddedObserver(targetUrl, contextAdapter, false /**
Legacy Api */); | 143 new DictionaryAddedObserver(targetUrl, contextAdapter, false /**
Legacy Api */); |
| 139 | 144 |
| 140 // Make a request to /sdch which advertises the dictionary. | 145 // Make a request to /sdch which advertises the dictionary. |
| 141 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor
k.mCronetEngine, | 146 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor
k.mCronetEngine, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 newObserver.waitForDictionaryAdded(); | 180 newObserver.waitForDictionaryAdded(); |
| 176 | 181 |
| 177 // Make a request to fetch encoded response at /sdch/test. | 182 // Make a request to fetch encoded response at /sdch/test. |
| 178 TestUrlRequestCallback callback3 = startAndWaitForComplete(newContext, t
argetUrl); | 183 TestUrlRequestCallback callback3 = startAndWaitForComplete(newContext, t
argetUrl); |
| 179 assertEquals(200, callback3.mResponseInfo.getHttpStatusCode()); | 184 assertEquals(200, callback3.mResponseInfo.getHttpStatusCode()); |
| 180 assertEquals("The quick brown fox jumps over the lazy dog.\n", callback3
.mResponseAsString); | 185 assertEquals("The quick brown fox jumps over the lazy dog.\n", callback3
.mResponseAsString); |
| 181 } | 186 } |
| 182 | 187 |
| 183 @SmallTest | 188 @SmallTest |
| 184 @Feature({"Cronet"}) | 189 @Feature({"Cronet"}) |
| 190 @OnlyRunNativeCronet |
| 185 public void testSdchDisabled() throws Exception { | 191 public void testSdchDisabled() throws Exception { |
| 186 setUp(Sdch.DISABLED, Api.ASYNC); | 192 setUp(Sdch.DISABLED, Api.ASYNC); |
| 187 // Make a request to /sdch. | 193 // Make a request to /sdch. |
| 188 // Since Sdch is not enabled, no dictionary should be advertised. | 194 // Since Sdch is not enabled, no dictionary should be advertised. |
| 189 TestUrlRequestCallback callback = startAndWaitForComplete(mTestFramework
.mCronetEngine, | 195 TestUrlRequestCallback callback = startAndWaitForComplete(mTestFramework
.mCronetEngine, |
| 190 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"); | 196 NativeTestServer.getSdchURL() + "/sdch/index?q=LeQxM80O"); |
| 191 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 197 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
| 192 assertEquals("This is an index page.\n", callback.mResponseAsString); | 198 assertEquals("This is an index page.\n", callback.mResponseAsString); |
| 193 assertEquals(null, callback.mResponseInfo.getAllHeaders().get("Get-Dicti
onary")); | 199 assertEquals(null, callback.mResponseInfo.getAllHeaders().get("Get-Dicti
onary")); |
| 194 } | 200 } |
| 195 | 201 |
| 196 @SmallTest | 202 @SmallTest |
| 197 @Feature({"Cronet"}) | 203 @Feature({"Cronet"}) |
| 204 @OnlyRunNativeCronet |
| 198 public void testDictionaryNotFound() throws Exception { | 205 public void testDictionaryNotFound() throws Exception { |
| 199 setUp(Sdch.ENABLED, Api.ASYNC); | 206 setUp(Sdch.ENABLED, Api.ASYNC); |
| 200 // Make a request to /sdch/index which advertises a bad dictionary that | 207 // Make a request to /sdch/index which advertises a bad dictionary that |
| 201 // does not exist. | 208 // does not exist. |
| 202 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor
k.mCronetEngine, | 209 TestUrlRequestCallback callback1 = startAndWaitForComplete(mTestFramewor
k.mCronetEngine, |
| 203 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound"); | 210 NativeTestServer.getSdchURL() + "/sdch/index?q=NotFound"); |
| 204 assertEquals(200, callback1.mResponseInfo.getHttpStatusCode()); | 211 assertEquals(200, callback1.mResponseInfo.getHttpStatusCode()); |
| 205 assertEquals("This is an index page.\n", callback1.mResponseAsString); | 212 assertEquals("This is an index page.\n", callback1.mResponseAsString); |
| 206 assertEquals(Arrays.asList("/sdch/dict/NotFound"), | 213 assertEquals(Arrays.asList("/sdch/dict/NotFound"), |
| 207 callback1.mResponseInfo.getAllHeaders().get("Get-Dictionary")); | 214 callback1.mResponseInfo.getAllHeaders().get("Get-Dictionary")); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 while ((line = reader.readLine()) != null) { | 279 while ((line = reader.readLine()) != null) { |
| 273 if (line.contains(content)) { | 280 if (line.contains(content)) { |
| 274 reader.close(); | 281 reader.close(); |
| 275 return true; | 282 return true; |
| 276 } | 283 } |
| 277 } | 284 } |
| 278 reader.close(); | 285 reader.close(); |
| 279 return false; | 286 return false; |
| 280 } | 287 } |
| 281 } | 288 } |
| OLD | NEW |