@@ -100,6 +100,70 @@ suite('KeybindingsSync', () => {
100
100
assert . equal ( ( await fileService . readFile ( keybindingsResource ) ) . value . toString ( ) , content ) ;
101
101
} ) ;
102
102
103
+ test ( 'when keybindings file is empty with comment and remote has no changes' , async ( ) => {
104
+ const fileService = client . instantiationService . get ( IFileService ) ;
105
+ const keybindingsResource = client . instantiationService . get ( IEnvironmentService ) . keybindingsResource ;
106
+ const expectedContent = '// Empty Keybindings' ;
107
+ await fileService . writeFile ( keybindingsResource , VSBuffer . fromString ( expectedContent ) ) ;
108
+
109
+ await testObject . sync ( await client . manifest ( ) ) ;
110
+
111
+ const lastSyncUserData = await testObject . getLastSyncUserData ( ) ;
112
+ const remoteUserData = await testObject . getRemoteUserData ( null ) ;
113
+ assert . equal ( testObject . getKeybindingsContentFromSyncContent ( lastSyncUserData ! . syncData ! . content ! ) , expectedContent ) ;
114
+ assert . equal ( testObject . getKeybindingsContentFromSyncContent ( remoteUserData ! . syncData ! . content ! ) , expectedContent ) ;
115
+ assert . equal ( ( await fileService . readFile ( keybindingsResource ) ) . value . toString ( ) , expectedContent ) ;
116
+ } ) ;
117
+
118
+ test ( 'when keybindings file is empty and remote has keybindings' , async ( ) => {
119
+ const client2 = disposableStore . add ( new UserDataSyncClient ( server ) ) ;
120
+ await client2 . setUp ( true ) ;
121
+ const content = JSON . stringify ( [
122
+ {
123
+ 'key' : 'shift+cmd+w' ,
124
+ 'command' : 'workbench.action.closeAllEditors' ,
125
+ }
126
+ ] ) ;
127
+ await client2 . instantiationService . get ( IFileService ) . writeFile ( client2 . instantiationService . get ( IEnvironmentService ) . keybindingsResource , VSBuffer . fromString ( content ) ) ;
128
+ await client2 . sync ( ) ;
129
+
130
+ const fileService = client . instantiationService . get ( IFileService ) ;
131
+ const keybindingsResource = client . instantiationService . get ( IEnvironmentService ) . keybindingsResource ;
132
+ await fileService . writeFile ( keybindingsResource , VSBuffer . fromString ( '// Empty Keybindings' ) ) ;
133
+
134
+ await testObject . sync ( await client . manifest ( ) ) ;
135
+
136
+ const lastSyncUserData = await testObject . getLastSyncUserData ( ) ;
137
+ const remoteUserData = await testObject . getRemoteUserData ( null ) ;
138
+ assert . equal ( testObject . getKeybindingsContentFromSyncContent ( lastSyncUserData ! . syncData ! . content ! ) , content ) ;
139
+ assert . equal ( testObject . getKeybindingsContentFromSyncContent ( remoteUserData ! . syncData ! . content ! ) , content ) ;
140
+ assert . equal ( ( await fileService . readFile ( keybindingsResource ) ) . value . toString ( ) , content ) ;
141
+ } ) ;
142
+
143
+ test ( 'when keybindings file is empty and remote has empty array' , async ( ) => {
144
+ const client2 = disposableStore . add ( new UserDataSyncClient ( server ) ) ;
145
+ await client2 . setUp ( true ) ;
146
+ const content =
147
+ `// Place your key bindings in this file to override the defaults
148
+ [
149
+ ]` ;
150
+ await client2 . instantiationService . get ( IFileService ) . writeFile ( client2 . instantiationService . get ( IEnvironmentService ) . keybindingsResource , VSBuffer . fromString ( content ) ) ;
151
+ await client2 . sync ( ) ;
152
+
153
+ const fileService = client . instantiationService . get ( IFileService ) ;
154
+ const keybindingsResource = client . instantiationService . get ( IEnvironmentService ) . keybindingsResource ;
155
+ const expectedLocalContent = '// Empty Keybindings' ;
156
+ await fileService . writeFile ( keybindingsResource , VSBuffer . fromString ( expectedLocalContent ) ) ;
157
+
158
+ await testObject . sync ( await client . manifest ( ) ) ;
159
+
160
+ const lastSyncUserData = await testObject . getLastSyncUserData ( ) ;
161
+ const remoteUserData = await testObject . getRemoteUserData ( null ) ;
162
+ assert . equal ( testObject . getKeybindingsContentFromSyncContent ( lastSyncUserData ! . syncData ! . content ! ) , content ) ;
163
+ assert . equal ( testObject . getKeybindingsContentFromSyncContent ( remoteUserData ! . syncData ! . content ! ) , content ) ;
164
+ assert . equal ( ( await fileService . readFile ( keybindingsResource ) ) . value . toString ( ) , expectedLocalContent ) ;
165
+ } ) ;
166
+
103
167
test ( 'when keybindings file is created after first sync' , async ( ) => {
104
168
const fileService = client . instantiationService . get ( IFileService ) ;
105
169
const keybindingsResource = client . instantiationService . get ( IEnvironmentService ) . keybindingsResource ;
0 commit comments