forked from vitalets/autotester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension_switching_test.js
103 lines (80 loc) · 3.23 KB
/
extension_switching_test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
'use strict';
var assert = require('../testing/assert');
var test = require('../lib/test');
test.suite(function (env) {
var driver;
var initialHandle;
test.before(function () {
driver = env.builder().build();
driver.getWindowHandle().then(handle => initialHandle = handle);
});
test.beforeEach(function () {
driver.switchTo().window(initialHandle);
driver.get('about:blank');
});
test.after(function () {
driver.quit();
});
describe('extension switching', function () {
describe('background', function () {
test.it('should contain extension background handler', function () {
driver.getAllWindowHandles().then(handles => {
assert(handles.indexOf(runContext.selftest.handle) >= 0).equalTo(true);
});
});
test.it('should exclude autotester background handler', function () {
driver.getAllWindowHandles().then(handles => {
const handle = `extension-${chrome.runtime.id}`;
assert(handles.indexOf(handle)).equalTo(-1);
});
});
test.it('should switch and call command', function () {
driver.switchTo().window(runContext.selftest.handle);
assert(driver.getCurrentUrl()).equalTo(runContext.selftest.bg);
});
test.it('should access chrome api', function () {
driver.switchTo().window(runContext.selftest.handle);
const manifestVersion = driver.executeScript(function () {
return chrome.runtime.getManifest().manifest_version;
});
assert(manifestVersion).equalTo(2);
});
test.it('should execute async script', function () {
driver.switchTo().window(runContext.selftest.handle);
const popup = driver.executeAsyncScript(function () {
chrome.browserAction.getTitle({}, arguments[arguments.length - 1]);
});
assert(popup).equalTo('Autotester');
});
test.it('should switch via .extension(id)', function () {
driver.switchTo().extension(runContext.selftest.id);
assert(driver.getCurrentUrl()).equalTo(runContext.selftest.bg);
});
test.it('should switch via .extension() without id to first available extension', function () {
driver.switchTo().extension();
assert(driver.getCurrentUrl()).startsWith('chrome-extension://');
});
test.it('should not fail on several .extension() calls', function () {
driver.switchTo().extension(runContext.selftest.id);
driver.switchTo().extension(runContext.selftest.id);
});
});
describe('tab with extension url', function () {
test.it('should navigate', function () {
driver.get(runContext.selftest.ui);
assert(driver.getCurrentUrl()).equalTo(runContext.selftest.ui);
});
test.it('should open as newtab', function () {
driver.switchTo().newTab(runContext.selftest.ui);
assert(driver.getCurrentUrl()).equalTo(runContext.selftest.ui);
});
test.it('should access chrome api', function () {
driver.get(runContext.selftest.ui);
const manifestVersion = driver.executeScript(function () {
return chrome.runtime.getManifest().manifest_version;
});
assert(manifestVersion).equalTo(2);
});
});
});
});