Skip to content

Commit ee6e6b5

Browse files
committed
Merge remote-tracking branch 'origin/master' into tools
Conflicts: tools/package_binaries.py
2 parents b81be41 + c81c94d commit ee6e6b5

File tree

21 files changed

+263
-113
lines changed

21 files changed

+263
-113
lines changed

src/net/app_protocol_handler.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ AppProtocolHandler::AppProtocolHandler(const base::FilePath& root)
2222
URLRequestJob* AppProtocolHandler::MaybeCreateJob(
2323
URLRequest* request, NetworkDelegate* network_delegate) const {
2424
base::FilePath file_path;
25-
const bool is_file = FileURLToFilePath(request->url(), &file_path);
25+
GURL url(request->url());
26+
url_canon::Replacements<char> replacements;
27+
replacements.SetScheme("file", url_parse::Component(0, 4));
28+
replacements.ClearHost();
29+
url = url.ReplaceComponents(replacements);
30+
31+
const bool is_file = FileURLToFilePath(url, &file_path);
2632

2733
file_path = root_path_.Append(file_path);
2834
// Check file access permissions.

src/renderer/shell_content_renderer_client.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,14 @@ void ShellContentRendererClient::InstallNodeSymbols(
285285

286286
if (use_node) {
287287
RenderViewImpl* rv = RenderViewImpl::FromWebView(frame->view());
288+
std::string root_path = rv->renderer_preferences_.nw_app_root_path.AsUTF8Unsafe();
289+
#if defined(OS_WIN)
290+
ReplaceChars(root_path, "\\", "\\\\", &root_path);
291+
#endif
288292
v8::Local<v8::Script> script = v8::Script::New(v8::String::New((
289293
// Make node's relative modules work
290294
"if (!process.mainModule.filename) {"
291-
" var root = '" + rv->renderer_preferences_.nw_app_root_path.AsUTF8Unsafe() + "';"
295+
" var root = '" + root_path + "';"
292296
#if defined(OS_WIN)
293297
"process.mainModule.filename = decodeURIComponent(window.location.pathname.substr(1));"
294298
#else
@@ -299,6 +303,7 @@ void ShellContentRendererClient::InstallNodeSymbols(
299303
"process.mainModule.loaded = true;"
300304
"}").c_str()
301305
));
306+
CHECK(*script);
302307
script->Run();
303308
}
304309

-73.9 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 169 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,179 @@
1-
var path = require('path');
2-
var app_test = require('./nw_test_app');
1+
var func = require('./' + global.tests_dir +'/start_app/script.js');
2+
var execPath = func.getExecPath();
3+
var fs = require('fs-extra');
4+
var os = require('os');
5+
var spawn = require('child_process').spawn;
36
var exec = require('child_process').exec;
4-
var pid1, pid2, pid3, pid4;
5-
var pid1_exist, pid2_exist, pid3_exist, pid4_exist;
6-
var cmd;
7-
var child1, child2, child3, child4;
8-
9-
if (process.platform == 'linux')
10-
cmd = 'ps -a | grep ';
11-
else if (process.platform == 'win32')
12-
cmd = 'tasklist | findstr ';
13-
else if (process.platform == 'darwin')
14-
return;
15-
16-
describe('single-instance', function() {
7+
8+
var app = new Array();
9+
var child1, child2;
10+
var mac_app_path = path.join('tmp-nw', 'node-webkit.app');
11+
function make_execuable_file(folder_path, done) {
12+
func.copyExecFiles(function() {
13+
func.copySourceFiles(folder_path);
14+
func.zipSourceFiles(function() {
15+
func.makeExecuableFile();
16+
if (os.platform() == 'darwin') {
17+
var app_path = 'tmp-nw/node-webkit.app/Contents/Resources/app.nw';
18+
fs.mkdir(app_path, function(err) {
19+
if(err && err.code !== 'EEXIST') throw err
20+
fs.copy('tmp-nw/index.html', path.join(app_path, 'index.html'));
21+
fs.copy('tmp-nw/package.html', path.join(app_path, 'package.html'));
22+
});
23+
}
24+
done();
25+
});
26+
});
27+
}
28+
29+
function check_have(i, cmd, options, msg, last, done) {
30+
var result = false;
31+
app[i] = spawn(cmd, options);
32+
app[i].on('exit', function() {
33+
result = true;
34+
});
35+
36+
if (last == 2) {
37+
setTimeout(function() {
38+
if (result) {
39+
done();
40+
} else {
41+
done(msg);
42+
}
43+
app[i].kill();
44+
app[i - 1].kill();
45+
}, 3000);
46+
} else {
47+
setTimeout(function() {
48+
if (result) {
49+
done(msg);
50+
} else {
51+
done();
52+
}
53+
if (last == 1) {
54+
app[i].kill();
55+
app[i - 1].kill();
56+
}
57+
}, 3000);
58+
}
59+
}
60+
61+
describe('single-instance', function() {
1762
this.timeout(0);
1863

1964
describe('single-instance false', function() {
20-
var app_mul_path = path.join(global.tests_dir, 'single_instance', process.platform, 'app_mul');
21-
before(function() {
22-
child3 = exec(app_mul_path);
23-
pid3 = child3.pid;
24-
console.log(pid3);
25-
26-
// normally we won't launch app one after another immediately
27-
setTimeout(function(){
28-
child4 = exec(app_mul_path);
29-
pid4 = child4.pid;
30-
console.log(pid4);
31-
},1000);
32-
});
33-
34-
it('should have a instance', function(done) {
35-
child = exec(cmd + pid3, function (error, stdout, stderr) {
36-
if (stdout == "")
37-
pid3_exist = false;
38-
else
39-
pid3_exist = true;
40-
41-
if (pid3_exist, true)
42-
done();
43-
else
44-
done("not have a instance");
45-
});
46-
});
47-
48-
it('should have a second instance', function(done) {
49-
setTimeout(function() {
50-
child = exec(cmd + pid4, function (error, stdout, stderr) {
51-
if (stdout == "")
52-
pid4_exist = false;
53-
else
54-
pid4_exist = true;
55-
56-
if (pid4_exist, true)
57-
done();
58-
else
59-
done('have a second instance');
60-
});
61-
}, 5500);
62-
});
65+
before(function(done) {
66+
make_execuable_file('single_instance/mul', done);
67+
});
68+
69+
after(function() {
70+
fs.remove('tmp-nw', function (er) {
71+
if (er) throw er;
72+
});
73+
});
74+
75+
it('should have a instance', function(done) {
76+
check_have(0, execPath, "", 'not have a instance', 0, done);
77+
});
78+
79+
it('should have a second instance', function(done) {
80+
check_have(1, execPath, "", 'not have a second instance', 1, done);
81+
});
6382
});
6483

84+
6585
describe('single-instance default', function() {
66-
var app_path = path.join(global.tests_dir, 'single_instance', process.platform, 'app');
67-
before(function(done) {
6886

87+
before(function(done) {
6988
setTimeout(function() {
70-
child1 = exec(app_path);
71-
pid1 = child1.pid;
72-
console.log(pid1);
73-
74-
// normally we won't launch app one after another immediately
75-
// Otherwise,sometimes it won't work here
76-
setTimeout(function(){
77-
child2 = exec(app_path);
78-
pid2 = child2.pid;
79-
console.log(pid2);
80-
done();
81-
}, 1000);
82-
}, 2000)
83-
});
84-
85-
it('should have a instance', function(done) {
86-
child = exec(cmd + pid1, function (error, stdout, stderr) {
87-
if (stdout == "")
88-
pid1_exist = false;
89-
else
90-
pid1_exist = true;
91-
92-
if (pid1_exist)
93-
done();
94-
else
95-
done('not have a instance');
96-
});
97-
});
98-
99-
it('should not have a second instance', function(done) {
100-
setTimeout(function() {
101-
child = exec(cmd + pid2, function (error, stdout, stderr) {
102-
if (stdout == "")
103-
pid2_exist = false;
104-
else
105-
pid2_exist = true;
106-
107-
if (!pid2_exist)
108-
done();
109-
else
110-
done("have a second instance");
111-
});
112-
}, 5500);
113-
});
89+
make_execuable_file('single_instance/single', done);
90+
}, 3000);
91+
});
92+
93+
after(function() {
94+
fs.remove('tmp-nw', function (er) {
95+
if (er) throw er;
96+
});
97+
});
98+
99+
it('should have a instance', function(done) {
100+
check_have(2, execPath, "", 'not have a instance', 0, done);
101+
});
102+
103+
it('should not have a second instance', function(done) {
104+
check_have(3, execPath, "", 'have a second instance', 2, done);
105+
});
114106
});
115-
116-
});
107+
108+
if (os.platform() == 'darwin') {
109+
describe('single-instance false(open app)', function(){
110+
before(function(done) {
111+
setTimeout(function() {
112+
make_execuable_file('single_instance/open_mul', done);
113+
}, 3000);
114+
});
115+
116+
after(function() {
117+
fs.remove('tmp-nw', function (er) {
118+
if (er) throw er;
119+
});
120+
});
121+
122+
it('should have a instance (open app)', function(done) {
123+
child1 = exec('open ' + mac_app_path);
124+
setTimeout(function () {
125+
var content = fs.readFileSync('tmp-nw/msg');
126+
if (content + "" != "")
127+
done();
128+
else
129+
done("not have a instance");
130+
}, 6000);
131+
});
132+
133+
it('should have a second instance (open app)', function(done) {
134+
child2 = exec('open ' + mac_app_path);
135+
var content = fs.readFileSync('tmp-nw/msg');
136+
if (content + "" == "11")
137+
done();
138+
else
139+
done("not have a instance");
140+
});
141+
142+
});
143+
144+
describe('single-instance default(open app)', function(){
145+
before(function(done) {
146+
setTimeout(function() {
147+
make_execuable_file('single_instance/open_single', done);
148+
}, 3000);
149+
});
150+
151+
after(function() {
152+
fs.remove('tmp-nw', function (er) {
153+
if (er) throw er;
154+
});
155+
});
156+
157+
it('should have a instance (open app)', function(done) {
158+
child1 = exec('open ' + mac_app_path);
159+
setTimeout(function () {
160+
var content = fs.readFileSync('tmp-nw/msg_s');
161+
if (content + "" != "")
162+
done();
163+
else
164+
done("not have a instance");
165+
}, 6000);
166+
});
167+
168+
it('should not have a second instance (open app)', function(done) {
169+
child2 = exec('open ' + mac_app_path);
170+
var content = fs.readFileSync('tmp-nw/msg_s');
171+
if (content + "" == "11")
172+
done("have a second instance");
173+
else
174+
done();
175+
176+
});
177+
});
178+
}
179+
});

0 commit comments

Comments
 (0)