Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: chrome/test/data/prerender/prerender_html5_common.js

Issue 8095007: Defer loading of audio/video tags while prerendering. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Retrying upload for commit. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
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
15 function assert(bool) {
16 if (!bool)
17 throw new Error('Assert Failed.');
18 }
19
20 var canPlaySeen = false;
21 var playingSeen = false;
22 var canPlayThroughSeen = false;
23 var stalledSeen = false;
24 var loadStartSeen = false;
25 var hasError = false;
26
27 assert(typeof(willPlay) != 'undefined');
28 assert(typeof(testNetworkEvents) != 'undefined');
29
30 var mediaEl = document.getElementById("mediaEl");
31
32 function mediaEventHandler(e) {
33 console.log(e.type);
34 switch (e.type) {
35 case 'canplay':
36 canPlaySeen = true;
37 break;
38 case 'playing':
39 assert(canPlaySeen);
40 playingSeen = true;
41 break;
42 case 'canplaythrough':
43 assert(canPlaySeen);
44 canPlayThroughSeen = true;
45 break;
46 case 'error':
47 hasError = true;
48 break;
49 case 'loadstart':
50 loadStartSeen = true;
51 break;
52 case 'stalled':
53 assert(loadStartSeen);
54 stalledSeen = true;
55 break;
56 }
57
58 var stallDone = !testNetworkEvents || stalledSeen;
59 var progressDone = (willPlay && canPlayThroughSeen && playingSeen) ||
60 (!willPlay && canPlayThroughSeen && !playingSeen);
61
62 if (stallDone && progressDone)
63 document.title = 'PASS';
64 }
65
66 mediaEl.addEventListener('playing', mediaEventHandler, false);
67 mediaEl.addEventListener('canplay', mediaEventHandler, false);
68 mediaEl.addEventListener('canplaythrough', mediaEventHandler, false);
69 mediaEl.addEventListener('error', mediaEventHandler, false);
70
71 if (testNetworkEvents) {
72 mediaEl.addEventListener('stalled', mediaEventHandler, false);
73 mediaEl.addEventListener('loadstart', mediaEventHandler, false);
74 }
75
76 function DidPrerenderPass() {
77 // The media should not have started at this point.
78 return !canPlaySeen && !playingSeen && !hasError &&
79 mediaEl.currentTime == 0 &&
80 mediaEl.readyState == mediaEl.HAVE_NOTHING &&
81 (!testNetworkEvents || (loadStartSeen && stalledSeen));
82 }
83
84 function DidDisplayPass() {
85 // The actual test is done via the TitleWatcher.
86 return true;
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698