PageRenderTime 63ms CodeModel.GetById 59ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/public/vendor/requirejs/tests/browsertests/async/async.php

https://github.com/beingentangled/appmaker
PHP | 94 lines | 85 code | 9 blank | 0 comment | 10 complexity | ad1e3cc0e66c4cb5ba2240379023b0fd MD5 | raw file
 1<?
 2if($_GET['quirks'] == "")
 3{
 4    echo "<!DOCTYPE html>\n";
 5}
 6else
 7{
 8    echo "\n";
 9}
10?>
11<html>
12<head>
13    <title>Async Attribute Test</title>
14    <script type="text/javascript" src="../common.js"></script>
15    <script type="text/javascript">
16    var attachScript = function(url, name, approach){
17        url += "?stamp=" + (new Date()).getTime();
18
19        var node = document.createElement("script");
20        node.src = url;
21        node.type = "text/javascript";
22        node.charset = "utf-8";
23        if (approach === 'boolean') {
24            node.async = true;
25        } else if (approach === 'string') {
26            node.async = 'async';
27        } else if (approach === 'attribute') {
28            node.setAttribute('async', 'async');
29        }
30
31        document.getElementsByTagName("head")[0].appendChild(node);
32    }
33
34    var urls = [
35        "one.php",
36        "two.js"
37    ];
38
39    var loadUrls = function(approach) {
40        for (var i = 0, url; url = urls[i]; i++) {
41            attachScript(url, url, approach);
42        }
43    }
44
45    function onFormAction () {
46        var select = document.getElementById('approach'),
47            approach = select.value,
48            text = select.options[select.selectedIndex].text;
49        window.log('Using approach: [' + text + '] (' + approach + ')...');
50        loadUrls(approach);
51    };
52
53    </script>
54</head>
55<body>
56    <h1>Async Attribute Test</h1>
57    <p><b>This test requires PHP to be enabled to run.</b></p>
58
59    <p>This test tests async attribute. It attaches two scripts to the DOM, <b>one.php</b> and <b>two.js</b>.
60    The URLs to the scripts always has a timestamp querystring to make sure the scripts are fetched
61    fresh for each request.</p>
62    
63    <p>one.php uses a PHP sleep of 3 seconds before returning its result (a log message), where two.js will return
64    immediately with a log message.</p>
65    
66    <p>If the async attribute is being effective (In Gecko 1.9.2+/Firefox 3.6+ browsers, maybe
67    Opera in the future), then the log message for two.js should appear before the one.php log message.
68    If async is <b>not</b> effective, then one.php's log message will appear first.</p>
69
70    <p>You can also <b><a href="async.php?quirks=true">try this page in quirks mode</a></b>.
71    When you are done, come back to <b><a href="async.php">standards mode</a></b>.</p>
72
73    <p>Watch the console for log messages. If no console is available, then it should print
74    the log messages in the DOM.</p>
75
76    <p><b>Expected Results in All Browsers (except Opera)</b>:</p>
77    <ul>
78        <li>two.js script</li>
79        <li>one.php script</li>
80    </ul>
81
82    <form onsubmit="onFormAction(); return false;">
83        <label for="approach">Choose an approach to indicate async:</label>
84        <select id="approach" onchange="onFormAction();">
85            <option value="boolean">script.async = true</option>
86            <option value="string">script.async = 'async'</option>
87            <option value="attribute">script.setAttribute('async', 'async')</option>
88            <option value="">No async (one.php should be first in Firefox 3.6+)</option>
89        </select>
90        <input type="submit" name="Go" value="Go"> 
91    </form>
92
93</body>
94</html>