19
19
20
20
const assert = require ( 'assert' )
21
21
const fs = require ( 'fs' )
22
+ const path = require ( 'path' )
22
23
23
24
const chrome = require ( '../../chrome' )
24
25
const symbols = require ( '../../lib/symbols' )
25
26
const test = require ( '../../lib/test' )
26
27
28
+ const WEBEXTENSION_CRX = path . join (
29
+ __dirname ,
30
+ '../../lib/test/data/chrome/webextension.crx'
31
+ )
32
+
27
33
describe ( 'chrome.Options' , function ( ) {
28
34
describe ( 'addArguments' , function ( ) {
29
35
it ( 'takes var_args' , function ( ) {
@@ -65,15 +71,16 @@ describe('chrome.Options', function () {
65
71
assert . strictEqual ( options . options_ . extensions , undefined )
66
72
67
73
options . addExtensions ( 'a' , 'b' )
68
- assert . deepStrictEqual ( options . options_ . extensions , [ 'a' , 'b' ] )
74
+ assert . deepStrictEqual ( options . options_ . extensions . extensions ,
75
+ [ 'a' , 'b' ] )
69
76
} )
70
77
71
78
it ( 'flattens input arrays' , function ( ) {
72
79
let options = new chrome . Options ( )
73
80
assert . strictEqual ( options . options_ . extensions , undefined )
74
81
75
82
options . addExtensions ( [ 'a' , 'b' ] , 'c' , [ 1 , 2 ] , 3 )
76
- assert . deepStrictEqual ( options . options_ . extensions , [
83
+ assert . deepStrictEqual ( options . options_ . extensions . extensions , [
77
84
'a' ,
78
85
'b' ,
79
86
'c' ,
@@ -86,16 +93,15 @@ describe('chrome.Options', function () {
86
93
87
94
describe ( 'serialize' , function ( ) {
88
95
it ( 'base64 encodes extensions' , async function ( ) {
89
- let expected = fs . readFileSync ( __filename , 'base64' )
96
+ let expected = fs . readFileSync ( WEBEXTENSION_CRX , 'base64' )
90
97
let wire = new chrome . Options ( )
91
- . addExtensions ( __filename )
98
+ . addExtensions ( WEBEXTENSION_CRX )
92
99
[ symbols . serialize ] ( )
93
100
94
- assert . strictEqual ( wire [ 'goog:chromeOptions' ] . extensions . length , 1 )
95
- assert . strictEqual (
96
- await wire [ 'goog:chromeOptions' ] . extensions [ 0 ] ,
97
- expected
98
- )
101
+ let extensions = wire [ 'goog:chromeOptions' ] . extensions
102
+ [ symbols . serialize ] ( )
103
+ assert . strictEqual ( extensions . length , 1 )
104
+ assert . strictEqual ( await extensions [ 0 ] , expected )
99
105
} )
100
106
} )
101
107
@@ -129,8 +135,12 @@ test.suite(
129
135
function ( env ) {
130
136
var driver
131
137
138
+ beforeEach ( function ( ) {
139
+ driver = null
140
+ } )
141
+
132
142
afterEach ( function ( ) {
133
- return driver . quit ( )
143
+ return driver && driver . quit ( )
134
144
} )
135
145
136
146
describe ( 'Chrome options' , function ( ) {
@@ -146,6 +156,38 @@ test.suite(
146
156
)
147
157
assert . strictEqual ( userAgent , 'foo;bar' )
148
158
} )
159
+
160
+ it ( 'can install an extension from path' , async function ( ) {
161
+ let options = new chrome . Options ( ) . addExtensions ( WEBEXTENSION_CRX )
162
+
163
+ driver = await env . builder ( ) . forBrowser ( 'chrome' )
164
+ . setChromeOptions ( options ) . build ( )
165
+
166
+ await driver . get ( test . Pages . echoPage )
167
+ await verifyWebExtensionWasInstalled ( )
168
+ } )
169
+
170
+ it ( 'can install an extension from Buffer' , async function ( ) {
171
+ let options = new chrome . Options ( )
172
+ . addExtensions ( fs . readFileSync ( WEBEXTENSION_CRX ) )
173
+
174
+ driver = await env . builder ( ) . forBrowser ( 'chrome' )
175
+ . setChromeOptions ( options ) . build ( )
176
+
177
+ await driver . get ( test . Pages . echoPage )
178
+ await verifyWebExtensionWasInstalled ( )
179
+ } )
180
+
181
+ async function verifyWebExtensionWasInstalled ( ) {
182
+ let footer = await driver . findElement ( {
183
+ id : 'webextensions-selenium-example' ,
184
+ } )
185
+ let text = await footer . getText ( )
186
+ assert . strictEqual (
187
+ text ,
188
+ 'Content injected by webextensions-selenium-example'
189
+ )
190
+ }
149
191
} )
150
192
} ,
151
193
{ browsers : [ 'chrome' ] }
0 commit comments