How to use keys method in Molotov

Best Python code snippet using molotov_python

keycapture_js_spec.js

Source:keycapture_js_spec.js Github

copy

Full Screen

1/**2 * @author: Steve Sutton, Ben Kennedy3 */4describe("KeyCapture JS API", function()5{6 beforeEach(function()7 {8 hardwareKeysTest.callbackFired = false;9 hardwareKeysTest.callbackFiredResult = null;10 hardwareKeysTest.callbackFiredTimeout = null;11 //getpropertiesdata = '';12 });13 14 describe("Setup", function()15 {16 it("0.1.focuses the RhoElements Window", function()17 {18 Rho.Instrumentation.simulate_touch_event(0, 5, 41);19 Rho.Instrumentation.simulate_touch_event(2, 5, 41);20 });21 });22 if (!isWindowsMobilePlatform) //putting check for WM because of issues in instumentation API for WM23 {24 if(!hardwareKeysTest.isAndroid())//Android doesnt do home key it seems25 {26 describe("HomeKey", function()27 {28 ///////////////////////////////////////////////////////////////////////29 // 1. Home key30 ///////////////////////////////////////////////////////////////////////31 it("1.1.should check default value of the Home Key", function()32 {33 expect(Rho.KeyCapture.homeKeyValue).toBe('disabled'); 34 });35 it("1.2.should set the Home Key to ENTER", function()36 {37 Rho.KeyCapture.homeKeyValue = hardwareKeysTest.enterKey.string; 38 expect(Rho.KeyCapture.homeKeyValue).toBe('' + hardwareKeysTest.enterKey.value); // ENTER 39 });40 it("1.3.should set the Home Key to disabled", function()41 {42 Rho.KeyCapture.homeKeyValue = 'disabled';43 expect(Rho.KeyCapture.homeKeyValue).toBe('disabled'); 44 });45 it("1.4.should set the Home Key to disable", function()46 {47 Rho.KeyCapture.homeKeyValue = 'disable';48 expect(Rho.KeyCapture.homeKeyValue).toBe('disabled'); 49 });50 51 it("1.5.should set the Home Key to enabled", function()52 {53 Rho.KeyCapture.homeKeyValue = 'enabled'; 54 expect(Rho.KeyCapture.homeKeyValue).toBe('' + hardwareKeysTest.f5Key.value); // F5 55 });56 57 it("1.6.should set the Home Key to enable", function()58 {59 Rho.KeyCapture.homeKeyValue = 'enable';60 expect(Rho.KeyCapture.homeKeyValue).toBe('' + hardwareKeysTest.f5Key.value); // F5 61 });62 63 //Added By ST//64 /* KeyCapture does not supported PROPERTY_BAG65 it("1.7.(VT289-049)set the Home Key to ENTER with setProperties", function()66 {67 Rho.KeyCapture.setProperties({'homeKeyValue':hardwareKeysTest.enterKey.string})68 Rho.KeyCapture.getProperties(['homeKeyValue'],function(data){getpropertiesdata = JSON.stringify(data);});69 expect(getpropertiesdata).toContain('13');70 });71 it("1.8.(VT289-050)set the Home Key to disabled with setProperty", function()72 {73 Rho.KeyCapture.setProperty('homeKeyValue','Disabled');74 Rho.KeyCapture.getProperty("homeKeyValue",function(data){getpropertiesdata = data;});75 expect(getpropertiesdata).toBe('Disabled'); 76 });*/77 78 it("1.9.(VT289-051)set the Home Key to enabled with setProperty and without callback", function()79 {80 Rho.KeyCapture.homeKeyValue = 'enabled'81 expect(Rho.KeyCapture.homeKeyValue).toBe('' + hardwareKeysTest.f5Key.value); // F5 82 });83 84 /* KeyCapture does not support PROPERTY_BAG85 it("1.10.(VT289-052)check for getallproperties", function() {86 Rho.KeyCapture.homeKeyValue = 'disabled';87 Rho.KeyCapture.getAllProperties(function(data){getpropertiesdata = JSON.stringify(data);});88 expect(getpropertiesdata).toContain('disabled');89 });90 it("1.11.(VT289-053)check for getSupportedProperties", function() {91 Rho.KeyCapture.homeKeyValue = hardwareKeysTest.enterKey.string;92 Rho.KeyCapture.getSupportedProperties(function(data){getpropertiesdata = JSON.stringify(data);});93 expect(getpropertiesdata).toContain('13');94 });*/95 });96 }97 }98 if (!isWindowsMobilePlatform) //putting check for WM because of issues in instumentation API for WM99 { 100 describe("captureKey", function()101 {102 ///////////////////////////////////////////////////////////////////////103 // 2. Key capture104 ///////////////////////////////////////////////////////////////////////105 106 it("2.1.should capture ENTER key when specified with HEX", function()107 {108 runs(function()109 {110 hardwareKeysTest.captureKey(true, hardwareKeysTest.enterKey.string); // ENTER111 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.enterKey.value); // ENTER112 }, "set capture key to ENTER & simulate ENTER key press..."); 113 114 waitsFor(function()115 {116 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.enterKey.value;117 }, "ERROR: Failed to capture ENTER key", 3000);118 119 runs(function()120 {121 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.enterKey.string);122 });123 });124 125 it("2.2.should ignore any other key than ENTER", function()126 {127 runs(function()128 {129 hardwareKeysTest.captureKey(true,hardwareKeysTest.enterKey.string); // ENTER130 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value);131 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);// TAB132 }, "set capture key to ENTER & simulate TAB key press..."); 133 134 waitsFor(function()135 {136 return hardwareKeysTest.callbackFiredResult == 'timedout';137 }, "ERROR: Test setup failed, timeout not occurring", 3000);138 139 runs(function()140 {141 expect(hardwareKeysTest.callbackFired).toBe(false);142 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.enterKey.string);143 }, 'expect the callback not to fire');144 });145 146 it("2.3.should capture any key using a lowercase 'all'", function()147 {148 runs(function()149 {150 hardwareKeysTest.captureKey(true,'all'); // Any Key151 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB152 }, "set capture key to any key & simulate TAB key press..."); 153 154 waitsFor(function()155 {156 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.tabKey.value;157 }, "ERROR: Failed to capture any key", 3000);158 159 runs(function()160 {161 hardwareKeysTest.resetCaptureKeyCallback('all');162 });163 });164 165 it("2.4.should capture any key using an uppercase ALL", function()166 {167 runs(function()168 {169 hardwareKeysTest.captureKey(true,'ALL'); // Any Key170 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB171 }, "set capture key to any key & simulate TAB key press..."); 172 173 waitsFor(function()174 {175 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.tabKey.value;176 }, "ERROR: Failed to capture any key", 3000);177 178 runs(function()179 {180 hardwareKeysTest.resetCaptureKeyCallback('ALL');181 });182 });183 184 it("2.5.should not capture any key after resetting 'all' keyValue keyCapture", function() {185 runs(function()186 {187 hardwareKeysTest.captureKey(true,'ALL'); // Any Key188 hardwareKeysTest.resetCaptureKeyCallback('ALL');189 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB190 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);// TAB191 }, "set capture key to ALL, then reset then press TAB"); 192 193 waitsFor(function()194 {195 return hardwareKeysTest.callbackFiredResult == 'timedout';196 }, "ERROR: Test setup failed, timeout not occurring", 3000);197 198 runs(function()199 {200 expect(hardwareKeysTest.callbackFired).toBe(false); 201 }, 'expect the callback not to fire'); 202 });203 204 it("2.6.should not capture any key after resetting 'all' keyValue keyCapture with mixed letter case", function()205 {206 runs(function()207 {208 hardwareKeysTest.captureKey(true,'ALL'); // Any Key209 hardwareKeysTest.resetCaptureKeyCallback('aLL');210 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB211 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);// TAB212 }, "set capture key to ALL, then reset then press TAB"); 213 214 waitsFor(function()215 {216 return hardwareKeysTest.callbackFiredResult == 'timedout';217 }, "ERROR: Test setup failed, timeout not occurring", 3000);218 219 runs(function()220 {221 expect(hardwareKeysTest.callbackFired).toBe(false); 222 hardwareKeysTest.resetCaptureKeyCallback('ALL');223 }, 'expect the callback not to fire'); 224 });225 226 it("2.7.should capture multiple keys", function()227 {228 runs(function()229 {230 setTimeout(function()231 {232 hardwareKeysTest.captureKey(false,hardwareKeysTest.enterKey.string); 233 hardwareKeysTest.captureKey(false,hardwareKeysTest.tabKey.string);234 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.enterKey.value);235 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value);236 },500);237 },'set capture key for ENTER and TAB and simulate key events');238 239 waitsFor(function()240 {241 if(hardwareKeysTest.callbackFiredResult == null) {return false;}242 if((typeof hardwareKeysTest.callbackFiredResult) != 'object') {return false;}243 if(hardwareKeysTest.callbackFiredResult.length != 2) {return false;}244 else{return true;}245 }, "ERROR: MultipleKeys NOT received", 3000);246 247 runs(function()248 {249 //console.log(hardwareKeysTest.callbackFiredResult[0] + ' = 13');250 //console.log(hardwareKeysTest.callbackFiredResult[1] + ' = 8');251 expect(hardwareKeysTest.callbackFiredResult[0]).toEqual(hardwareKeysTest.enterKey.value);252 expect(hardwareKeysTest.callbackFiredResult[1]).toEqual(hardwareKeysTest.tabKey.value);253 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.enterKey.string);254 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.tabKey.string);255 }, 'expect both callbacks to fire with each keyValues');256 });257 258 it("2.8.should not capture a key after it has been reset", function()259 {260 runs(function()261 {262 hardwareKeysTest.captureKey(true,hardwareKeysTest.tabKey.string); // Any Key263 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.tabKey.string);264 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value);},100); // TAB265 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1100);// TAB266 }, "set capture key to TAB, then reset then press TAB"); 267 268 waitsFor(function()269 {270 return hardwareKeysTest.callbackFiredResult == 'timedout';271 }, "ERROR: Test setup failed, timeout not occurring", 3000);272 273 runs(function()274 {275 expect(hardwareKeysTest.callbackFired).toBe(false);276 }, 'expect the callback not to fire'); 277 });278 279 it("2.9.should only fire 'all' callback if both 'all' and a key has been registered", function()280 {281 runs(function()282 {283 hardwareKeysTest.captureKey(true,'ALL');284 hardwareKeysTest.captureKey(true,hardwareKeysTest.tabKey.string); 285 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value);286 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB287 },"set all captureKey and then " + hardwareKeysTest.tabKey.string + " capture key and fire a " + hardwareKeysTest.tabKey.string + " key press");288 289 waitsFor(function()290 {291 return hardwareKeysTest.callbackFiredTimeout == 'timedout';292 }, "ERROR: Test setup failed, timeout not occurring", 3000); 293 294 runs(function()295 {296 hardwareKeysTest.resetCaptureKeyCallback('ALL');297 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.tabKey.string);298 expect(hardwareKeysTest.callbackFired).toBe(true);299 expect(typeof hardwareKeysTest.callbackFiredResult).toEqual('number');300 }, 'expect the callback to fire only once'); 301 });302 303 it("2.10.should fire 'all' callback if a key specific callback is registered after the all callback is registered (all persistence)", function()304 {305 runs(function()306 {307 hardwareKeysTest.captureKey(true,'ALL');308 hardwareKeysTest.captureKey(true,hardwareKeysTest.enterKey.string); 309 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value);310 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB311 },"set all captureKey and then " + hardwareKeysTest.enterKey.string + " capture key and fire a " + hardwareKeysTest.tabKey.string + " key press");312 waitsFor(function()313 {314 return hardwareKeysTest.callbackFiredTimeout == 'timedout';315 }, "ERROR: Test setup failed, timeout not occurring", 3000); 316 runs(function()317 {318 hardwareKeysTest.resetCaptureKeyCallback('ALL');319 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.enterKey.string);320 expect(hardwareKeysTest.callbackFired).toBe(true);321 expect(hardwareKeysTest.callbackFiredResult).toEqual(hardwareKeysTest.tabKey.value);322 }, 'expect the callback to fire only once'); 323 });324 325 it("2.11.should not obstruct the key event from reaching the page when dispatch is set to true", function()326 {327 runs(function()328 {329 hardwareKeysTest.captureKey(true,hardwareKeysTest.aKey.string);330 hardwareKeysTest.createTextBox();331 hardwareKeysTest.textBox.focus();332 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.aKey.value);333 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB334 }, 'Create a text box, add it to the page and focus it. Setup the ' + hardwareKeysTest.LETTER_A_CODE + ' key capture with dispatch and fire ' + hardwareKeysTest.LETTER_A_CODE + ' key');335 waitsFor(function()336 {337 return hardwareKeysTest.callbackFiredTimeout == 'timedout';338 }, "Callback didnt fire", 3000);339 runs(function()340 {341 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.aKey.string);342 textBoxValue = hardwareKeysTest.textBox.value;343 hardwareKeysTest.removeTextBox();344 expect(hardwareKeysTest.callbackFired).toBe(true);345 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.aKey.value);346 expect(textBoxValue).toEqual(hardwareKeysTest.aKey.description);347 },'expect the key to be input into the input box and the callback to fire');348 });349 350 it("2.12.should obstruct the key event from reaching the page when dispatch is set to false", function()351 {352 runs(function()353 {354 hardwareKeysTest.captureKey(false,hardwareKeysTest.aKey.string);355 hardwareKeysTest.createTextBox();356 hardwareKeysTest.textBox.focus();357 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.aKey.value);358 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB359 }, 'Create a text box, add it to the page and focus it. Setup the ' + hardwareKeysTest.LETTER_A_CODE + ' key capture with dispatch and fire ' + hardwareKeysTest.LETTER_A_CODE + ' key');360 361 waitsFor(function()362 {363 return hardwareKeysTest.callbackFiredTimeout == 'timedout';364 }, "Callback didnt fire", 3000);365 366 runs(function()367 {368 textBoxValue = hardwareKeysTest.textBox.value;369 hardwareKeysTest.removeTextBox();370 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.aKey.string);371 expect(hardwareKeysTest.callbackFired).toBe(true);372 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.aKey.value);373 expect(textBoxValue).toEqual('');374 },'expect the key not to be input into the input box and the callback to fire');375 });376 377 it("2.13.should capture ENTER key when specified with DECIMAL", function()378 {379 runs(function()380 {381 hardwareKeysTest.captureKey(true,'' + hardwareKeysTest.enterKey.value); // ENTER382 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.enterKey.value); // ENTER383 }, "set capture key to ENTER & simulate ENTER key press...");384 waitsFor(function()385 {386 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.enterKey.value;387 }, "ERROR: Failed to capture ENTER key", 3000);388 389 runs(function()390 { 391 hardwareKeysTest.resetCaptureKeyCallback('' + hardwareKeysTest.enterKey.value);392 });393 });394 395 if(hardwareKeysTest.isAndroid())396 {397 it("2.14.should capture P1 (volume down) key", function()398 {399 runs(function()400 {401 hardwareKeysTest.captureKey(false, hardwareKeysTest.volumeDown.string);402 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.volumeDown.value);403 }, 'set capture P1 key and fire P1 key event');404 405 waitsFor(function()406 {407 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.volumeDown.value;408 }, 'ERROR: couldnt catch P1 event',3000);409 runs(function()410 {411 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.volumeDown.string);412 });413 });414 415 it("2.15.should capture P2 (volume up) key", function()416 {417 runs(function()418 {419 hardwareKeysTest.captureKey(false, hardwareKeysTest.volumeUp.string);420 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.volumeUp.value);421 }, 'set capture P2 key and fire P2 key event');422 423 waitsFor(function()424 {425 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.volumeUp.value;426 }, 'ERROR: couldnt catch P2 event',3000);427 428 runs(function()429 {430 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.volumeUp.string);431 });432 });433 it("2.16.should capture P3 (search) key", function()434 {435 runs(function()436 {437 hardwareKeysTest.captureKey(false, hardwareKeysTest.searchKey.string);438 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.searchKey.value);439 }, 'set capture P3 key and fire P3 key event');440 441 waitsFor(function()442 {443 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.searchKey.value;444 }, 'ERROR: couldnt catch P3 event',3000);445 446 runs(function()447 {448 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.searchKey.string);449 });450 });451 452 it("2.17.should capture back key", function()453 {454 runs(function()455 {456 hardwareKeysTest.captureKey(false, hardwareKeysTest.backKey.string);457 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.backKey.value);458 }, 'set capture back key and fire back key event');459 460 waitsFor(function()461 {462 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.backKey.value;463 }, 'ERROR: couldnt catch back event',3000);464 465 runs(function()466 {467 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.backKey.string);468 });469 });470 471 it("2.18.should capture menu key", function()472 {473 runs(function()474 {475 hardwareKeysTest.captureKey(false, hardwareKeysTest.menuKey.string);476 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.menuKey.value);477 }, 'set capture menu key and fire menu key event');478 479 waitsFor(function()480 {481 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.menuKey.value;482 }, 'ERROR: couldnt catch menu event',3000);483 484 runs(function()485 {486 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.menuKey.string);487 });488 });489 }490 491 ///////////////////////////////////////////////////////////////////////492 // converted manual Tests493 ///////////////////////////////////////////////////////////////////////494 it("VT289-011 | call captureKey with dispatch true, keyValue for " +hardwareKeysTest.testKey11.description+" and function callback |", function()495 {496 runs(function()497 {498 //Click inside Textbox and Press numeric key " +hardwareKeysTest.testKey11.description499 hardwareKeysTest.captureKey(true,hardwareKeysTest.testKey11.string);500 hardwareKeysTest.createTextBox();501 hardwareKeysTest.textBox.focus();502 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey11.value);503 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB504 });505 waitsFor(function()506 {507 return hardwareKeysTest.callbackFiredTimeout == 'timedout';508 }, "Callback didnt fire", 3000);509 510 runs(function()511 {512 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey11.string);513 textBoxValue = hardwareKeysTest.textBox.value;514 hardwareKeysTest.removeTextBox();515 expect(hardwareKeysTest.callbackFired).toBe(true);516 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.testKey11.value);517 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey11.description);518 });519 });520 521 it("VT289-012 | call captureKey with dispatch false, keyValue for " +hardwareKeysTest.testKey11.description+" and function callback |", function()522 {523 runs(function()524 {525 hardwareKeysTest.captureKey(false,hardwareKeysTest.testKey11.string);526 hardwareKeysTest.createTextBox();527 hardwareKeysTest.textBox.focus();528 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey11.value);529 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB530 });531 waitsFor(function()532 {533 return hardwareKeysTest.callbackFiredTimeout == 'timedout';534 }, "Callback didnt fire", 3000);535 536 runs(function()537 {538 //Callback should fire with value " +hardwareKeysTest.testKey11.string+" and number " +hardwareKeysTest.testKey11.description+" should not be dispatched inside the textbox539 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey11.string);540 textBoxValue = hardwareKeysTest.textBox.value;541 hardwareKeysTest.removeTextBox();542 expect(hardwareKeysTest.callbackFired).toBe(true);543 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.testKey11.value);544 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual('');545 });546 });547 548 it("VT289-013 | call captureKey with dispatch true, keyValue for" +hardwareKeysTest.testKey13.description+" and no callback(Sync) |", function()549 {550 runs(function()551 {552 //Callback should fire with value " +hardwareKeysTest.testKey13.string+" and " +hardwareKeysTest.testKey13.description+" should be dispatched inside the textbox553 hardwareKeysTest.captureKey(true,hardwareKeysTest.testKey13.string);554 hardwareKeysTest.createTextBox();555 hardwareKeysTest.textBox.focus();556 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey13.value);557 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB558 });559 waitsFor(function()560 {561 return hardwareKeysTest.callbackFiredTimeout == 'timedout';562 }, "Callback didnt fire", 3000);563 564 runs(function()565 {566 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey13.string);567 expect(hardwareKeysTest.callbackFired).toBe(true);568 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.testKey13.value);569 textBoxValue = hardwareKeysTest.textBox.value;570 hardwareKeysTest.removeTextBox();571 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey13.description);572 });573 });574 575 it("VT289-014 | call captureKey with dispatch true, keyValue for " +hardwareKeysTest.testKey14.description+" and callback as anonymous function |", function()576 {577 runs(function()578 {579 //Click inside Textbox and Press " +hardwareKeysTest.testKey14.description580 Rho.KeyCapture.captureKey(true,hardwareKeysTest.testKey14.string,function(data){hardwareKeysTest.captureKeyCallback(data);});581 hardwareKeysTest.createTextBox();582 hardwareKeysTest.textBox.focus();583 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey14.value);584 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB585 });586 waitsFor(function()587 {588 return hardwareKeysTest.callbackFiredTimeout == 'timedout';589 }, "Callback didnt fire", 3000);590 591 runs(function()592 {593 //Callback should fire with value " +hardwareKeysTest.testKey14.string+" check for Callback to fire with value and " +hardwareKeysTest.testKey14.description+" should be dispatched inside the textbox594 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey14.string);595 expect(hardwareKeysTest.callbackFired).toBe(true);596 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.testKey14.value);597 textBoxValue = hardwareKeysTest.textBox.value;598 hardwareKeysTest.removeTextBox();599 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey14.description);600 });601 });602 603 it("VT289-015 | call captureKey with dispatch false, keyValue for" +hardwareKeysTest.testKey15.description+" and press "+hardwareKeysTest.testKey14.description, function()604 {605 runs(function()606 {607 //Click inside Textbox and Press "+hardwareKeysTest.testKey14.description608 hardwareKeysTest.captureKey(true,hardwareKeysTest.testKey15.string);609 hardwareKeysTest.createTextBox();610 hardwareKeysTest.textBox.focus();611 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey14.value);612 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB613 });614 waitsFor(function()615 {616 return hardwareKeysTest.callbackFiredTimeout == 'timedout';617 }, "Callback didnt fire", 3000);618 619 runs(function()620 {621 //Callback should not fire and " +hardwareKeysTest.testKey14.description+ "should be dispatched inside the textbox622 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey15.string);623 expect(hardwareKeysTest.callbackFired).toBe(false);624 textBoxValue = hardwareKeysTest.textBox.value;625 hardwareKeysTest.removeTextBox();626 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey14.description);627 });628 });629 630 it("VT289-016 | call captureKey with dispatch True, keyValue ALL and callback |", function()631 {632 runs(function()633 {634 //Press all type of key (a-z 0-9 symbol, function)635 hardwareKeysTest.captureKey(true,'ALL');636 hardwareKeysTest.createTextBox();637 hardwareKeysTest.textBox.focus();638 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.aKey.value);639 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.hashKey.value)},200);640 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.oneKey.value)},400);641 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.f1Key.value)},600);642 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},4800);// TAB643 });644 waitsFor(function()645 {646 return hardwareKeysTest.callbackFiredTimeout == 'timedout';647 }, "Callback didnt fire", 4800);648 649 runs(function()650 {651 //Callback should fire with retrun key values all pressed keys should be dispatched652 hardwareKeysTest.resetCaptureKeyCallback('ALL');653 textBoxValue = hardwareKeysTest.textBox.value;654 hardwareKeysTest.removeTextBox();655 656 expect(hardwareKeysTest.callbackFired).toBe(true);657 expect(hardwareKeysTest.callbackFiredResult.length).toBe(4);658 expect(hardwareKeysTest.callbackFiredResult[0]).toEqual(hardwareKeysTest.aKey.value);659 expect(hardwareKeysTest.callbackFiredResult[1]).toEqual(hardwareKeysTest.hashKey.value);660 expect(hardwareKeysTest.callbackFiredResult[2]).toEqual(hardwareKeysTest.oneKey.value);661 expect(hardwareKeysTest.callbackFiredResult[3]).toEqual(hardwareKeysTest.f1Key.value);662 expect(textBoxValue).toEqual(hardwareKeysTest.aKey.description + hardwareKeysTest.hashKey.description + hardwareKeysTest.oneKey.description);663 });664 });665 666 it("VT289-021 | call captureKey twice, one with callback and other without callback |", function()667 {668 runs(function()669 {670 //Press " +hardwareKeysTest.testKey15.description+", Press numeric key " +hardwareKeysTest.testKey21.description+"671 hardwareKeysTest.captureKey(true,hardwareKeysTest.testKey15.string);672 Rho.KeyCapture.captureKey(true,hardwareKeysTest.testKey21.string);673 hardwareKeysTest.createTextBox();674 hardwareKeysTest.textBox.focus();675 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey15.value);676 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey21.value);},200);677 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1200);// TAB678 });679 waitsFor(function()680 {681 return hardwareKeysTest.callbackFiredTimeout == 'timedout';682 }, "Callback didnt fire", 3200);683 684 runs(function()685 {686 //callback1 should fire after pressing " +hardwareKeysTest.testKey15.description+" and no callback should fire after pressing " +hardwareKeysTest.testKey21.description+" and both key should be dispatched687 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey15.string);688 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey21.string);689 expect(hardwareKeysTest.callbackFired).toBe(true);690 expect(hardwareKeysTest.callbackFiredResult).toBe(hardwareKeysTest.testKey15.value);691 textBoxValue = hardwareKeysTest.textBox.value;692 hardwareKeysTest.removeTextBox();693 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey15.description + hardwareKeysTest.testKey21.description);694 }); 695 });696 // Removed because requirements have changed.697 // it("VT289-022 | call captureKey twice, one with callback and other without callback for keyValue ALL |", function()698 // {699 // runs(function()700 // {701 // //Press " +hardwareKeysTest.testKey15.description+", Press numeric key " +hardwareKeysTest.testKey21.description+"702 // hardwareKeysTest.captureKey(true,hardwareKeysTest.testKey15.string);703 // Rho.KeyCapture.captureKey(false,'ALL');704 // hardwareKeysTest.createTextBox();705 // hardwareKeysTest.textBox.focus();706 // hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey15.value);707 // setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB708 // });709 //710 // waitsFor(function()711 // {712 // return hardwareKeysTest.callbackFiredTimeout == 'timedout';713 // }, "Callback didnt fire", 3000);714 // 715 // runs(function()716 // {717 // //callback should fire only after pressing " +hardwareKeysTest.testKey15.description+" and allkeys should not be dispatched inside the textbox718 // hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey15.string);719 // hardwareKeysTest.resetCaptureKeyCallback('ALL');720 // expect(hardwareKeysTest.callbackFired).toBe(false);721 // textBoxValue = hardwareKeysTest.textBox.value;722 // hardwareKeysTest.removeTextBox();723 // if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey15.description);724 // }); 725 // });726 727 it("VT289-030 | call captureKey with no callback |", function()728 {729 runs(function()730 {731 //Click inside Textbox and Press key 1 and a from Hardware key, Press key 2 and b from soft key732 Rho.KeyCapture.captureKey(false,'ALL');733 Rho.KeyCapture.captureKey(true,'ALL');734 hardwareKeysTest.createTextBox();735 hardwareKeysTest.textBox.focus();736 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.aKey.value);737 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.zKey.value)},200);738 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.hashKey.value)},400);739 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.oneKey.value)},600);740 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},3800);// TAB741 });742 waitsFor(function()743 {744 return hardwareKeysTest.callbackFiredTimeout == 'timedout';745 }, "Callback didnt fire", 5800);746 747 runs(function()748 {749 //No callback should fire after pressing any hardware and soft key, all keys should be dispatched inside textbox after pressing any key750 hardwareKeysTest.resetCaptureKeyCallback('ALL');751 expect(hardwareKeysTest.callbackFired).toBe(false);752 textBoxValue = hardwareKeysTest.textBox.value;753 hardwareKeysTest.removeTextBox();754 var expectedOut = hardwareKeysTest.aKey.description + hardwareKeysTest.zKey.description + hardwareKeysTest.hashKey.description + hardwareKeysTest.oneKey.description;755 expect(textBoxValue).toEqual(expectedOut);756 });757 });758 759 it("VT289-031 | call captureKey with no callback after setting "+ hardwareKeysTest.testKey11.description, function()760 {761 runs(function()762 {763 764 //Click inside Textbox and"+ hardwareKeysTest.testKey11.description765 hardwareKeysTest.captureKey(false,hardwareKeysTest.testKey11.string);766 Rho.KeyCapture.captureKey(true,hardwareKeysTest.testKey11.string);767 hardwareKeysTest.createTextBox();768 hardwareKeysTest.textBox.focus();769 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.testKey11.value);770 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB771 });772 waitsFor(function()773 {774 return hardwareKeysTest.callbackFiredTimeout == 'timedout';775 }, "Callback didnt fire", 3000);776 777 runs(function()778 {779 //No callback should fire after pressing" +hardwareKeysTest.testKey11.description+" and" +hardwareKeysTest.testKey11.description+" should be dispatched inside text box780 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.testKey11.string);781 expect(hardwareKeysTest.callbackFired).toBe(false);782 textBoxValue = hardwareKeysTest.textBox.value;783 hardwareKeysTest.removeTextBox();784 if(!hardwareKeysTest.isAndroid()) expect(textBoxValue).toEqual(hardwareKeysTest.testKey11.description);785 });786 });787 });788 }789 if (!isWindowsMobilePlatform) //putting check for WM because of issues in instumentation API for WM790 { 791 describe("Remap", function()792 {793 ///////////////////////////////////////////////////////////////////////794 // 3. Key remap795 ///////////////////////////////////////////////////////////////////////796 it("3.1.should remap TAB key to the ENTER key", function() {797 runs(function()798 {799 hardwareKeysTest.remapKey(hardwareKeysTest.tabKey.string, hardwareKeysTest.enterKey.string); // TAB->ENTER800 hardwareKeysTest.captureKey(true,'ALL'); // Any Key801 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB802 }, "remap TAB to ENTER, & simulate TAB key press...");803 804 waitsFor(function()805 {806 return hardwareKeysTest.callbackFiredResult == hardwareKeysTest.enterKey.value;807 }, "ERROR: ENTER key has not been remapped", 3000);808 809 runs(function()810 {811 hardwareKeysTest.resetCaptureKeyCallback('ALL');812 hardwareKeysTest.clearRemap(hardwareKeysTest.tabKey.string);813 });814 });815 816 it("3.2.should clear a remap using null value", function() {817 runs(function()818 {819 hardwareKeysTest.remapKey(hardwareKeysTest.tabKey.string, hardwareKeysTest.enterKey.string); // TAB->ENTER820 hardwareKeysTest.remapKey(hardwareKeysTest.tabKey.string, null);821 hardwareKeysTest.captureKey(false, hardwareKeysTest.enterKey.string);822 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB823 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);// TAB824 }, "remap TAB to ENTER, then reset and simulate TAB key press..."); 825 826 waitsFor(function()827 {828 return hardwareKeysTest.callbackFiredResult == 'timedout';829 }, "ERROR: Test setup failed, timeout not occurring", 3000);830 831 runs(function()832 {833 expect(hardwareKeysTest.callbackFired).toBe(false);834 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.enterKey.string);835 hardwareKeysTest.clearRemap(hardwareKeysTest.tabKey.string);836 }, 'expect the callback not to fire'); 837 });838 839 it("3.3.should clear a remap using empty string", function()840 {841 runs(function()842 {843 hardwareKeysTest.remapKey(hardwareKeysTest.tabKey.string, hardwareKeysTest.enterKey.string); // TAB->ENTER844 Rho.KeyCapture.remapKey(hardwareKeysTest.tabKey.string, '');845 hardwareKeysTest.captureKey(false, hardwareKeysTest.enterKey.string);846 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB847 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);// TAB848 }, "remap TAB to ENTER, then reset and simulate TAB key press..."); 849 850 waitsFor(function()851 {852 return hardwareKeysTest.callbackFiredResult == 'timedout';853 }, "ERROR: Test setup failed, timeout not occurring", 3000);854 855 runs(function()856 {857 expect(hardwareKeysTest.callbackFired).toBe(false);858 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.enterKey.string);859 hardwareKeysTest.clearRemap(hardwareKeysTest.tabKey.string);860 }, 'expect the callback not to fire'); 861 });862 863 ///////////////////////////////////////////////////////////////////////864 // From Manual ReMap key Tests865 ///////////////////////////////////////////////////////////////////////866 it("VT289-039 | call remapKey with enter and numeric key 1 |", function()867 {868 runs(function()869 {870 hardwareKeysTest.remapKey(hardwareKeysTest.enterKey.string, hardwareKeysTest.oneKey.string);871 hardwareKeysTest.createTextBox();872 hardwareKeysTest.textBox.focus();873 874 //Press enter key and press numeric key 1875 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.enterKey.value);876 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.oneKey.value);},200);877 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1200);// TAB878 });879 880 waitsFor(function()881 {882 return hardwareKeysTest.callbackFiredTimeout == 'timedout';883 }, "Error in delay", 3200);884 runs(function()885 {886 //Both key should be dispatched as 1887 expect(hardwareKeysTest.textBox.value).toEqual(hardwareKeysTest.oneKey.description + hardwareKeysTest.oneKey.description);888 889 //Tear down890 hardwareKeysTest.clearRemap(hardwareKeysTest.enterKey.string);891 hardwareKeysTest.removeTextBox();892 });893 });894 it("VT289-040 | call remapKey with functionkey F1 and numeric key 9 |", function()895 {896 runs(function()897 {898 hardwareKeysTest.remapKey(hardwareKeysTest.f1Key.string, hardwareKeysTest.nineKey.string);899 hardwareKeysTest.createTextBox();900 hardwareKeysTest.textBox.focus();901 902 //Press functionkey F1 and numeric key 9903 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.f1Key.value);904 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.nineKey.value);},200);905 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB906 });907 908 waitsFor(function()909 {910 return hardwareKeysTest.callbackFiredTimeout == 'timedout';911 }, "Error in delay", 3000);912 runs(function()913 {914 //Both key should be dispatched as 9915 expect(hardwareKeysTest.textBox.value).toEqual(hardwareKeysTest.nineKey.description + hardwareKeysTest.nineKey.description);916 917 //Tear down918 hardwareKeysTest.clearRemap(hardwareKeysTest.f1Key.string);919 hardwareKeysTest.removeTextBox();920 });921 });922 it("VT289-041 | call remapKey with numeric key 5 and null |", function() {923 runs(function()924 {925 //click inside the textbox, .Press numeric key 5 and 2926 hardwareKeysTest.remapKey(hardwareKeysTest.fiveKey.string,hardwareKeysTest.twoKey.string);927 hardwareKeysTest.remapKey(hardwareKeysTest.fiveKey.string, null);928 hardwareKeysTest.createTextBox();929 hardwareKeysTest.textBox.focus();930 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.fiveKey.value);931 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.twoKey.value);},200);932 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB933 });934 935 waitsFor(function()936 {937 return hardwareKeysTest.callbackFiredTimeout == 'timedout';938 }, "Error in delay", 3000);939 runs(function()940 {941 //5 should be dispatched after pressing 5 and 2 should be dispatched after pressing 2, No Remap942 expect(hardwareKeysTest.textBox.value).toEqual(hardwareKeysTest.fiveKey.description + hardwareKeysTest.twoKey.description);943 //Tear down944 hardwareKeysTest.removeTextBox();945 });946 });947 it("VT289-044 | call capturekey after remapKey |", function() {948 runs(function()949 {950 hardwareKeysTest.remapKey(hardwareKeysTest.aKey.string, hardwareKeysTest.bKey.string);951 hardwareKeysTest.captureKey(true, hardwareKeysTest.aKey.string);952 hardwareKeysTest.createTextBox();953 hardwareKeysTest.textBox.focus();954 955 //Press keys a and b956 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.aKey.value);957 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.bKey.value);},200);958 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB959 });960 961 waitsFor(function()962 {963 return hardwareKeysTest.callbackFiredTimeout == 'timedout';964 }, "Error in delay", 3000);965 runs(function()966 { 967 //Callback should not fire after pressing key a, Both key should be dispatched as b after pressing a and b968 hardwareKeysTest.clearRemap(hardwareKeysTest.aKey.string);969 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.aKey.string);970 expect(hardwareKeysTest.textBox.value).toEqual(hardwareKeysTest.bKey.description + hardwareKeysTest.bKey.description);971 expect(hardwareKeysTest.callbackFired).toBe(false);972 hardwareKeysTest.removeTextBox();973 });974 });975 it("VT289-045 | call capturekey after remapKey and callback to fire |", function()976 {977 runs(function()978 {979 hardwareKeysTest.remapKey(hardwareKeysTest.zKey.string,hardwareKeysTest.yKey.string);980 hardwareKeysTest.captureKey(true,hardwareKeysTest.yKey.string);981 hardwareKeysTest.createTextBox();982 hardwareKeysTest.textBox.focus();983 984 //Press keys y and z985 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.zKey.value);986 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.yKey.value);},200);987 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB988 });989 990 waitsFor(function()991 {992 return hardwareKeysTest.callbackFiredTimeout == 'timedout';993 }, "Error in delay", 3000);994 runs(function()995 { 996 hardwareKeysTest.clearRemap(hardwareKeysTest.zKey.string);997 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.yKey.string);998 //Callback should fire after pressing key z and y, Both key should be dispatched as y after pressing z and y999 expect(hardwareKeysTest.textBox.value).toEqual(hardwareKeysTest.yKey.description + hardwareKeysTest.yKey.description);1000 expect(hardwareKeysTest.callbackFired).toBe(true);1001 expect(hardwareKeysTest.callbackFiredResult.length).toBe(2);1002 expect(hardwareKeysTest.callbackFiredResult[0]).toEqual(hardwareKeysTest.yKey.value);1003 expect(hardwareKeysTest.callbackFiredResult[1]).toEqual(hardwareKeysTest.yKey.value);1004 hardwareKeysTest.removeTextBox();1005 });1006 });1007 it("VT289-046 | call remapKey after capturekey and callback to fire |", function()1008 {1009 runs(function()1010 {1011 hardwareKeysTest.captureKey(true,hardwareKeysTest.hashKey.string);1012 hardwareKeysTest.remapKey(hardwareKeysTest.starKey.string, hardwareKeysTest.hashKey.string);1013 hardwareKeysTest.createTextBox();1014 hardwareKeysTest.textBox.focus();1015 1016 //Press numeric key * and #1017 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.starKey.value);1018 setTimeout(function(){hardwareKeysTest.simulateKeyPress(hardwareKeysTest.hashKey.value);},200);1019 setTimeout(function(){hardwareKeysTest.callbackFiredTimeout = 'timedout'},1000);// TAB1020 });1021 1022 waitsFor(function()1023 {1024 return hardwareKeysTest.callbackFiredTimeout == 'timedout';1025 }, "Error in delay", 3000);1026 runs(function()1027 { 1028 hardwareKeysTest.clearRemap(hardwareKeysTest.starKey.string);1029 hardwareKeysTest.resetCaptureKeyCallback(hardwareKeysTest.hashKey.string);1030 //Callback should fire after pressing key * and #, Both key should be dispatched as # after pressing * and #1031 expect(hardwareKeysTest.textBox.value).toEqual(hardwareKeysTest.hashKey.description + hardwareKeysTest.hashKey.description);1032 expect(hardwareKeysTest.callbackFired).toBe(true);1033 expect(hardwareKeysTest.callbackFiredResult.length).toBe(2);1034 expect(hardwareKeysTest.callbackFiredResult[0]).toEqual(hardwareKeysTest.hashKey.value);1035 expect(hardwareKeysTest.callbackFiredResult[1]).toEqual(hardwareKeysTest.hashKey.value);1036 hardwareKeysTest.removeTextBox();1037 });1038 });1039 });1040 }1041 if (!isWindowsMobilePlatform) //putting check for WM because of issues in instumentation API for WM1042 {1043 if (isWindowsMobileOrAndroidPlatform() && Rho.System.isSymbolDevice == true) 1044 {1045 describe("Trigger", function()1046 {1047 ///////////////////////////////////////////////////////////////////////1048 // 4. Trigger1049 ///////////////////////////////////////////////////////////////////////1050 it("4.1.should capture the trigger press", function()1051 {1052 runs(function()1053 {1054 hardwareKeysTest.setTrigger();1055 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.TRIGGER); // TRIGGER1056 }, "enable Trigger and simulate trigger press..."); 1057 1058 waitsFor(function()1059 {1060 if(hardwareKeysTest.callbackFiredResult == null){return false;}1061 if((typeof hardwareKeysTest.callbackFiredResult) != 'object'){return false;}1062 if(hardwareKeysTest.callbackFiredResult.length != 2){return false;}1063 else{return true;}1064 }, "ERROR: Trigger NOT received", 3000);1065 1066 runs(function()1067 {1068 expect(hardwareKeysTest.callbackFiredResult[0]).toEqual(hardwareKeysTest.TRIGGER);1069 expect(hardwareKeysTest.callbackFiredResult[1]).toEqual(0);1070 hardwareKeysTest.resetTrigger();1071 },'expect both trigger down and trigger up events are fired');1072 });1073 1074 it("4.2.should NOT capture the trigger when other key pressed", function()1075 {1076 runs(function()1077 {1078 hardwareKeysTest.setTrigger();1079 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.tabKey.value); // TAB1080 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);1081 }, "enable Trigger and simulate tab key..."); 1082 1083 waitsFor(function()1084 {1085 return hardwareKeysTest.callbackFiredResult == 'timedout';1086 }, "ERROR: Test setup failed, timeout not occurring", 3000);1087 1088 runs(function()1089 {1090 expect(hardwareKeysTest.callbackFired).toBe(false);1091 hardwareKeysTest.resetTrigger();1092 }, 'expect the callback not to fire');1093 });1094 1095 it("4.3.should NOT capture the trigger after the trigger callback is cleared", function()1096 {1097 runs(function()1098 {1099 hardwareKeysTest.setTrigger();1100 hardwareKeysTest.resetTrigger();1101 hardwareKeysTest.simulateKeyPress(hardwareKeysTest.TRIGGER); // TRIGGER1102 setTimeout(function(){hardwareKeysTest.callbackFiredResult = 'timedout'},1000);// TAB1103 }, "reset trigger callback and fire trigger.");1104 1105 waitsFor(function()1106 {1107 return hardwareKeysTest.callbackFiredResult == 'timedout';1108 }, "ERROR: Test setup failed, timeout not occurring", 3000);1109 runs(function()1110 {1111 expect(hardwareKeysTest.callbackFired).toBe(false);1112 }, 'expect the callback not to fire');1113 });1114 });1115 }1116 }...

Full Screen

Full Screen

autocomplete-list-keys-coverage.js

Source:autocomplete-list-keys-coverage.js Github

copy

Full Screen

1/*2YUI 3.7.3 (build 5687)3Copyright 2012 Yahoo! Inc. All rights reserved.4Licensed under the BSD License.5http://yuilibrary.com/license/6*/7if (typeof _yuitest_coverage == "undefined"){8 _yuitest_coverage = {};9 _yuitest_coverline = function(src, line){10 var coverage = _yuitest_coverage[src];11 if (!coverage.lines[line]){12 coverage.calledLines++;13 }14 coverage.lines[line]++;15 };16 _yuitest_coverfunc = function(src, name, line){17 var coverage = _yuitest_coverage[src],18 funcId = name + ":" + line;19 if (!coverage.functions[funcId]){20 coverage.calledFunctions++;21 }22 coverage.functions[funcId]++;23 };24}25_yuitest_coverage["build/autocomplete-list-keys/autocomplete-list-keys.js"] = {26 lines: {},27 functions: {},28 coveredLines: 0,29 calledLines: 0,30 coveredFunctions: 0,31 calledFunctions: 0,32 path: "build/autocomplete-list-keys/autocomplete-list-keys.js",33 code: []34};35_yuitest_coverage["build/autocomplete-list-keys/autocomplete-list-keys.js"].code=["YUI.add('autocomplete-list-keys', function (Y, NAME) {","","/**","Mixes keyboard support into AutoCompleteList. By default, this module is not","loaded for iOS and Android devices.","","@module autocomplete","@submodule autocomplete-list-keys","**/",""," // keyCode constants.","var KEY_DOWN = 40,"," KEY_ENTER = 13,"," KEY_ESC = 27,"," KEY_TAB = 9,"," KEY_UP = 38;","","function ListKeys() {"," Y.before(this._bindKeys, this, 'bindUI');"," this._initKeys();","}","","ListKeys.prototype = {"," // -- Lifecycle Methods ----------------------------------------------------",""," /**"," Initializes keyboard command mappings.",""," @method _initKeys"," @protected"," @for AutoCompleteList"," **/"," _initKeys: function () {"," var keys = {},"," keysVisible = {};",""," // Register keyboard command handlers. _keys contains handlers that will"," // always be called; _keysVisible contains handlers that will only be"," // called when the list is visible."," keys[KEY_DOWN] = this._keyDown;",""," keysVisible[KEY_ENTER] = this._keyEnter;"," keysVisible[KEY_ESC] = this._keyEsc;"," keysVisible[KEY_TAB] = this._keyTab;"," keysVisible[KEY_UP] = this._keyUp;",""," this._keys = keys;"," this._keysVisible = keysVisible;"," },",""," destructor: function () {"," this._unbindKeys();"," },",""," /**"," Binds keyboard events.",""," @method _bindKeys"," @protected"," **/"," _bindKeys: function () {"," this._keyEvents = this._inputNode.on('keydown', this._onInputKey, this);"," },",""," /**"," Unbinds keyboard events.",""," @method _unbindKeys"," @protected"," **/"," _unbindKeys: function () {"," this._keyEvents && this._keyEvents.detach();"," this._keyEvents = null;"," },",""," // -- Protected Methods ----------------------------------------------------",""," /**"," Called when the down arrow key is pressed.",""," @method _keyDown"," @protected"," **/"," _keyDown: function () {"," if (this.get('visible')) {"," this._activateNextItem();"," } else {"," this.show();"," }"," },",""," /**"," Called when the enter key is pressed.",""," @method _keyEnter"," @protected"," **/"," _keyEnter: function (e) {"," var item = this.get('activeItem');",""," if (item) {"," this.selectItem(item, e);"," } else {"," // Don't prevent form submission when there's no active item."," return false;"," }"," },",""," /**"," Called when the escape key is pressed.",""," @method _keyEsc"," @protected"," **/"," _keyEsc: function () {"," this.hide();"," },",""," /**"," Called when the tab key is pressed.",""," @method _keyTab"," @protected"," **/"," _keyTab: function (e) {"," var item;",""," if (this.get('tabSelect')) {"," item = this.get('activeItem');",""," if (item) {"," this.selectItem(item, e);"," return true;"," }"," }",""," return false;"," },",""," /**"," Called when the up arrow key is pressed.",""," @method _keyUp"," @protected"," **/"," _keyUp: function () {"," this._activatePrevItem();"," },",""," // -- Protected Event Handlers ---------------------------------------------",""," /**"," Handles `inputNode` key events.",""," @method _onInputKey"," @param {EventTarget} e"," @protected"," **/"," _onInputKey: function (e) {"," var handler,"," keyCode = e.keyCode;",""," this._lastInputKey = keyCode;",""," if (this.get('results').length) {"," handler = this._keys[keyCode];",""," if (!handler && this.get('visible')) {"," handler = this._keysVisible[keyCode];"," }",""," if (handler) {"," // A handler may return false to indicate that it doesn't wish"," // to prevent the default key behavior."," if (handler.call(this, e) !== false) {"," e.preventDefault();"," }"," }"," }"," }","};","","Y.Base.mix(Y.AutoCompleteList, [ListKeys]);","","","}, '3.7.3', {\"requires\": [\"autocomplete-list\", \"base-build\"]});"];36_yuitest_coverage["build/autocomplete-list-keys/autocomplete-list-keys.js"].lines = {"1":0,"12":0,"18":0,"19":0,"20":0,"23":0,"34":0,"40":0,"42":0,"43":0,"44":0,"45":0,"47":0,"48":0,"52":0,"62":0,"72":0,"73":0,"85":0,"86":0,"88":0,"99":0,"101":0,"102":0,"105":0,"116":0,"126":0,"128":0,"129":0,"131":0,"132":0,"133":0,"137":0,"147":0,"160":0,"163":0,"165":0,"166":0,"168":0,"169":0,"172":0,"175":0,"176":0,"183":0};37_yuitest_coverage["build/autocomplete-list-keys/autocomplete-list-keys.js"].functions = {"ListKeys:18":0,"_initKeys:33":0,"destructor:51":0,"_bindKeys:61":0,"_unbindKeys:71":0,"_keyDown:84":0,"_keyEnter:98":0,"_keyEsc:115":0,"_keyTab:125":0,"_keyUp:146":0,"_onInputKey:159":0,"(anonymous 1):1":0};38_yuitest_coverage["build/autocomplete-list-keys/autocomplete-list-keys.js"].coveredLines = 44;39_yuitest_coverage["build/autocomplete-list-keys/autocomplete-list-keys.js"].coveredFunctions = 12;40_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 1);41YUI.add('autocomplete-list-keys', function (Y, NAME) {42/**43Mixes keyboard support into AutoCompleteList. By default, this module is not44loaded for iOS and Android devices.45@module autocomplete46@submodule autocomplete-list-keys47**/48 // keyCode constants.49_yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "(anonymous 1)", 1);50_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 12);51var KEY_DOWN = 40,52 KEY_ENTER = 13,53 KEY_ESC = 27,54 KEY_TAB = 9,55 KEY_UP = 38;56_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 18);57function ListKeys() {58 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "ListKeys", 18);59_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 19);60Y.before(this._bindKeys, this, 'bindUI');61 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 20);62this._initKeys();63}64_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 23);65ListKeys.prototype = {66 // -- Lifecycle Methods ----------------------------------------------------67 /**68 Initializes keyboard command mappings.69 @method _initKeys70 @protected71 @for AutoCompleteList72 **/73 _initKeys: function () {74 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_initKeys", 33);75_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 34);76var keys = {},77 keysVisible = {};78 // Register keyboard command handlers. _keys contains handlers that will79 // always be called; _keysVisible contains handlers that will only be80 // called when the list is visible.81 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 40);82keys[KEY_DOWN] = this._keyDown;83 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 42);84keysVisible[KEY_ENTER] = this._keyEnter;85 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 43);86keysVisible[KEY_ESC] = this._keyEsc;87 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 44);88keysVisible[KEY_TAB] = this._keyTab;89 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 45);90keysVisible[KEY_UP] = this._keyUp;91 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 47);92this._keys = keys;93 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 48);94this._keysVisible = keysVisible;95 },96 destructor: function () {97 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "destructor", 51);98_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 52);99this._unbindKeys();100 },101 /**102 Binds keyboard events.103 @method _bindKeys104 @protected105 **/106 _bindKeys: function () {107 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_bindKeys", 61);108_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 62);109this._keyEvents = this._inputNode.on('keydown', this._onInputKey, this);110 },111 /**112 Unbinds keyboard events.113 @method _unbindKeys114 @protected115 **/116 _unbindKeys: function () {117 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_unbindKeys", 71);118_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 72);119this._keyEvents && this._keyEvents.detach();120 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 73);121this._keyEvents = null;122 },123 // -- Protected Methods ----------------------------------------------------124 /**125 Called when the down arrow key is pressed.126 @method _keyDown127 @protected128 **/129 _keyDown: function () {130 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_keyDown", 84);131_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 85);132if (this.get('visible')) {133 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 86);134this._activateNextItem();135 } else {136 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 88);137this.show();138 }139 },140 /**141 Called when the enter key is pressed.142 @method _keyEnter143 @protected144 **/145 _keyEnter: function (e) {146 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_keyEnter", 98);147_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 99);148var item = this.get('activeItem');149 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 101);150if (item) {151 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 102);152this.selectItem(item, e);153 } else {154 // Don't prevent form submission when there's no active item.155 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 105);156return false;157 }158 },159 /**160 Called when the escape key is pressed.161 @method _keyEsc162 @protected163 **/164 _keyEsc: function () {165 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_keyEsc", 115);166_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 116);167this.hide();168 },169 /**170 Called when the tab key is pressed.171 @method _keyTab172 @protected173 **/174 _keyTab: function (e) {175 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_keyTab", 125);176_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 126);177var item;178 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 128);179if (this.get('tabSelect')) {180 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 129);181item = this.get('activeItem');182 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 131);183if (item) {184 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 132);185this.selectItem(item, e);186 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 133);187return true;188 }189 }190 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 137);191return false;192 },193 /**194 Called when the up arrow key is pressed.195 @method _keyUp196 @protected197 **/198 _keyUp: function () {199 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_keyUp", 146);200_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 147);201this._activatePrevItem();202 },203 // -- Protected Event Handlers ---------------------------------------------204 /**205 Handles `inputNode` key events.206 @method _onInputKey207 @param {EventTarget} e208 @protected209 **/210 _onInputKey: function (e) {211 _yuitest_coverfunc("build/autocomplete-list-keys/autocomplete-list-keys.js", "_onInputKey", 159);212_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 160);213var handler,214 keyCode = e.keyCode;215 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 163);216this._lastInputKey = keyCode;217 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 165);218if (this.get('results').length) {219 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 166);220handler = this._keys[keyCode];221 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 168);222if (!handler && this.get('visible')) {223 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 169);224handler = this._keysVisible[keyCode];225 }226 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 172);227if (handler) {228 // A handler may return false to indicate that it doesn't wish229 // to prevent the default key behavior.230 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 175);231if (handler.call(this, e) !== false) {232 _yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 176);233e.preventDefault();234 }235 }236 }237 }238};239_yuitest_coverline("build/autocomplete-list-keys/autocomplete-list-keys.js", 183);240Y.Base.mix(Y.AutoCompleteList, [ListKeys]);...

Full Screen

Full Screen

boundedcollectablestorage.js

Source:boundedcollectablestorage.js Github

copy

Full Screen

1// Copyright 2013 The Closure Library Authors. All Rights Reserved.2//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 at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// 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 and13// limitations under the License.14/**15 * @fileoverview Provides a convenient API for data persistence with data16 * expiration and number of items limit.17 *18 * Setting and removing values keeps a max number of items invariant.19 * Collecting values can be user initiated. If oversize, first removes20 * expired items, if still oversize than removes the oldest items until a size21 * constraint is fulfilled.22 *23 */24goog.provide('goog.labs.storage.BoundedCollectableStorage');25goog.require('goog.array');26goog.require('goog.asserts');27goog.require('goog.iter');28goog.require('goog.storage.CollectableStorage');29goog.require('goog.storage.ErrorCode');30goog.require('goog.storage.ExpiringStorage');31/**32 * Provides a storage with bounded number of elements, expiring keys and33 * a collection method.34 *35 * @param {!goog.storage.mechanism.IterableMechanism} mechanism The underlying36 * storage mechanism.37 * @param {number} maxItems Maximum number of items in storage.38 * @constructor39 * @struct40 * @extends {goog.storage.CollectableStorage}41 * @final42 */43goog.labs.storage.BoundedCollectableStorage = function(mechanism, maxItems) {44 goog.labs.storage.BoundedCollectableStorage.base(45 this, 'constructor', mechanism);46 /**47 * A maximum number of items that should be stored.48 * @private {number}49 */50 this.maxItems_ = maxItems;51};52goog.inherits(53 goog.labs.storage.BoundedCollectableStorage,54 goog.storage.CollectableStorage);55/**56 * An item key used to store a list of keys.57 * @const58 * @private59 */60goog.labs.storage.BoundedCollectableStorage.KEY_LIST_KEY_ =61 'bounded-collectable-storage';62/**63 * Recreates a list of keys in order of creation.64 *65 * @return {!Array<string>} a list of unexpired keys.66 * @private67 */68goog.labs.storage.BoundedCollectableStorage.prototype.rebuildIndex_ =69 function() {70 var keys = [];71 goog.iter.forEach(72 /** @type {goog.storage.mechanism.IterableMechanism} */ (this.mechanism)73 .__iterator__(true),74 function(key) {75 if (goog.labs.storage.BoundedCollectableStorage.KEY_LIST_KEY_ == key) {76 return;77 }78 var wrapper;79 try {80 wrapper = this.getWrapper(key, true);81 } catch (ex) {82 if (ex == goog.storage.ErrorCode.INVALID_VALUE) {83 // Skip over bad wrappers and continue.84 return;85 }86 // Unknown error, escalate.87 throw ex;88 }89 goog.asserts.assert(wrapper);90 var creationTime =91 goog.storage.ExpiringStorage.getCreationTime(wrapper);92 keys.push({key: key, created: creationTime});93 },94 this);95 goog.array.sort(keys, function(a, b) { return a.created - b.created; });96 return goog.array.map(keys, function(v) { return v.key; });97};98/**99 * Gets key list from a local storage. If an item does not exist,100 * may recreate it.101 *102 * @param {boolean} rebuild Whether to rebuild a index if no index item exists.103 * @return {!Array<string>} a list of keys if index exist, otherwise undefined.104 * @private105 */106goog.labs.storage.BoundedCollectableStorage.prototype.getKeys_ = function(107 rebuild) {108 var keys =109 goog.labs.storage.BoundedCollectableStorage.superClass_.get.call(110 this, goog.labs.storage.BoundedCollectableStorage.KEY_LIST_KEY_) ||111 null;112 if (!keys || !goog.isArray(keys)) {113 if (rebuild) {114 keys = this.rebuildIndex_();115 } else {116 keys = [];117 }118 }119 return /** @type {!Array<string>} */ (keys);120};121/**122 * Saves a list of keys in a local storage.123 *124 * @param {Array<string>} keys a list of keys to save.125 * @private126 */127goog.labs.storage.BoundedCollectableStorage.prototype.setKeys_ = function(128 keys) {129 goog.labs.storage.BoundedCollectableStorage.superClass_.set.call(130 this, goog.labs.storage.BoundedCollectableStorage.KEY_LIST_KEY_, keys);131};132/**133 * Remove subsequence from a sequence.134 *135 * @param {!Array<string>} keys is a sequence.136 * @param {!Array<string>} keysToRemove subsequence of keys, the order must137 * be kept.138 * @return {!Array<string>} a keys sequence after removing keysToRemove.139 * @private140 */141goog.labs.storage.BoundedCollectableStorage.removeSubsequence_ = function(142 keys, keysToRemove) {143 if (keysToRemove.length == 0) {144 return goog.array.clone(keys);145 }146 var keysToKeep = [];147 var keysIdx = 0;148 var keysToRemoveIdx = 0;149 while (keysToRemoveIdx < keysToRemove.length && keysIdx < keys.length) {150 var key = keysToRemove[keysToRemoveIdx];151 while (keysIdx < keys.length && keys[keysIdx] != key) {152 keysToKeep.push(keys[keysIdx]);153 ++keysIdx;154 }155 ++keysToRemoveIdx;156 }157 goog.asserts.assert(keysToRemoveIdx == keysToRemove.length);158 goog.asserts.assert(keysIdx < keys.length);159 return goog.array.concat(keysToKeep, goog.array.slice(keys, keysIdx + 1));160};161/**162 * Keeps the number of items in storage under maxItems. Removes elements in the163 * order of creation.164 *165 * @param {!Array<string>} keys a list of keys in order of creation.166 * @param {number} maxSize a number of items to keep.167 * @return {!Array<string>} keys left after removing oversize data.168 * @private169 */170goog.labs.storage.BoundedCollectableStorage.prototype.collectOversize_ =171 function(keys, maxSize) {172 if (keys.length <= maxSize) {173 return goog.array.clone(keys);174 }175 var keysToRemove = goog.array.slice(keys, 0, keys.length - maxSize);176 goog.array.forEach(keysToRemove, function(key) {177 goog.labs.storage.BoundedCollectableStorage.superClass_.remove.call(178 this, key);179 }, this);180 return goog.labs.storage.BoundedCollectableStorage.removeSubsequence_(181 keys, keysToRemove);182};183/**184 * Cleans up the storage by removing expired keys.185 *186 * @param {boolean=} opt_strict Also remove invalid keys.187 * @override188 */189goog.labs.storage.BoundedCollectableStorage.prototype.collect = function(190 opt_strict) {191 var keys = this.getKeys_(true);192 var keysToRemove = this.collectInternal(keys, opt_strict);193 keys = goog.labs.storage.BoundedCollectableStorage.removeSubsequence_(194 keys, keysToRemove);195 this.setKeys_(keys);196};197/**198 * Ensures that we keep only maxItems number of items in a local storage.199 * @param {boolean=} opt_skipExpired skip removing expired items first.200 * @param {boolean=} opt_strict Also remove invalid keys.201 */202goog.labs.storage.BoundedCollectableStorage.prototype.collectOversize =203 function(opt_skipExpired, opt_strict) {204 var keys = this.getKeys_(true);205 if (!opt_skipExpired) {206 var keysToRemove = this.collectInternal(keys, opt_strict);207 keys = goog.labs.storage.BoundedCollectableStorage.removeSubsequence_(208 keys, keysToRemove);209 }210 keys = this.collectOversize_(keys, this.maxItems_);211 this.setKeys_(keys);212};213/**214 * Set an item in the storage.215 *216 * @param {string} key The key to set.217 * @param {*} value The value to serialize to a string and save.218 * @param {number=} opt_expiration The number of miliseconds since epoch219 * (as in goog.now()) when the value is to expire. If the expiration220 * time is not provided, the value will persist as long as possible.221 * @override222 */223goog.labs.storage.BoundedCollectableStorage.prototype.set = function(224 key, value, opt_expiration) {225 goog.labs.storage.BoundedCollectableStorage.base(226 this, 'set', key, value, opt_expiration);227 var keys = this.getKeys_(true);228 goog.array.remove(keys, key);229 if (goog.isDef(value)) {230 keys.push(key);231 if (keys.length >= this.maxItems_) {232 var keysToRemove = this.collectInternal(keys);233 keys = goog.labs.storage.BoundedCollectableStorage.removeSubsequence_(234 keys, keysToRemove);235 keys = this.collectOversize_(keys, this.maxItems_);236 }237 }238 this.setKeys_(keys);239};240/**241 * Remove an item from the data storage.242 *243 * @param {string} key The key to remove.244 * @override245 */246goog.labs.storage.BoundedCollectableStorage.prototype.remove = function(key) {247 goog.labs.storage.BoundedCollectableStorage.base(this, 'remove', key);248 var keys = this.getKeys_(false);249 if (goog.isDef(keys)) {250 goog.array.remove(keys, key);251 this.setKeys_(keys);252 }...

Full Screen

Full Screen

keycode.js

Source:keycode.js Github

copy

Full Screen

1/**2 * Enumerates the supported keys.3 * NOTE: The maps represents physical keys on the keyboard, not chars.4 * @readonly5 * @enum {string}6 */7export const KEYS = {8 BACKSPACE: 'backspace',9 DELETE: 'delete',10 RETURN: 'enter',11 TAB: 'tab',12 ESCAPE: 'escape',13 UP: 'up',14 DOWN: 'down',15 RIGHT: 'right',16 LEFT: 'left',17 HOME: 'home',18 END: 'end',19 PAGEUP: 'pageup',20 PAGEDOWN: 'pagedown',21 F1: 'f1',22 F2: 'f2',23 F3: 'f3',24 F4: 'f4',25 F5: 'f5',26 F6: 'f6',27 F7: 'f7',28 F8: 'f8',29 F9: 'f9',30 F10: 'f10',31 F11: 'f11',32 F12: 'f12',33 META: 'command',34 CMD_L: 'command',35 CMD_R: 'command',36 ALT: 'alt',37 CONTROL: 'control',38 SHIFT: 'shift',39 CAPS_LOCK: 'caps_lock', // not supported by robotjs40 SPACE: 'space',41 PRINTSCREEN: 'printscreen',42 INSERT: 'insert',43 NUMPAD_0: 'numpad_0',44 NUMPAD_1: 'numpad_1',45 NUMPAD_2: 'numpad_2',46 NUMPAD_3: 'numpad_3',47 NUMPAD_4: 'numpad_4',48 NUMPAD_5: 'numpad_5',49 NUMPAD_6: 'numpad_6',50 NUMPAD_7: 'numpad_7',51 NUMPAD_8: 'numpad_8',52 NUMPAD_9: 'numpad_9',53 COMMA: ',',54 PERIOD: '.',55 SEMICOLON: ';',56 QUOTE: '\'',57 BRACKET_LEFT: '[',58 BRACKET_RIGHT: ']',59 BACKQUOTE: '`',60 BACKSLASH: '\\',61 MINUS: '-',62 EQUAL: '=',63 SLASH: '/'64};65/* eslint-disable max-len */66/**67 * Mapping between the key codes and keys deined in KEYS.68 * The mappings are based on69 * https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode#Specifications70 */71/* eslint-enable max-len */72const keyCodeToKey = {73 8: KEYS.BACKSPACE,74 9: KEYS.TAB,75 13: KEYS.RETURN,76 16: KEYS.SHIFT,77 17: KEYS.CONTROL,78 18: KEYS.ALT,79 20: KEYS.CAPS_LOCK,80 27: KEYS.ESCAPE,81 32: KEYS.SPACE,82 33: KEYS.PAGEUP,83 34: KEYS.PAGEDOWN,84 35: KEYS.END,85 36: KEYS.HOME,86 37: KEYS.LEFT,87 38: KEYS.UP,88 39: KEYS.RIGHT,89 40: KEYS.DOWN,90 42: KEYS.PRINTSCREEN,91 44: KEYS.PRINTSCREEN,92 45: KEYS.INSERT,93 46: KEYS.DELETE,94 59: KEYS.SEMICOLON,95 61: KEYS.EQUAL,96 91: KEYS.CMD_L,97 92: KEYS.CMD_R,98 93: KEYS.CMD_R,99 96: KEYS.NUMPAD_0,100 97: KEYS.NUMPAD_1,101 98: KEYS.NUMPAD_2,102 99: KEYS.NUMPAD_3,103 100: KEYS.NUMPAD_4,104 101: KEYS.NUMPAD_5,105 102: KEYS.NUMPAD_6,106 103: KEYS.NUMPAD_7,107 104: KEYS.NUMPAD_8,108 105: KEYS.NUMPAD_9,109 112: KEYS.F1,110 113: KEYS.F2,111 114: KEYS.F3,112 115: KEYS.F4,113 116: KEYS.F5,114 117: KEYS.F6,115 118: KEYS.F7,116 119: KEYS.F8,117 120: KEYS.F9,118 121: KEYS.F10,119 122: KEYS.F11,120 123: KEYS.F12,121 124: KEYS.PRINTSCREEN,122 173: KEYS.MINUS,123 186: KEYS.SEMICOLON,124 187: KEYS.EQUAL,125 188: KEYS.COMMA,126 189: KEYS.MINUS,127 190: KEYS.PERIOD,128 191: KEYS.SLASH,129 192: KEYS.BACKQUOTE,130 219: KEYS.BRACKET_LEFT,131 220: KEYS.BACKSLASH,132 221: KEYS.BRACKET_RIGHT,133 222: KEYS.QUOTE,134 224: KEYS.META,135 229: KEYS.SEMICOLON136};137/**138 * Generate codes for digit keys (0-9)139 */140for (let i = 0; i < 10; i++) {141 keyCodeToKey[i + 48] = `${i}`;142}143/**144 * Generate codes for letter keys (a-z)145 */146for (let i = 0; i < 26; i++) {147 const keyCode = i + 65;148 keyCodeToKey[keyCode] = String.fromCharCode(keyCode).toLowerCase();149}150/**151 * Returns key associated with the keyCode from the passed event.152 * @param {KeyboardEvent} event the event153 * @returns {KEYS} the key on the keyboard.154 */155export function keyboardEventToKey(event) {156 return keyCodeToKey[event.which];...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Molotov automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful