OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.os.StrictMode; | 8 import android.os.StrictMode; |
9 import android.test.MoreAsserts; | 9 import android.test.MoreAsserts; |
10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 @Override | 884 @Override |
885 public void run() { | 885 public void run() { |
886 urlRequest.start(); | 886 urlRequest.start(); |
887 try { | 887 try { |
888 callback.startNextRead(urlRequest); | 888 callback.startNextRead(urlRequest); |
889 fail("Exception not thrown"); | 889 fail("Exception not thrown"); |
890 } catch (IllegalStateException e) { | 890 } catch (IllegalStateException e) { |
891 } | 891 } |
892 } | 892 } |
893 }; | 893 }; |
894 callback.getExecutor().execute(startAndRead); | 894 callback.getExecutor().submit(startAndRead).get(); |
895 callback.waitForNextStep(); | 895 callback.waitForNextStep(); |
896 | 896 |
897 assertEquals(callback.mResponseStep, ResponseStep.ON_RECEIVED_REDIRECT); | 897 assertEquals(callback.mResponseStep, ResponseStep.ON_RECEIVED_REDIRECT); |
898 // Try to read after the redirect. | 898 // Try to read after the redirect. |
899 try { | 899 try { |
900 callback.startNextRead(urlRequest); | 900 callback.startNextRead(urlRequest); |
901 fail("Exception not thrown"); | 901 fail("Exception not thrown"); |
902 } catch (IllegalStateException e) { | 902 } catch (IllegalStateException e) { |
903 } | 903 } |
904 urlRequest.followRedirect(); | 904 urlRequest.followRedirect(); |
905 callback.waitForNextStep(); | 905 callback.waitForNextStep(); |
906 | 906 |
907 assertEquals(callback.mResponseStep, ResponseStep.ON_RESPONSE_STARTED); | 907 assertEquals(callback.mResponseStep, ResponseStep.ON_RESPONSE_STARTED); |
908 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); | 908 assertEquals(200, callback.mResponseInfo.getHttpStatusCode()); |
909 | 909 |
910 while (!callback.isDone()) { | 910 while (!callback.isDone()) { |
911 Runnable readTwice = new Runnable() { | 911 Runnable readTwice = new Runnable() { |
912 @Override | 912 @Override |
913 public void run() { | 913 public void run() { |
914 callback.startNextRead(urlRequest); | 914 callback.startNextRead(urlRequest); |
915 // Try to read again before the last read completes. | 915 // Try to read again before the last read completes. |
916 try { | 916 try { |
917 callback.startNextRead(urlRequest); | 917 callback.startNextRead(urlRequest); |
918 fail("Exception not thrown"); | 918 fail("Exception not thrown"); |
919 } catch (IllegalStateException e) { | 919 } catch (IllegalStateException e) { |
920 } | 920 } |
921 } | 921 } |
922 }; | 922 }; |
923 callback.getExecutor().execute(readTwice); | 923 callback.getExecutor().submit(readTwice).get(); |
924 callback.waitForNextStep(); | 924 callback.waitForNextStep(); |
925 } | 925 } |
926 | 926 |
927 assertEquals(callback.mResponseStep, ResponseStep.ON_SUCCEEDED); | 927 assertEquals(callback.mResponseStep, ResponseStep.ON_SUCCEEDED); |
928 assertEquals(NativeTestServer.SUCCESS_BODY, callback.mResponseAsString); | 928 assertEquals(NativeTestServer.SUCCESS_BODY, callback.mResponseAsString); |
929 | 929 |
930 // Try to read after request is complete. | 930 // Try to read after request is complete. |
931 try { | 931 try { |
932 callback.startNextRead(urlRequest); | 932 callback.startNextRead(urlRequest); |
933 fail("Exception not thrown"); | 933 fail("Exception not thrown"); |
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { | 2017 private String bufferContentsToString(ByteBuffer byteBuffer, int start, int
end) { |
2018 // Use a duplicate to avoid modifying byteBuffer. | 2018 // Use a duplicate to avoid modifying byteBuffer. |
2019 ByteBuffer duplicate = byteBuffer.duplicate(); | 2019 ByteBuffer duplicate = byteBuffer.duplicate(); |
2020 duplicate.position(start); | 2020 duplicate.position(start); |
2021 duplicate.limit(end); | 2021 duplicate.limit(end); |
2022 byte[] contents = new byte[duplicate.remaining()]; | 2022 byte[] contents = new byte[duplicate.remaining()]; |
2023 duplicate.get(contents); | 2023 duplicate.get(contents); |
2024 return new String(contents); | 2024 return new String(contents); |
2025 } | 2025 } |
2026 } | 2026 } |
OLD | NEW |