• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14// @ts-nocheck
15import request from '@ohos.request';
16import {describe, expect, it} from 'deccjsunit/index.ets'
17
18let DownloadConfig = {
19  url: 'https://mirror.bjtu.edu.cn/kernel/linux/libs/libc5/libc5.cvs.tar.gz',// Resource address.
20  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
21  enableMetered: true,
22  enableRoaming: true, // Allows download in a roaming network.
23  description: 'a', // Sets the description of a download session.
24  networkType: 1, // Sets the network type allowed for download.
25  filePath: '/data/abc1.txt', // Sets the path for downloads.
26  title: 'a', // Sets a download session title.
27}
28let DownloadConfig1 = {
29  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.10.91.0.2-1.i386.rpm',// Resource address.
30  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
31  enableMetered: true,
32  enableRoaming: true, // Allows download in a roaming network.
33  description: 'a1', // Sets the description of a download session.
34  networkType: 1, // Sets the network type allowed for download.
35  filePath: '/system/lib/abc1.txt', // Sets the path for downloads.
36  title: 'a1', // Sets a download session title.
37}
38let DownloadConfig2 = {
39  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.23-2.11.90.0.24.sign',// Resource address.
40  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
41  enableMetered: true,
42  enableRoaming: true, // Allows download in a roaming network.
43  description: 'a2', // Sets the description of a download session.
44  networkType: 1, // Sets the network type allowed for download.
45  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
46  title: 'a2', // Sets a download session title.
47}
48let DownloadConfig3 = {
49  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
50  enableMetered: true,
51  enableRoaming: true, // Allows download in a roaming network.
52}
53let DownloadConfig4 = {
54  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/autoconf-2.13-10.tar.gz',// Resource address.
55  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
56  enableMetered: true,
57  enableRoaming: true, // Allows download in a roaming network.
58  description: 'a2', // Sets the description of a download session.
59  networkType: 1, // Sets the network type allowed for download.
60  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
61  title: 'a2', // Sets a download session title.
62}
63let DownloadConfig5 = {
64  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/automake-1.4-8.3.tar.gz',// Resource address.
65  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
66  enableMetered: true,
67  enableRoaming: true, // Allows download in a roaming network.
68  description: 'a2', // Sets the description of a download session.
69  networkType: 1, // Sets the network type allowed for download.
70  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
71  title: 'a2', // Sets a download session title.
72}
73let DownloadConfig6 = {
74  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.10.91.0.2-2.10.91.0.4.diff.gz',// Resource address.
75  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
76  enableMetered: true,
77  enableRoaming: true, // Allows download in a roaming network.
78  description: 'a2', // Sets the description of a download session.
79  networkType: 1, // Sets the network type allowed for download.
80  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
81  title: 'a2', // Sets a download session title.
82}
83let DownloadConfig7 = {
84  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.23-2.11.90.0.24.sign',// Resource address.
85  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
86  enableMetered: true,
87  enableRoaming: true, // Allows download in a roaming network.
88  description: 'a2', // Sets the description of a download session.
89  networkType: 1, // Sets the network type allowed for download.
90  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
91  title: 'a2', // Sets a download session title.
92}
93let DownloadConfig8 = {
94  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.5-2.11.90.0.6.diff.gz',// Resource address.
95  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
96  enableMetered: true,
97  enableRoaming: true, // Allows download in a roaming network.
98  description: 'a2', // Sets the description of a download session.
99  networkType: 1, // Sets the network type allowed for download.
100  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
101  title: 'a2', // Sets a download session title.
102}
103let DownloadConfig9 = {
104  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.6-2.11.90.0.7.diff.gz',// Resource address.
105  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
106  enableMetered: true,
107  enableRoaming: true, // Allows download in a roaming network.
108  description: 'a2', // Sets the description of a download session.
109  networkType: 1, // Sets the network type allowed for download.
110  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
111  title: 'a2', // Sets a download session title.
112}
113let DownloadConfig10 = {
114  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.7-2.11.90.0.8.diff.gz',// Resource address.
115  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
116  enableMetered: true,
117  enableRoaming: true, // Allows download in a roaming network.
118  description: 'a2', // Sets the description of a download session.
119  networkType: 1, // Sets the network type allowed for download.
120  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
121  title: 'a2', // Sets a download session title.
122}
123let DownloadConfig11 = {
124  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.90.0.8-2.11.90.0.15.diff.gz',// Resource address.
125  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
126  enableMetered: true,
127  enableRoaming: true, // Allows download in a roaming network.
128  description: 'a2', // Sets the description of a download session.
129  networkType: 1, // Sets the network type allowed for download.
130  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
131  title: 'a2', // Sets a download session title.
132}
133let DownloadConfig12 = {
134  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.92.0.5-2.11.92.0.7.diff.gz',// Resource address.
135  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
136  enableMetered: true,
137  enableRoaming: true, // Allows download in a roaming network.
138  description: 'a2', // Sets the description of a download session.
139  networkType: 1, // Sets the network type allowed for download.
140  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
141  title: 'a2', // Sets a download session title.
142}
143let DownloadConfig13 = {
144  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.11.92.0.7-2.11.92.0.10.diff.gz',// Resource address.
145  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
146  enableMetered: true,
147  enableRoaming: true, // Allows download in a roaming network.
148  description: 'a2', // Sets the description of a download session.
149  networkType: 1, // Sets the network type allowed for download.
150  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
151  title: 'a2', // Sets a download session title.
152}
153let DownloadConfig14 = {
154  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.12.90.0.1-2.12.90.0.3.diff.gz',// Resource address.
155  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
156  enableMetered: true,
157  enableRoaming: true, // Allows download in a roaming network.
158  description: 'a2', // Sets the description of a download session.
159  networkType: 1, // Sets the network type allowed for download.
160  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
161  title: 'a2', // Sets a download session title.
162}
163let DownloadConfig15 = {
164  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.12.90.0.11-2.12.90.0.12.diff.gz',// Resource address.
165  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
166  enableMetered: true,
167  enableRoaming: true, // Allows download in a roaming network.
168  description: 'a2', // Sets the description of a download session.
169  networkType: 1, // Sets the network type allowed for download.
170  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
171  title: 'a2', // Sets a download session title.
172}
173let DownloadConfig16 = {
174  url: 'https://mirror.bjtu.edu.cn/kernel/linux/devel/binutils/binutils-2.12.90.0.14-2.12.90.0.15.diff.gz',// Resource address.
175  header: { }, // Adds an HTTP or HTTPS header to be included with the upload request.
176  enableMetered: true,
177  enableRoaming: true, // Allows download in a roaming network.
178  description: 'a2', // Sets the description of a download session.
179  networkType: 1, // Sets the network type allowed for download.
180  filePath: '/system/lib/abc2.txt', // Sets the path for downloads.
181  title: 'a2', // Sets a download session title.
182}
183const SLEEP_TIME = 1000
184
185export default function exampleTestJsunit() {
186
187  describe('appInfoTest', function () {
188    function sleep(numberMillis)
189    {
190      var now = new Date();
191      var exitTime = now.getTime() + numberMillis;
192      while (true) {
193        now = new Date();
194        if (now.getTime() > exitTime)
195        return;
196      }
197    }
198    console.log("-----------------------Download_Test is starting-----------------------");
199    /*
200     * @tc.number  Download_Test_0100
201     * @tc.name    Create file downloads
202     * @tc.desc    Function test
203     * @tc.level   0
204     */
205    it("Download_Test_0100", 0, async function(done){
206      console.log("Download_Test_DownloadConfig", JSON.stringify(DownloadConfig));
207      console.log("------------------start Download_Test_0100-------------------");
208      try{
209        console.log("Show me the log");
210        request.download(DownloadConfig, (err, data) => {
211            console.log("Download_Test_0100: register download issue successful, result = " +data);
212            expect(typeof(data) == 'number').assertTrue();
213          done();
214        });
215        sleep(SLEEP_TIME);
216      } catch (error) {
217        console.log("logMessage Download_Test_0100: error = " + error);
218      }
219      console.log("------------------end Download_Test_0100-------------------");
220    });
221    /*
222     * @tc.number  Download_Test_0200
223     * @tc.name    Create a file download, monitor the download process
224     * @tc.desc    Function test
225     * @tc.level   0
226     */
227    it("Download_Test_0200", 0, async function(done){
228      console.log("------------------start Download_Test_0200 on progress-------------------");
229      try{
230        let eventType = 'progress'
231        request.download(DownloadConfig4, (err, data) => {
232          console.log("Download_Test_0200: register download  issue successful, result = " +data);
233          data.on(eventType,(err1,data1,data2) =>{
234            console.log("Download_Test_0200: , on progress result data1 = "+data1);
235            console.log("Download_Test_0200: , on progress result data2 = "+data2);
236            expect(typeof(data1) == 'number').assertTrue();
237            expect(typeof(data2) == 'number').assertTrue();
238            done();
239          })
240          sleep(SLEEP_TIME);
241//          done();
242        });
243        sleep(SLEEP_TIME);
244      } catch (error) {
245        console.log("logMessage pause: error = " + error);
246      }
247    });
248    /*
249     * @tc.number  Download_Test_0300
250     * @tc.name    Create file download, monitor download failure
251     * @tc.desc    Function test
252     * @tc.level   0
253     */
254    it("Download_Test_0300", 0, async function(done){
255      console.log("------------------start Download_Test_0300 on fail-------------------");
256      try{
257        let isEnter = 1
258        let eventType = 'fail'
259        request.download(DownloadConfig5, (err, data) => {
260          console.log("Download_Test_0300: register download issue successful, result = " +data);
261          data.on(eventType,(err1,data1) =>{
262            isEnter = 2
263            console.log("Download_Test_0300: , on fail result = "+data1);
264            expect(isEnter == 2).assertTrue();
265            done();
266          })
267//          done();
268        });
269        sleep(SLEEP_TIME);
270      } catch (error) {
271        console.log("logMessage on fail: error = " + error);
272      }
273    });
274    /*
275     * @tc.number  Download_Test_0400
276     * @tc.name    Create file download, monitor download completion
277     * @tc.desc    Function test
278     * @tc.level   0
279     */
280    it("Download_Test_0400", 0, async function(done){
281      console.log("------------------start Download_Test_0400-------------------");
282      try{
283        let isEnter = 1
284        let eventType = 'complete';
285        request.download(DownloadConfig6, (err, data) => {
286          console.log("Download_Test_0400: register download issue successful, result = " +data);
287          data.on(eventType,(err1,data1) =>{
288            isEnter = 2
289            console.log("Download_Test_0400: , on complete result = "+data1);
290            expect(isEnter == 2).assertTrue();
291            done();
292          })
293//          done();
294        });
295        sleep(SLEEP_TIME);
296      } catch (error) {
297        console.log("logMessage remove: error = " + error);
298      }
299    });
300    /*
301     * @tc.number  Download_Test_0500
302     * @tc.name    Create a file download, monitor and cancel the monitor download process
303     * @tc.desc    Function test
304     * @tc.level   0
305     */
306    it("Download_Test_0500", 0, async function(done){
307      console.log("------------------start Download_Test_0500-------------------");
308      try{
309        let isEnter = 1
310        let eventType = 'progress';
311        request.download(DownloadConfig7, (err, data) => {
312          console.log("Download_Test_0500: register download issue successful, result = " +data);
313          data.on(eventType,(err1,data1) =>{
314            console.log("Download_Test_0500: , on progress result = "+data1);
315          });
316          sleep(SLEEP_TIME);
317          data.off(eventType,(err1,data1,data2) =>{
318            isEnter = 2
319            console.log("Download_Test_0500: , off progress result = "+data1);
320            console.log("Download_Test_0500: , off progress result = "+data2);
321            expect(isEnter == 2).assertTrue();
322            done();
323          });
324//          done();
325        });
326        sleep(SLEEP_TIME);
327      } catch (error) {
328        console.log("Download_Test_0500 queryMimeType: error = " + error);
329      }
330    });
331    /*
332     * @tc.number  Download_Test_0600
333     * @tc.name    Create file downloads, monitor and cancel monitoring download failures
334     * @tc.desc    Function test
335     * @tc.level   0
336     */
337    it("Download_Test_0600", 0, async function(done){
338      console.log("------------------start Download_Test_0600-------------------");
339      try{
340        let isEnter = 1
341        let eventType = 'fail';
342        request.download(DownloadConfig8, (err, data) => {
343          console.log("Download_Test_0600: register download issue successful, result = " +data);
344          data.on(eventType,(err,data) =>{
345            console.log("Download_Test_0600: register on fail  issue successful, result = " +data);
346          });
347          sleep(SLEEP_TIME);
348          data.off(eventType,(err,data) =>{
349            isEnter = 2
350            console.log("Download_Test_0600: register off fail  issue successful, result = " +data);
351            expect(isEnter == 2).assertTrue();
352            done();
353          });
354        });
355        sleep(SLEEP_TIME);
356      } catch (error) {
357        console.log("Download_Test_0600 off fail: error = " + error);
358      }
359    });
360    /*
361     * @tc.number  Download_Test_0700
362     * @tc.name    Create file download, listen for download completion and cancel listening for download completion
363     * @tc.desc    Function test
364     * @tc.level   0
365     */
366    it("Download_Test_0700", 0, async function(done){
367      console.log("------------------start Download_Test_0700-------------------");
368      try{
369        let isEnter = 1
370        let eventType = 'complete';
371        request.download(DownloadConfig9, (err, data) => {
372          console.log("Download_Test_0700: register download issue successful, result = " +data);
373          data.on(eventType,(err1,data1) =>{
374            console.log("Download_Test_0700: , on complete result = "+data1);
375          })
376          sleep(SLEEP_TIME);
377          data.off(eventType,(err1,data1) =>{
378            isEnter = 2
379            console.log("Download_Test_0700: , off complete result = "+data1);
380            expect(isEnter == 2).assertTrue();
381            done();
382          })
383        });
384        sleep(SLEEP_TIME);
385      } catch (error) {
386        console.log("Download_Test_0700 off complete: error = " + error);
387      }
388    });
389    /*
390     * @tc.number  Download_Test_0800
391     * @tc.name    Create file download, pause file download
392     * @tc.desc    Function test
393     * @tc.level   0
394     */
395    it("Download_Test_0800", 0, async function(done){
396      console.log("------------------start Download_Test_0800-------------------");
397      try{
398        request.download(DownloadConfig10, (err, data) => {
399          let eventType = 'pause';
400          console.log("Download_Test_0800: register download issue successful, result = " +data);
401          data.on(eventType,(err1,data1) =>{
402            console.log("Download_Test_0800: , on pause result = "+data1);
403          })
404          data.pause((err1,data1) =>{
405            console.log("Download_Test_0800: , off pause result = "+data1);
406            expect(data1==true).assertTrue();
407            done();
408          })
409        });
410        sleep(SLEEP_TIME);
411      } catch (error) {
412        console.log("Download_Test_0800 pause: error = " + error);
413      }
414    });
415    /*
416     * @tc.number  Download_Test_0900
417     * @tc.name    Create a file download, pause the file download and resume the download
418     * @tc.desc    Function test
419     * @tc.level   0
420     */
421    it("Download_Test_0900", 0, async function(done){
422      console.log("------------------start Download_Test_0900-------------------");
423      try{
424        request.download(DownloadConfig11, (err, data) => {
425          console.log("Download_Test_0900: register download issue successful, result = " +data);
426          data.pause((err1,data1) =>{
427            console.log("Download_Test_0900: , pause result = "+data1);
428          })
429          data.resume((err1,data1) =>{
430            console.log("Download_Test_0900: , resume result = "+data1);
431            expect(data1==true).assertTrue();
432            done();
433          })
434        });
435        sleep(SLEEP_TIME);
436      } catch (error) {
437        console.log("Download_Test_0900 resume: error = " + error);
438      }
439    });
440    /*
441     * @tc.number  Download_Test_1000
442     * @tc.name    Create file download, cancel file download
443     * @tc.desc    Function test
444     * @tc.level   0
445     */
446    it("Download_Test_1000", 0, async function(done){
447      console.log("------------------start Download_Test_1000-------------------");
448      try{
449        request.download(DownloadConfig12, (err, data) => {
450          console.log("Download_Test_1000: register download issue successful, result = " +data);
451          data.remove((err1,data1) =>{
452            console.log("Download_Test_1000: , remove result = "+data1);
453            expect(data1==true).assertTrue();
454            done();
455          })
456        });
457        sleep(SLEEP_TIME);
458      } catch (error) {
459        console.log("Download_Test_1000 remove: error = " + error);
460      }
461    });
462    /*
463     * @tc.number  Download_Test_1100
464     * @tc.name    Create multiple file downloads
465     * @tc.desc    Function test
466     * @tc.level   0
467     */
468    it("Download_Test_1100", 0, async function(done){
469      console.log("------------------start Download_Test_1100-------------------");
470      try{
471        request.download(DownloadConfig13, (err, data) => {
472          console.log("Download_Test_1100: register download issue successful, result = " +data);
473          expect(typeof(data) == 'object').assertTrue();
474        });
475        request.download(DownloadConfig12, (err, data) => {
476          console.log("Download_Test_1100: register download issue successful, result = " +data);
477          expect(typeof(data) == 'object').assertTrue();
478        });
479        request.download(DownloadConfig2, (err, data) => {
480          console.log("Download_Test_1100: register download issue successful, result = " +data);
481          expect(typeof(data) == 'object').assertTrue();
482          done();
483        });
484        sleep(SLEEP_TIME);
485      } catch (error) {
486        console.log("Download_Test_1100 multiple: error = " + error);
487      }
488    });
489    /*
490     * @tc.number  Download_Test_1200
491     * @tc.name    Create file downloads and receive download file MIME type
492     * @tc.desc    Function test
493     * @tc.level   0
494     */
495    it("Download_Test_1200", 0, async function(done){
496      console.log("------------------start Download_Test_1200-------------------");
497      try{
498        request.download(DownloadConfig14, (err, data) => {
499          console.log("Download_Test_1200: register download issue successful, result = " +data);
500          data.queryMimeType((err1,data1) =>{
501            console.log("Download_Test_1200: register queryMimeType  issue successful, result ="+data1);
502            expect(typeof(data1) == 'string').assertTrue();
503          })
504          done();
505        });
506        sleep(SLEEP_TIME);
507      } catch (error) {
508        console.log("Download_Test_1200 queryMimeType: error = " + error);
509      }
510    });
511    /*
512     * @tc.number  Download_Test_1300
513     * @tc.name    Create file downloads and receive download info
514     * @tc.desc    Function test
515     * @tc.level   0
516     */
517    it("Download_Test_1300", 0, async function(done){
518      console.log("------------------start Download_Test_1300-------------------");
519      try{
520        request.download(DownloadConfig15, (err, data) => {
521          console.log("Download_Test_1300: register download issue successful, result = " +data);
522          data.query((err1,data1) =>{
523            console.log("Download_Test_1300: register query  issue successful, result ="+JSON.stringify(data1));
524            expect(typeof(data1) == 'object').assertTrue();
525          })
526          done();
527        });
528      } catch (error) {
529        console.log("Download_Test_1300 query: error = " + error);
530      }
531    });
532    /*
533     * @tc.number  Download_Test_1400
534     * @tc.name    Create file downloads and missing parameters
535     * @tc.desc    Function test
536     * @tc.level   0
537     */
538    it("Download_Test_1400", 0, async function(done){
539      console.log("------------------start Download_Test_1400-------------------");
540      try{
541        request.download(DownloadConfig3, (err, data) => {
542          console.log("Download_Test_1400: register download issue successful, result = " +data);
543          expect(data==obj).assertTrue();
544          done();
545        });
546        sleep(SLEEP_TIME);
547      } catch (error) {
548        console.log("Download_Test_1400 missing parameters: error = " + error);
549      }
550    });
551  })
552}
553
554