summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_case.html
blob: d055e52b77785f56acc76f5aad9b7f909dbe5c87 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<html><head>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="test_page.css">
<script>
function AdjustHeight(frameWin) {
  var div = frameWin.document.getElementsByTagName("div")[0];
  var height = frameWin.getComputedStyle(div).height;
  frameWin.frameElement.style.height = height;
}

function DidExecuteTests() {
  if (window == top)
    return;

  // Otherwise, we are in a subframe, so we can use this opportunity to resize
  // ourselves.
  AdjustHeight(window);
}

function AppendFrame(testcase, i) {
  var p = document.createElement("P");
  p.setAttribute("class", "frame-container");

  var title = document.createElement("H2");
  title.appendChild(document.createTextNode(testcase));
  p.appendChild(title);

  var frame = document.createElement("IFRAME");
  var mode = ExtractSearchParameter("mode");
  if (mode == "nacl")
    frame.setAttribute("src", "?testcase=" + testcase + "&mode=nacl");
  else
    frame.setAttribute("src", "?testcase=" + testcase);
  frame.setAttribute("onload", "LoadNext(" + (i + 1) + ")");
  p.appendChild(frame);

  document.body.appendChild(p);
}

function LoadNext(i) {
  var links = document.links;
  if (links.length > i)
    AppendFrame(links[i].firstChild.nodeValue, i);
}

function RunAll() {
  // Remove any existing frames.
  var existing = document.getElementsByClassName("frame-container");
  while (existing.length)
    existing[0].parentNode.removeChild(existing[0]);

  // Add new frames for each test, but do so one frame at a time.
  LoadNext(0);
}

function ExtractSearchParameter(name) {
  var nameIndex = location.search.indexOf(name + "=");
  if (nameIndex != -1) {
    var value = location.search.substring(nameIndex + name.length + 1);
    var endIndex = value.indexOf("&");
    if (endIndex != -1)
      value = value.substring(0, endIndex);
    return value;
  }
  return "";
}

onload = function() {
  var testcase = ExtractSearchParameter("testcase");
  var mode = ExtractSearchParameter("mode");
  document.title = 'Test ' + testcase;
  var obj;
  if (mode == "nacl") {
    obj = document.createElement("OBJECT");
    obj.setAttribute("type", "application/x-nacl");
    obj.setAttribute("nacl", "test_case.nmf");
    obj.setAttribute("mode", mode);
  } else {
    var mimeType = "application/x-ppapi-tests";
    if (mimeType in navigator.mimeTypes) {
      obj = document.createElement("OBJECT");
      obj.setAttribute("type", mimeType);
    } else {
      document.getElementById("console").innerHTML =
          '<span class="fail">FAIL</span>: ' +
          '<span class="err_msg">Test plug-in is not registered.</span>';
    }
  }
  if (obj) {
    obj.setAttribute("id", "plugin");
    obj.setAttribute("testcase", testcase);
    obj.setAttribute("src", "http://a.b.c/test");
    document.getElementById("container").appendChild(obj);
  }
}
</script>
</head><body>
<div>
  <div id="container"></div>
  <div id="console" /><span class="load_msg">loading...</span></div>
</div>
</body></html>