B2G/gecko/netwerk/test/httpserver/test/test_default_index_handler.js
/** Verifies data in bytes for the trailing-caret path above. */
Verifies data in bytes for the trailing-caret path above.
Verifies data in bytes for the trailing - caret path above .
function hiddenDataCheck(bytes, uri, path)
{
  var data = String.fromCharCode.apply(null, bytes);
  var parser = Cc["@mozilla.org/xmlextras/domparser;1"]
                 .createInstance(Ci.nsIDOMParser);
  try
  {
    var doc = parser.parseFromString(data, "application/xml");
  }
  catch (e)
  {
    do_throw("document failed to parse as XML");
  }
  var body = doc.documentElement.getElementsByTagName("body");
  do_check_eq(body.length, 1);
  body = body.item(0);
  var header = body.QueryInterface(Ci.nsIDOMElement)
                   .getElementsByTagName("h1");
  do_check_eq(header.length, 1);
  do_check_eq(header.item(0).QueryInterface(Ci.nsIDOMNode).textContent, path);
  var lst = body.getElementsByTagName("ol");
  do_check_eq(lst.length, 1);
  var items = lst.item(0).QueryInterface(Ci.nsIDOMElement)
                         .getElementsByTagName("li");
  var ios = Cc["@mozilla.org/network/io-service;1"]
              .getService(Ci.nsIIOService);
  var top = ios.newURI(uri, null, null);
  var dirEntries = [{name: "file.txt", isDirectory: false},
                    {name: "SHOULD_SEE_THIS.txt^", isDirectory: false}];
  for (var i = 0; i < items.length; i++)
  {
    var link = items.item(i)
                    .childNodes
                    .item(0)
                    .QueryInterface(Ci.nsIDOMNode)
                    .QueryInterface(Ci.nsIDOMElement);
    var f = dirEntries[i];
    var sep = f.isDirectory ? "/" : "";
    do_check_eq(link.textContent, f.name + sep);
    uri = ios.newURI(link.getAttribute("href"), null, top);
    do_check_eq(decodeURIComponent(uri.path), path + f.name + sep);
  }
}
function hiddenDataCheck ( bytes , uri , path ) { var data = String . fromCharCode . apply ( null , bytes ) ; var parser = Cc [ "@mozilla.org/xmlextras/domparser;1" ] . createInstance ( Ci . nsIDOMParser ) ; try { var doc = parser . parseFromString ( data , "application/xml" ) ; } catch ( e ) { do_throw ( "document failed to parse as XML" ) ; } var body = doc . documentElement . getElementsByTagName ( "body" ) ; do_check_eq ( body . length , 1 ) ; body = body . item ( 0 ) ; var header = body . QueryInterface ( Ci . nsIDOMElement ) . getElementsByTagName ( "h1" ) ; do_check_eq ( header . length , 1 ) ; do_check_eq ( header . item ( 0 ) . QueryInterface ( Ci . nsIDOMNode ) . textContent , path ) ; var lst = body . getElementsByTagName ( "ol" ) ; do_check_eq ( lst . length , 1 ) ; var items = lst . item ( 0 ) . QueryInterface ( Ci . nsIDOMElement ) . getElementsByTagName ( "li" ) ; var ios = Cc [ "@mozilla.org/network/io-service;1" ] . getService ( Ci . nsIIOService ) ; var top = ios . newURI ( uri , null , null ) ; var dirEntries = [ { name : "file.txt" , isDirectory : false } , { name : "SHOULD_SEE_THIS.txt^" , isDirectory : false } ] ; for ( var i = 0 ; i < items . length ; i ++ ) { var link = items . item ( i ) . childNodes . item ( 0 ) . QueryInterface ( Ci . nsIDOMNode ) . QueryInterface ( Ci . nsIDOMElement ) ; var f = dirEntries [ i ] ; var sep = f . isDirectory ? "/" : "" ; do_check_eq ( link . textContent , f . name + sep ) ; uri = ios . newURI ( link . getAttribute ( "href" ) , null , top ) ; do_check_eq ( decodeURIComponent ( uri . path ) , path + f . name + sep ) ; } }
Verifies data in bytes for the trailing-caret path above.
Verifies data in bytes for the trailing - caret path above .
// Note: the index format isn't XML -- it's actually HTML -- but we require //       the index format also be valid XML, albeit XML without namespaces, //       XML declarations, etc.  Doing this simplifies output checking. // See all the .QueryInterface()s and .item()s happening here?  That's because // xpcshell sucks and doesn't have classinfo, so no automatic interface // flattening or array-style access to items in NodeLists.  Suck. // header // files // N.B. No ERROR_IF_SEE_THIS.txt^ file!