@@ -145,11 +145,18 @@ interface ISerializedTestInput {
145
145
146
146
class TestEditorInputFactory implements IEditorInputFactory {
147
147
148
+ static disableSerialize = false ;
149
+ static disableDeserialize = false ;
150
+
148
151
canSerialize ( editorInput : EditorInput ) : boolean {
149
152
return true ;
150
153
}
151
154
152
- serialize ( editorInput : EditorInput ) : string {
155
+ serialize ( editorInput : EditorInput ) : string | undefined {
156
+ if ( TestEditorInputFactory . disableSerialize ) {
157
+ return undefined ;
158
+ }
159
+
153
160
let testEditorInput = < TestEditorInput > editorInput ;
154
161
let testInput : ISerializedTestInput = {
155
162
id : testEditorInput . id
@@ -158,7 +165,11 @@ class TestEditorInputFactory implements IEditorInputFactory {
158
165
return JSON . stringify ( testInput ) ;
159
166
}
160
167
161
- deserialize ( instantiationService : IInstantiationService , serializedEditorInput : string ) : EditorInput {
168
+ deserialize ( instantiationService : IInstantiationService , serializedEditorInput : string ) : EditorInput | undefined {
169
+ if ( TestEditorInputFactory . disableDeserialize ) {
170
+ return undefined ;
171
+ }
172
+
162
173
let testInput : ISerializedTestInput = JSON . parse ( serializedEditorInput ) ;
163
174
164
175
return new TestEditorInput ( testInput . id ) ;
@@ -170,6 +181,9 @@ suite('Workbench editor groups', () => {
170
181
let disposables : IDisposable [ ] = [ ] ;
171
182
172
183
setup ( ( ) => {
184
+ TestEditorInputFactory . disableSerialize = false ;
185
+ TestEditorInputFactory . disableDeserialize = false ;
186
+
173
187
disposables . push ( Registry . as < IEditorInputFactoryRegistry > ( EditorExtensions . EditorInputFactories ) . registerEditorInputFactory ( 'testEditorInputForGroups' , TestEditorInputFactory ) ) ;
174
188
} ) ;
175
189
@@ -296,18 +310,40 @@ suite('Workbench editor groups', () => {
296
310
const input2 = input ( ) ;
297
311
const input3 = input ( ) ;
298
312
299
- // Pinned and Active
313
+ // Case 1: inputs can be serialized and deserialized
314
+
300
315
group . openEditor ( input1 , { pinned : true , active : true } ) ;
301
316
group . openEditor ( input2 , { pinned : true , active : true } ) ;
302
317
group . openEditor ( input3 , { pinned : false , active : true } ) ;
303
318
304
- const deserialized = createGroup ( group . serialize ( ) ) ;
319
+ let deserialized = createGroup ( group . serialize ( ) ) ;
305
320
assert . equal ( group . id , deserialized . id ) ;
306
321
assert . equal ( deserialized . count , 3 ) ;
322
+ assert . equal ( deserialized . getEditors ( EditorsOrder . SEQUENTIAL ) . length , 3 ) ;
323
+ assert . equal ( deserialized . getEditors ( EditorsOrder . MOST_RECENTLY_ACTIVE ) . length , 3 ) ;
307
324
assert . equal ( deserialized . isPinned ( input1 ) , true ) ;
308
325
assert . equal ( deserialized . isPinned ( input2 ) , true ) ;
309
326
assert . equal ( deserialized . isPinned ( input3 ) , false ) ;
310
327
assert . equal ( deserialized . isActive ( input3 ) , true ) ;
328
+
329
+ // Case 2: inputs cannot be serialized
330
+ TestEditorInputFactory . disableSerialize = true ;
331
+
332
+ deserialized = createGroup ( group . serialize ( ) ) ;
333
+ assert . equal ( group . id , deserialized . id ) ;
334
+ assert . equal ( deserialized . count , 0 ) ;
335
+ assert . equal ( deserialized . getEditors ( EditorsOrder . SEQUENTIAL ) . length , 0 ) ;
336
+ assert . equal ( deserialized . getEditors ( EditorsOrder . MOST_RECENTLY_ACTIVE ) . length , 0 ) ;
337
+
338
+ // Case 3: inputs cannot be deserialized
339
+ TestEditorInputFactory . disableSerialize = false ;
340
+ TestEditorInputFactory . disableDeserialize = true ;
341
+
342
+ deserialized = createGroup ( group . serialize ( ) ) ;
343
+ assert . equal ( group . id , deserialized . id ) ;
344
+ assert . equal ( deserialized . count , 0 ) ;
345
+ assert . equal ( deserialized . getEditors ( EditorsOrder . SEQUENTIAL ) . length , 0 ) ;
346
+ assert . equal ( deserialized . getEditors ( EditorsOrder . MOST_RECENTLY_ACTIVE ) . length , 0 ) ;
311
347
} ) ;
312
348
313
349
test ( 'One Editor' , function ( ) {
0 commit comments