@@ -7,6 +7,7 @@ const commands = require('lib/commands');
77const { mkConfig_, mkBrowser_} = require ( '../utils' ) ;
88
99describe ( 'plugin' , ( ) => {
10+ let initialDocument ;
1011 const mkHermione_ = ( opts = { } ) => {
1112 opts = _ . defaults ( opts , {
1213 proc : 'master' ,
@@ -15,7 +16,7 @@ describe('plugin', () => {
1516
1617 const hermione = new EventEmitter ( ) ;
1718
18- hermione . events = { NEW_BROWSER : 'newBrowser' } ;
19+ hermione . events = { NEW_BROWSER : 'newBrowser' , SESSION_START : 'sessionStart' } ;
1920 hermione . isWorker = sinon . stub ( ) . returns ( opts . proc === 'worker' ) ;
2021 hermione . config = {
2122 forBrowser : ( id ) => opts . browsers [ id ] || { desiredCapabilities : { } }
@@ -28,9 +29,21 @@ describe('plugin', () => {
2829 Object . keys ( commands ) . forEach ( ( command ) => {
2930 commands [ command ] = sinon . stub ( ) ;
3031 } ) ;
32+
33+ global . document = {
34+ createElement : sinon . stub ( ) ,
35+ body : {
36+ append : sinon . stub ( )
37+ }
38+ } ;
39+
40+ initialDocument = global . document ;
3141 } ) ;
3242
33- afterEach ( ( ) => sinon . restore ( ) ) ;
43+ afterEach ( ( ) => {
44+ sinon . restore ( ) ;
45+ global . document = initialDocument ;
46+ } ) ;
3447
3548 it ( 'should do nothing if plugin is disabled' , ( ) => {
3649 const hermione = mkHermione_ ( ) ;
@@ -42,17 +55,72 @@ describe('plugin', () => {
4255 } ) ;
4356
4457 describe ( 'master process' , ( ) => {
45- it ( 'should do nothing' , ( ) => {
46- const hermione = mkHermione_ ( { proc : 'master' } ) ;
47- sinon . spy ( hermione , 'on' ) ;
58+ describe ( '"SESSION_START" event' , ( ) => {
59+ it ( 'should create fake input and focus on it for plugin browsers' , ( ) => {
60+ const hermione = mkHermione_ ( { proc : 'master' } ) ;
61+
62+ plugin ( hermione , mkConfig_ ( {
63+ browsers : {
64+ b1 : {
65+ commands : [ ]
66+ }
67+ }
68+ } ) ) ;
4869
49- plugin ( hermione , mkConfig_ ( ) ) ;
70+ const fakeInput = {
71+ setAttribute : sinon . stub ( ) ,
72+ focus : sinon . stub ( )
73+ } ;
74+ global . document . createElement . returns ( fakeInput ) ;
75+
76+ const browser = mkBrowser_ ( ) ;
77+ browser . execute . callsFake ( ( ) => {
78+ browser . execute . firstCall . args [ 0 ] ( ) ;
79+ } ) ;
80+
81+ hermione . emit ( hermione . events . SESSION_START , browser , { browserId : 'b1' } ) ;
82+
83+ assert . calledWith ( document . createElement , 'input' ) ;
84+ assert . calledWith ( fakeInput . setAttribute , 'type' , 'text' ) ;
85+ assert . calledWith ( document . body . append , fakeInput ) ;
86+ assert . callOrder ( fakeInput . setAttribute , global . document . body . append , fakeInput . focus ) ;
87+ } ) ;
5088
51- assert . notCalled ( hermione . on ) ;
89+ it ( 'should not create fake input for not plugin browsers' , ( ) => {
90+ const hermione = mkHermione_ ( { proc : 'master' } ) ;
91+
92+ plugin ( hermione , mkConfig_ ( {
93+ browsers : {
94+ b1 : {
95+ commands : [ ]
96+ }
97+ }
98+ } ) ) ;
99+ const browser = mkBrowser_ ( ) ;
100+
101+ hermione . emit ( hermione . events . SESSION_START , browser , { browserId : 'b2' } ) ;
102+
103+ assert . notCalled ( browser . execute ) ;
104+ } ) ;
52105 } ) ;
53106 } ) ;
54107
55108 describe ( 'worker process' , ( ) => {
109+ it ( 'should not subscribe on "SESSION_START" event' , ( ) => {
110+ const hermione = mkHermione_ ( { proc : 'worker' } ) ;
111+ sinon . spy ( hermione , 'on' ) ;
112+
113+ plugin ( hermione , mkConfig_ ( {
114+ browsers : {
115+ b1 : {
116+ commands : [ ]
117+ }
118+ }
119+ } ) ) ;
120+
121+ assert . calledOnceWith ( hermione . on , hermione . events . NEW_BROWSER ) ;
122+ } ) ;
123+
56124 describe ( '"NEW_BROWSER" event' , ( ) => {
57125 it ( 'should throws if passed command is not implemented' , ( ) => {
58126 const hermione = mkHermione_ ( { proc : 'worker' } ) ;
0 commit comments