|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +'use strict' |
| 19 | + |
| 20 | +const assert = require('assert') |
| 21 | +const fs = require('fs') |
| 22 | + |
| 23 | +const edge = require('../../edge') |
| 24 | +const symbols = require('../../lib/symbols') |
| 25 | +const test = require('../../lib/test') |
| 26 | + |
| 27 | +describe('edge.Options', function () { |
| 28 | + describe('addArguments', function () { |
| 29 | + it('takes var_args', function () { |
| 30 | + let options = new edge.Options() |
| 31 | + assert.deepStrictEqual(options[symbols.serialize](), { |
| 32 | + browserName: 'MicrosoftEdge', |
| 33 | + 'ms:edgeOptions': {}, |
| 34 | + }) |
| 35 | + |
| 36 | + options.addArguments('a', 'b') |
| 37 | + assert.deepStrictEqual(options[symbols.serialize](), { |
| 38 | + browserName: 'MicrosoftEdge', |
| 39 | + 'ms:edgeOptions': { |
| 40 | + args: ['a', 'b'], |
| 41 | + }, |
| 42 | + }) |
| 43 | + }) |
| 44 | + |
| 45 | + it('flattens input arrays', function () { |
| 46 | + let options = new edge.Options() |
| 47 | + assert.deepStrictEqual(options[symbols.serialize](), { |
| 48 | + browserName: 'MicrosoftEdge', |
| 49 | + 'ms:edgeOptions': {}, |
| 50 | + }) |
| 51 | + |
| 52 | + options.addArguments(['a', 'b'], 'c', [1, 2], 3) |
| 53 | + assert.deepStrictEqual(options[symbols.serialize](), { |
| 54 | + browserName: 'MicrosoftEdge', |
| 55 | + 'ms:edgeOptions': { |
| 56 | + args: ['a', 'b', 'c', 1, 2, 3], |
| 57 | + }, |
| 58 | + }) |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + describe('addExtensions', function () { |
| 63 | + it('takes var_args', function () { |
| 64 | + let options = new edge.Options() |
| 65 | + assert.strictEqual(options.options_.extensions, undefined) |
| 66 | + |
| 67 | + options.addExtensions('a', 'b') |
| 68 | + assert.deepStrictEqual(options.options_.extensions, ['a', 'b']) |
| 69 | + }) |
| 70 | + |
| 71 | + it('flattens input arrays', function () { |
| 72 | + let options = new edge.Options() |
| 73 | + assert.strictEqual(options.options_.extensions, undefined) |
| 74 | + |
| 75 | + options.addExtensions(['a', 'b'], 'c', [1, 2], 3) |
| 76 | + assert.deepStrictEqual(options.options_.extensions, ['a', 'b', 'c', 1, 2, 3]) |
| 77 | + }) |
| 78 | + }) |
| 79 | + |
| 80 | + describe('serialize', function () { |
| 81 | + it('base64 encodes extensions', async function () { |
| 82 | + let expected = fs.readFileSync(__filename, 'base64') |
| 83 | + let wire = new edge.Options() |
| 84 | + .addExtensions(__filename) |
| 85 | + [symbols.serialize]() |
| 86 | + |
| 87 | + assert.strictEqual(wire['ms:edgeOptions'].extensions.length, 1) |
| 88 | + assert.strictEqual( |
| 89 | + await wire['ms:edgeOptions'].extensions[0], |
| 90 | + expected |
| 91 | + ) |
| 92 | + }) |
| 93 | + }) |
| 94 | + |
| 95 | + describe('windowTypes', function() { |
| 96 | + it('takes var_args', function() { |
| 97 | + let options = new edge.Options(); |
| 98 | + assert.strictEqual(options.options_.windowTypes, undefined); |
| 99 | + |
| 100 | + options.windowTypes('a', 'b'); |
| 101 | + assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b']); |
| 102 | + }) |
| 103 | + |
| 104 | + it('flattens input arrays', function() { |
| 105 | + let options = new edge.Options(); |
| 106 | + assert.strictEqual(options.options_.windowTypes, undefined); |
| 107 | + |
| 108 | + options.windowTypes(['a', 'b'], 'c', [1, 2], 3); |
| 109 | + assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b', 'c', 1, 2, 3]); |
| 110 | + }) |
| 111 | + }) |
| 112 | +}) |
| 113 | + |
| 114 | +test.suite( |
| 115 | + function (env) { |
| 116 | + var driver |
| 117 | + |
| 118 | + afterEach(function () { |
| 119 | + return driver.quit() |
| 120 | + }) |
| 121 | + |
| 122 | + describe('Edge options', function () { |
| 123 | + it('can start edge with custom args', async function () { |
| 124 | + var options = new edge.Options().addArguments('user-agent=foo;bar') |
| 125 | + |
| 126 | + driver = await env.builder().setEdgeOptions(options).build() |
| 127 | + |
| 128 | + await driver.get(test.Pages.ajaxyPage) |
| 129 | + |
| 130 | + var userAgent = await driver.executeScript( |
| 131 | + 'return window.navigator.userAgent' |
| 132 | + ) |
| 133 | + assert.strictEqual(userAgent, 'foo;bar') |
| 134 | + }) |
| 135 | + |
| 136 | + it('can start edge with network conditions set', async function () { |
| 137 | + |
| 138 | + driver = await env.builder().build() |
| 139 | + await driver.get(test.Pages.ajaxyPage) |
| 140 | + await driver.setNetworkConditions({ |
| 141 | + offline: true, |
| 142 | + latency: 0, |
| 143 | + download_throughput: 0, |
| 144 | + upload_throughput: 0 |
| 145 | + }); |
| 146 | + assert.deepStrictEqual(await driver.getNetworkConditions(), |
| 147 | + { |
| 148 | + download_throughput: 0, |
| 149 | + latency: 0, |
| 150 | + offline: true, |
| 151 | + upload_throughput: 0 |
| 152 | + }) |
| 153 | + }) |
| 154 | + }) |
| 155 | + }, |
| 156 | + { browsers: ['MicrosoftEdge'] } |
| 157 | +) |
0 commit comments