File size: 2,725 Bytes
7e79d67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
Components.utils.import('resource://hatenabar/modules/20-ExpireCache.js');

function warmUp() {
    HTTPCache.counter = HTTPCache.bookmarked;
}

function setUp() {
    let filter = "['\\^https:\\/\\/.*\\$', '\\^https?:\\/\\/192\\\\.168\\\\.\\\\d+\\\\.\\\\d+.*\\$', '\\^https?:\\/\\/172\\\\.((1[6-9])|(2[0-9])|(3[0-1]))\\\\.\\\\d+\\\\.\\\\d+.*\\$', '\\^https?:\\/\\/10\\\\.\\\\d+\\\\.\\\\d+\\\\.\\\\d+.*\\$']";
    HTTPCache.counter.setFilter(eval(filter));
}

function testHTTPCounter() {
    let got = {};
    let result;

    got.value = false;
    result = NaN;
    HTTPCache.counter.get('http://www.hatena.ne.jp/my', function (val) {
        result = val;
        got.value = true;
    });
    yield got;
    assert.compare(10, '<', result);

    assert.isTrue(HTTPCache.counter.has('http://www.hatena.ne.jp/my'));
    
    got.value = false;
    result = NaN;
    HTTPCache.counter.get('http://www.hatena.ne.jp/my', function (val) {
        result = val;
        got.value = true;
    });
    yield got;
    assert.compare(10, '<', result);
}

function testHTTPSCounter() {
    let c = HTTPCache.counter;

    assert.isFalse(c.isValid('https://example.com/'));
    assert.isTrue(c.isValid('http://example.com/'));
}

function testLocalURLS() {
    let c = HTTPCache.counter;
    assert.isFalse(c.isValid('http://10.3.2.2/hogehuga?foo=bar'));
    assert.isFalse(c.isValid('https://10.3.2.2/hogehuga?foo=bar'));
    assert.isFalse(c.isValid('http://192.168.3.22/'));
    assert.isFalse(c.isValid('https://192.168.3.22/'));
    assert.isFalse(c.isValid('http://192.168.255.200/hogehuga?foo=bar'));
    assert.isTrue(c.isValid('http://10.example.com/hogehuga?foo=bar'));
    assert.isTrue(c.isValid('http://172.168.3.22/'));
    assert.isFalse(c.isValid('http://172.16.3.22/'));
    assert.isFalse(c.isValid('http://172.16.3.22/foobar?baz'));
    assert.isFalse(c.isValid('http://172.22.3.22/'));
    assert.isFalse(c.isValid('http://172.31.3.22/'));
    assert.isFalse(c.isValid('https://172.31.3.22/'));
    assert.isTrue(c.isValid('http://172.32.3.22/'));
}

function testReferredCounter() {
    let got = {};
    let result;

    got.value = false;
    result = undefined;
    HTTPCache.referred.get('http://www.hatena.ne.jp/', function (val) {
        result = val;
        got.value = true;
    });
    yield got;
    assert.compare(1000, '<', +result.count.(@name == 'diary'));

    assert.isTrue(HTTPCache.referred.has('http://www.hatena.ne.jp/'));
    
    got.value = false;
    result = undefined;
    HTTPCache.referred.get('http://www.hatena.ne.jp/', function (val) {
        result = val;
        got.value = true;
    });
    yield got;
    assert.equals('1', result.count.(@name == 'antenna').toString());
}