| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // This script runs in HTML files and loads the corresponding test scripts for | 5 // This script runs in HTML files and loads the corresponding test scripts for |
| 6 // either Dartium or a JS browser. It's used by "pub serve" and user-authored | 6 // either Dartium or a JS browser. It's used by "pub serve" and user-authored |
| 7 // HTML files; when running without "pub serve", the default HTML file manually | 7 // HTML files; when running without "pub serve", the default HTML file manually |
| 8 // chooses between serving a Dart or JS script tag. | 8 // chooses between serving a Dart or JS script tag. |
| 9 window.onload = function() { | 9 window.onload = function() { |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 var name = window.location.href.replace(/.*\//, '').replace(/#.*/, ''); | 23 var name = window.location.href.replace(/.*\//, '').replace(/#.*/, ''); |
| 24 | 24 |
| 25 // Find <link rel="x-dart-test">. | 25 // Find <link rel="x-dart-test">. |
| 26 var links = document.getElementsByTagName("link"); | 26 var links = document.getElementsByTagName("link"); |
| 27 var testLinks = []; | 27 var testLinks = []; |
| 28 var length = links.length; | 28 var length = links.length; |
| 29 for (var i = 0; i < length; ++i) { | 29 for (var i = 0; i < length; ++i) { |
| 30 if (links[i].rel == "x-dart-test") testLinks.push(links[i]); | 30 if (links[i].rel == "x-dart-test") testLinks.push(links[i]); |
| 31 } | 31 } |
| 32 | 32 |
| 33 if (links.length != 1) { | 33 if (testLinks.length != 1) { |
| 34 sendLoadException( | 34 sendLoadException( |
| 35 'Expected exactly 1 <link rel="x-dart-test"> in ' + name + ', found ' + | 35 'Expected exactly 1 <link rel="x-dart-test"> in ' + name + ', found ' + |
| 36 links.length + '.'); | 36 testLinks.length + '.'); |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 | 39 |
| 40 var link = links[0]; | 40 var link = testLinks[0]; |
| 41 | 41 |
| 42 if (link.href == '') { | 42 if (link.href == '') { |
| 43 sendLoadException( | 43 sendLoadException( |
| 44 'Expected <link rel="x-dart-test"> in ' + name + ' to have an "href" ' + | 44 'Expected <link rel="x-dart-test"> in ' + name + ' to have an "href" ' + |
| 45 'attribute.'); | 45 'attribute.'); |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 var script = document.createElement('script'); | 49 var script = document.createElement('script'); |
| 50 | 50 |
| 51 // Load the compiled JS for a normal browser, and the Dart code for Dartium. | 51 // Load the compiled JS for a normal browser, and the Dart code for Dartium. |
| 52 if (navigator.userAgent.indexOf('(Dart)') === -1) { | 52 if (navigator.userAgent.indexOf('(Dart)') === -1) { |
| 53 script.src = link.href + '.browser_test.dart.js'; | 53 script.src = link.href + '.browser_test.dart.js'; |
| 54 } else { | 54 } else { |
| 55 script.src = link.href + '.browser_test.dart'; | 55 script.src = link.href + '.browser_test.dart'; |
| 56 script.type = 'application/dart'; | 56 script.type = 'application/dart'; |
| 57 } | 57 } |
| 58 | 58 |
| 59 script.onerror = function(event) { | 59 script.onerror = function(event) { |
| 60 var message = "Failed to load script at " + script.src + | 60 var message = "Failed to load script at " + script.src + |
| 61 (event.message ? ": " + event.message : "."); | 61 (event.message ? ": " + event.message : "."); |
| 62 sendLoadException(message); | 62 sendLoadException(message); |
| 63 } | 63 } |
| 64 | 64 |
| 65 var parent = link.parentNode; | 65 var parent = link.parentNode; |
| 66 document.currentScript = script; | 66 document.currentScript = script; |
| 67 parent.replaceChild(script, link); | 67 parent.replaceChild(script, link); |
| 68 | 68 |
| 69 }; | 69 }; |
| OLD | NEW |