[ACS-12098] firefox headless race condition viewer fix (#12023)

* [ACS-12098] firefox headless race condition viewer fix

* [ACS-12098] review fixes 1

* [ACS-12098] review fixes 2

* [ACS-12098] review fixes 3

* last firefox headless fixes
This commit is contained in:
Adam Świderski
2026-07-07 13:21:14 +02:00
committed by GitHub
parent 2f50af623d
commit 45d1818f04
8 changed files with 342 additions and 36 deletions
@@ -539,7 +539,7 @@ describe('ViewerComponent', () => {
fixture.detectChanges();
expect(getMainLoader()).toBeNull();
expect(component.viewerType).toBe('media');
expect(testingUtils.getByDirective(MediaPlayerComponent)).not.toBeNull();
});
it('should display spinner when viewerType is pdf', () => {
@@ -553,7 +553,7 @@ describe('ViewerComponent', () => {
imgViewer.triggerEventHandler('pagesLoaded', null);
fixture.detectChanges();
expect(component.viewerType).toBe('pdf');
expect(testingUtils.getByDirective(MockPdfViewerComponent)).not.toBeNull();
});
it('should show spinner until renderer calls markAsLoaded', () => {
@@ -570,7 +570,7 @@ describe('ViewerComponent', () => {
fixture.detectChanges();
expect(getMainLoader()).toBeNull();
expect(component.viewerType).toBe('image');
expect(testingUtils.getByDirective(ImgViewerComponent)).not.toBeNull();
expect(component.markAsLoaded).toHaveBeenCalled();
});
@@ -582,7 +582,77 @@ describe('ViewerComponent', () => {
component.onUnsupportedFile();
fixture.detectChanges();
expect(getMainLoader()).toBeNull();
expect(component.viewerType).toBe('unknown');
expect(testingUtils.getByCSS('adf-viewer-unknown-format')).not.toBeNull();
});
});
describe('Blob MIME type handling', () => {
it('should resolve viewerType from blob type when blob has valid MIME type', () => {
component.blobFile = new Blob(['content'], { type: 'application/pdf' });
component.ngOnChanges();
fixture.detectChanges();
expect(testingUtils.getByDirective(MockPdfViewerComponent)).not.toBeNull();
});
it('should fall back to mimeType input when blob type resolves to unknown', () => {
component.blobFile = new Blob(['content'], { type: '' });
component.mimeType = 'application/pdf';
component.ngOnChanges();
fixture.detectChanges();
expect(testingUtils.getByDirective(MockPdfViewerComponent)).not.toBeNull();
});
it('should remain unknown when both blob type and mimeType input are empty', () => {
component.blobFile = new Blob(['content'], { type: '' });
component.mimeType = '';
component.ngOnChanges();
fixture.detectChanges();
expect(testingUtils.getByCSS('adf-viewer-unknown-format')).not.toBeNull();
});
it('should strip MIME type parameters (e.g. charset) from blob type before resolving viewer type', () => {
component.blobFile = new Blob(['content'], { type: 'application/pdf;charset=utf-8' });
component.ngOnChanges();
fixture.detectChanges();
expect(testingUtils.getByDirective(MockPdfViewerComponent)).not.toBeNull();
});
it('should strip MIME type parameters from mimeType input during fallback', () => {
component.blobFile = new Blob(['content'], { type: '' });
component.mimeType = 'application/pdf;charset=utf-8';
component.ngOnChanges();
fixture.detectChanges();
expect(testingUtils.getByDirective(MockPdfViewerComponent)).not.toBeNull();
});
it('should resolve image viewer from blob type with parameters', () => {
component.blobFile = new Blob(['content'], { type: 'image/png; charset=binary' });
component.ngOnChanges();
fixture.detectChanges();
expect(testingUtils.getByDirective(ImgViewerComponent)).not.toBeNull();
});
it('should emit extensionChange with blob MIME type when available', () => {
spyOn(component.extensionChange, 'emit');
component.blobFile = new Blob(['content'], { type: 'application/pdf' });
component.ngOnChanges();
expect(component.extensionChange.emit).toHaveBeenCalledWith('application/pdf');
});
it('should emit extensionChange with mimeType input when blob type is empty', () => {
spyOn(component.extensionChange, 'emit');
component.blobFile = new Blob(['content'], { type: '' });
component.mimeType = 'application/pdf';
component.ngOnChanges();
expect(component.extensionChange.emit).toHaveBeenCalledWith('application/pdf');
});
});
});
@@ -241,15 +241,23 @@ export class ViewerRenderComponent implements OnChanges, OnInit {
private setUpBlobData() {
this.internalFileName = this.fileName;
this.viewerType = this.viewUtilService.getViewerTypeByMimeType(this.blobFile.type);
const blobMimeType = this.extractMimeTypeEssence(this.blobFile.type);
this.viewerType = this.viewUtilService.getViewerTypeByMimeType(blobMimeType);
if (this.viewerType === 'unknown' && this.mimeType) {
this.viewerType = this.viewUtilService.getViewerTypeByMimeType(this.extractMimeTypeEssence(this.mimeType));
}
if (this.viewerType === 'unknown') {
this.isLoading = false;
}
this.extensionChange.emit(this.blobFile.type);
this.extensionChange.emit(blobMimeType || this.extractMimeTypeEssence(this.mimeType));
this.scrollTop();
}
private extractMimeTypeEssence(mimeType: string): string {
return (mimeType || '').split(';')[0].trim();
}
private setUpUrlFile() {
this.internalFileName = this.fileName ? this.fileName : this.viewUtilService.getFilenameFromUrl(this.urlFile);
this.extension = this.viewUtilService.getFileExtension(this.internalFileName);
@@ -34,6 +34,7 @@ import { ViewerWithCustomToolbarComponent } from './mock/adf-viewer-container-to
import { ViewerComponent } from './viewer.component';
import { ThumbnailService } from '../../common/services/thumbnail.service';
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { ViewerRenderComponent } from './viewer-render/viewer-render.component';
@Component({
selector: 'adf-dialog-dummy',
@@ -113,8 +114,57 @@ describe('ViewerComponent', () => {
};
component.ngOnChanges(mockSimpleChanges);
fixture.detectChanges();
expect(component.mimeType).toBe('image/png');
const viewerRender = testingUtils.getByDirective(ViewerRenderComponent).componentInstance as ViewerRenderComponent;
expect(viewerRender.mimeType).toBe('image/png');
});
it('should strip MIME type parameters from blob type', () => {
const mockSimpleChanges: SimpleChanges = {
blobFile: new SimpleChange(null, { type: 'application/pdf;charset=utf-8' }, true)
};
component.ngOnChanges(mockSimpleChanges);
fixture.detectChanges();
const viewerRender = testingUtils.getByDirective(ViewerRenderComponent).componentInstance as ViewerRenderComponent;
expect(viewerRender.mimeType).toBe('application/pdf');
});
it('should strip MIME type parameters with spaces from blob type', () => {
const mockSimpleChanges: SimpleChanges = {
blobFile: new SimpleChange(null, { type: 'image/png; charset=binary' }, true)
};
component.ngOnChanges(mockSimpleChanges);
fixture.detectChanges();
const viewerRender = testingUtils.getByDirective(ViewerRenderComponent).componentInstance as ViewerRenderComponent;
expect(viewerRender.mimeType).toBe('image/png');
});
it('should handle empty blob type gracefully', () => {
const mockSimpleChanges: SimpleChanges = {
blobFile: new SimpleChange(null, { type: '' }, true)
};
component.ngOnChanges(mockSimpleChanges);
fixture.detectChanges();
const viewerRender = testingUtils.getByDirective(ViewerRenderComponent).componentInstance as ViewerRenderComponent;
expect(viewerRender.mimeType).toBe('');
});
it('should set mimeTypeIconUrl with stripped MIME type from blob', () => {
spyOn(thumbnailService, 'getMimeTypeIcon').and.returnValue('icon-url');
const mockSimpleChanges: SimpleChanges = {
blobFile: new SimpleChange(null, { type: 'application/pdf;charset=utf-8' }, true)
};
component.ngOnChanges(mockSimpleChanges);
expect(thumbnailService.getMimeTypeIcon).toHaveBeenCalledWith('application/pdf');
});
it('should set mimeTypeIconUrl when mimeType changes and no nodeMimeType is provided', () => {
@@ -347,8 +347,9 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
const { blobFile, urlFile, mimeType, nodeMimeType } = changes;
if (blobFile?.currentValue) {
this.mimeType = blobFile.currentValue.type;
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(blobFile.currentValue.type);
const blobMimeType = this.extractMimeTypeEssence(blobFile.currentValue.type);
this.mimeType = blobMimeType;
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(blobMimeType);
}
if (urlFile?.currentValue) {
@@ -356,14 +357,18 @@ export class ViewerComponent<T> implements OnDestroy, OnInit, OnChanges {
}
if (mimeType?.currentValue && !nodeMimeType?.currentValue) {
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(mimeType.currentValue);
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(this.extractMimeTypeEssence(mimeType.currentValue));
}
if (nodeMimeType?.currentValue) {
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(nodeMimeType.currentValue);
this.mimeTypeIconUrl = this.thumbnailService.getMimeTypeIcon(this.extractMimeTypeEssence(nodeMimeType.currentValue));
}
}
private extractMimeTypeEssence(mimeType: string): string {
return (mimeType || '').split(';')[0].trim();
}
ngOnInit(): void {
this.closeOverlayManager();
this.configureAndInitDownloadPrompt();