1
1
'use strict'
2
+ /* eslint-env browser, webextensions */
3
+
2
4
const { describe, it, before, beforeEach, after } = require ( 'mocha' )
3
5
const { expect } = require ( 'chai' )
4
6
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' )
6
8
7
9
describe ( 'runtime-checks.js' , function ( ) {
8
10
before ( ( ) => {
9
11
global . browser = browser
12
+ global . chrome = { }
10
13
} )
11
14
12
15
beforeEach ( function ( ) {
@@ -57,6 +60,31 @@ describe('runtime-checks.js', function () {
57
60
} )
58
61
} )
59
62
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
+
60
88
describe ( 'hasNativeProtocolHandler' , function ( ) {
61
89
beforeEach ( function ( ) {
62
90
browser . flush ( )
@@ -78,21 +106,28 @@ describe('runtime-checks.js', function () {
78
106
} )
79
107
} )
80
108
81
- /* TODO
82
109
describe ( 'hasChromeSocketsForTcp' , function ( ) {
83
110
beforeEach ( function ( ) {
84
111
browser . flush ( )
85
112
} )
86
113
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 ( ) )
89
121
} )
90
122
91
123
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 ( ) )
93
129
} )
94
130
} )
95
- */
96
131
97
132
after ( function ( ) {
98
133
delete global . browser
0 commit comments