4 Copyright (c) 2014 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
9 <title>TVCM Tests: loading...</title>
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11 <script src="/platform.min.js"></script>
12 <script src="/polymer.min.js"></script>
14 <link rel="import" href="/tvcm.html">
15 <link rel="shortcut icon" href="data:image/x-icon;base64," type="image/x-icon">
16 <link rel="import" href="/tvcm/unittest.html">
17 <link rel="import" href="/tvcm/unittest/interactive_test_runner.html">
20 box-sizing: border-box;
26 body > x-base-interactive-test-runner {
37 // The test runner no-ops pushState so keep it around.
38 var realWindowHistoryPushState = window.history.pushState.bind(
41 function stateToSearchString(defaultState, state) {
43 for (var k in state) {
44 if (state[k] === defaultState[k])
50 } else if (v === false) {
52 } else if (v === '') {
59 return parts.join('&');
62 function stateFromSearchString(string) {
64 string.split('&').forEach(function(part) {
67 var kv = part.split('=');
84 function loadAndRunTests() {
85 var state = stateFromSearchString(
86 window.location.search.substring(1));
90 if (state.testSuiteName) {
91 suiteNamesToLoad = [];
92 suiteNamesToLoad.push(state.testSuiteName);
95 var loader = new tvcm.unittest.SuiteLoader(suiteNamesToLoad);
96 return loader.allSuitesLoadedPromise.then(
98 runTests(loader, state);
101 tvcm.showPanic('Module loading failure', err);
105 function updateTitle(state) {
106 var testFilterString = state.testFilterString || '';
107 var testSuiteName = state.testSuiteName || '';
110 if (testSuiteName && testFilterString.length) {
111 title = testFilterString + ' in ' + testSuiteName;
112 } else if (testSuiteName) {
113 title = testSuiteName;
114 } else if (testFilterString) {
115 title = testFilterString + ' in all tests';
117 title = 'All TVCM Tests';
120 if (state.shortFormat)
122 document.title = title;
123 var runner = document.querySelector('x-base-interactive-test-runner');
125 runner.title = title;
128 function runTests(loader, state) {
129 var runner = new tvcm.unittest.InteractiveTestRunner();
130 runner.testLinks = loader.testLinks;
131 runner.allTests = loader.getAllTests();
132 document.body.appendChild(runner);
134 runner.setState(state);
137 runner.addEventListener('statechange', function() {
138 var state = runner.getState();
139 var stateString = stateToSearchString(runner.getDefaultState(),
141 if (window.location.search.substring(1) == stateString)
146 if (stateString.length > 0)
147 stateURL = window.location.pathname + '?' + stateString;
149 stateURL = window.location.pathname;
150 realWindowHistoryPushState(state, document.title, stateURL);
153 window.addEventListener('popstate', function(state) {
154 runner.setState(state, true);
157 runner.getHRefForTestCase = function(testCase) {
158 var state = runner.getState();
159 state.testSuiteName = testCase.suite.name;
160 state.testFilterString = testCase.name;
161 state.shortFormat = false;
163 var stateString = stateToSearchString(runner.getDefaultState(),
165 if (stateString.length > 0)
166 return window.location.pathname + '?' + stateString;
168 return window.location.pathname;
172 window.addEventListener('load', loadAndRunTests);