|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + <head> |
| 4 | + <title>RUM Integ Test for SPA</title> |
| 5 | + <script src="./loader_spa.js"></script> |
| 6 | + |
| 7 | + <link |
| 8 | + rel="icon" |
| 9 | + type="image/png" |
| 10 | + href="https://awsmedia.s3.amazonaws.com/favicon.ico" |
| 11 | + /> |
| 12 | + <script> |
| 13 | + function pushStateOneToHistory() { |
| 14 | + createXMLRequest(); |
| 15 | + window.history.pushState( |
| 16 | + { state: 'one' }, |
| 17 | + 'Page One', |
| 18 | + '/page_view_one?search=foo#hash1' |
| 19 | + ); |
| 20 | + createXMLRequest(); |
| 21 | + beginMutation(50); |
| 22 | + } |
| 23 | + |
| 24 | + function pushStateTwoToHistory() { |
| 25 | + createXMLRequest(); |
| 26 | + window.history.pushState( |
| 27 | + { state: 'two' }, |
| 28 | + 'Page Two', |
| 29 | + '/page_view_two?search=bar#hash2' |
| 30 | + ); |
| 31 | + createXMLRequest(); |
| 32 | + beginMutation(50); |
| 33 | + } |
| 34 | + |
| 35 | + function replaceState() { |
| 36 | + createXMLRequest(); |
| 37 | + window.history.replaceState( |
| 38 | + { state: 'one' }, |
| 39 | + 'Page Ten', |
| 40 | + '/page_view_Ten?search=bar#asdf' |
| 41 | + ); |
| 42 | + createXMLRequest(); |
| 43 | + beginMutation(50); |
| 44 | + } |
| 45 | + |
| 46 | + function defaultState() { |
| 47 | + createXMLRequest(); |
| 48 | + window.history.replaceState( |
| 49 | + { state: 'one' }, |
| 50 | + 'Page Ten', |
| 51 | + '/page_event.html' |
| 52 | + ); |
| 53 | + createXMLRequest(); |
| 54 | + beginMutation(50); |
| 55 | + } |
| 56 | + |
| 57 | + function createHashChange() { |
| 58 | + createXMLRequest(); |
| 59 | + location.hash = 'hash_change'; |
| 60 | + createXMLRequest(); |
| 61 | + beginMutation(50); |
| 62 | + } |
| 63 | + |
| 64 | + function createHashChangeWithPushState() { |
| 65 | + createXMLRequest(); |
| 66 | + window.history.pushState( |
| 67 | + { state: 'two' }, |
| 68 | + 'Page Two', |
| 69 | + '#hash_changed_pushState' |
| 70 | + ); |
| 71 | + createXMLRequest(); |
| 72 | + beginMutation(50); |
| 73 | + } |
| 74 | + function back() { |
| 75 | + createXMLRequest(); |
| 76 | + window.history.back(); |
| 77 | + createXMLRequest(); |
| 78 | + beginMutation(50); |
| 79 | + } |
| 80 | + |
| 81 | + function back() { |
| 82 | + createXMLRequest(); |
| 83 | + window.history.back(); |
| 84 | + createXMLRequest(); |
| 85 | + beginMutation(50); |
| 86 | + } |
| 87 | + |
| 88 | + function forward() { |
| 89 | + createXMLRequest(); |
| 90 | + window.history.forward(); |
| 91 | + createXMLRequest(); |
| 92 | + beginMutation(50); |
| 93 | + } |
| 94 | + |
| 95 | + function go(number) { |
| 96 | + createXMLRequest(); |
| 97 | + window.history.go(number); |
| 98 | + createXMLRequest(); |
| 99 | + beginMutation(50); |
| 100 | + } |
| 101 | + |
| 102 | + function beginMutation(epoch) { |
| 103 | + let i = 0; |
| 104 | + function helper() { |
| 105 | + domMutation(); |
| 106 | + if (i++ < epoch) { |
| 107 | + console.log('MUTATING'); |
| 108 | + setTimeout(helper, 10); |
| 109 | + } |
| 110 | + } |
| 111 | + helper(); |
| 112 | + } |
| 113 | + |
| 114 | + function dispatch() { |
| 115 | + cwr('dispatch'); |
| 116 | + } |
| 117 | + |
| 118 | + function clearRequestResponse() { |
| 119 | + document.getElementById('request_url').innerText = ''; |
| 120 | + document.getElementById('request_header').innerText = ''; |
| 121 | + document.getElementById('request_body').innerText = ''; |
| 122 | + |
| 123 | + document.getElementById('response_status').innerText = ''; |
| 124 | + document.getElementById('response_header').innerText = ''; |
| 125 | + document.getElementById('response_body').innerText = ''; |
| 126 | + } |
| 127 | + |
| 128 | + function timeoutLoad() { |
| 129 | + createXMLRequest(); |
| 130 | + window.history.pushState( |
| 131 | + { state: 'two' }, |
| 132 | + 'Page Two', |
| 133 | + '/page_view_two?search=foo#hash2' |
| 134 | + ); |
| 135 | + beginMutation(200); |
| 136 | + } |
| 137 | + |
| 138 | + function createXMLRequest() { |
| 139 | + var xhr = new XMLHttpRequest((async = true)); |
| 140 | + var url = 'https://aws.amazon.com'; |
| 141 | + xhr.open('GET', url, true); |
| 142 | + xhr.send(); |
| 143 | + |
| 144 | + setTimeout(sendFetchWithParam, 20); |
| 145 | + } |
| 146 | + |
| 147 | + function sendFetchWithParam() { |
| 148 | + fetch('https://aws.amazon.com', { |
| 149 | + method: 'POST', |
| 150 | + body: JSON.stringify('data'), |
| 151 | + headers: new Headers({ |
| 152 | + 'Content-Type': 'application/json; charset=UTF-8' |
| 153 | + }) |
| 154 | + }); |
| 155 | + |
| 156 | + setTimeout(sendFetchWithoutParam, 20); |
| 157 | + } |
| 158 | + |
| 159 | + function sendFetchWithoutParam() { |
| 160 | + fetch('https://aws.amazon.com'); |
| 161 | + } |
| 162 | + |
| 163 | + function domMutation() { |
| 164 | + createElement(); |
| 165 | + deleteElement(); |
| 166 | + } |
| 167 | + |
| 168 | + function createElement() { |
| 169 | + const div = document.createElement('div'); |
| 170 | + div.setAttribute('id', 'mockMutation'); |
| 171 | + const welcome = document.getElementById('welcome'); |
| 172 | + document.body.insertBefore(div, welcome); |
| 173 | + } |
| 174 | + |
| 175 | + function deleteElement() { |
| 176 | + const div = document.getElementById('mockMutation'); |
| 177 | + div.remove(); |
| 178 | + } |
| 179 | + </script> |
| 180 | + |
| 181 | + <style> |
| 182 | + table { |
| 183 | + border-collapse: collapse; |
| 184 | + margin-top: 10px; |
| 185 | + margin-bottom: 10px; |
| 186 | + } |
| 187 | + |
| 188 | + td, |
| 189 | + th { |
| 190 | + border: 1px solid black; |
| 191 | + text-align: left; |
| 192 | + padding: 8px; |
| 193 | + } |
| 194 | + </style> |
| 195 | + </head> |
| 196 | + |
| 197 | + <body> |
| 198 | + <p id="welcome">This application is used for RUM integ testing.</p> |
| 199 | + <hr /> |
| 200 | + <button id="pushStateOneToHistory" onclick="pushStateOneToHistory()"> |
| 201 | + Push State One to History |
| 202 | + </button> |
| 203 | + <button id="pushStateTwoToHistory" onclick="pushStateTwoToHistory()"> |
| 204 | + Push State Two to History |
| 205 | + </button> |
| 206 | + <button id="replaceState" onclick="replaceState()"> |
| 207 | + Replace current state in History |
| 208 | + </button> |
| 209 | + <button id="replaceDefault" onclick="defaultState()"> |
| 210 | + Return to default |
| 211 | + </button> |
| 212 | + <button id="createHashChange" onclick="createHashChange()"> |
| 213 | + Create HashChange |
| 214 | + </button> |
| 215 | + <button id="timeOutLoad" onclick="timeoutLoad()"> |
| 216 | + Create TimeoutLoad |
| 217 | + </button> |
| 218 | + <button id="back" onclick="back()">Back</button> |
| 219 | + <button id="forward" onclick="forward()">Forward</button> |
| 220 | + <button id="go-back" onclick="go(-2)">Go (back two pages)</button> |
| 221 | + <button id="go-forward" onclick="go(2)">Go (forward two pages)</button> |
| 222 | + <hr /> |
| 223 | + <button id="dispatch" onclick="dispatch()">Dispatch</button> |
| 224 | + <button id="clearRequestResponse" onclick="clearRequestResponse()"> |
| 225 | + Clear |
| 226 | + </button> |
| 227 | + <hr /> |
| 228 | + <span id="request"></span> |
| 229 | + <span id="response"></span> |
| 230 | + <table> |
| 231 | + <tr> |
| 232 | + <td>Request URL</td> |
| 233 | + <td id="request_url"></td> |
| 234 | + </tr> |
| 235 | + <tr> |
| 236 | + <td>Request Header</td> |
| 237 | + <td id="request_header"></td> |
| 238 | + </tr> |
| 239 | + <tr> |
| 240 | + <td>Request Body</td> |
| 241 | + <td id="request_body"></td> |
| 242 | + </tr> |
| 243 | + </table> |
| 244 | + <table> |
| 245 | + <tr> |
| 246 | + <td>Response Status Code</td> |
| 247 | + <td id="response_status"></td> |
| 248 | + </tr> |
| 249 | + <tr> |
| 250 | + <td>Response Header</td> |
| 251 | + <td id="response_header"></td> |
| 252 | + </tr> |
| 253 | + <tr> |
| 254 | + <td>Response Body</td> |
| 255 | + <td id="response_body"></td> |
| 256 | + </tr> |
| 257 | + </table> |
| 258 | + </body> |
| 259 | +</html> |
0 commit comments