Skip to content

Commit 5a96d77

Browse files
committed
test: runtime-checks isBrave, hasChromeSocketsForTcp
1 parent 2b63636 commit 5a96d77

File tree

1 file changed

+41
-6
lines changed

1 file changed

+41
-6
lines changed

test/functional/lib/runtime-checks.test.js

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
'use strict'
2+
/* eslint-env browser, webextensions */
3+
24
const { describe, it, before, beforeEach, after } = require('mocha')
35
const { expect } = require('chai')
46
const browser = require('sinon-chrome')
5-
const { createRuntimeChecks } = require('../../../add-on/src/lib/runtime-checks')
7+
const { createRuntimeChecks, hasChromeSocketsForTcp } = require('../../../add-on/src/lib/runtime-checks')
68

79
describe('runtime-checks.js', function () {
810
before(() => {
911
global.browser = browser
12+
global.chrome = {}
1013
})
1114

1215
beforeEach(function () {
@@ -57,6 +60,31 @@ describe('runtime-checks.js', function () {
5760
})
5861
})
5962

63+
describe('isBrave', function () {
64+
beforeEach(function () {
65+
browser.flush()
66+
})
67+
68+
it('should return true when expected chrome.sockets.tcp* are present', async function () {
69+
chrome.runtime = { id: 'fakeid' }
70+
chrome.sockets = { tcpServer: {}, tcp: {} }
71+
const runtime = await createRuntimeChecks(browser)
72+
expect(runtime.isBrave).to.equal(true)
73+
/* TODO: right now its just an alias for hasChromeSocketsForTcpm but
74+
we need to find a better way to tell Brave from Opera */
75+
expect(runtime.isBrave).to.equal(runtime.hasChromeSocketsForTcp)
76+
})
77+
78+
it('should return false when chrome.sockets.tcp* are missing', async function () {
79+
delete chrome.sockets
80+
const runtime = await createRuntimeChecks(browser)
81+
expect(runtime.isBrave).to.equal(false)
82+
/* TODO: right now its just an alias for hasChromeSocketsForTcpm but
83+
we need to find a better way to tell Brave from Opera */
84+
expect(runtime.isBrave).to.equal(runtime.hasChromeSocketsForTcp)
85+
})
86+
})
87+
6088
describe('hasNativeProtocolHandler', function () {
6189
beforeEach(function () {
6290
browser.flush()
@@ -78,21 +106,28 @@ describe('runtime-checks.js', function () {
78106
})
79107
})
80108

81-
/* TODO
82109
describe('hasChromeSocketsForTcp', function () {
83110
beforeEach(function () {
84111
browser.flush()
85112
})
86113

87-
it('should return true when chrome.sockets.tcp* are present', async function () {
88-
// TODO
114+
it('should return true when expected chrome.sockets.tcp* are present', async function () {
115+
chrome.runtime = { id: 'fakeid' }
116+
chrome.sockets = { tcpServer: {}, tcp: {} }
117+
const runtime = await createRuntimeChecks(browser)
118+
expect(runtime.hasChromeSocketsForTcp).to.equal(true)
119+
// static version should return the same value
120+
expect(runtime.hasChromeSocketsForTcp).to.equal(hasChromeSocketsForTcp())
89121
})
90122

91123
it('should return false when chrome.sockets.tcp* are missing', async function () {
92-
// TODO
124+
delete chrome.sockets
125+
const runtime = await createRuntimeChecks(browser)
126+
expect(runtime.hasChromeSocketsForTcp).to.equal(false)
127+
// static version should return the same value
128+
expect(runtime.hasChromeSocketsForTcp).to.equal(hasChromeSocketsForTcp())
93129
})
94130
})
95-
*/
96131

97132
after(function () {
98133
delete global.browser

0 commit comments

Comments
 (0)