Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / test / data / prerender / prerender_events_common.js
blob637e7505a73bfb4d07ec12862e79317600359420
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 prerender loaders; defines the helper functions that put
6 // event handlers on prerenders and track the events for browser tests.
8 // TODO(gavinp): Put more common loader logic in here.
10 // Currently only errors with the ordering of Prerender events are caught.
11 var hadPrerenderEventErrors = false;
13 var receivedPrerenderStartEvents = [];
14 var receivedPrerenderLoadEvents = [];
15 var receivedPrerenderStopEvents = [];
17 function PrerenderStartHandler(index) {
18 if (receivedPrerenderStartEvents[index] ||
19 receivedPrerenderLoadEvents[index] ||
20 receivedPrerenderStopEvents[index]) {
21 hadPrerenderEventErrors = true;
22 return;
24 receivedPrerenderStartEvents[index] = true;
27 function PrerenderLoadHandler(index) {
28 if (!receivedPrerenderStartEvents[index] ||
29 receivedPrerenderStopEvents[index]) {
30 hadPrerenderEventErrors = true;
31 return;
33 if (!receivedPrerenderLoadEvents[index])
34 receivedPrerenderLoadEvents[index] = 0;
35 receivedPrerenderLoadEvents[index]++;
38 function PrerenderStopHandler(index) {
39 if (!receivedPrerenderStartEvents[index] ||
40 receivedPrerenderStopEvents[index]) {
41 hadPrerenderEventErrors = true;
42 return;
44 receivedPrerenderStopEvents[index] = true;
47 function AddEventHandlersToLinkElement(link, index) {
48 link.addEventListener('webkitprerenderstart',
49 PrerenderStartHandler.bind(null, index), false);
50 link.addEventListener('webkitprerenderload',
51 PrerenderLoadHandler.bind(null, index), false);
52 link.addEventListener('webkitprerenderstop',
53 PrerenderStopHandler.bind(null, index), false);
56 function AddPrerender(url, index) {
57 var link = document.createElement('link');
58 link.rel = 'prerender';
59 link.href = url;
60 AddEventHandlersToLinkElement(link, index);
61 document.body.appendChild(link);
62 return link;
65 function Click() {
66 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', {
67 view: window,
68 bubbles: true,
69 cancelable: true,
70 detail: 1
71 }));
74 function ClickTarget() {
75 var eventObject = new MouseEvent('click', {
76 view: window,
77 bubbles: true,
78 cancelable: true,
79 detail: 1
80 });
81 document.getElementById('toClickTarget').dispatchEvent(eventObject);
84 function ShiftClick() {
85 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', {
86 view: window,
87 bubbles: true,
88 cancelable: true,
89 detail: 1,
90 shiftKey: true
91 }));
94 function CtrlClick() {
95 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', {
96 view: window,
97 bubbles: true,
98 cancelable: true,
99 detail: 1,
100 ctrlKey: true
101 }));
104 function CtrlShiftClick() {
105 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', {
106 view: window,
107 bubbles: true,
108 cancelable: true,
109 detail: 1,
110 ctrlKey: true,
111 shiftKey: true
112 }));
115 function MetaClick() {
116 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', {
117 view: window,
118 bubbles: true,
119 cancelable: true,
120 detail: 1,
121 metaKey: true
122 }));
125 function MetaShiftClick() {
126 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', {
127 view: window,
128 bubbles: true,
129 cancelable: true,
130 detail: 1,
131 metaKey: true,
132 shiftKey: true
133 }));
136 function WindowOpen() {
137 window.open(document.getElementById('toClick').href);