Skip to content

Commit 3083c0f

Browse files
committed
Add test case for App.clearCache
1 parent c0a151f commit 3083c0f

File tree

6 files changed

+63
-2
lines changed

6 files changed

+63
-2
lines changed

tests/automatic_tests/app/index.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Test Case for 'App.clearCache'</title>
6+
</head>
7+
<body onload='fun()'>
8+
<p id="wait" style="font-size:1.5em">Please wait to be closed.</p>
9+
<img src='http://127.0.0.1:8123/img.jpg'/>
10+
</body>
11+
</html>
12+
<script>
13+
function fun() {
14+
var gui = require('nw.gui');
15+
16+
if (self.name == '')
17+
self.name = 0; //initial
18+
else
19+
self.name++;//1:304,2:200;
20+
21+
if (self.name == 2)
22+
gui.App.clearCache();
23+
else if (self.name == 3) {
24+
var client = require('../../nw_test_app').createClient({
25+
argv: gui.App.argv,
26+
data: {}
27+
});
28+
}
29+
location.reload();
30+
}
31+
</script>
32+

tests/automatic_tests/app/mocha_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
var gui = require('nw.gui');
22
var assert = require('assert');
3+
var app_test = require('./nw_test_app');
34

45
describe('gui.App', function() {
6+
before(function(done) {
7+
this.timeout(0);
8+
var child = app_test.createChildProcess({
9+
execPath: process.execPath,
10+
appPath: path.join(global.tests_dir, 'app'),
11+
end: function(data, app) {
12+
app.kill();
13+
done();
14+
}
15+
});
16+
});
17+
518
describe('manifest', function() {
619
it('`gui.App.manifest` should equle to value of package.json', function() {
720
assert.equal(gui.App.manifest.name, 'nw-tests');
@@ -21,4 +34,14 @@ describe('gui.App', function() {
2134
});
2235
});
2336

37+
describe('clearCache()', function(done) {
38+
it('should clear the HTTP cache in memory and the one on disk', function() {
39+
var res_save = global.local_server.res_save;
40+
41+
assert.equal(res_save[1].status, 304);
42+
assert.equal(res_save[1].pathname, 'img.jpg');
43+
assert.equal(res_save[2].status, 200);
44+
assert.equal(res_save[2].pathname, 'img.jpg');
45+
});
46+
});
2447
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "nw-gui.App-test",
3+
"main": "index.html"
4+
}

tests/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
var gui = require('nw.gui');
3333
var path = require('path');
3434
var program = require('commander');
35-
var local_server = require('./server/server');
35+
global.local_server = require('./server/server');
36+
var local_server = global.local_server;
3637

3738
//socket server
3839
var net = require('net');

tests/server/img.jpg

5.83 KB
Loading

tests/server/server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ types = {
3131

3232
function request_listener(req, res) {
3333
var pathname=__dirname+url.parse(req.url).pathname;
34-
34+
console.log("Receive request");
3535
if (path.extname(pathname)=="") {
3636
pathname+="/";
3737
}
@@ -57,6 +57,7 @@ function request_listener(req, res) {
5757
res.writeHead(304, "Not Modified");
5858
res.end();
5959
} else {
60+
res_save.push({"status": 200, 'pathname':req.url.slice(1)});
6061
fs.readFile(pathname,function (err,data){
6162
res.end(data);
6263
});

0 commit comments

Comments
 (0)