Skip to content

Commit 73ceb2f

Browse files
committed
Merge pull request #139 from marco-c/simplify_test
Simplify Selenium test
2 parents 656876a + fa55543 commit 73ceb2f

File tree

3 files changed

+60
-45
lines changed

3 files changed

+60
-45
lines changed

test/index.html

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,42 @@
1313
});
1414
}
1515

16-
var serverAddress;
16+
navigator.serviceWorker.ready
17+
.then(function(reg) {
18+
var channel = new MessageChannel();
19+
channel.port1.onmessage = function(e) {
20+
window.document.title = e.data;
21+
}
22+
reg.active.postMessage('setup', [channel.port2]);
1723

18-
function go() {
19-
navigator.serviceWorker.ready
20-
.then(function(reg) {
21-
var channel = new MessageChannel();
22-
channel.port1.onmessage = function(e) {
23-
window.document.title = e.data;
24-
}
25-
reg.active.postMessage('setup', [channel.port2]);
26-
27-
return reg.pushManager.getSubscription()
28-
.then(function(subscription) {
29-
if (!subscription) {
30-
return reg.pushManager.subscribe({ userVisibleOnly: true })
31-
.then(function(subscription) {
32-
return subscription;
33-
});
34-
} else {
35-
return subscription;
36-
}
37-
});
38-
})
24+
return reg.pushManager.getSubscription()
3925
.then(function(subscription) {
40-
var key = subscription.getKey ? subscription.getKey('p256dh') : '';
41-
var auth = subscription.getKey ? subscription.getKey('auth') : '';
26+
if (!subscription) {
27+
return reg.pushManager.subscribe({ userVisibleOnly: true })
28+
.then(function(subscription) {
29+
return subscription;
30+
});
31+
} else {
32+
return subscription;
33+
}
34+
});
35+
})
36+
.then(function(subscription) {
37+
var key = subscription.getKey ? subscription.getKey('p256dh') : '';
38+
var auth = subscription.getKey ? subscription.getKey('auth') : '';
4239

43-
return fetch(serverAddress, {
44-
method: 'post',
45-
headers: {
46-
'Content-type': 'application/json'
47-
},
48-
body: JSON.stringify({
49-
endpoint: subscription.endpoint,
50-
key: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : '',
51-
auth: auth ? btoa(String.fromCharCode.apply(null, new Uint8Array(auth))) : '',
52-
}),
53-
});
40+
return fetch('/', {
41+
method: 'post',
42+
headers: {
43+
'Content-type': 'application/json'
44+
},
45+
body: JSON.stringify({
46+
endpoint: subscription.endpoint,
47+
key: key ? btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : '',
48+
auth: auth ? btoa(String.fromCharCode.apply(null, new Uint8Array(auth))) : '',
49+
}),
5450
});
55-
}
51+
});
5652
</script>
5753
</body>
5854
</html>

test/selenium-init.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function unzip(dir, file) {
4646
var destDir = 'test_tools';
4747
var stableDestDir = 'test_tools/stable';
4848
var betaDestDir = 'test_tools/beta';
49+
var auroraDestDir = 'test_tools/aurora';
4950

5051
try {
5152
fs.mkdirSync(destDir);
@@ -62,6 +63,11 @@ try {
6263
} catch (e) {
6364
}
6465

66+
try {
67+
fs.mkdirSync(auroraDestDir);
68+
} catch (e) {
69+
}
70+
6571
if (process.platform !== 'linux' && process.platform !== 'darwin') {
6672
throw new Error('Platform ' + process.platform + ' not supported.');
6773
}
@@ -204,6 +210,10 @@ function downloadFirefoxBeta() {
204210
return downloadFirefoxFromDMO('firefox-beta-latest', betaDestDir);
205211
}
206212

213+
function downloadFirefoxAurora() {
214+
return downloadFirefoxFromDMO('firefox-aurora-latest', auroraDestDir);
215+
}
216+
207217
// Download Chrome Canary
208218

209219
var chromePlatform, chromeZipPlatform;
@@ -273,6 +283,7 @@ module.exports = {
273283
downloadFirefoxNightly: downloadFirefoxNightly,
274284
downloadFirefoxRelease: downloadFirefoxRelease,
275285
downloadFirefoxBeta: downloadFirefoxBeta,
286+
downloadFirefoxAurora: downloadFirefoxAurora,
276287
downloadChromiumNightly: downloadChromiumNightly,
277288
downloadChromeDriver: downloadChromeDriver,
278289
};

test/testSelenium.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ suite('selenium', function() {
3636

3737
this.timeout(180000);
3838

39-
var firefoxStableBinaryPath, firefoxBetaBinaryPath, firefoxNightlyBinaryPath, chromeBinaryPath;
39+
var firefoxStableBinaryPath, firefoxBetaBinaryPath, firefoxAuroraBinaryPath, firefoxNightlyBinaryPath, chromeBinaryPath;
4040
var server, driver;
4141

4242
function runTest(params) {
@@ -46,6 +46,10 @@ suite('selenium', function() {
4646
} else if (params.browser === 'firefox-beta') {
4747
params.browser = 'firefox';
4848
firefoxBinaryPath = firefoxBetaBinaryPath;
49+
} else if (params.browser === 'firefox-aurora') {
50+
params.browser = 'firefox';
51+
firefoxBinaryPath = firefoxAuroraBinaryPath;
52+
process.env.SELENIUM_MARIONETTE = true;
4953
}
5054

5155
process.env.SELENIUM_BROWSER = params.browser;
@@ -92,11 +96,6 @@ suite('selenium', function() {
9296

9397
driver.get('http://127.0.0.1:' + server.port);
9498

95-
driver.executeScript(function(port) {
96-
serverAddress = 'http://127.0.0.1:' + port;
97-
go();
98-
}, server.port);
99-
10099
return driver.wait(webdriver.until.titleIs(params.payload ? params.payload : 'no payload'), 60000);
101100
});
102101
}
@@ -122,6 +121,14 @@ suite('selenium', function() {
122121

123122
promises.push(seleniumInit.downloadFirefoxBeta());
124123

124+
/*if (process.platform === 'linux') {
125+
firefoxAuroraBinaryPath = 'test_tools/aurora/firefox/firefox-bin';
126+
} else if (process.platform === 'darwin') {
127+
firefoxAuroraBinaryPath = 'test_tools/aurora/Firefox.app/Contents/MacOS/firefox-bin';
128+
}
129+
130+
promises.push(seleniumInit.downloadFirefoxAurora());*/
131+
125132
if (process.platform === 'linux') {
126133
firefoxNightlyBinaryPath = 'test_tools/firefox/firefox-bin';
127134
} else if (process.platform === 'darwin') {
@@ -154,8 +161,9 @@ suite('selenium', function() {
154161

155162
try {
156163
console.log('Using Firefox: ' + firefoxStableBinaryPath);
157-
console.log('Version: ' + childProcess.execSync(firefoxStableBinaryPath + ' --version'));
158-
console.log('Beta Version: ' + childProcess.execSync(firefoxBetaBinaryPath + ' --version'));
164+
console.log('Version: ' + childProcess.execSync(firefoxStableBinaryPath + ' --version').replace('\n', ''));
165+
console.log('Beta Version: ' + childProcess.execSync(firefoxBetaBinaryPath + ' --version').replace('\n', ''));
166+
console.log('Aurora Version: ' + childProcess.execSync(firefoxAuroraBinaryPath + ' --version').replace('\n', ''));
159167
} catch (e) {}
160168

161169
if (process.env.GCM_API_KEY && !fs.existsSync(chromeBinaryPath)) {
@@ -164,7 +172,7 @@ suite('selenium', function() {
164172

165173
try {
166174
console.log('Using Chromium: ' + chromeBinaryPath);
167-
console.log('Version: ' + childProcess.execSync(chromeBinaryPath + ' --version'));
175+
console.log('Version: ' + childProcess.execSync(chromeBinaryPath + ' --version').replace('\n', ''));
168176
} catch (e) {}
169177
});
170178
});

0 commit comments

Comments
 (0)