File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -356,6 +356,15 @@ class Glean {
356356 * @param flag When true, enable metric collection.
357357 */
358358 static setUploadEnabled ( flag : boolean ) : void {
359+ if ( ! isBoolean ( flag ) ) {
360+ log (
361+ LOG_TAG ,
362+ "Unable to change upload state, new value must be a boolean. Ignoring." ,
363+ LoggingLevel . Error
364+ ) ;
365+ return ;
366+ }
367+
359368 Context . dispatcher . launch ( async ( ) => {
360369 if ( ! Context . initialized ) {
361370 log (
Original file line number Diff line number Diff line change @@ -605,4 +605,18 @@ describe("Glean", function() {
605605 await Glean . testResetGlean ( testAppId , true ) ;
606606 assert . strictEqual ( Context . initialized , true ) ;
607607 } ) ;
608+
609+ it ( "setUploadEnabled does nothing in case a non-boolean value is passed to it" , async function ( ) {
610+ // Set the current upload value to false,
611+ // strings are "truthy", this way we can be sure calling with the wrong type dod not work.
612+ Glean . setUploadEnabled ( false ) ;
613+ await Context . dispatcher . testBlockOnQueue ( ) ;
614+ assert . strictEqual ( Context . uploadEnabled , false ) ;
615+
616+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
617+ // @ts -ignore
618+ Glean . setUploadEnabled ( "not a boolean" ) ;
619+ await Context . dispatcher . testBlockOnQueue ( ) ;
620+ assert . strictEqual ( Context . uploadEnabled , false ) ;
621+ } ) ;
608622} ) ;
You can’t perform that action at this time.
0 commit comments