File tree Expand file tree Collapse file tree 5 files changed +119
-0
lines changed
tests/automatic_tests/window Expand file tree Collapse file tree 5 files changed +119
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > Test Case for 'Window.focus'</ title >
6
+ < script >
7
+ var gui = require ( 'nw.gui' ) ;
8
+ var win = gui . Window . get ( ) ;
9
+ var win_c = new Array ( ) ;
10
+ var win2_clicked = false , win1_clicked = false ;
11
+
12
+ for ( var i = 0 ; i < 3 ; i ++ )
13
+ win_c [ i ] = 0 ;
14
+
15
+ localStorage . win1 = 0 ;
16
+
17
+ var win1 = gui . Window . open ( 'index1.html' , {
18
+ 'new-instance' : true
19
+ } ) ;
20
+
21
+ var win2 = gui . Window . open ( 'index2.html' ) ;
22
+
23
+ win . on ( 'focus' , function ( ) {
24
+ console . log ( 'win' ) ;
25
+ win_c [ 0 ] ++ ;
26
+ } ) ;
27
+
28
+ win2 . on ( 'focus' , function ( ) {
29
+ console . log ( 'win2' ) ;
30
+ win_c [ 2 ] ++ ;
31
+ win2_clicked = true ;
32
+ } ) ;
33
+
34
+ function focus1 ( ) {
35
+ win1_clicked = true ;
36
+ win_c [ 1 ] = localStorage . win1 ;
37
+ }
38
+
39
+ function done ( ) {
40
+ if ( win1_clicked && win2_clicked ) {
41
+ var client = require ( '../../nw_test_app' ) . createClient ( {
42
+ argv : gui . App . argv ,
43
+ data : win_c
44
+ } ) ;
45
+ } else
46
+ setTimeout ( done , 2000 ) ;
47
+ }
48
+
49
+ done ( ) ;
50
+ </ script >
51
+ </ head >
52
+ < body >
53
+ < p id ="wait " style ="font-size:1.5em "> For now you should manually click the button to test the case</ p >
54
+ < button onclick ="focus1() "> You should click this only after you focused win1</ button >
55
+ < button onclick ="win2.focus() "> win2 Focus</ button >
56
+ </ body >
57
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > new_win1</ title >
6
+ < script >
7
+ var gui = require ( 'nw.gui' ) ;
8
+ var win1 = gui . Window . get ( ) ;
9
+ localStorage . win1 = 0 ;
10
+ win1 . on ( 'focus' , function ( ) {
11
+ localStorage . win1 ++ ;
12
+ console . log ( 'win1' ) ;
13
+ } ) ;
14
+ </ script >
15
+ </ head >
16
+ < body >
17
+ < p id ="wait " style ="font-size:1.5em "> Please focus this before click the according button .</ p >
18
+ </ body >
19
+ </ html >
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < title > new_win2</ title >
6
+ </ head >
7
+ < body >
8
+ < p id ="wait " style ="font-size:1.5em "> Please wait to be closed.</ p >
9
+ </ body >
10
+ </ html >
Original file line number Diff line number Diff line change
1
+ var path = require ( 'path' ) ;
2
+ var app_test = require ( './nw_test_app' ) ;
3
+ var assert = require ( 'assert' ) ;
4
+ var window_counts = 3 ;
5
+ var results ;
6
+
7
+ describe ( 'windoww' , function ( ) {
8
+ this . timeout ( 0 ) ;
9
+ before ( function ( done ) {
10
+ this . timeout ( 0 ) ;
11
+ var child = app_test . createChildProcess ( {
12
+ execPath : process . execPath ,
13
+ appPath : path . join ( global . tests_dir , 'window' ) ,
14
+ end : function ( data , app ) {
15
+ results = data ;
16
+ app . kill ( ) ;
17
+ done ( ) ;
18
+ }
19
+ } ) ;
20
+
21
+ } ) ;
22
+ describe ( 'focus()' , function ( ) {
23
+ it ( 'should focus on the window' , function ( ) {
24
+ for ( var i = 0 ; i < window_counts ; i ++ )
25
+ assert . notEqual ( results [ i ] , 0 )
26
+ } ) ;
27
+ } )
28
+ } )
29
+
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " nw-window-test" ,
3
+ "main" : " index.html"
4
+ }
You can’t perform that action at this time.
0 commit comments