1/* 2 * Copyright (c) 2021 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 { paramMock } from '../utils'; 17 18export function mockUrl() { 19 const URLSearchParamsClass = class URLSearchParams { 20 constructor(...args) { 21 console.warn('url.URLSearchParams.constructor interface mocked in the Previewer. How this interface works on' + 22 ' the Previewer' + 23 ' may be different from that on a real device.'); 24 this.append = function (...args) { 25 console.warn('url.URLSearchParams.append interface mocked in the Previewer. How this interface works on the Previewer' + 26 ' may be different from that on a real device.'); 27 }; 28 this.delete = function (...args) { 29 console.warn('url.URLSearchParams.delete interface mocked in the Previewer. How this interface works on the Previewer' + 30 ' may be different from that on a real device.'); 31 }; 32 this.getAll = function (...args) { 33 console.warn('url.URLSearchParams.getAll interface mocked in the Previewer. How this interface works on the Previewer' + 34 ' may be different from that on a real device.'); 35 return [paramMock.paramStringMock]; 36 }; 37 this.entries = function (...args) { 38 console.warn('url.URLSearchParams.entries interface mocked in the Previewer. How this interface works on the Previewer' + 39 ' may be different from that on a real device.'); 40 const IteratorTwoStringMock = { 41 *[Symbol.iterator]() { 42 yield [paramMock.paramStringMock, paramMock.paramStringMock]; 43 } 44 }; 45 return IteratorTwoStringMock; 46 }; 47 this.forEach = function (...args) { 48 console.warn('url.URLSearchParams.forEach interface mocked in the Previewer. How this interface works on the Previewer' + 49 ' may be different from that on a real device.'); 50 }; 51 this.get = function (...args) { 52 console.warn('url.URLSearchParams.get interface mocked in the Previewer. How this interface works on the Previewer' + 53 ' may be different from that on a real device.'); 54 return paramMock.paramStringMock; 55 }; 56 this.has = function (...args) { 57 console.warn('url.URLSearchParams.has interface mocked in the Previewer. How this interface works on the Previewer' + 58 ' may be different from that on a real device.'); 59 return paramMock.paramBooleanMock; 60 }; 61 this.set = function (...args) { 62 console.warn('url.URLSearchParams.set interface mocked in the Previewer. How this interface works on the Previewer' + 63 ' may be different from that on a real device.'); 64 }; 65 this.sort = function (...args) { 66 console.warn('url.URLSearchParams.sort interface mocked in the Previewer. How this interface works on the Previewer' + 67 ' may be different from that on a real device.'); 68 }; 69 this.keys = function (...args) { 70 console.warn('url.URLSearchParams.keys interface mocked in the Previewer. How this interface works on the Previewer' + 71 ' may be different from that on a real device.'); 72 const IteratorStringMock = { 73 *[Symbol.iterator]() { 74 yield paramMock.paramStringMock; 75 } 76 }; 77 return IteratorStringMock; 78 }; 79 this.values = function (...args) { 80 console.warn('url.URLSearchParams.values interface mocked in the Previewer. How this interface works on the Previewer' + 81 ' may be different from that on a real device.'); 82 const IteratorStringMock = { 83 *[Symbol.iterator]() { 84 yield paramMock.paramStringMock; 85 } 86 }; 87 return IteratorStringMock; 88 }; 89 this.toString = function (...args) { 90 console.warn('url.URLSearchParams.toString interface mocked in the Previewer. How this interface works on the Previewer' + 91 ' may be different from that on a real device.'); 92 return paramMock.paramStringMock; 93 }; 94 } 95 [Symbol.iterator]() { 96 console.warn('url.URLSearchParams.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer' + 97 ' may be different from that on a real device.'); 98 let index = 0; 99 const IteratorTwoStringMock = { 100 next: () => { 101 if (index < 1) { 102 const returnValue = [paramMock.paramStringMock, paramMock.paramStringMock]; 103 index++; 104 return { 105 value: returnValue, 106 done: false 107 }; 108 } else { 109 return { 110 done: true 111 }; 112 } 113 } 114 }; 115 return IteratorTwoStringMock; 116 } 117 }; 118 const URLClass = class URL { 119 constructor(...args) { 120 console.warn('url.URL.constructor interface mocked in the Previewer. How this interface works on the Previewer' + 121 ' may be different from that on a real device.'); 122 this.toString = function (...args) { 123 console.warn('URL.toString interface mocked in the Previewer. How this interface works on the Previewer' + 124 ' may be different from that on a real device.'); 125 return paramMock.paramStringMock; 126 }; 127 this.toJSON = function (...args) { 128 console.warn('URL.toJSON interface mocked in the Previewer. How this interface works on the Previewer' + 129 ' may be different from that on a real device.'); 130 return paramMock.paramStringMock; 131 }; 132 this.hash = '[PC preview] unknow hash'; 133 this.host = '[PC preview] unknow host'; 134 this.hostname = '[PC preview] unknow hostname'; 135 this.href = '[PC preview] unknow href'; 136 this.origin = '[PC preview] unknow origin'; 137 this.password = '[PC preview] unknow password'; 138 this.pathname = '[PC preview] unknow pathname'; 139 this.port = '[PC preview] unknow port'; 140 this.protocol = '[PC preview] unknow protocol'; 141 this.search = '[PC preview] unknow search'; 142 this.searchParams = new URLSearchParamsClass(); 143 this.username = '[PC preview] unknow username'; 144 } 145 }; 146 const result = { 147 URLSearchParams: URLSearchParamsClass, 148 URL: URLClass 149 }; 150 return result; 151} 152