2015-04-04 09:53:59 -07:00
|
|
|
// Licensed to the Software Freedom Conservancy (SFC) under one
|
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
|
// distributed with this work for additional information
|
|
|
|
|
// regarding copyright ownership. The SFC licenses this file
|
|
|
|
|
// to you under the Apache License, Version 2.0 (the
|
|
|
|
|
// "License"); you may not use this file except in compliance
|
|
|
|
|
// with the License. You may obtain a copy of the License at
|
2015-03-18 21:06:36 -07:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2015-03-18 21:06:36 -07:00
|
|
|
//
|
2015-04-04 09:53:59 -07:00
|
|
|
// Unless required by applicable law or agreed to in writing,
|
|
|
|
|
// software distributed under the License is distributed on an
|
|
|
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
|
// KIND, either express or implied. See the License for the
|
|
|
|
|
// specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
2015-03-18 21:06:36 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
'use strict'
|
2015-03-18 21:06:36 -07:00
|
|
|
|
2024-04-16 01:50:58 +05:30
|
|
|
const assert = require('node:assert')
|
|
|
|
|
const path = require('node:path')
|
2024-06-27 18:33:36 +01:00
|
|
|
const io = require('selenium-webdriver/io')
|
|
|
|
|
const cmd = require('selenium-webdriver/lib/command')
|
|
|
|
|
const remote = require('selenium-webdriver/remote')
|
|
|
|
|
const { CancellationError } = require('selenium-webdriver/http/util')
|
2016-10-30 11:30:58 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
describe('DriverService', function () {
|
|
|
|
|
describe('start()', function () {
|
|
|
|
|
var service
|
2015-03-18 21:06:36 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
beforeEach(function () {
|
2015-03-19 09:23:54 -07:00
|
|
|
service = new remote.DriverService(process.execPath, {
|
|
|
|
|
port: 1234,
|
2020-08-03 17:56:31 +03:00
|
|
|
args: ['-e', 'process.exit(1)'],
|
|
|
|
|
})
|
|
|
|
|
})
|
2015-03-18 21:06:36 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
afterEach(function () {
|
|
|
|
|
return service.kill()
|
|
|
|
|
})
|
2015-03-18 21:06:36 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
it('fails if child-process dies', function () {
|
|
|
|
|
return service.start(500).then(expectFailure, verifyFailure)
|
|
|
|
|
})
|
2015-03-19 09:23:54 -07:00
|
|
|
|
2016-10-30 11:30:58 -07:00
|
|
|
function verifyFailure(e) {
|
2020-08-03 17:56:31 +03:00
|
|
|
assert.ok(!(e instanceof CancellationError))
|
2021-03-24 10:42:10 -07:00
|
|
|
assert.strictEqual('Server terminated early with status 1', e.message)
|
2015-03-19 09:23:54 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-30 11:30:58 -07:00
|
|
|
function expectFailure() {
|
2020-08-03 17:56:31 +03:00
|
|
|
throw Error('expected to fail')
|
2015-03-19 09:23:54 -07:00
|
|
|
}
|
2020-08-03 17:56:31 +03:00
|
|
|
})
|
|
|
|
|
})
|
2016-03-15 14:01:00 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
describe('FileDetector', function () {
|
2016-03-15 14:01:00 -07:00
|
|
|
class ExplodingDriver {
|
2017-10-02 22:08:51 -04:00
|
|
|
execute() {
|
2020-08-03 17:56:31 +03:00
|
|
|
throw Error('unexpected call')
|
2016-03-15 14:01:00 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
it('returns the original path if the file does not exist', function () {
|
|
|
|
|
return io.tmpDir().then((dir) => {
|
|
|
|
|
let theFile = path.join(dir, 'not-there')
|
|
|
|
|
return new remote.FileDetector()
|
|
|
|
|
.handleFile(new ExplodingDriver(), theFile)
|
2021-03-24 10:42:10 -07:00
|
|
|
.then((f) => assert.strictEqual(f, theFile))
|
2020-08-03 17:56:31 +03:00
|
|
|
})
|
|
|
|
|
})
|
2016-03-15 14:01:00 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
it('returns the original path if it is a directory', function () {
|
|
|
|
|
return io.tmpDir().then((dir) => {
|
2024-02-07 16:07:24 +00:00
|
|
|
return new remote.FileDetector().handleFile(new ExplodingDriver(), dir).then((f) => assert.strictEqual(f, dir))
|
2020-08-03 17:56:31 +03:00
|
|
|
})
|
|
|
|
|
})
|
2016-03-15 14:01:00 -07:00
|
|
|
|
2020-08-03 17:56:31 +03:00
|
|
|
it('attempts to upload valid files', function () {
|
|
|
|
|
return io.tmpFile().then((theFile) => {
|
|
|
|
|
return new remote.FileDetector()
|
|
|
|
|
.handleFile(
|
|
|
|
|
new (class FakeDriver {
|
|
|
|
|
execute(command) {
|
2021-03-24 10:42:10 -07:00
|
|
|
assert.strictEqual(command.getName(), cmd.Name.UPLOAD_FILE)
|
2024-02-07 16:07:24 +00:00
|
|
|
assert.strictEqual(typeof command.getParameters()['file'], 'string')
|
2020-08-03 17:56:31 +03:00
|
|
|
return Promise.resolve('success!')
|
|
|
|
|
}
|
|
|
|
|
})(),
|
2024-02-07 16:07:24 +00:00
|
|
|
theFile,
|
2020-08-03 17:56:31 +03:00
|
|
|
)
|
2021-03-24 10:42:10 -07:00
|
|
|
.then((f) => assert.strictEqual(f, 'success!'))
|
2020-08-03 17:56:31 +03:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|