content/events/test/test_bug226361.xhtml
author David Mandelin <dmandelin@mozilla.com>
Mon, 09 Aug 2010 18:29:34 -0700
changeset 53358 688ca6c81137c6972b5a7f172394c7b4d332e93d
parent 34406 c2f0df485f9dae985f4527096aa476d7c43be6d8
child 75086 95496a360748609134a5c666d57c7f48aa23393e
permissions -rw-r--r--
[JAEGER] Bug 585801 trial fix: innerize object passed as scope chain for JS evaluation

<html xmlns="http://www.w3.org/1999/xhtml">
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=226361
-->
<head>
  <title>Test for Bug 226361</title>
  <script type="application/javascript" src="/MochiKit/packed.js"></script>
  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body id="body1">
<p id="display">

 <a id="b1" tabindex="1" href="http://home.mozilla.org">start</a><br />
<br />

<iframe id="iframe" tabindex="2" src="bug226361_iframe.xhtml"></iframe>

 <a id="b2" tabindex="3" href="http://home.mozilla.org">end</a>

</p>
<div id="content" style="display: none">
  
</div>
<pre id="test">
<script type="application/javascript">
<![CDATA[

/** Test for Bug 226361 **/

// accessibility.tabfocus must be set to value 7 before running test also
// on a mac.
function setOrRestoreTabFocus(newValue) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  const prefSvcContractID = "@mozilla.org/preferences-service;1";
  const prefSvcIID = Components.interfaces.nsIPrefService;
  var prefs = Components.classes[prefSvcContractID].getService(prefSvcIID)
                                                   .getBranch("accessibility.");
  if (!newValue) {
    if (prefs.prefHasUserValue("tabfocus")) {
      prefs.clearUserPref("tabfocus");
    }
  } else {
    prefs.setIntPref("tabfocus", newValue);
  }
}

// =================================

var doc = document;
function tab_to(id) {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
  var wu =  doc.defaultView.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                .getInterface(Components.interfaces.nsIDOMWindowUtils);
  wu.sendKeyEvent('keypress',  9, 0, 0);
  is(doc.activeElement.id, id, "element with id=" + id + " should have focus");
}

function tab_iframe() {
  doc = document;
  tab_to('iframe');

  // inside iframe
  doc = document.getElementById('iframe').contentDocument
  tab_to('a3');tab_to('a5');tab_to('a1');tab_to('a2');tab_to('a4');
}


function doTest() {

  setOrRestoreTabFocus(7);

  try {
    window.getSelection().removeAllRanges();
    document.getElementById('body1').focus();
    is(document.activeElement.id, document.body.id, "body element should be focused");

    doc = document;
    tab_to('b1');

    tab_iframe();

    doc=document
    document.getElementById('iframe').focus()
    tab_to('b2');
    // Change tabindex so the next TAB goes back to the IFRAME
    document.getElementById('iframe').setAttribute('tabindex','4');

    tab_iframe();

  } finally {
    setOrRestoreTabFocus(0);
  }

  SimpleTest.finish();
}

SimpleTest.waitForExplicitFinish();
addLoadEvent(doTest);

]]>
</script>
</pre>
</body>
</html>