Advertisement
Guest User

Untitled

a guest
Aug 10th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     describe('testing exclude options', function () {
  2.         function camelCase(text){
  3.             return text.split(/[\W_]/g).map(function(word,index){
  4.                 return word.charAt(0).toUpperCase() + word.slice(1)
  5.             }).join('')
  6.         }
  7.  
  8.         var checks = [
  9.             'user_agent',
  10.             'language',
  11.             'color_depth',
  12.             'color_depth',
  13.             'device_memory',
  14.             'hardware_concurrency',
  15.             ['resolution', 'excludeScreenResolution'],
  16.             ['available_resolution', 'excludeAvailableScreenResolution'],
  17.             'timezone_offset',
  18.             'timezone',
  19.             'session_storage',
  20.             'local_storage',
  21.             ['indexed_db', 'excludeIndexedDB'],
  22.             'cpu_class',
  23.             ['navigator_platform', 'excludePlatform'],
  24.             ['regular_plugins', 'excludePlugins'],
  25.             'canvas',
  26.             ['webgl', 'excludeWebGL'],
  27.             ['webgl_vendor', 'excludeWebGLVendorAndRenderer'],
  28.             ['adblock', 'excludeAdBlock'],
  29.             'has_lied_languages',
  30.             'has_lied_resolution',
  31.             'has_lied_os',
  32.             'has_lied_browser',
  33.             'touch_support',
  34.             'js_fonts',
  35.             ['audio_fp', 'excludeAudio'],
  36.             'enumerate_devices',
  37.             'add_behavior',
  38.             'open_database',
  39.         ];
  40.  
  41.         it('empty components when exluding everything', function(done){
  42.             var options = {};
  43.             for(var i = 0; i < checks.length; ++i) {
  44.                 var exclude_key = checks[i] instanceof Array ? checks[i][1] : "exclude" + camelCase(checks[i]);
  45.                 options[exclude_key] = true;
  46.             }
  47.             var fp2 = new Fingerprint2(options)
  48.             fp2.get(function(result, components){
  49.                 expect(components.length).toEqual(0)
  50.                 done()
  51.             })
  52.         })
  53.        
  54.         it('components available when NOT exluded', function(done){
  55.             var fp2 = new Fingerprint2()
  56.             fp2.get(function(result, components){
  57.                 expect(function() {
  58.                     for(var i = 0; i < checks.length; ++i) {
  59.                         var key = checks[i] instanceof Array ? checks[i][0] : checks[i];
  60.                         if(key == 'enumerate_devices' && !fp2.isEnumerateDevicesSupported())
  61.                             continue
  62.                         if(key == 'session_storage' && !fp2.hasSessionStorage())
  63.                             continue
  64.                         if(key == 'local_storage' && !fp2.hasLocalStorage())
  65.                             continue
  66.                         if(key == 'indexed_db' && !fp2.hasIndexedDB())
  67.                             continue
  68.                         if(key == 'add_behavior' && !(document.body && document.body.addBehavior))
  69.                             continue
  70.                         if(key == 'open_database' && !window.openDatabase)
  71.                             continue
  72.                         if(key == 'canvas' && !fp2.isCanvasSupported())
  73.                             continue
  74.                         if((key == 'webgl' || key == 'webgl_vendor') && !fp2.isWebGlSupported())
  75.                             continue
  76.                         if(key == 'regular_plugins' && fp2.isIE())
  77.                             key = 'ie_plugins'
  78.                         getComponent(components, key)
  79.                     }
  80.                 }).not.toThrow()
  81.                 done()
  82.             })
  83.         })
  84.     })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement