1// Copyright 2014 Google Inc. All rights reserved.
2//
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//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//     See the License for the specific language governing permissions and
13// limitations under the License.
14
15(function() {
16  var assert = chai.assert;
17  mocha.setup({ ui: 'tdd' });
18
19  var iframe;
20  function defineTestharnessTest(shouldPass, testFile) {
21    var name = shouldPass ? testFile : 'Expected Failure: ' + testFile;
22    test(name, function(done) {
23      window.initTestHarness = function(child) {
24        child.add_completion_callback(function(tests, harness_status) {
25          var failures = tests.filter(function(result) {
26            return result.status != 0;
27          }).map(function(failure) {
28            return failure.name + ':\n' + failure.message;
29          });
30          var error;
31          if (shouldPass && failures.length) {
32            error = new Error('\n' + failures.join('\n\n'));
33            error.stack = null;
34          } else if (!shouldPass && failures.length == 0) {
35            error = new Error('\nExpected to fail, but passed');
36            error.stack = null;
37          }
38          done(error);
39        });
40      };
41      iframe.src = testFile;
42    });
43  }
44
45  suite('testharness tests', function() {
46    setup(function() {
47      iframe = document.createElement('iframe');
48      document.body.appendChild(iframe);
49    });
50    teardown(function() {
51      iframe.parentNode.removeChild(iframe);
52    });
53    testHarnessTests.forEach(defineTestharnessTest.bind(null, true));
54    testHarnessFailures.forEach(defineTestharnessTest.bind(null, false));
55  });
56
57  suite('interpolation tests', function() {
58    setup(function() {
59      iframe = document.createElement('iframe');
60      document.body.appendChild(iframe);
61    });
62    teardown(function() {
63      iframe.parentNode.removeChild(iframe);
64    });
65    interpolationTests.forEach(defineTestharnessTest.bind(null, true));
66    interpolationFailures.forEach(defineTestharnessTest.bind(null, false));
67  });
68
69  addEventListener('load', function() {
70    mocha.run();
71  });
72})();
73