summaryrefslogtreecommitdiffstats
path: root/toolkit/components/url-classifier/tests/mochitest/test_safebrowsing_bug1272239.html
blob: 8066c2a37214b2b46156aadbbda0985f4240446c (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1272239 - Only tables with provider could register gethash url in listmanager.</title>
  <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>

<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">

<script class="testbody" type="text/javascript">

var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;

// List all the tables
const prefs = [
  "urlclassifier.phishTable",
  "urlclassifier.malwareTable",
  "urlclassifier.downloadBlockTable",
  "urlclassifier.downloadAllowTable",
  "urlclassifier.trackingTable",
  "urlclassifier.trackingWhitelistTable",
  "urlclassifier.blockedTable"
];

var prefService = Cc["@mozilla.org/preferences-service;1"]
                  .getService(Ci.nsIPrefService);

// Get providers
var providers = {};

var branch = prefService.getBranch("browser.safebrowsing.provider.");
var children = branch.getChildList("", {});

for (var child of children) {
  var prefComponents =  child.split(".");
  var providerName = prefComponents[0];
  providers[providerName] = {};
}

// Get lists from |browser.safebrowsing.provider.PROVIDER_NAME.lists| preference.
var listsWithProvider = [];
var listsToProvider = [];
for (var provider in providers) {
  var pref = "browser.safebrowsing.provider." + provider + ".lists";
  var list = SpecialPowers.getCharPref(pref).split(",");

  listsToProvider = listsToProvider.concat(list.map( () => { return provider; }));
  listsWithProvider = listsWithProvider.concat(list);
}

// Get all the lists
var lists = [];
for (var pref of prefs) {
  lists = lists.concat(SpecialPowers.getCharPref(pref).split(","));
}

var listmanager = Cc["@mozilla.org/url-classifier/listmanager;1"].
                  getService(Ci.nsIUrlListManager);

for (var list of lists) {
  if (!list)
    continue;

  // For lists having a provider, it should have a correct gethash url
  // For lists without a provider, for example, test-malware-simple, it should not
  // have a gethash url.
  var url = listmanager.getGethashUrl(list);
  var index = listsWithProvider.indexOf(list);
  if (index >= 0) {
    var provider = listsToProvider[index];
    var pref = "browser.safebrowsing.provider." + provider + ".gethashURL";
    is(url, SpecialPowers.getCharPref(pref), list + " matches its gethash url");
  } else {
    is(url, "", list + " should not have a gethash url");
  }
}

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