Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / chrome / test / data / prerender / prerender_html5_common.js
blobedb381c4a2f1c46ea21bfd3b2ef157197d3bb66b
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Common js for the HTML5_* tests. The following variables need to be defined
6 // before this js is included:
7 // - 'willPlay' - indicates if the media is expected to start playing during
8 // the test.
9 // - 'testNetworkEvents' - if set to true, the test will test for the
10 // loadstart and stalled events. NOTE that since the loadstart event fires
11 // very early, to test for it reliably, the source of the media tag
12 // should be added after this script is included or add
13 // 'onLoadStart=mediEventHandler' as an attribute to the media element.
14 // Also to reliably test the stalled event, the the test should wait for the
15 // prerendered page's title to change to "READY" before calling
16 // DidPrerenderPass.
18 function assert(bool) {
19 if (!bool)
20 throw new Error('Assert Failed.');
23 var canPlaySeen = false;
24 var playingSeen = false;
25 var canPlayThroughSeen = false;
26 var loadStartSeen = false;
27 var stalledSeen = false;
28 var hasError = false;
30 assert(typeof(willPlay) != 'undefined');
31 assert(typeof(testNetworkEvents) != 'undefined');
33 var mediaEl = document.getElementById("mediaEl");
35 function mediaEventHandler(e) {
36 switch (e.type) {
37 case 'canplay':
38 canPlaySeen = true;
39 break;
40 case 'playing':
41 assert(canPlaySeen);
42 playingSeen = true;
43 break;
44 case 'canplaythrough':
45 assert(canPlaySeen);
46 canPlayThroughSeen = true;
47 break;
48 case 'error':
49 hasError = true;
50 break;
51 case 'loadstart':
52 loadStartSeen = true;
53 break;
54 case 'stalled':
55 assert(loadStartSeen);
56 stalledSeen = true;
57 if (testNetworkEvents) {
58 document.title = 'READY';
60 break;
63 var progressDone = (willPlay && canPlayThroughSeen && playingSeen) ||
64 (!willPlay && canPlayThroughSeen && !playingSeen);
66 if (progressDone)
67 document.title = 'PASS';
70 mediaEl.addEventListener('playing', mediaEventHandler, false);
71 mediaEl.addEventListener('canplay', mediaEventHandler, false);
72 mediaEl.addEventListener('canplaythrough', mediaEventHandler, false);
73 mediaEl.addEventListener('error', mediaEventHandler, false);
75 if (testNetworkEvents) {
76 mediaEl.addEventListener('stalled', mediaEventHandler, false);
77 mediaEl.addEventListener('loadstart', mediaEventHandler, false);
80 // TODO(shishir): Remove this once http://crbug.com/130788 is fixed.
81 function printDebugInfo() {
82 console.log("\ncanPlaySeen: " + canPlaySeen);
83 console.log("playingSeen: " + playingSeen);
84 console.log("canPlayThroughSeen: " + canPlayThroughSeen);
85 console.log("loadStartSeen: " + loadStartSeen);
86 console.log("stalledSeen: " + stalledSeen);
87 console.log("hasError: " + hasError + "\n");
89 setInterval(printDebugInfo, 5000);
91 function DidPrerenderPass() {
92 // The media should not have started at this point.
93 return !canPlaySeen && !playingSeen && !hasError &&
94 mediaEl.currentTime == 0 &&
95 mediaEl.readyState == mediaEl.HAVE_NOTHING &&
96 (!testNetworkEvents || stalledSeen);
99 function DidDisplayPass() {
100 // The actual test is done via the TitleWatcher.
101 return true;