~didrocks/+junk/face-detection-15.04

« back to all changes in this revision

Viewing changes to facedetection/www/bower_components/sw-toolbox/test/index.html

  • Committer: Didier Roche
  • Date: 2016-05-10 23:09:11 UTC
  • Revision ID: didier.roche@canonical.com-20160510230911-c7xr490zrj3yrzxd
New version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<!--
 
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.
 
12
-->
 
13
<html>
 
14
<head>
 
15
  <meta charset="utf-8">
 
16
  <title>SW Toolbox Tests</title>
 
17
  <link href="/node_modules/mocha/mocha.css" rel="stylesheet" />
 
18
 
 
19
  <!--
 
20
    iframes are used to manage service worker scoping.
 
21
    This will hide them and stop the page from jumping around
 
22
  -->
 
23
  <style>
 
24
    iframe {
 
25
      width: 0;
 
26
      height: 0;
 
27
    }
 
28
  </style>
 
29
</head>
 
30
<body>
 
31
  <div id="mocha"></div>
 
32
 
 
33
  <script src="/node_modules/chai/chai.js"></script>
 
34
  <script src="/node_modules/mocha/mocha.js"></script>
 
35
 
 
36
  <!-- Helper functions will be under window.testHelper -->
 
37
  <script src="/test/libs/helper-functions.js"></script>
 
38
 
 
39
  <!--
 
40
    Timeout is extended to ensure tests for max-cache-age
 
41
    have enough time to complete
 
42
  -->
 
43
  <script>mocha.setup({
 
44
    ui: 'bdd',
 
45
    timeout: 5000
 
46
  })</script>
 
47
 
 
48
  <!-- In browser test scripts should be added to the page here-->
 
49
  <script src="/test/browser-tests/precache/precache.js"></script>
 
50
 
 
51
  <script>
 
52
    (function() {
 
53
      // To automate the tests with selenium, we need a way
 
54
      // to inform selenium when the tests are completed and
 
55
      // pass results back.
 
56
      // This is done by waiting for window.swtoolbox to be defined.
 
57
      // This is done in publishTestResults();
 
58
      var passedTests = [];
 
59
      var failedTests = [];
 
60
 
 
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) {
 
64
        return {
 
65
          title: testResult.title,
 
66
          state: testResult.state
 
67
        };
 
68
      };
 
69
 
 
70
      // Once this is called, automated tests should be
 
71
      // able to read sw.toolbox and get test results.
 
72
      function publishTestResults() {
 
73
        window.swtoolbox = {
 
74
          testResults: {
 
75
            passed: passedTests,
 
76
            failed: failedTests
 
77
          }
 
78
        };
 
79
      }
 
80
 
 
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)) {
 
87
        publishTestResults();
 
88
        return;
 
89
      }
 
90
 
 
91
      // should adds objects to primitives which requires this call to be made
 
92
      // before any tests are run.
 
93
      window.chai.should();
 
94
 
 
95
      // We unregister all service workers, clear all caches and remove
 
96
      // All registered iframes
 
97
      beforeEach(function() {
 
98
        return testHelper.cleanState();
 
99
      });
 
100
 
 
101
      // Clean up after the final test has finished
 
102
      after(function() {
 
103
        return testHelper.cleanState();
 
104
      });
 
105
 
 
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));
 
111
      })
 
112
      .on('fail', function(test) {
 
113
        failedTests.push(getFriendlyTestResult(test));
 
114
      })
 
115
      .on('end', function() {
 
116
        publishTestResults();
 
117
      });
 
118
    })();
 
119
  </script>
 
120
</body>
 
121
</html>