summaryrefslogtreecommitdiffstats
path: root/toolkit/components/feeds/test/head.js
blob: 65aa64b948d1924b0a8de52bf1608203765142e8 (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
"use strict";

var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
var Cr = Components.results;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/NetUtil.jsm");

function readTestData(testFile) {
  var testcase = {};

  // Got a feed file, now we need to parse out the Description and Expect headers.
  var istream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
  try {
    istream.init(testFile, 0x01, parseInt("0444", 8), 0);
    istream.QueryInterface(Ci.nsILineInputStream);

    var hasmore = false;
    do {
      var line = {};
      hasmore = istream.readLine(line);

      if (line.value.indexOf('Description:') > -1) {
        testcase.desc = line.value.substring(line.value.indexOf(':')+1).trim();
      }

      if (line.value.indexOf('Expect:') > -1) {
        testcase.expect = line.value.substring(line.value.indexOf(':')+1).trim();
      }

      if (line.value.indexOf('Base:') > -1) {
        testcase.base = NetUtil.newURI(line.value.substring(line.value.indexOf(':')+1).trim());
      }

      if (testcase.expect && testcase.desc) {
        testcase.path = 'xml/' + testFile.parent.leafName + '/' + testFile.leafName;
        testcase.file = testFile;
        break;
      }

    } while (hasmore);

  } catch (e) {
    Assert.ok(false, "FAILED! Error reading testFile case in file " + testFile.leafName  + " ---- " + e);
  } finally {
    istream.close();
  }

  return testcase;
}

function iterateDir(dir, recurse, callback) {
  do_print("Iterate " + dir.leafName);
  let entries = dir.directoryEntries;

  // Loop over everything in this dir. If its a dir
  while (entries.hasMoreElements()) {
    let entry = entries.getNext();
    entry.QueryInterface(Ci.nsILocalFile);

    if (entry.isDirectory()) {
      if (recurse) {
        iterateDir(entry, recurse, callback);
      }
    } else {
      callback(entry);
    }
  }
}

function isIID(a, iid) {
  try {
    a.QueryInterface(iid);
    return true;
  } catch (e) { }

  return false;
}