Best JavaScript code snippet using playwright-internal
viewport.unit.js
Source:viewport.unit.js
...37 window.innerHeight = 2;38 ionic.Platform.ua = '';39 ionic.Platform.platforms = null;40 ionic.Platform.setPlatform('');41 ionic.Platform.setVersion('');42 ionic.keyboard.isOpen = false;43 viewportProperties = {};44 vportTag = document.createElement('meta');45 vportTag.setAttribute('name', 'viewport');46 document.head.appendChild(vportTag);47 }));48 afterEach(function(){49 window.setTimeout = window._setTimeout;50 if(vportTag) vportTag.parentNode.removeChild(vportTag);51 });52 // iOS 7.1, iPad, WebView53 it('Should remove width and height from viewport for iOS >= 7.1, iPad, WebView', function(){54 ionic.Platform.setPlatform('ios');55 ionic.Platform.ua = 'ipad';56 ionic.Platform.setVersion('7.1');57 window.cordova = {};58 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';59 viewportLoadTag();60 expect( vportTag.content ).toEqual('user-scalable=no');61 });62 // iOS 7.1, iPad, Browser63 it('Should remove width and height from viewport for iOS >= 7.1, iPad, Browser', function(){64 ionic.Platform.setPlatform('ios');65 ionic.Platform.ua = 'ipad';66 ionic.Platform.setVersion('7.1');67 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';68 viewportLoadTag();69 expect( vportTag.content ).toEqual('user-scalable=no');70 });71 // iOS 7.0, iPad, WebView72 it('Should keep width and height in viewport for iOS 7.0, iPad, WebView, Portrait', function(){73 ionic.Platform.setPlatform('ios');74 ionic.Platform.ua = 'ipad';75 ionic.Platform.setVersion('7.0');76 window.cordova = {};77 window.innerWidth = 1;78 window.innerHeight = 2;79 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';80 viewportLoadTag();81 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=device-height');82 });83 it('Should add width and height to viewport for iOS 7.0, iPad, WebView, Portrait', function(){84 ionic.Platform.setPlatform('ios');85 ionic.Platform.ua = 'ipad';86 ionic.Platform.setVersion('7.0');87 window.cordova = {};88 window.innerWidth = 1;89 window.innerHeight = 2;90 vportTag.content = 'user-scalable=no';91 viewportLoadTag();92 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=device-height');93 });94 it('Should add width and height=0 to viewport for iOS 7.0, iPad, WebView, Landscape', function(){95 ionic.Platform.setPlatform('ios');96 ionic.Platform.ua = 'ipad';97 ionic.Platform.setVersion('7.0');98 window.cordova = {};99 window.innerWidth = 2;100 window.innerHeight = 1;101 vportTag.content = 'user-scalable=no';102 viewportLoadTag();103 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');104 });105 it('Should keep width reset height to 0 in viewport for iOS 7.0, iPad, WebView, Landscape', function(){106 ionic.Platform.setPlatform('ios');107 ionic.Platform.ua = 'ipad';108 ionic.Platform.setVersion('7.0');109 window.cordova = {};110 window.innerWidth = 2;111 window.innerHeight = 1;112 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';113 viewportLoadTag();114 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');115 });116 // iOS 7.0, iPad, Browser117 it('Should keep width, but remove height from viewport for iOS 7.0, iPad, Browser', function(){118 ionic.Platform.setPlatform('ios');119 ionic.Platform.ua = 'ipad';120 ionic.Platform.setVersion('7.0');121 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';122 viewportLoadTag();123 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');124 });125 it('Should add width, but not add height to viewport for iOS 7.0, iPad, Browser', function(){126 ionic.Platform.setPlatform('ios');127 ionic.Platform.ua = 'ipad';128 ionic.Platform.setVersion('7.0');129 vportTag.content = 'user-scalable=no';130 viewportLoadTag();131 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');132 });133 // iOS 6.1, iPad, WebView134 it('Should keep width, but remove height from viewport for iOS 6.1, iPad, WebView, Portrait', function(){135 ionic.Platform.setPlatform('ios');136 ionic.Platform.ua = 'ipad';137 ionic.Platform.setVersion('6.1');138 window.cordova = {};139 window.innerWidth = 1;140 window.innerHeight = 2;141 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';142 viewportLoadTag();143 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');144 });145 it('Should add width, but not add height to viewport for iOS 6.1, iPad, WebView, Portrait', function(){146 ionic.Platform.setPlatform('ios');147 ionic.Platform.ua = 'ipad';148 ionic.Platform.setVersion('6.1');149 window.cordova = {};150 window.innerWidth = 1;151 window.innerHeight = 2;152 vportTag.content = 'user-scalable=no';153 viewportLoadTag();154 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');155 });156 it('Should keep width, but replace height with 0 in viewport for iOS 6.1, iPad, WebView, Landscape', function(){157 ionic.Platform.setPlatform('ios');158 ionic.Platform.ua = 'ipad';159 ionic.Platform.setVersion('6.1');160 window.cordova = {};161 window.innerWidth = 2;162 window.innerHeight = 1;163 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';164 viewportLoadTag();165 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');166 });167 it('Should add width and add height=0 to viewport for iOS 6.1, iPad, WebView, Landscape', function(){168 ionic.Platform.setPlatform('ios');169 ionic.Platform.ua = 'ipad';170 ionic.Platform.setVersion('6.1');171 window.cordova = {};172 window.innerWidth = 2;173 window.innerHeight = 1;174 vportTag.content = 'user-scalable=no';175 viewportLoadTag();176 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');177 });178 // iOS 6.1, iPad, Browser179 it('Should keep width, and set height=0 for viewport for iOS 6.1, iPad, Browser, Portrait', function(){180 ionic.Platform.setPlatform('ios');181 ionic.Platform.ua = 'ipad';182 ionic.Platform.setVersion('6.1');183 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';184 viewportLoadTag();185 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');186 });187 it('Should add width, and add height=0 to viewport for iOS 6.1, iPad, Browser', function(){188 ionic.Platform.setPlatform('ios');189 ionic.Platform.ua = 'ipad';190 ionic.Platform.setVersion('6.1');191 vportTag.content = 'user-scalable=no';192 viewportLoadTag();193 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');194 });195 // iOS 7.1, iPhone, WebView196 it('Should remove width and height from viewport for iOS 7.1, iPhone, WebView', function(){197 ionic.Platform.setPlatform('ios');198 ionic.Platform.setVersion('7.1');199 window.cordova = {};200 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';201 viewportLoadTag();202 expect( vportTag.content ).toEqual('user-scalable=no');203 });204 it('Should do nothing width and height already in viewport for iOS 7.1, iPhone, WebView', function(){205 ionic.Platform.setPlatform('ios');206 ionic.Platform.setVersion('7.1');207 window.cordova = {};208 vportTag.content = 'user-scalable=no';209 viewportLoadTag();210 expect( vportTag.content ).toEqual('user-scalable=no');211 });212 // iOS 7.1, iPhone, Browser213 it('Should keep width, but remove height from viewport for iOS >= 7.1, iPhone, Browser', function(){214 ionic.Platform.setPlatform('iOS');215 ionic.Platform.setVersion('7.1');216 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';217 viewportLoadTag();218 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');219 });220 it('Should add width, but not height to viewport for iOS >= 7.1, iPhone, Browser', function(){221 ionic.Platform.setPlatform('iOS');222 ionic.Platform.setVersion('7.1');223 vportTag.content = 'user-scalable=no';224 viewportLoadTag();225 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');226 });227 // iOS 7.0, iPhone, WebView228 it('Should keep width, but not height in viewport for iOS 7.0, iPhone, WebView', function(){229 ionic.Platform.setPlatform('iOS');230 ionic.Platform.setVersion('7.0');231 window.cordova = {};232 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';233 viewportLoadTag();234 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=device-height');235 });236 it('Should add width and height to viewport for iOS 7.0, iPhone, WebView', function(){237 ionic.Platform.setPlatform('iOS');238 ionic.Platform.setVersion('7.0');239 window.cordova = {};240 vportTag.content = 'user-scalable=no';241 viewportLoadTag();242 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=device-height');243 });244 // iOS 7.0, iPhone, Browser245 it('Should keep width but remove height from viewport for iOS 7.0, iPhone, Browser', function(){246 ionic.Platform.setPlatform('iOS');247 ionic.Platform.setVersion('7.0');248 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';249 viewportLoadTag();250 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');251 });252 it('Should add width but not height to viewport for iOS 7.0, iPhone, Browser', function(){253 ionic.Platform.setPlatform('iOS');254 ionic.Platform.setVersion('7.0');255 vportTag.content = 'user-scalable=no';256 viewportLoadTag();257 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');258 });259 // iOS 6.1, iPhone, WebView260 it('Should add width but not height to viewport for iOS 6.1, iPhone, WebView', function(){261 ionic.Platform.setPlatform('iOS');262 ionic.Platform.setVersion('6.1');263 window.cordova = {};264 vportTag.content = 'user-scalable=no';265 viewportLoadTag();266 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');267 });268 it('Should keep width but replace height=device-height with height=0 in viewport for iOS 6.1, iPhone, WebView', function(){269 ionic.Platform.setPlatform('iOS');270 ionic.Platform.setVersion('6.1');271 window.cordova = {};272 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';273 viewportLoadTag();274 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');275 });276 // iOS 6.1, iPhone, Browser277 it('Should add width but not height to viewport for iOS 6.1, iPhone, Browser', function(){278 ionic.Platform.setPlatform('iOS');279 ionic.Platform.setVersion('6.1');280 vportTag.content = 'user-scalable=no';281 viewportLoadTag();282 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');283 });284 it('Should keep width but remove height from viewport for iOS 6.1, iPhone, Browser', function(){285 ionic.Platform.setPlatform('iOS');286 ionic.Platform.setVersion('6.1');287 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';288 viewportLoadTag();289 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width, height=0');290 });291 // Android 4.4, WebView292 it('Should add width, but not height to viewport for Android 4.4, WebView', function(){293 ionic.Platform.setPlatform('android');294 ionic.Platform.setVersion('4.4');295 window.cordova = {};296 vportTag.content = 'user-scalable=no';297 viewportLoadTag();298 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');299 });300 it('Should keep width, but remove height from viewport for Android 4.4, WebView', function(){301 ionic.Platform.setPlatform('android');302 ionic.Platform.setVersion('4.4');303 window.cordova = {};304 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';305 viewportLoadTag();306 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');307 });308 // Android 4.4, Browser309 it('Should add width, but not height to viewport for Android 4.4, Browser', function(){310 ionic.Platform.setPlatform('android');311 ionic.Platform.setVersion('4.4');312 vportTag.content = 'user-scalable=no';313 viewportLoadTag();314 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');315 });316 it('Should keep width, but remove height from viewport for Android 4.4, Browser', function(){317 ionic.Platform.setPlatform('android');318 ionic.Platform.setVersion('4.4');319 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';320 viewportLoadTag();321 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');322 });323 // Standard Browser324 it('Should add width, but not height to viewport for Standard Browser', function(){325 ionic.Platform.ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36';326 vportTag.content = 'user-scalable=no';327 viewportLoadTag();328 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');329 });330 it('Should keep width, but remove height from viewport for Standard Browser', function(){331 ionic.Platform.setPlatform('android');332 ionic.Platform.setVersion('4.4');333 vportTag.content = 'user-scalable=no, width=device-width, height=device-height';334 viewportLoadTag();335 expect( vportTag.content ).toEqual('user-scalable=no, width=device-width');336 });337 it('Should set viewport properties that have a key but without a value', function(){338 vportTag.content = ' keyonly, , ,, WIDTH=DeViCe-wIDTH , minimal-ui ';339 viewportLoadTag();340 expect( viewportProperties.keyonly ).toEqual('_');341 expect( viewportProperties.width ).toEqual('device-width');342 expect( viewportProperties['minimal-ui'] ).toEqual('_');343 viewportTagUpdate();344 expect( vportTag.content ).toEqual('keyonly, width=device-width, minimal-ui');345 });346 it('Should get portrait (0) orientation', function(){...
platform.unit.js
Source:platform.unit.js
...17 ionic.Platform.setPlatform('iOS');18 expect(ionic.Platform.platform()).toEqual('ios');19 });20 it('set version with device', function() {21 ionic.Platform.setVersion('1.2.3');22 expect(ionic.Platform.version()).toEqual(1.2);23 ionic.Platform.setVersion('1.2');24 expect(ionic.Platform.version()).toEqual(1.2);25 ionic.Platform.setVersion('1');26 expect(ionic.Platform.version()).toEqual(1.0);27 ionic.Platform.setVersion('0.1');28 expect(ionic.Platform.version()).toEqual(0.1);29 ionic.Platform.setVersion(' ');30 expect(ionic.Platform.version()).toEqual(0);31 ionic.Platform.setVersion('me-not-number');32 expect(ionic.Platform.version()).toEqual(0);33 ionic.Platform.setVersion('');34 expect(ionic.Platform.version()).toEqual(0);35 ionic.Platform.setVersion(null);36 expect(ionic.Platform.version()).toEqual(0);37 ionic.Platform.setVersion('0');38 expect(ionic.Platform.version()).toEqual(0);39 ionic.Platform.setVersion();40 expect(ionic.Platform.version()).toEqual(0);41 });42 it('set android with user agent', function() {43 ionic.Platform.ua = 'Mozilla/5.0 (Linux; U; Android 2.2.1; fr-ch; A43 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';44 ionic.Platform.setPlatform(undefined);45 ionic.Platform.setVersion(undefined);46 expect(ionic.Platform.platform()).toEqual('android');47 expect(ionic.Platform.version()).toEqual(2.2);48 });49 it('set windowsphone with user agent', function() {50 ionic.Platform.ua = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch;';51 ionic.Platform.setPlatform(undefined);52 ionic.Platform.setVersion(undefined);53 expect(ionic.Platform.platform()).toEqual('windowsphone');54 expect(ionic.Platform.version()).toEqual(8);55 });56 it('set ios with iPhone user agent', function() {57 ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';58 ionic.Platform.setPlatform(undefined);59 ionic.Platform.setVersion(undefined);60 expect(ionic.Platform.platform()).toEqual('ios');61 expect(ionic.Platform.version()).toEqual(6.1);62 });63 it('set ios with iPad user agent', function() {64 ionic.Platform.ua = 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53';65 ionic.Platform.setPlatform(undefined);66 ionic.Platform.setVersion(undefined);67 expect(ionic.Platform.platform()).toEqual('ios');68 expect(ionic.Platform.version()).toEqual(7.0);69 });70 it('set ios with iPod user agent', function() {71 ionic.Platform.ua = 'Mozilla/5.0 (iPod touch; CPU OS 8_1_3 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B511 Safari/9537.53';72 ionic.Platform.setPlatform(undefined);73 ionic.Platform.setVersion(undefined);74 expect(ionic.Platform.platform()).toEqual('ios');75 expect(ionic.Platform.version()).toEqual(8.1);76 });77 it('should not be iPad from none iPad user agent', function() {78 ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53';79 ionic.Platform.setPlatform(undefined);80 ionic.Platform.setVersion(undefined);81 expect(ionic.Platform.isIPad()).toEqual(false);82 });83 it('should be iPad from user agent', function() {84 ionic.Platform.ua = 'Mozilla/5.0 (iPad; CPU OS 7_0_4 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11B554a Safari/9537.53';85 ionic.Platform.setPlatform(undefined);86 ionic.Platform.setVersion(undefined);87 expect(ionic.Platform.isIPad()).toEqual(true);88 });89 it('should be iPad from iPad in ionic.Platform.navigator.platform and webview, but iPhone in user agent', function() {90 window.cordova = {};91 ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';92 ionic.Platform.navigator = {93 platform: 'iPad Simulator'94 };95 ionic.Platform.setPlatform(undefined);96 ionic.Platform.setVersion(undefined);97 expect(ionic.Platform.isIPad()).toEqual(true);98 });99 it('should not be iPad from no in ionic.Platform.navigator.platform, and iPhone in user agent', function() {100 ionic.Platform.ua = 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25';101 ionic.Platform.navigator = {};102 ionic.Platform.setPlatform(undefined);103 ionic.Platform.setVersion(undefined);104 expect(ionic.Platform.isIPad()).toEqual(false);105 });106 it('is not iOS', function() {107 ionic.Platform.ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36';108 ionic.Platform.navigator = {};109 ionic.Platform.setPlatform(undefined);110 ionic.Platform.setVersion(undefined);111 expect(ionic.Platform.isIOS()).toEqual(false);112 });113 it('is iOS', function() {114 ionic.Platform.setPlatform('iOS');115 expect(ionic.Platform.isIOS()).toEqual(true);116 ionic.Platform.setPlatform('ios');117 expect(ionic.Platform.isIOS()).toEqual(true);118 ionic.Platform.setPlatform('Android');119 expect(ionic.Platform.isIOS()).toEqual(false);120 });121 it('is Android', function() {122 ionic.Platform.setPlatform('Android');123 expect(ionic.Platform.isAndroid()).toEqual(true);124 ionic.Platform.setPlatform('android');125 expect(ionic.Platform.isAndroid()).toEqual(true);126 });127 it('is WebView', function() {128 window.cordova = undefined;129 expect(ionic.Platform.isWebView()).toEqual(false);130 window.cordova = {};131 expect(ionic.Platform.isWebView()).toEqual(true);132 delete window.cordova;133 window.PhoneGap = {};134 expect(ionic.Platform.isWebView()).toEqual(true);135 delete window.phonegap;136 window.phonegap = {};137 expect(ionic.Platform.isWebView()).toEqual(true);138 });139 it('sets ios platforms', function() {140 window.cordova = {};141 ionic.Platform.setPlatform('iOS');142 ionic.Platform.setVersion('7.0.3');143 ionic.Platform._checkPlatforms();144 expect(ionic.Platform.platforms[0]).toEqual('webview');145 expect(ionic.Platform.platforms[1]).toEqual('cordova');146 expect(ionic.Platform.platforms[2]).toEqual('ios');147 expect(ionic.Platform.platforms[3]).toEqual('ios7');148 expect(ionic.Platform.platforms[4]).toEqual('ios7_0');149 });150 it('sets android platforms', function() {151 window.cordova = {};152 ionic.Platform.setPlatform('android');153 ionic.Platform.setVersion('4.2.3');154 ionic.Platform._checkPlatforms();155 expect(ionic.Platform.platforms[0]).toEqual('webview');156 expect(ionic.Platform.platforms[1]).toEqual('cordova');157 expect(ionic.Platform.platforms[2]).toEqual('android');158 expect(ionic.Platform.platforms[3]).toEqual('android4');159 expect(ionic.Platform.platforms[4]).toEqual('android4_2');160 });161 it('should only set the webview', function() {162 window.cordova = {};163 ionic.Platform.setPlatform('');164 ionic.Platform.setVersion('');165 ionic.Platform._checkPlatforms();166 expect(ionic.Platform.platforms.length).toEqual(2);167 expect(ionic.Platform.platforms[0]).toEqual('webview');168 expect(ionic.Platform.platforms[1]).toEqual('cordova');169 });170 it('should not set if its not a webview but only a browser', function() {171 window.cordova = null;172 window.PhoneGap = null;173 window.phonegap = null;174 ionic.Platform.setPlatform('');175 ionic.Platform.setVersion('');176 ionic.Platform._checkPlatforms();177 expect(ionic.Platform.platforms[0]).toEqual('browser');178 });179 it('sets grade a from iOS7', function() {180 window.cordova = {};181 ionic.Platform.setPlatform('iOS');182 ionic.Platform.setVersion('7.1.1');183 ionic.Platform._checkPlatforms();184 expect(ionic.Platform.grade).toEqual('a');185 });186 it('sets grade a from iOS6', function() {187 window.cordova = {};188 ionic.Platform.setPlatform('iOS');189 ionic.Platform.setVersion('6.1.1');190 ionic.Platform._checkPlatforms();191 expect(ionic.Platform.grade).toEqual('a');192 });193 it('sets grade a from Android 4.4', function() {194 window.cordova = {};195 ionic.Platform.setPlatform('android');196 ionic.Platform.setVersion('4.4.1');197 ionic.Platform._checkPlatforms();198 expect(ionic.Platform.grade).toEqual('a');199 });200 it('sets grade b from Android 4.3', function() {201 window.cordova = {};202 ionic.Platform.setPlatform('android');203 ionic.Platform.setVersion('4.3.1');204 ionic.Platform._checkPlatforms();205 expect(ionic.Platform.grade).toEqual('b');206 });207 it('sets grade b from Android 4.0', function() {208 window.cordova = {};209 ionic.Platform.setPlatform('android');210 ionic.Platform.setVersion('4.0.0');211 ionic.Platform._checkPlatforms();212 expect(ionic.Platform.grade).toEqual('b');213 });214 it('sets grade c from Android 3.0', function() {215 window.cordova = {};216 ionic.Platform.setPlatform('android');217 ionic.Platform.setVersion('3.0.0');218 ionic.Platform._checkPlatforms();219 expect(ionic.Platform.grade).toEqual('c');220 });221 it('sets grade c from Android 2.3.4', function() {222 window.cordova = {};223 ionic.Platform.setPlatform('android');224 ionic.Platform.setVersion('2.3.4');225 ionic.Platform._checkPlatforms();226 expect(ionic.Platform.grade).toEqual('c');227 });228 it('sets grade a from unknown android version', function() {229 window.cordova = {};230 ionic.Platform.setPlatform('android');231 ionic.Platform.setVersion('0');232 ionic.Platform._checkPlatforms();233 expect(ionic.Platform.grade).toEqual('a');234 });235 it('sets grade b from Windows Phone platform', function() {236 window.cordova = {};237 ionic.Platform.setPlatform('windowsphone');238 ionic.Platform.setVersion('8.0');239 ionic.Platform._checkPlatforms();240 expect(ionic.Platform.grade).toEqual('b');241 });242 it('sets grade a from unknown platform', function() {243 window.cordova = {};244 ionic.Platform.setPlatform('whatever');245 ionic.Platform.setVersion('20.3.4');246 ionic.Platform._checkPlatforms();247 expect(ionic.Platform.grade).toEqual('a');248 });249 it('is android', function() {250 ionic.Platform.setPlatform('AnDrOiD');251 expect(ionic.Platform.is('android')).toEqual(true);252 ionic.Platform.setPlatform('ANDROID');253 expect(ionic.Platform.is('android')).toEqual(true);254 ionic.Platform.setPlatform('android');255 expect(ionic.Platform.is('android')).toEqual(true);256 ionic.Platform.setPlatform('ios');257 expect(ionic.Platform.is('android')).toEqual(false);258 });259 it('is iOS', function() {260 ionic.Platform.setPlatform('iOs');261 expect(ionic.Platform.is('ios')).toEqual(true);262 ionic.Platform.setPlatform('iOs');263 expect(ionic.Platform.is('IOS')).toEqual(true);264 ionic.Platform.setPlatform('IOS');265 expect(ionic.Platform.is('ios')).toEqual(true);266 ionic.Platform.setPlatform('IOS');267 expect(ionic.Platform.is('android')).toEqual(false);268 });269 it('should be all platforms for ios', function() {270 window.cordova = {};271 ionic.Platform.setPlatform('iOS');272 ionic.Platform.setVersion('7.1.4');273 ionic.Platform._checkPlatforms();274 expect(ionic.Platform.is('ios')).toEqual(true);275 expect(ionic.Platform.is('ios7')).toEqual(true);276 expect(ionic.Platform.is('ios7_1')).toEqual(true);277 expect(ionic.Platform.is('cordova')).toEqual(true);278 expect(ionic.Platform.is('android')).toEqual(false);279 });280 it('should register/deregister a hardware back button action and add it to $ionicPlatform.backButtonActions', function() {281 var deregisterFn = ionicPlatform.registerBackButtonAction(function(){});282 expect( Object.keys( ionicPlatform.$backButtonActions ).length ).toEqual(1);283 deregisterFn();284 expect( Object.keys( ionicPlatform.$backButtonActions ).length ).toEqual(0);285 });286 it('should register multiple back button actions and only call the highest priority on hardwareBackButtonClick', function() {...
PokemonCard.js
Source:PokemonCard.js
...109 const [version, setVersion] = useState('');110 useEffect(() => {111 if (species?.id < 152) {112 setGame('yellow');113 setVersion('yellow');114 } else if (species?.id > 151 && species?.id < 252) {115 setGame('crystal');116 setVersion('crystal');117 } else if (species?.id > 251 && species?.id < 387) {118 setGame('emerald');119 setVersion('emerald');120 } else if (species?.id > 386 && species?.id < 494) {121 setGame('platinum');122 setVersion('platinum');123 } else if (species?.id > 493 && species?.id < 650) {124 setGame('black-2');125 setVersion('black-2-white-2');126 } else if (species?.id > 649 && species?.id < 722) {127 setGame('x');128 setVersion('x-y');129 } else if (species?.id > 721 && species?.id < 810) {130 setGame('ultra-sun');131 setVersion('ultra-sun-ultra-moon');132 } else if (species?.id > 809 && species?.id < 898) {133 setGame('sword');134 setVersion('sword-shield');135 }136 }, [species])137 const [toggleState, setToggleState] = useState(1);138 const toggleTable = (index) => {139 setToggleState(index);140 };141 const [toggleType, setToggleType] = useState(1);142 const toggleTypeTable = (index) => {143 setToggleType(index);144 };145 const title = `${name.replace(/-/g, ' ')}`;146 useEffect(() => {147 document.title = `${148 title.charAt(0).toUpperCase() + title.slice(1)149 } | Pokémon | PokéInfo`;150 }, [title]);151 return (152 <MainBig>153 {loading ? (154 <BarWave width='40px' height='20px' color='#cc0000' />155 ) : (156 <>157 {pokemon?.name?.includes('mega') ? (158 <PokemonTitle>159 {pokemon?.name?.replace(/-/g, ' ').split(' ').reverse().join(' ')}160 </PokemonTitle>161 ) : (162 <PokemonTitle>{pokemon?.name?.replace(/-/g, ' ')}</PokemonTitle>163 )}164 <PokemonSubtitle>165 {species?.generation?.name?.replace(/-/g, ' ')}166 </PokemonSubtitle>167 <GenNav>168 <ol>169 {(pokemon?.id < 152 || species?.id < 152) && (170 <li>171 <button>Gen I</button>172 <div>173 <button174 onClick={() => {175 setGame('red');176 setVersion('red-blue');177 }}178 >179 Red180 </button>181 <button182 onClick={() => {183 setGame('blue');184 setVersion('red-blue');185 }}186 >187 Blue188 </button>189 <button190 onClick={() => {191 setGame('yellow');192 setVersion('yellow');193 }}194 >195 Yellow196 </button>197 </div>198 </li>199 )}200 {(pokemon?.id < 252 || species?.id < 252) && (201 <li>202 <button>Gen II</button>203 <div>204 <button205 onClick={() => {206 setGame('gold');207 setVersion('gold-silver');208 }}209 >210 Gold211 </button>212 <button213 onClick={() => {214 setGame('silver');215 setVersion('gold-silver');216 }}217 >218 Silver219 </button>220 <button221 onClick={() => {222 setGame('crystal');223 setVersion('crystal');224 }}225 >226 Crystal227 </button>228 </div>229 </li>230 )}231 {(pokemon?.id < 387 || species?.id < 387) && (232 <li>233 <button>Gen III</button>234 <div>235 <button236 onClick={() => {237 setGame('ruby');238 setVersion('ruby-sapphire');239 }}240 >241 Ruby242 </button>243 <button244 onClick={() => {245 setGame('sapphire');246 setVersion('rub-sapphire');247 }}248 >249 Sapphire250 </button>251 <button252 onClick={() => {253 setGame('emerald');254 setVersion('emerald');255 }}256 >257 Emerald258 </button>259 <button260 onClick={() => {261 setGame('firered');262 setVersion('firered-leafgreen');263 }}264 >265 Fire Red266 </button>267 <button268 onClick={() => {269 setGame('leafgreen');270 setVersion('firered-leafgreen');271 }}272 >273 Leaf Green274 </button>275 </div>276 </li>277 )}278 {(pokemon?.id < 494 || species?.id < 494) && (279 <li>280 <button>Gen IV</button>281 <div>282 <button283 onClick={() => {284 setGame('diamond');285 setVersion('diamond-pearl');286 }}287 >288 Diamond289 </button>290 <button291 onClick={() => {292 setGame('pearl');293 setVersion('diamond-pearl');294 }}295 >296 Pearl297 </button>298 <button299 onClick={() => {300 setGame('platinum');301 setVersion('platinum');302 }}303 >304 Platinum305 </button>306 <button307 onClick={() => {308 setGame('heartgold');309 setVersion('heartgold-soulsilver');310 }}311 >312 Heart Gold313 </button>314 <button315 onClick={() => {316 setGame('soulsilver');317 setVersion('heartgold-soulsilver');318 }}319 >320 Soul Silver321 </button>322 </div>323 </li>324 )}325 {(pokemon?.id < 650 || species?.id < 650) && (326 <li>327 <button>Gen V</button>328 <div>329 <button330 onClick={() => {331 setGame('black');332 setVersion('black-white');333 }}334 >335 Black336 </button>337 <button338 onClick={() => {339 setGame('white');340 setVersion('black-white');341 }}342 >343 White344 </button>345 <button346 onClick={() => {347 setGame('black-2');348 setVersion('black-2-white-2');349 }}350 >351 Black 2352 </button>353 <button354 onClick={() => {355 setGame('white-2');356 setVersion('black-2-white-2');357 }}358 >359 White 2360 </button>361 </div>362 </li>363 )}364 {(pokemon?.id < 722 || species?.id < 722) && (365 <li>366 <button>Gen VI</button>367 <div>368 <button369 onClick={() => {370 setGame('x');371 setVersion('x-y');372 }}373 >374 X375 </button>376 <button377 onClick={() => {378 setGame('y');379 setVersion('x-y');380 }}381 >382 Y383 </button>384 <button385 onClick={() => {386 setGame('omega-ruby');387 setVersion('omega-ruby-alpha-sapphire');388 }}389 >390 Omega Ruby391 </button>392 <button393 onClick={() => {394 setGame('alpha-sapphire');395 setVersion('omega-ruby-alpha-sapphire');396 }}397 >398 Alpha Sapphire399 </button>400 </div>401 </li>402 )}403 {(pokemon?.id < 810 || species?.id < 810) && (404 <li>405 <button>Gen VII</button>406 <div>407 <button408 onClick={() => {409 setGame('sun');410 setVersion('sun-moon');411 }}412 >413 Sun414 </button>415 <button416 onClick={() => {417 setGame('moon');418 setVersion('sun-moon');419 }}420 >421 Moon422 </button>423 <button424 onClick={() => {425 setGame('ultra-sun');426 setVersion('ultra-sun-ultra-moon');427 }}428 >429 Ultra Sun430 </button>431 <button432 onClick={() => {433 setGame('ultra-moon');434 setVersion('ultra-sun-ultra-moon');435 }}436 >437 Ultra Moon438 </button>439 <button440 onClick={() => {441 setGame('lets-go-pikachu');442 setVersion('lets-go-pikachu-lets-go-eevee');443 }}444 >445 Let's Go Pikachu446 </button>447 <button448 onClick={() => {449 setGame('lets-go-eevee');450 setVersion('lets-go-pikachu-lets-go-eevee');451 }}452 >453 Let's Go Eevee454 </button>455 </div>456 </li>457 )}458 {(pokemon?.id < 899 || species?.id < 899) && (459 <li>460 <button>Gen VIII</button>461 <div>462 <button463 onClick={() => {464 setGame('sword');465 setVersion('sword-shield');466 }}467 >468 Sword469 </button>470 <button471 onClick={() => {472 setGame('shield');473 setVersion('sword-shield');474 }}475 >476 Shield477 </button>478 </div>479 </li>480 )}481 </ol>482 </GenNav>483 <Data484 pokemon={pokemon}485 species={species}486 location={location}487 game={game}...
open-close-version.js
Source:open-close-version.js
...25 this.handle.close();26 };27 this.setVersion = function(opts) {28 self.steps.push(evalAndLog("'" + id + ".setVersion'"));29 var req = this.handle.setVersion(String(self.ver++));30 req.onabort = function (e) {31 self.steps.push(evalAndLog("'" + id + ".setVersion.onabort'"));32 if (opts && opts.onabort) { opts.onabort.call(that); }33 };34 req.onblocked = function (e) {35 self.steps.push(evalAndLog("'" + id + ".setVersion.onblocked'"));36 if (opts && opts.onblocked) { opts.onblocked.call(that); }37 };38 req.onsuccess = function (e) {39 self.steps.push(evalAndLog("'" + id + ".setVersion.onsuccess'"));40 if (that.handle.objectStoreNames.contains("test-store" + self.ver)) {41 that.handle.deleteObjectStore("test-store" + self.ver);42 }43 var store = that.handle.createObjectStore("test-store" + self.ver);44 var count = 0;45 do_async_puts(); // Keep this transaction running for a while46 function do_async_puts() {47 var req = store.put(count, count);48 req.onerror = unexpectedErrorCallback;49 req.onsuccess = function (e) {50 if (++count < 10) {51 do_async_puts();52 } else {53 self.steps.push(evalAndLog("'" + id + ".setVersion.transaction-complete'"));54 if (opts && opts.onsuccess) { opts.onsuccess.call(that); }55 }56 };57 }58 };59 req.onerror = function (e) {60 self.steps.push(evalAndLog("'" + id + ".setVersion.onerror'"));61 if (opts && opts.onerror) { opts.onerror.call(that); }62 };63 };64}65// run a series of steps that take a continuation function66function runSteps(commands) {67 if (commands.length) {68 var command = commands.shift();69 command(function() { runSteps(commands); });70 }71}72function test() {73 removeVendorPrefixes();74 test1();75}76function test1() {77 debug("");78 debug("TEST: setVersion blocked on open handles");79 evalAndLog("self.dbname = 'test1'; self.ver = 1; self.steps = []");80 var h1 = new Connection("h1");81 var h2 = new Connection("h2");82 runSteps([function(doNext) { h1.open({onsuccess: doNext}); },83 function(doNext) { h2.open({onsuccess: doNext,84 onversion: function() {85 debug(" h2 closing, but not immediately");86 setTimeout(function() { h2.close(); }, 0);87 }}); },88 function(doNext) { h1.setVersion({onsuccess: finishTest}); },89 ]);90 function finishTest() {91 shouldBeEqualToString("self.steps.toString()",92 ["h1.open",93 "h1.open.onsuccess",94 "h2.open",95 "h2.open.onsuccess",96 "h1.setVersion",97 "h2.onversionchange",98 "h1.setVersion.onblocked",99 "h2.close",100 "h1.setVersion.onsuccess",101 "h1.setVersion.transaction-complete"102 ].toString());103 test2();104 }105}106function test2() {107 debug("");108 debug("TEST: setVersion not blocked if handle closed immediately");109 evalAndLog("self.dbname = 'test2'; self.ver = 1; self.steps = []");110 var h1 = new Connection("h1");111 var h2 = new Connection("h2");112 runSteps([function(doNext) { h1.open({onsuccess: doNext}); },113 function(doNext) { h2.open({onsuccess: doNext,114 onversion: function() {115 debug(" h2 closing immediately");116 h2.close();117 }}); },118 function(doNext) { h1.setVersion({onsuccess: doNext}); },119 finishTest120 ]);121 function finishTest() {122 debug("NOTE: Will FAIL with extra bogus h1.setVersion.onblocked step; https://bugs.webkit.org/show_bug.cgi?id=71130");123 shouldBeEqualToString("self.steps.toString()",124 ["h1.open",125 "h1.open.onsuccess",126 "h2.open",127 "h2.open.onsuccess",128 "h1.setVersion",129 "h2.onversionchange",130 "h2.close",131 "h1.setVersion.onsuccess",132 "h1.setVersion.transaction-complete"133 ].toString());134 test3();135 }136}137function test3() {138 debug("");139 debug("TEST: open and setVersion blocked if a VERSION_CHANGE transaction is running - close when blocked");140 evalAndLog("self.dbname = 'test3'; self.ver = 1; self.steps = []");141 var h1 = new Connection("h1");142 var h2 = new Connection("h2");143 var h3 = new Connection("h3");144 runSteps([function(doNext) { h1.open({onsuccess: doNext}); },145 function(doNext) { h2.open({onsuccess: doNext}); },146 function(doNext) { h1.setVersion(); doNext(); },147 function(doNext) { h2.setVersion({148 onblocked: function() {149 debug(" h2 blocked so closing");150 h2.close();151 doNext();152 }}); },153 function() { h3.open({onsuccess: finishTest});}154 ]);155 function finishTest() {156 shouldBeEqualToString("self.steps.toString()",157 ["h1.open",158 "h1.open.onsuccess",159 "h2.open",160 "h2.open.onsuccess",161 "h1.setVersion",162 "h2.setVersion",163 "h2.onversionchange",164 "h1.setVersion.onblocked",165 "h1.onversionchange",166 "h2.setVersion.onblocked",167 "h2.close",168 "h3.open",169 "h2.setVersion.onerror",170 "h1.setVersion.onsuccess",171 "h1.setVersion.transaction-complete",172 "h3.open.onsuccess"173 ].toString());174 test4();175 }176}177function test4() {178 debug("");179 debug("TEST: open and setVersion blocked if a VERSION_CHANGE transaction is running - just close");180 evalAndLog("self.dbname = 'test4'; self.ver = 1; self.steps = []");181 var h1 = new Connection("h1");182 var h2 = new Connection("h2");183 var h3 = new Connection("h3");184 runSteps([function(doNext) { h1.open({onsuccess: doNext}); },185 function(doNext) { h2.open({onsuccess: doNext}); },186 function(doNext) { h1.setVersion(); doNext(); },187 function(doNext) { h3.open({onsuccess: finishTest}); doNext(); },188 function(doNext) { h2.close(); },189 ]);190 function finishTest() {191 debug("NOTE: Will FAIL with extra bogus h1.setVersion.onblocked step; https://bugs.webkit.org/show_bug.cgi?id=71130");192 shouldBeEqualToString("self.steps.toString()",193 ["h1.open",194 "h1.open.onsuccess",195 "h2.open",196 "h2.open.onsuccess",197 "h1.setVersion",198 "h3.open",199 "h2.close",200 "h1.setVersion.onsuccess",201 "h1.setVersion.transaction-complete",202 "h3.open.onsuccess"203 ].toString());204 test5();205 }206}207function test5() {208 debug("");209 debug("TEST: open blocked if a VERSION_CHANGE transaction is running");210 evalAndLog("self.dbname = 'test5'; self.ver = 1; self.steps = []");211 var h1 = new Connection("h1");212 var h2 = new Connection("h2");213 runSteps([function(doNext) { h1.open({onsuccess: doNext}); },214 function(doNext) { h1.setVersion(); doNext(); },215 function(doNext) { h2.open({onsuccess: finishTest}); }216 ]);217 function finishTest() {218 shouldBeEqualToString("self.steps.toString()",219 ["h1.open",220 "h1.open.onsuccess",221 "h1.setVersion",222 "h2.open",223 "h1.setVersion.onsuccess",224 "h1.setVersion.transaction-complete",225 "h2.open.onsuccess"226 ].toString());227 test6();228 }229}230function test6() {231 debug("");232 debug("TEST: two setVersions from the same connection");233 evalAndLog("self.dbname = 'test6'; self.ver = 1; self.steps = []");234 var h1 = new Connection("h1");235 runSteps([function(doNext) { h1.open({onsuccess: doNext}); }, 236 function(doNext) { h1.setVersion({onsuccess: halfDone}); 237 h1.setVersion({onsuccess: halfDone}); }238 ]);239 var counter = 0;240 function halfDone() {241 counter++;242 if (counter < 2) {243 debug('half done');244 } else {245 finishTest();246 }247 } 248 function finishTest() {249 shouldBeEqualToString("self.steps.toString()",250 ["h1.open",251 "h1.open.onsuccess",...
idb.js
Source:idb.js
...54 self.instance.stores.idb = idb.db;55 }56 // New way to do it57 if ( idb.open.onupgradeneeded === null ) {58 request = setVersion(function() {59 createObjectStore( name );60 }, this.instance );61 request.done(function() {62 self.def.resolve();63 });64 request.fail( reject );65 // Old way66 } else {67 // If db exist than just update it68 if ( idb.db ) {69 update( this );70 }71 // This will not execute if db already exist72 (request = idb.open).addEventListener( "success", function() {73 // Create link in jar for new db74 self.instance.stores.idb = idb.db = this.result;75 update( self );76 });77 request.addEventListener( "error", reject );78 }79 return this;80 }81 };82 proto.init.prototype = proto;83 this.idb.set = function( name, data, type, id ) {84 var request, store,85 self = this;86 // We can't store DOM nodes87 if ( cantStore[ type ] ) {88 data = jar.text[ type ]( data );89 }90 data = {91 name: name,92 data: data93 };94 try {95 store = idb.db.transaction([ this.name ], readwrite ).objectStore( this.name );96 // Use "put", so we can rewrite data97 request = store.put( data );98 } catch ( _ ) {99 jar.reject( id );100 return this;101 }102 request.onsuccess = function() {103 jar.resolve( id, type, "idb" );104 };105 request.onerror = function() {106 jar.reject( id );107 };108 return this;109 };110 this.idb.get = function( name, type, id ) {111 var store, index, request,112 self = this;113 try {114 store = idb.db.transaction([ this.name ], readonly ).objectStore( this.name );115 index = store.index( "name" );116 request = index.get( name );117 } catch ( _ ) {118 jar.reject( id );119 return this;120 }121 request.onsuccess = function() {122 var data = this.result && this.result.data;123 // When data isn't there its still succesfull operation for this api, but not for jar124 if ( !data ) {125 return jar.reject( id );126 }127 // IndexedDB can't store some types of data in it original type128 // we need to serialize it to right type129 if ( cantStore[ type ] ) {130 data = jar.filters[ type ]( data );131 }132 // Some types of data can't be serialize to right type133 // like javascript code, so instead we return it like text134 // and execute it135 if ( executable[ type ] ) {136 data = jar.filters[ type ]( data );137 }138 jar.resolve( id, data, type, "idb" );139 };140 request.onerror = function() {141 jar.reject( id );142 };143 return this;144 };145 this.idb.remove = function( name, id ) {146 var request, store,147 self = this;148 try {149 store = idb.db.transaction([ this.name ], readwrite ).objectStore( this.name );150 // Even though IE < 10 don't used this storage, it still raises exception151 // if we use delete method through dot notaion while parsing this code152 request = store[ "delete" ]( name );153 } catch ( _ ) {154 jar.reject( id );155 return this;156 }157 request.onsuccess = function() {158 jar.resolve( id );159 };160 request.onerror = function() {161 jar.reject( id );162 };163 return this;164 };165 this.idb.clear = function( id, destroy /* internal */ ) {166 var request, store, clear,167 stores = this.stores,168 self = this,169 name = this.name;170 function resolve() {171 jar.resolve( id );172 }173 function reject() {174 jar.reject( id );175 }176 // Either clear or destroy177 if ( destroy ) {178 request = setVersion(function() {179 if ( contains( name ) ) {180 idb.db.deleteObjectStore( name );181 }182 }, this );183 } else {184 if ( contains( name ) ) {185 store = idb.db.transaction([ name ], readwrite ).objectStore( name );186 clear = store.clear();187 clear.addEventListener( "success", resolve );188 clear.addEventListener( "error", reject );189 return this;190 } else {191 resolve();192 return this;193 }194 }195 request.done( resolve ).fail( reject );196 return this;197 };198 function setVersion( success, instance, v ) {199 v = v || jar.Deferred();200 var state;201 // Old way to set database version202 if ( idb.db && idb.db.setVersion ) {203 state = idb.v && idb.v.state();204 // If we have active request â attach to it, if not â create new one205 if ( !idb.setVersion || idb.setVersion.readyState == "done" ) {206 // readystate might be "done", but it just means that versionchange transaction207 // was succesfull, it does not mean it was completed (wtf right?),208 // our deferred will be resolved only when everything is done209 if ( state != "pending" ) {210 idb.setVersion = idb.db.setVersion( version() );211 } else {212 idb.v.done(function() {213 setVersion( success, instance, v );214 });215 // we should not do anything until versionchange transaction is not completed216 return v;217 }218 }219 idb.setVersion.addEventListener( "success", function() {220 instance.stores.idb = idb.db = this.source;221 // We can change store only in versionchange transaction222 success();223 this.result.addEventListener( "complete", function() {224 // But we cannot change version of base until it's not completed225 v.resolve();226 });227 });228 } else {229 if ( idb.open.readyState == "pending" ) {230 idb.setVersion = idb.open;231 } else {232 idb.setVersion = indexedDB.open( "jar", version() );233 }234 idb.setVersion.addEventListener( "upgradeneeded", function() {235 instance.stores.idb = idb.db = this.result;236 success.apply( this, arguments );237 idb.setVersion.addEventListener( "success", function() {238 v.resolve();239 });240 });241 }242 idb.setVersion.addEventListener( "success", function() {243 this.result.onversionchange = function() {244 this.close();245 };246 });247 idb.setVersion.addEventListener( "blocked", function() {248 if ( idb.db ) {249 idb.db.close();250 }251 });252 idb.setVersion.addEventListener( "error", function( a,b ) {253 v.reject();254 });255 return idb.v = v;256 }257 function update( instance ) {258 var request = setVersion(function() {259 createObjectStore( instance.name );260 }, instance.instance );261 request.done(function() {262 instance.def.resolve();263 }).fail(function() {264 instance.def.reject();265 });266 }267 function contains( name ) {268 return idb.db.objectStoreNames.contains( name );269 }270 function createObjectStore( name ) {271 if ( !contains( name ) ) {272 idb.db.createObjectStore( name, {...
factory-deletedatabase-interactions.js
Source:factory-deletedatabase-interactions.js
...27 this.handle.close();28 };29 this.setVersion = function(opts) {30 self.steps.push(evalAndLog("'" + id + ".setVersion'"));31 var req = this.handle.setVersion(String(self.ver++));32 req.onabort = function (e) {33 self.steps.push(evalAndLog("'" + id + ".setVersion.onabort'"));34 if (opts && opts.onabort) { opts.onabort.call(that); }35 };36 req.onblocked = function (e) {37 self.steps.push(evalAndLog("'" + id + ".setVersion.onblocked'"));38 if (opts && opts.onblocked) { opts.onblocked.call(that); }39 };40 req.onsuccess = function (e) {41 self.steps.push(evalAndLog("'" + id + ".setVersion.onsuccess'"));42 if (that.handle.objectStoreNames.contains("test-store" + self.ver)) {43 that.handle.deleteObjectStore("test-store" + self.ver);44 }45 var store = that.handle.createObjectStore("test-store" + self.ver);46 var count = 0;47 do_async_puts(); // Keep this transaction running for a while48 function do_async_puts() {49 var req = store.put(count, count);50 req.onerror = unexpectedErrorCallback;51 req.onsuccess = function (e) {52 if (++count < 10) {53 do_async_puts();54 } else {55 self.steps.push(evalAndLog("'" + id + ".setVersion.transaction-complete'"));56 if (opts && opts.onsuccess) { opts.onsuccess.call(that); }57 }58 };59 }60 };61 req.onerror = function (e) {62 self.steps.push(evalAndLog("'" + id + ".setVersion.onerror'"));63 if (opts && opts.onerror) { opts.onerror.call(that); }64 };65 };66}67function deleteDatabase(id, name, opts) {68 self.steps.push(evalAndLog("'deleteDatabase(" + id + ")'"));69 var req = indexedDB.deleteDatabase(dbprefix + name);70 req.onsuccess = function (e) {71 self.steps.push(evalAndLog("'deleteDatabase(" + id + ").onsuccess'"));72 if (opts && opts.onsuccess) { opts.onsuccess.call(null); }73 };74 req.onerror = function (e) {75 self.steps.push(evalAndLog("'deleteDatabase(" + id + ").onerror'"));76 if (opts && opts.onerror) { opts.onerror.call(null); }77 };78 req.onblocked = function (e) {79 self.steps.push(evalAndLog("'deleteDatabase(" + id + ").onblocked'"));80 if (opts && opts.onblocked) { opts.onblocked.call(null); }81 };82}83// run a series of steps that take a continuation function84function runSteps(commands) {85 if (commands.length) {86 var command = commands.shift();87 command(function() { runSteps(commands); });88 }89}90function test() {91 removeVendorPrefixes();92 test1();93}94function test1() {95 debug("");96 debug("TEST: deleteDatabase blocked on open handles");97 evalAndLog("self.dbname = 'test1'; self.ver = 1; self.steps = []");98 var h = new Connection("h");99 runSteps([function(doNext) { h.open({onsuccess: doNext,100 onversion: function() {101 debug(" h closing, but not immediately");102 setTimeout(function() { h.close(); }, 0);103 }}); },104 function(doNext) { deleteDatabase("", self.dbname, {105 onsuccess: finishTest}); },106 ]);107 function finishTest() {108 shouldBeEqualToString("self.steps.toString()",109 ["h.open",110 "h.open.onsuccess",111 "deleteDatabase()",112 "h.onversionchange",113 "deleteDatabase().onblocked",114 "h.close",115 "deleteDatabase().onsuccess"116 ].toString());117 test2();118 }119}120function test2() {121 debug("");122 debug("TEST: deleteDatabase not blocked when handles close immediately");123 evalAndLog("self.dbname = 'test2'; self.ver = 1; self.steps = []");124 var h = new Connection("h");125 runSteps([function(doNext) { h.open({onsuccess: doNext,126 onversion: function() {127 debug(" h closing immediately");128 h.close();129 }}); },130 function(doNext) { deleteDatabase("", self.dbname, {131 onsuccess: finishTest}); },132 ]);133 function finishTest() {134 debug("NOTE: Will FAIL with extra bogus deleteDatabase().onblocked step; https://bugs.webkit.org/show_bug.cgi?id=71130");135 shouldBeEqualToString("self.steps.toString()",136 ["h.open",137 "h.open.onsuccess",138 "deleteDatabase()",139 "h.onversionchange",140 "h.close",141 "deleteDatabase().onsuccess"142 ].toString());143 test3();144 }145}146function test3() {147 debug("");148 debug("TEST: deleteDatabase is delayed if a VERSION_CHANGE transaction is running");149 evalAndLog("self.dbname = 'test3'; self.ver = 1; self.steps = []");150 var h = new Connection("h");151 runSteps([function(doNext) { h.open({onsuccess: doNext,152 onversion: function() {153 debug(" h closing, but not immediately");154 setTimeout(function() { h.close(); }, 0);155 }}); },156 function(doNext) { h.setVersion(); doNext(); },157 function(doNext) { deleteDatabase("", self.dbname,158 {onsuccess: finishTest}); },159 ]);160 function finishTest() {161 shouldBeEqualToString("self.steps.toString()",162 ["h.open",163 "h.open.onsuccess",164 "h.setVersion",165 "deleteDatabase()",166 "h.setVersion.onsuccess",167 "h.setVersion.transaction-complete",168 "h.onversionchange",169 "deleteDatabase().onblocked",170 "h.close",171 "deleteDatabase().onsuccess"172 ].toString());173 test4();174 }175}176function test4() {177 debug("");178 debug("TEST: Correct order when there are pending setVersion, delete and open calls.");179 evalAndLog("self.dbname = 'test4'; self.ver = 1; self.steps = []");180 var h = new Connection("h");181 var h2 = new Connection("h2");182 var h3 = new Connection("h3");183 runSteps([function(doNext) { h.open({onsuccess: doNext,184 onversion: function() {185 debug(" h closing, but not immediately");186 setTimeout(function() { h.close(); }, 0);187 }});188 },189 function(doNext) { h2.open({onsuccess: doNext}); },190 function(doNext) { h.setVersion({onblocked: function() {191 h3.open({onsuccess: finishTest});192 h2.close();193 }});194 doNext();195 },196 function(doNext) { deleteDatabase("", self.dbname); },197 ]);198 function finishTest() {199 shouldBeEqualToString("self.steps.toString()",200 ["h.open",201 "h.open.onsuccess",202 "h2.open",203 "h2.open.onsuccess",204 "h.setVersion",...
doc.js
Source:doc.js
...40 };41 }));42 describe('#canStart', function () {43 it('can if the doc is unknown', function () {44 setVersion(undefined, undefined);45 expect(req.canStart()).to.be(true);46 });47 it('cannot if the doc is unknown but the request is already in progress', function () {48 setVersion(undefined, undefined);49 req.start();50 expect(req.canStart()).to.be(false);51 });52 it('can if the doc is out of date', function () {53 setVersion(1, 2);54 expect(req.canStart()).to.be(true);55 });56 it('can if the doc is out of date and the request is in progress', function () {57 setVersion(1, 2);58 req.start();59 expect(req.canStart()).to.be(true);60 });61 it('cannot if the doc is up to date', function () {62 setVersion(2, 2);63 expect(req.canStart()).to.be(false);64 });65 it('can if the doc is overdated', function () {66 setVersion(5, 2);67 expect(req.canStart()).to.be(true);68 });69 it('can if shared version is cleared', function () {70 setVersion(10, undefined);71 expect(req.canStart()).to.be(true);72 });73 it('can if everyone else has a doc', function () {74 setVersion(undefined, 10);75 expect(req.canStart()).to.be(true);76 });77 });...
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.setVersion('1.2.3');7 await page.screenshot({ path: 'example.png' });8 await browser.close();9})();10import { chromium } from 'playwright';11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page.setVersion('1.2.3');16 await page.screenshot({ path: 'example.png' });17 await browser.close();18})();19#### **`page.setExtraHTTPHeaders(headers)`**20const playwright = require('playwright');21(async () => {22 const browser = await playwright.chromium.launch();23 const context = await browser.newContext();24 const page = await context.newPage();25 await page.setExtraHTTPHeaders({26 });27 await page.screenshot({ path: 'example.png' });28 await browser.close();29})();30import { chromium } from 'playwright';31(async () => {32 const browser = await chromium.launch();33 const context = await browser.newContext();
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.setVersion('1.2.3');7 await browser.close();8})();9 at Page.setVersion (/Users/username/Documents/Playwright/playwright-internal-api/node_modules/playwright/lib/client/page.js:1021:13)10 at processTicksAndRejections (internal/process/task_queues.js:93:5)11 at async Object.<anonymous> (/Users/username/Documents/Playwright/playwright-internal-api/test.js:9:5)
Using AI Code Generation
1const playwright = require('playwright');2(async () => {3 const browser = await playwright.chromium.launch();4 const page = await browser.newPage();5 await browser.close();6})();7const playwright = require('playwright');8(async () => {9 const browser = await playwright.chromium.launch();10 const page = await browser.newPage();11 await browser.close();12})();13const playwright = require('playwright');14(async () => {15 const browser = await playwright.chromium.launch();16 const page = await browser.newPage();17 await browser.close();18})();19const playwright = require('playwright');20(async () => {21 const browser = await playwright.chromium.launch();22 const page = await browser.newPage();23 await browser.close();24})();25const playwright = require('playwright');26(async () => {27 const browser = await playwright.chromium.launch();28 const page = await browser.newPage();29 await browser.close();30})();31const playwright = require('playwright');32(async () => {33 const browser = await playwright.chromium.launch();34 const page = await browser.newPage();35 await browser.close();36})();37const playwright = require('playwright');38(async () => {39 const browser = await playwright.chromium.launch();40 const page = await browser.newPage();41 await browser.close();42})();43const playwright = require('playwright');44(async () => {45 const browser = await playwright.chromium.launch();46 const page = await browser.newPage();47 await browser.close();48})();49const playwright = require('playwright');
Using AI Code Generation
1const { setVersion } = require('playwright/lib/server/browserType');2setVersion('chromium', '1.2.3');3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 await browser.close();7})();8const { setVersion } = require('playwright/lib/server/browserType');9setVersion('chromium', '1.2.3');10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 await browser.close();14})();15const { setVersion } = require('playwright/lib/server/browserType');16setVersion('chromium', '1.2.3');17const { chromium } = require('playwright');18(async () => {19 const browser = await chromium.launch();20 await browser.close();21})();22const { setVersion } = require('playwright/lib/server/browserType');23setVersion('chromium', '1.2.3');24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 await browser.close();28})();29const { setVersion } = require('playwright/lib/server/browserType');30setVersion('chromium', '1.2.3');31const { chromium } = require('playwright');32(async () => {33 const browser = await chromium.launch();34 await browser.close();35})();36const { setVersion } = require('playwright/lib/server/browserType');37setVersion('chromium', '1.2.3');38const { chromium } = require('playwright');39(async () => {40 const browser = await chromium.launch();41 await browser.close();42})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({4 });5 await browser.setVersion('87.0.4280.66');6 const context = await browser.newContext();7 const page = await context.newPage();8 await page.screenshot({ path: `example.png` });9 await browser.close();10})();11const { chromium } = require('playwright');12(async () => {13 const browser = await chromium.launch({14 });15 await browser.setPath('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome');16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.screenshot({ path: `example.png` });19 await browser.close();20})();21const { chromium } = require('playwright');22(async () => {23 const browser = await chromium.launch({24 });25 await browser.setExecutablePath('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome');
Using AI Code Generation
1const playwright = require('playwright');2const { setVersion } = require('playwright/lib/server/registry');3const browser = await playwright.chromium.launch();4setVersion('chromium', '1234');5await browser.close();6const playwright = require('playwright');7const { setVersion } = require('playwright/lib/server/registry');8const browser = await playwright.chromium.launch();9setVersion('chromium', '1234');10await browser.close();11const playwright = require('playwright');12const { setVersion } = require('playwright/lib/server/registry');13const browser = await playwright.chromium.launch();14setVersion('chromium', '1234');15await browser.close();16const playwright = require('playwright');17const browser = await playwright.chromium.launch();18const browserVersion = await browser.version();19console.log(browserVersion);20await browser.close();21const playwright = require('playwright');22const browser = await playwright.chromium.launch();23const browserVersion = await browser.version();24console.log(browserVersion);25await browser.close();26const playwright = require('playwright');27const browser = await playwright.chromium.launch();28const browserVersion = await browser.version();29console.log(browserVersion);30await browser.close();31const playwright = require('playwright');32const browser = await playwright.chromium.launch();33const browserVersion = await browser.version();34console.log(browserVersion);35await browser.close();36const playwright = require('playwright');37const browser = await playwright.chromium.launch();38const browserVersion = await browser.version();39console.log(browserVersion);40await browser.close();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!