1/** 2 * Copyright (C) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License") 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import net_Http from '@ohos.net.http'; 17import { describe, expect, it, Level, Size, TestType } from '@ohos/hypium' 18 19export default function Http2Test() { 20 describe('Http2Test', function () { 21 let cc = net_Http.ResponseCode.RANGE_NOT_SATISFIABLE 22 23 /** 24 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0100 25 * @tc.name set usingCache to true 26 * @tc.desc usingCache test 27 */ 28 it('Telephony_NETSTACK_Http2TestBasicGet_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 29 let http = net_Http.createHttp(); 30 http.request("https://www.baidu.com", { 31 usingProtocol: net_Http.HttpProtocol.HTTP1_1 32 }).then(function (data) { 33 expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); 34 http.destroy(); 35 done(); 36 }); 37 }); 38 39 /** 40 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0200 41 * @tc.name set usingCache to true 42 * @tc.desc usingCache test 43 */ 44 it('Telephony_NETSTACK_Http2TestBasicGet_0200', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 45 let http = net_Http.createHttp(); 46 http.request("https://www.baidu.com", { 47 usingProtocol: net_Http.HttpProtocol.HTTP2 48 }).then(function (data) { 49 console.info("Telephony_NETSTACK_Http2TestBasicGet_0200" + JSON.stringify(data)); 50 expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); 51 http.destroy(); 52 done(); 53 }); 54 }); 55 56 /** 57 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0300 58 * @tc.name set usingCache to true 59 * @tc.desc usingCache test 60 */ 61 it('Telephony_NETSTACK_Http2TestBasicGet_0300', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 62 let http = net_Http.createHttp(); 63 http.request("https://www.baidu.com").then(function (data) { 64 console.info("Telephony_NETSTACK_Http2TestBasicGet_0300" + JSON.stringify(data)); 65 expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); 66 http.destroy(); 67 done(); 68 }); 69 }); 70 71 /** 72 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0400 73 * @tc.name set usingCache to true 74 * @tc.desc usingCache test 75 */ 76 it('Telephony_NETSTACK_Http2TestBasicGet_0400', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 77 expect(net_Http.HttpProtocol.HTTP1_1).assertEqual(0); 78 expect(net_Http.HttpProtocol.HTTP2).assertEqual(1); 79 done(); 80 }); 81 82 /** 83 * @tc.number Telephony_NETSTACK_Http2TestBasicGet_0500 84 * @tc.name set usingCache to true 85 * @tc.desc usingCache test 86 */ 87 it('Telephony_NETSTACK_Http2TestBasicGet_0500', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 88 expect(net_Http.HttpDataType.STRING).assertEqual(0); 89 expect(net_Http.HttpDataType.OBJECT).assertEqual(1); 90 expect(net_Http.HttpDataType.ARRAY_BUFFER).assertEqual(2); 91 done(); 92 }); 93 94 /** 95 * @tc.number Telephony_http_HttpTestPriority_0100 96 * @tc.name set usingCache to true 97 * @tc.desc usingCache test 98 */ 99 it('Telephony_http_HttpTestPriority_0100', TestType.FUNCTION | Size.MEDIUMTEST | Level.LEVEL2, async function (done) { 100 let CaseName = 'Telephony_http_HttpTestPriority_0100'; 101 try { 102 let httpRequestOptions = { 103 method: net_Http.RequestMethod.GET, 104 extraData: '', 105 expectDataType: net_Http.HttpDataType.STRING, 106 header: "content-type': 'application/json", 107 readTimeout: 6000, 108 connectTimeout: 6000, 109 priority: 100, 110 caPath: '' 111 } 112 let httpRequest = net_Http.createHttp(); 113 httpRequest.request("https://www.baidu.com", httpRequestOptions, (err, data) => { 114 console.info(CaseName + JSON.stringify(err) + "data" + JSON.stringify(data)); 115 expect(data.responseCode === net_Http.ResponseCode.OK).assertTrue(); 116 expect(data.resultType == net_Http.HttpDataType.STRING).assertTrue(); 117 httpRequest.destroy(); 118 done(); 119 }); 120 } catch (err) { 121 console.info(CaseName + "err=" + err); 122 done(); 123 return; 124 } 125 }); 126 }); 127}