File tree Expand file tree Collapse file tree 4 files changed +113
-0
lines changed
tests/app_tests/new-instance Expand file tree Collapse file tree 4 files changed +113
-0
lines changed Original file line number Diff line number Diff line change
1
+ < html >
2
+ < head >
3
+ </ head >
4
+ < body >
5
+ < span > The pid of main page is: </ span >
6
+ < span id ="msg " style ="color:Green "> </ span >
7
+ < br />
8
+ < span > The pid of new-instance page is: </ span >
9
+ < span id ="msg2 " style ="color:Green "> </ span >
10
+ < script >
11
+ var gui = require ( 'nw.gui' ) ;
12
+ document . getElementById ( 'msg' ) . innerHTML = process . pid ;
13
+
14
+ var wnd = gui . Window . open ( "popup.html" , { show : true , 'new-instance' : true } )
15
+
16
+
17
+ var client = require ( '../../nw_test_app' ) . createClient ( {
18
+ argv : gui . App . argv ,
19
+ data : process . pid
20
+ } ) ;
21
+
22
+
23
+ gui . Window . get ( ) . on ( 'close' , function ( ) {
24
+ gui . App . quit ( ) ;
25
+ } )
26
+
27
+
28
+
29
+
30
+ </ script >
31
+
32
+
33
+ </ body >
34
+ </ html >
Original file line number Diff line number Diff line change
1
+
2
+ var path = require ( 'path' ) ;
3
+ var app_test = require ( './nw_test_app' ) ;
4
+ var server = global . server ;
5
+ var cb ;
6
+
7
+ describe ( 'new-instance' , function ( ) {
8
+
9
+ after ( function ( ) {
10
+ server . removeListener ( 'connection' , cb ) ;
11
+ } ) ;
12
+
13
+ it ( 'loaded event can been fired' , function ( done ) {
14
+ this . timeout ( 0 ) ;
15
+ var result = false ;
16
+ var times = 0 ;
17
+ var pid1 , pid2 ;
18
+
19
+ var child = app_test . createChildProcess ( {
20
+ execPath : process . execPath ,
21
+ appPath : path . join ( 'app_tests' , 'new-instance' ) ,
22
+ no_connect : true ,
23
+
24
+ } ) ;
25
+
26
+
27
+ server . on ( 'connection' , cb = function ( socket ) {
28
+ socket . setEncoding ( 'utf8' ) ;
29
+
30
+ socket . on ( 'data' , function ( data ) {
31
+
32
+ if ( times == 0 ) {
33
+ pid1 = data ;
34
+ times += 1 ;
35
+ } else {
36
+ pid2 = data ;
37
+
38
+ if ( pid1 != pid2 ) {
39
+ done ( ) ;
40
+ } else {
41
+ done ( 'they are in the same process' ) ;
42
+ }
43
+
44
+ child . app . kill ( ) ;
45
+ } // if (times == 0)
46
+ } ) ;
47
+ } ) ; // server.on('connection', cb = function(socket)
48
+
49
+
50
+ } )
51
+
52
+
53
+ } )
54
+
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " nw-demo" ,
3
+ "main" : " index.html"
4
+ }
Original file line number Diff line number Diff line change
1
+ < html >
2
+ < head >
3
+ </ head >
4
+ < body >
5
+ < span > The pid of page is: </ span >
6
+ < span id ="msg " style ="color:Green "> </ span >
7
+ < script >
8
+
9
+ var gui = require ( 'nw.gui' ) ;
10
+
11
+ document . getElementById ( 'msg' ) . innerHTML = process . pid ;
12
+
13
+ var client = require ( '../../nw_test_app' ) . createClient ( {
14
+ argv : gui . App . argv ,
15
+ data : process . pid
16
+ } ) ;
17
+ </ script >
18
+
19
+
20
+ </ body >
21
+ </ html >
You can’t perform that action at this time.
0 commit comments