2
Copyright 2016 Google Inc. All rights reserved.
3
Licensed under the Apache License, Version 2.0 (the "License");
4
you may not use this file except in compliance with the License.
5
You may obtain a copy of the License at
6
http://www.apache.org/licenses/LICENSE-2.0
7
Unless required by applicable law or agreed to in writing, software
8
distributed under the License is distributed on an "AS IS" BASIS,
9
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
See the License for the specific language governing permissions and
11
limitations under the License.
15
<meta charset="utf-8">
16
<title>SW Toolbox Tests</title>
17
<link href="/node_modules/mocha/mocha.css" rel="stylesheet" />
20
iframes are used to manage service worker scoping.
21
This will hide them and stop the page from jumping around
31
<div id="mocha"></div>
33
<script src="/node_modules/chai/chai.js"></script>
34
<script src="/node_modules/mocha/mocha.js"></script>
36
<!-- Helper functions will be under window.testHelper -->
37
<script src="/test/libs/helper-functions.js"></script>
40
Timeout is extended to ensure tests for max-cache-age
41
have enough time to complete
48
<!-- In browser test scripts should be added to the page here-->
49
<script src="/test/browser-tests/precache/precache.js"></script>
53
// To automate the tests with selenium, we need a way
54
// to inform selenium when the tests are completed and
56
// This is done by waiting for window.swtoolbox to be defined.
57
// This is done in publishTestResults();
61
// This is a helper method that simplifies the test
62
// results to an object that can be JSON.string-ified.
63
function getFriendlyTestResult(testResult) {
65
title: testResult.title,
66
state: testResult.state
70
// Once this is called, automated tests should be
71
// able to read sw.toolbox and get test results.
72
function publishTestResults() {
81
// This make browsers without a service worker pass tests by
82
// bypassing the tests altogether.
83
// This is desirable to allow travis to run tests in all browsers
84
// regardless of support or not and perform tests when the browser
85
// starts to support service workers.
86
if (!('serviceWorker' in navigator)) {
91
// should adds objects to primitives which requires this call to be made
92
// before any tests are run.
95
// We unregister all service workers, clear all caches and remove
96
// All registered iframes
97
beforeEach(function() {
98
return testHelper.cleanState();
101
// Clean up after the final test has finished
103
return testHelper.cleanState();
106
var runResults = mocha.run();
107
// pass, fail and end events allow up to capture results and
108
// determine when to publish test results
109
runResults.on('pass', function(test) {
110
passedTests.push(getFriendlyTestResult(test));
112
.on('fail', function(test) {
113
failedTests.push(getFriendlyTestResult(test));
115
.on('end', function() {
116
publishTestResults();