summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/data/simple_object_focus.html
blob: 138ffa5040ff2bb6a207329785bdcf56b4e73b0c (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
<!-- saved from url=(0014)about:internet -->
<html>
<!-- This page is meant to load inside the host browser like IE/FF -->
<head>
<script type="text/javascript" src="chrome_frame_tester_helpers.js"></script>
<script type="text/javascript">
var g_failure_timeout = null;
var g_test_id = 1;
var g_test_name = "ObjectFocus";

function onLoad() {
  status("onload");

  try {
    var cf = getCf();
    cf.onmessage = OnChromeFrameMessage;
    window.setTimeout(NavigateToURL, 100);
  } catch(e) {
    status("error: onload");
    onFailure(g_test_name, g_test_id, "error in onload");
  }

  sendOnLoadEvent();
}

function NavigateToURL() {
  try {
    status("Navigate to URL");
    var cf = getCf();
    cf.src = "simple_object_focus_cf.html";
    g_failure_timeout = window.setTimeout(OnObjectFocusFailed, 10000);
  } catch(e) {
    status("error: NavigateToURL");
    onFailure(g_test_name, g_test_id, "NavigateToURL error");
  }
}

function OnObjectFocusFailed() {
  status("OnNavigationFailed");
  onFailure(g_test_name, g_test_id, "focus test failed");
}

function OnChromeFrameLoaded() {
  status("OnChromeFrameLoaded");
  try {
    // Set focus to chrome frame.  This should set focus to the first element
    // inside the frame, which a script inside the page will detect and notify
    // us back by sending us a message.
    getCf().focus();
  } catch(e) {
    status("error: can't set focus");
    onFailure(g_test_name, g_test_id, "focus() error");
  }
}

function OnChromeFrameMessage(evt) {
  if (evt.data != "btnOnFocus") {
    status("unexpected message: " + evt.data + " from " + evt.origin);
  } else {
    window.clearTimeout(g_failure_timeout);
    g_failure_timeout = null;
    status("success");
  }
  onSuccess(g_test_name, g_test_id);
}

function getCf() {
  // Fetching chrome frame with getElementById doesn't work in Firefox.
  // Most likely due to object vs embed.
  return document.ChromeFrame;
}

// Useful while writing and debugging the unit test.
function status(s) {
  var panel = document.getElementById("status_panel");
  panel.innerHTML = s;
}

</script>
</head>
<body onload="onLoad();">
<div id="status_panel" style="border: 1px solid red; width: 100%">
Test running....
</div>
<object id="ChromeFrame" width="300" height="60" tabindex="0"
        codebase="http://www.google.com"
        classid="CLSID:E0A900DF-9611-4446-86BD-4B1D47E7DB2A">
  <param name="onload" value="return OnChromeFrameLoaded();">
  <embed width="300" height="60" name="ChromeFrame"
         onload="return OnChromeFrameLoaded();"
         type="application/chromeframe">
  </embed>
</object>
</body>
</html>