summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/apptest/dom_mutations.html
blob: c03a9e49d548dfeefd0c0587be031c620e73b6fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<!-- This is an example app used by chrome/functional/apptest.py to demonstrate
     use of the Automation Event Queue for testing webapps using DomMutation
     observers.

     This example webapp simulates an asyncronous login flow. -->
<html>

  <head>
    <title>AppTest Example</title>
    <script type="text/javascript">
      var globalTimeout;

      function write(str) {
        document.getElementById("console").innerHTML += "> " + str + "<br \>";
      }

      /* Calls a function after a specified number of miliseconds. */
      function delayedCallback(f, ms) {
        globalTimeout = setTimeout(f, ms);
      }

      function init() {
        write("Initializing...");
        delayedCallback(createLoginLink, 2000);
      }

      function createLoginLink() {
        write("<a id='login' href='' onclick='return login();'>Log In</a>");
      }

      function login() {
        write("Logging in...");
        delayedCallback(loginSuccess, 2000);
        return false;
      }

      function loginSuccess() {
        write("Login succeeded!");
        document.getElementById("fail").innerHTML = "";
      }

      function fail() {
        clearTimeout(globalTimeout);
        write("App failed!");
        return false;
      }
    </script>
  </head>

  <body onload="init()">
    <div id="fail">
      [ <a href='' onclick='return fail();'>Fail Test</a> ]
      <br /><br />
    </div>

    <div id="console">
    </div>

  </body>

</html>