<commit_before>'use strict'

require('../lib/peer-watch.js')

const { setTimeout } = require('sdk/timers')
const { prefs } = require('sdk/simple-prefs')
const tabs = require('sdk/tabs')
const gw = require('../lib/gateways.js')

exports['test automatic mode disabling redirect when IPFS API is offline'] = function (assert, done) {
  const ipfsPath = 'ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/Makefile'
  prefs.apiPollInterval = 100 // faster test
  prefs.customApiPort = 59999 // change to something that will always fail
  prefs.useCustomGateway = true
  prefs.automatic = true

  setTimeout(function () {
    assert.equal(prefs.automatic, true, 'automatic mode should be enabled')
    assert.equal(prefs.useCustomGateway, false, 'redirect should be automatically disabled')
    assert.equal(gw.redirectEnabled, false, 'redirect should be automatically disabled')
    tabs.open({
      url: 'https://ipfs.io/' + ipfsPath,
      onReady: function onReady (tab) {
        assert.equal(tab.url, 'https://ipfs.io/' + ipfsPath, 'expected no redirect')
        tab.close(done)
      }
    })
  }, prefs.apiPollInterval + 500)
}

require('./prefs-util.js').isolateTestCases(exports)
require('sdk/test').run(exports)
<commit_msg>Increase test timeout when run in TravisCI<commit_after>'use strict'

require('../lib/peer-watch.js')

const { env } = require('sdk/system/environment')
const { setTimeout } = require('sdk/timers')
const { prefs } = require('sdk/simple-prefs')
const tabs = require('sdk/tabs')
const gw = require('../lib/gateways.js')

exports['test automatic mode disabling redirect when IPFS API is offline'] = function (assert, done) {
  const ipfsPath = 'ipfs/QmTkzDwWqPbnAh5YiV5VwcTLnGdwSNsNTn2aDxdXBFca7D/Makefile'
  const checkDelay = ('TRAVIS' in env && 'CI' in env) ? 5000 : 500
  prefs.apiPollInterval = 100 // faster test
  prefs.customApiPort = 59999 // change to something that will always fail
  prefs.useCustomGateway = true
  prefs.automatic = true

  setTimeout(function () {
    assert.equal(prefs.automatic, true, 'automatic mode should be enabled')
    assert.equal(prefs.useCustomGateway, false, 'redirect should be automatically disabled')
    assert.equal(gw.redirectEnabled, false, 'redirect should be automatically disabled')
    tabs.open({
      url: 'https://ipfs.io/' + ipfsPath,
      onReady: function onReady (tab) {
        assert.equal(tab.url, 'https://ipfs.io/' + ipfsPath, 'expected no redirect')
        tab.close(done)
      }
    })
  }, prefs.apiPollInterval + checkDelay)
}

require('./prefs-util.js').isolateTestCases(exports)
require('sdk/test').run(exports)

{'fraction_non_alphanumeric': 0.1344024436807942, 'fraction_numerical': 0.012982054219167621, 'mean_word_length': 4.12720156555773, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1333410', 'n_tokens_mistral': 886, 'n_tokens_neox': 851, 'n_words': 197}