| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Common js for prerender loaders; defines the helper functions that put | 5 // Common js for prerender loaders; defines the helper functions that put |
| 6 // event handlers on prerenders and track the events for browser tests. | 6 // event handlers on prerenders and track the events for browser tests. |
| 7 | 7 |
| 8 // TODO(gavinp): Put more common loader logic in here. | 8 // TODO(gavinp): Put more common loader logic in here. |
| 9 | 9 |
| 10 // Currently only errors with the ordering of Prerender events are caught. | 10 // Currently only errors with the ordering of Prerender events are caught. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 function AddPrerender(url, index) { | 56 function AddPrerender(url, index) { |
| 57 var link = document.createElement('link'); | 57 var link = document.createElement('link'); |
| 58 link.rel = 'prerender'; | 58 link.rel = 'prerender'; |
| 59 link.href = url; | 59 link.href = url; |
| 60 AddEventHandlersToLinkElement(link, index); | 60 AddEventHandlersToLinkElement(link, index); |
| 61 document.body.appendChild(link); | 61 document.body.appendChild(link); |
| 62 return link; | 62 return link; |
| 63 } | 63 } |
| 64 | 64 |
| 65 function Click() { | 65 function AddAnchor(href, target) { |
| 66 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', { | 66 var a = document.createElement('a'); |
| 67 a.href = href; |
| 68 if (target) |
| 69 a.target = target; |
| 70 document.body.appendChild(a); |
| 71 return a; |
| 72 } |
| 73 |
| 74 function Click(url) { |
| 75 AddAnchor(url).dispatchEvent(new MouseEvent('click', { |
| 67 view: window, | 76 view: window, |
| 68 bubbles: true, | 77 bubbles: true, |
| 69 cancelable: true, | 78 cancelable: true, |
| 70 detail: 1 | 79 detail: 1 |
| 71 })); | 80 })); |
| 72 } | 81 } |
| 73 | 82 |
| 74 function ClickTarget() { | 83 function ClickTarget(url) { |
| 75 var eventObject = new MouseEvent('click', { | 84 var eventObject = new MouseEvent('click', { |
| 76 view: window, | 85 view: window, |
| 77 bubbles: true, | 86 bubbles: true, |
| 78 cancelable: true, | 87 cancelable: true, |
| 79 detail: 1 | 88 detail: 1 |
| 80 }); | 89 }); |
| 81 document.getElementById('toClickTarget').dispatchEvent(eventObject); | 90 AddAnchor(url, '_blank').dispatchEvent(eventObject); |
| 82 } | 91 } |
| 83 | 92 |
| 84 function ShiftClick() { | 93 function ShiftClick(url) { |
| 85 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', { | 94 AddAnchor(url).dispatchEvent(new MouseEvent('click', { |
| 86 view: window, | 95 view: window, |
| 87 bubbles: true, | 96 bubbles: true, |
| 88 cancelable: true, | 97 cancelable: true, |
| 89 detail: 1, | 98 detail: 1, |
| 90 shiftKey: true | 99 shiftKey: true |
| 91 })); | 100 })); |
| 92 } | 101 } |
| 93 | 102 |
| 94 function CtrlClick() { | 103 function CtrlClick(url) { |
| 95 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', { | 104 AddAnchor(url).dispatchEvent(new MouseEvent('click', { |
| 96 view: window, | 105 view: window, |
| 97 bubbles: true, | 106 bubbles: true, |
| 98 cancelable: true, | 107 cancelable: true, |
| 99 detail: 1, | 108 detail: 1, |
| 100 ctrlKey: true | 109 ctrlKey: true |
| 101 })); | 110 })); |
| 102 } | 111 } |
| 103 | 112 |
| 104 function CtrlShiftClick() { | 113 function CtrlShiftClick(url) { |
| 105 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', { | 114 AddAnchor(url).dispatchEvent(new MouseEvent('click', { |
| 106 view: window, | 115 view: window, |
| 107 bubbles: true, | 116 bubbles: true, |
| 108 cancelable: true, | 117 cancelable: true, |
| 109 detail: 1, | 118 detail: 1, |
| 110 ctrlKey: true, | 119 ctrlKey: true, |
| 111 shiftKey: true | 120 shiftKey: true |
| 112 })); | 121 })); |
| 113 } | 122 } |
| 114 | 123 |
| 115 function MetaClick() { | 124 function MetaClick(url) { |
| 116 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', { | 125 AddAnchor(url).dispatchEvent(new MouseEvent('click', { |
| 117 view: window, | 126 view: window, |
| 118 bubbles: true, | 127 bubbles: true, |
| 119 cancelable: true, | 128 cancelable: true, |
| 120 detail: 1, | 129 detail: 1, |
| 121 metaKey: true | 130 metaKey: true |
| 122 })); | 131 })); |
| 123 } | 132 } |
| 124 | 133 |
| 125 function MetaShiftClick() { | 134 function MetaShiftClick(url) { |
| 126 document.getElementById('toClick').dispatchEvent(new MouseEvent('click', { | 135 AddAnchor(url).dispatchEvent(new MouseEvent('click', { |
| 127 view: window, | 136 view: window, |
| 128 bubbles: true, | 137 bubbles: true, |
| 129 cancelable: true, | 138 cancelable: true, |
| 130 detail: 1, | 139 detail: 1, |
| 131 metaKey: true, | 140 metaKey: true, |
| 132 shiftKey: true | 141 shiftKey: true |
| 133 })); | 142 })); |
| 134 } | 143 } |
| 135 | 144 |
| 136 function WindowOpen() { | 145 function WindowOpen(url) { |
| 137 window.open(document.getElementById('toClick').href); | 146 window.open(url); |
| 138 } | 147 } |
| OLD | NEW |