aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/extension-test.js
blob: 86e1d887a9f1d1f2b18cdaa95ffdd00b981d8b5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var assert = require('assert')
var sinon = require('sinon')
const ethUtil = require('ethereumjs-util')
GLOBAL.chrome = {}
GLOBAL.browser = {}

var path = require('path')
var Extension = require(path.join(__dirname, '..', '..', 'app', 'scripts', 'lib', 'extension-instance.js'))

describe('extension', function() {

  describe('extension.getURL', function() {
    const desiredResult = 'http://the-desired-result.io'

    describe('in Chrome or Firefox', function() {
      GLOBAL.chrome.extension = {
        getURL: () => desiredResult
      }

      it('returns the desired result', function() {
        const extension = new Extension()
        const result = extension.extension.getURL()
        assert.equal(result, desiredResult)
      })
    })

    describe('in Microsoft Edge', function() {
      GLOBAL.browser.extension = {
        getURL: () => desiredResult
      }

      it('returns the desired result', function() {
        const extension = new Extension()
        const result = extension.extension.getURL()
        assert.equal(result, desiredResult)
      })
    })
  })

  describe('with chrome global', function() {
    let extension

    beforeEach(function() {
      GLOBAL.chrome = {
        alarms: 'foo'
      }
      extension = new Extension()
    })

    it('should use the chrome global apis', function() {
      assert.equal(extension.alarms, 'foo')
    })
  })

  describe('without chrome global', function() {
    let extension
    let realWindow

    beforeEach(function() {
      realWindow = window
      window = GLOBAL
      GLOBAL.chrome = undefined
      GLOBAL.alarms = 'foo'
      extension = new Extension()
    })

    after(function() {
      window = realWindow
    })

    it('should use the global apis', function() {
      assert.equal(extension.alarms, 'foo')
    })
  })


})