@@ -76,6 +76,8 @@ def __init__(self, board, parent_test, test_name):
76
76
self ._mock_file_list_after = []
77
77
self ._mock_dir_list_after = []
78
78
self ._programming_file_name = None
79
+ self ._new_name = None
80
+ self ._new_name_delay = None
79
81
80
82
def set_shutils_copy (self , source_file_name ):
81
83
"""
@@ -118,6 +120,11 @@ def set_expected_failure_msg(self, msg):
118
120
assert msg is None or type (msg ) is str
119
121
self ._expected_failure_msg = msg
120
122
123
+ def set_rename_after_delay (self , delay , name ):
124
+ """Set delay and name to rename file to"""
125
+ self ._new_name = name
126
+ self ._new_name_delay = delay
127
+
121
128
def add_mock_files (self , file_list ):
122
129
"""Add a list of tuples containing a file and contents"""
123
130
self ._mock_file_list .extend (file_list )
@@ -202,7 +209,18 @@ def run(self):
202
209
with open (file_path , 'wb' ) as file_handle :
203
210
file_handle .write (file_contents )
204
211
205
- self .board .wait_for_remount (test_info )
212
+ # Delay if set
213
+ if self ._new_name_delay is not None :
214
+ time .sleep (self ._new_name_delay )
215
+
216
+ # Wait for remount if the copied file is present
217
+ if os .path .isfile (programming_file_name ):
218
+ if self ._new_name is not None :
219
+ new_name = self .board .get_file_path (self ._new_name )
220
+ os .rename (programming_file_name , new_name )
221
+ self .board .wait_for_remount (test_info )
222
+ else :
223
+ test_info .failure ('Missed device remount' )
206
224
207
225
# Verify the disk is still valid
208
226
self .board .test_fs (test_info )
@@ -336,6 +354,16 @@ def test_mass_storage(workspace, parent_test):
336
354
# when a binary file is loaded, since there is no way to
337
355
# tell where the end of the file is.
338
356
357
+ # Test writing a file with an unknown extension and then renaming it
358
+ # This simulates a browser downloading a file
359
+ # Note - firefox on linux typically creates an empty file and
360
+ # after ~8s the contents get flushed to the disk
361
+ test = MassStorageTester (board , test_info , "Rename after delay" )
362
+ test .set_programming_data (hex_file_contents , 'image.cdownload' )
363
+ test .set_rename_after_delay (10.0 , 'image.hex' )
364
+ test .set_expected_data (bin_file_contents )
365
+ test .run ()
366
+
339
367
# Finally, load a good binary
340
368
test = MassStorageTester (board , test_info , "Load good file to restore state" )
341
369
test .set_programming_data (hex_file_contents , 'image.hex' )
0 commit comments