提交 9b0e1d35 编写于 作者: B Benjamin Pasero

simplify all tests that deal with textFileServices

上级 82d9fb51
......@@ -7,26 +7,24 @@
import {Promise, TPromise} from 'vs/base/common/winjs.base';
import {TestInstantiationService} from 'vs/test/utils/instantiationTestUtils';
import EventEmitter = require('vs/base/common/eventEmitter');
import Paths = require('vs/base/common/paths');
import {EventEmitter} from 'vs/base/common/eventEmitter';
import * as paths from 'vs/base/common/paths';
import URI from 'vs/base/common/uri';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import Storage = require('vs/workbench/common/storage');
import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {Storage, InMemoryLocalStorage} from 'vs/workbench/common/storage';
import {EditorInputEvent, IEditorGroup} from 'vs/workbench/common/editor';
import Event, {Emitter} from 'vs/base/common/event';
import Severity from 'vs/base/common/severity';
import {IConfigurationService, getConfigurationValue, IConfigurationValue} from 'vs/platform/configuration/common/configuration';
import {IStorageService, StorageScope} from 'vs/platform/storage/common/storage';
import WorkbenchEditorService = require('vs/workbench/services/editor/common/editorService');
import QuickOpenService = require('vs/workbench/services/quickopen/common/quickOpenService');
import PartService = require('vs/workbench/services/part/common/partService');
import WorkspaceContextService = require('vs/platform/workspace/common/workspace');
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {IEditorInput, IEditorModel, Position, Direction, IEditor, IResourceInput, ITextEditorModel} from 'vs/platform/editor/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IUntitledEditorService, UntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IMessageService, IConfirmation} from 'vs/platform/message/common/message';
import {IWorkspace} from 'vs/platform/workspace/common/workspace';
import {ILifecycleService, ShutdownEvent} from 'vs/platform/lifecycle/common/lifecycle';
import {IWorkspace, IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {ILifecycleService, ShutdownEvent, NullLifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {EditorStacksModel} from 'vs/workbench/common/editor/editorStacksModel';
import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollection';
import {InstantiationService} from 'vs/platform/instantiation/common/instantiationService';
......@@ -40,6 +38,10 @@ import {IRawTextContent} from 'vs/workbench/parts/files/common/files';
import {RawText} from 'vs/editor/common/model/textModel';
import {parseArgs} from 'vs/code/node/argv';
import {EnvironmentService} from 'vs/platform/environment/node/environmentService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {ITextFileService} from 'vs/workbench/parts/files/common/files';
import {IHistoryService} from 'vs/workbench/services/history/common/history';
export const TestWorkspace: IWorkspace = {
resource: URI.file('C:\\testWorkspace'),
......@@ -49,7 +51,7 @@ export const TestWorkspace: IWorkspace = {
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv), process.execPath);
export class TestContextService implements WorkspaceContextService.IWorkspaceContextService {
export class TestContextService implements IWorkspaceContextService {
public _serviceBrand: any;
private workspace: any;
......@@ -74,55 +76,78 @@ export class TestContextService implements WorkspaceContextService.IWorkspaceCon
public isInsideWorkspace(resource: URI): boolean {
if (resource && this.workspace) {
return Paths.isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath);
return paths.isEqualOrParent(resource.fsPath, this.workspace.resource.fsPath);
}
return false;
}
public toWorkspaceRelativePath(resource: URI): string {
return Paths.makePosixAbsolute(Paths.normalize(resource.fsPath.substr('c:'.length)));
return paths.makePosixAbsolute(paths.normalize(resource.fsPath.substr('c:'.length)));
}
public toResource(workspaceRelativePath: string): URI {
return URI.file(Paths.join('C:\\', workspaceRelativePath));
return URI.file(paths.join('C:\\', workspaceRelativePath));
}
}
export abstract class TestTextFileService extends TextFileService {
constructor(
@WorkspaceContextService.IWorkspaceContextService contextService: WorkspaceContextService.IWorkspaceContextService,
@ILifecycleService lifecycleService: ILifecycleService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IInstantiationService instantiationService: IInstantiationService,
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService telemetryService: ITelemetryService,
@WorkbenchEditorService.IWorkbenchEditorService editorService: WorkbenchEditorService.IWorkbenchEditorService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IEventService eventService: IEventService,
@IFileService fileService: IFileService,
@IModelService modelService: IModelService
) {
super(contextService, instantiationService, configurationService, telemetryService, editorService, eventService, fileService, modelService);
super(lifecycleService, contextService, instantiationService, configurationService, telemetryService, editorGroupService, editorService, eventService, fileService, modelService);
}
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
return this.fileService.resolveContent(resource, options).then((content) => {
const raw = RawText.fromString(content.value, { defaultEOL: 1, detectIndentation: false, insertSpaces: false, tabSize: 4, trimAutoWhitespace: false });
return <IRawTextContent> {
return <IRawTextContent>{
resource: content.resource,
name: content.name,
mtime: content.mtime,
etag: content.etag,
mime: content.mime,
encoding: content.encoding,
value: raw,
valueLogicalHash: null
name: content.name,
mtime: content.mtime,
etag: content.etag,
mime: content.mime,
encoding: content.encoding,
value: raw,
valueLogicalHash: null
};
});
}
}
export function textFileServiceInstantiationService(): TestInstantiationService {
let instantiationService = new TestInstantiationService();
instantiationService.stub(IEventService, new TestEventService());
instantiationService.stub(IWorkspaceContextService, new TestContextService(TestWorkspace));
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, new TestEditorService(function () { }));
instantiationService.stub(IPartService, new TestPartService());
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
instantiationService.stub(IModeService);
instantiationService.stub(IHistoryService, 'getHistory', []);
instantiationService.stub(IModelService, createMockModelService(instantiationService));
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IFileService, TestFileService);
instantiationService.stub(ITelemetryService, NullTelemetryService);
instantiationService.stub(IMessageService, new TestMessageService());
instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(<any>TestTextFileService));
return instantiationService;
}
export class TestMessageService implements IMessageService {
public _serviceBrand: any;
......@@ -151,7 +176,7 @@ export class TestMessageService implements IMessageService {
}
}
export class TestPartService implements PartService.IPartService {
export class TestPartService implements IPartService {
public _serviceBrand: any;
public layout(): void { }
......@@ -200,20 +225,20 @@ export class TestPartService implements PartService.IPartService {
public getWorkbenchElementId(): string { return ''; }
}
export class TestEventService extends EventEmitter.EventEmitter implements IEventService {
export class TestEventService extends EventEmitter implements IEventService {
public _serviceBrand: any;
}
export class TestStorageService extends EventEmitter.EventEmitter implements IStorageService {
export class TestStorageService extends EventEmitter implements IStorageService {
public _serviceBrand: any;
private storage: Storage.Storage;
private storage: Storage;
constructor() {
super();
let context = new TestContextService();
this.storage = new Storage.Storage(new Storage.InMemoryLocalStorage(), null, context);
this.storage = new Storage(new InMemoryLocalStorage(), null, context);
}
store(key: string, value: any, scope: StorageScope = StorageScope.GLOBAL): void {
......@@ -256,7 +281,7 @@ export class TestUntitledEditorService implements IUntitledEditorService {
return [];
}
public revertAll(resources?: URI[]): URI[] {
public revertAll(resources?: URI[]): URI[] {
return [];
}
......@@ -292,7 +317,7 @@ export class TestEditorGroupService implements IEditorGroupService {
let services = new ServiceCollection();
services.set(IStorageService, new TestStorageService());
services.set(WorkspaceContextService.IWorkspaceContextService, new TestContextService());
services.set(IWorkspaceContextService, new TestContextService());
const lifecycle = new TestLifecycleService();
services.set(ILifecycleService, lifecycle);
......@@ -363,7 +388,7 @@ export class TestEditorGroupService implements IEditorGroupService {
}
}
export class TestEditorService implements WorkbenchEditorService.IWorkbenchEditorService {
export class TestEditorService implements IWorkbenchEditorService {
public _serviceBrand: any;
public activeEditorInput;
......@@ -443,7 +468,7 @@ export class TestEditorService implements WorkbenchEditorService.IWorkbenchEdito
}
}
export class TestQuickOpenService implements QuickOpenService.IQuickOpenService {
export class TestQuickOpenService implements IQuickOpenService {
public _serviceBrand: any;
private callback: (prefix: string) => void;
......@@ -498,7 +523,7 @@ export const TestFileService = {
mime: 'text/plain',
encoding: 'utf8',
mtime: new Date().getTime(),
name: Paths.basename(resource.fsPath)
name: paths.basename(resource.fsPath)
});
},
......@@ -506,7 +531,7 @@ export const TestFileService = {
return TPromise.as({
resource: resource,
value: {
on: (event:string, callback:Function): void => {
on: (event: string, callback: Function): void => {
if (event === 'data') {
callback('Hello Html');
}
......@@ -519,7 +544,7 @@ export const TestFileService = {
mime: 'text/plain',
encoding: 'utf8',
mtime: new Date().getTime(),
name: Paths.basename(resource.fsPath)
name: paths.basename(resource.fsPath)
});
},
......@@ -531,13 +556,13 @@ export const TestFileService = {
mime: 'text/plain',
encoding: 'utf8',
mtime: new Date().getTime(),
name: Paths.basename(res.fsPath)
name: paths.basename(res.fsPath)
};
});
}
};
export class TestConfigurationService extends EventEmitter.EventEmitter implements IConfigurationService {
export class TestConfigurationService extends EventEmitter implements IConfigurationService {
public _serviceBrand: any;
private configuration = Object.create(null);
......
......@@ -21,7 +21,7 @@ export class BinaryEditorModel extends EditorModel {
constructor(
resource: URI,
name: string,
@IFileService protected fileService: IFileService
@IFileService private fileService: IFileService
) {
super();
......
......@@ -12,6 +12,7 @@ import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEdito
import {CACHE, TextFileEditorModel} from 'vs/workbench/parts/files/common/editors/textFileEditorModel';
import {IResult, ITextFileOperationResult, ITextFileService, IRawTextContent, IAutoSaveConfiguration, AutoSaveMode} from 'vs/workbench/parts/files/common/files';
import {ConfirmResult} from 'vs/workbench/common/editor';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IFileService, IResolveContentOptions, IFilesConfiguration, IFileOperationResult, FileOperationResult, AutoSaveConfiguration} from 'vs/platform/files/common/files';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
......@@ -21,6 +22,7 @@ import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IDisposable, dispose} from 'vs/base/common/lifecycle';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
/**
* The workbench file service implementation implements the raw file service spec and adds additional methods on top.
......@@ -40,10 +42,12 @@ export abstract class TextFileService implements ITextFileService {
protected configuredAutoSaveOnWindowChange: boolean;
constructor(
@ILifecycleService protected lifecycleService: ILifecycleService,
@IWorkspaceContextService protected contextService: IWorkspaceContextService,
@IInstantiationService private instantiationService: IInstantiationService,
@IConfigurationService private configurationService: IConfigurationService,
@ITelemetryService private telemetryService: ITelemetryService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IWorkbenchEditorService protected editorService: IWorkbenchEditorService,
@IEventService private eventService: IEventService,
@IFileService protected fileService: IFileService,
......@@ -51,15 +55,13 @@ export abstract class TextFileService implements ITextFileService {
) {
this.listenerToUnbind = [];
this._onAutoSaveConfigurationChange = new Emitter<IAutoSaveConfiguration>();
}
protected init(): void {
this.registerListeners();
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
this.onConfigurationChange(configuration);
this.telemetryService.publicLog('autoSave', this.getAutoSaveConfiguration());
this.registerListeners();
}
public abstract resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent>;
......@@ -72,6 +74,23 @@ export abstract class TextFileService implements ITextFileService {
// Configuration changes
this.listenerToUnbind.push(this.configurationService.onDidUpdateConfiguration(e => this.onConfigurationChange(e.config)));
// Application & Editor focus change
window.addEventListener('blur', () => this.onWindowFocusLost());
window.addEventListener('blur', () => this.onEditorFocusChanged(), true);
this.listenerToUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorFocusChanged()));
}
private onWindowFocusLost(): void {
if (this.configuredAutoSaveOnWindowChange && this.isDirty()) {
this.saveAll().done(null, errors.onUnexpectedError);
}
}
private onEditorFocusChanged(): void {
if (this.configuredAutoSaveOnFocusChange && this.isDirty()) {
this.saveAll().done(null, errors.onUnexpectedError);
}
}
private onConfigurationChange(configuration: IFilesConfiguration): void {
......
......@@ -11,7 +11,6 @@ import paths = require('vs/base/common/paths');
import strings = require('vs/base/common/strings');
import {isWindows, isLinux} from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import errors = require('vs/base/common/errors');
import {UntitledEditorModel} from 'vs/workbench/common/editor/untitledEditorModel';
import {ConfirmResult} from 'vs/workbench/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
......@@ -44,20 +43,18 @@ export class TextFileService extends AbstractTextFileService {
@IInstantiationService instantiationService: IInstantiationService,
@IFileService fileService: IFileService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@ILifecycleService private lifecycleService: ILifecycleService,
@ILifecycleService lifecycleService: ILifecycleService,
@ITelemetryService telemetryService: ITelemetryService,
@IConfigurationService configurationService: IConfigurationService,
@IEventService eventService: IEventService,
@IModeService private modeService: IModeService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService private editorGroupService: IEditorGroupService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IWindowService private windowService: IWindowService,
@IModelService modelService: IModelService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super(contextService, instantiationService, configurationService, telemetryService, editorService, eventService, fileService, modelService);
this.init();
super(lifecycleService, contextService, instantiationService, configurationService, telemetryService, editorGroupService, editorService, eventService, fileService, modelService);
}
protected registerListeners(): void {
......@@ -66,23 +63,6 @@ export class TextFileService extends AbstractTextFileService {
// Lifecycle
this.lifecycleService.onWillShutdown(event => event.veto(this.beforeShutdown()));
this.lifecycleService.onShutdown(this.onShutdown, this);
// Application & Editor focus change
window.addEventListener('blur', () => this.onWindowFocusLost());
window.addEventListener('blur', () => this.onEditorFocusChanged(), true);
this.listenerToUnbind.push(this.editorGroupService.onEditorsChanged(() => this.onEditorFocusChanged()));
}
private onWindowFocusLost(): void {
if (this.configuredAutoSaveOnWindowChange && this.isDirty()) {
this.saveAll().done(null, errors.onUnexpectedError);
}
}
private onEditorFocusChanged(): void {
if (this.configuredAutoSaveOnFocusChange && this.isDirty()) {
this.saveAll().done(null, errors.onUnexpectedError);
}
}
public resolveTextContent(resource: URI, options?: IResolveContentOptions): TPromise<IRawTextContent> {
......
......@@ -12,10 +12,10 @@ import {FileImportedEvent} from 'vs/workbench/parts/files/browser/fileActions';
suite('Files - Events', () => {
test('File Change Event (simple)', function () {
let origEvent: any = {};
let oldValue: any = { foo: 'bar' };
let newValue: any = { foo: 'foo' };
let event = new LocalFileChangeEvent(oldValue, newValue, origEvent);
const origEvent: any = {};
const oldValue: any = { foo: 'bar' };
const newValue: any = { foo: 'foo' };
const event = new LocalFileChangeEvent(oldValue, newValue, origEvent);
assert.strictEqual(event.originalEvent, origEvent);
assert.strictEqual(event.oldValue, oldValue);
......@@ -24,8 +24,8 @@ suite('Files - Events', () => {
});
test('File Upload Event', function () {
let origEvent: any = {};
let value: any = { foo: 'bar' };
const origEvent: any = {};
const value: any = { foo: 'bar' };
let event = new FileImportedEvent(value, true, origEvent);
assert.strictEqual(event.originalEvent, origEvent);
......
......@@ -6,64 +6,38 @@
import 'vs/workbench/parts/files/browser/files.contribution'; // load our contribution into the test
import * as assert from 'assert';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import {TestInstantiationService} from 'vs/test/utils/instantiationTestUtils';
import URI from 'vs/base/common/uri';
import {join} from 'vs/base/common/paths';
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IEventService} from 'vs/platform/event/common/event';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IStorageService} from 'vs/platform/storage/common/storage';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ILifecycleService, NullLifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IFileService} from 'vs/platform/files/common/files';
import {IQuickOpenService} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IPartService} from 'vs/workbench/services/part/common/partService';
import {ITextFileService} from 'vs/workbench/parts/files/common/files';
import {FileTracker} from 'vs/workbench/parts/files/browser/fileTracker';
import {createMockModelService, TestTextFileService, TestEditorGroupService, TestFileService, TestEditorService, TestPartService, TestConfigurationService, TestEventService, TestContextService, TestQuickOpenService, TestStorageService} from 'vs/test/utils/servicesTestUtils';
import {IHistoryService} from 'vs/workbench/services/history/common/history';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {textFileServiceInstantiationService} from 'vs/test/utils/servicesTestUtils';
function toResource(path) {
return URI.file(join('C:\\', path));
}
class ServiceAccessor {
constructor(@IWorkbenchEditorService public editorService: IWorkbenchEditorService) {
}
}
let accessor: ServiceAccessor;
suite('Files - FileEditorInput', () => {
let instantiationService: TestInstantiationService;
setup(() => {
instantiationService= new TestInstantiationService();
instantiationService.stub(IHistoryService, 'getHistory', []);
instantiationService= textFileServiceInstantiationService();
accessor = instantiationService.createInstance(ServiceAccessor);
});
test('FileEditorInput', function (done) {
let editorService = new TestEditorService(function () { });
let eventService = new TestEventService();
let telemetryService = NullTelemetryService;
let contextService = new TestContextService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(IFileService, <any>TestFileService);
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, editorService);
instantiationService.stub(IPartService, new TestPartService());
instantiationService.stub(IModeService);
instantiationService.stub(IModelService, createMockModelService(instantiationService));
instantiationService.stub(ITelemetryService, telemetryService);
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(ITextFileService, <ITextFileService> instantiationService.createInstance(<any> TestTextFileService));
let input = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/file.js'), 'text/javascript', void 0);
let otherInput = instantiationService.createInstance(FileEditorInput, toResource('foo/bar/otherfile.js'), 'text/javascript', void 0);
let otherInputSame = instantiationService.createInstance(FileEditorInput, toResource('foo/bar/file.js'), 'text/javascript', void 0);
const otherInput = instantiationService.createInstance(FileEditorInput, toResource('foo/bar/otherfile.js'), 'text/javascript', void 0);
const otherInputSame = instantiationService.createInstance(FileEditorInput, toResource('foo/bar/file.js'), 'text/javascript', void 0);
assert(input.matches(input));
assert(input.matches(otherInputSame));
......@@ -78,20 +52,20 @@ suite('Files - FileEditorInput', () => {
input = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar.html'), 'text/html', void 0);
let inputToResolve:any = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/file.js'), 'text/javascript', void 0);
let sameOtherInput = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/file.js'), 'text/javascript', void 0);
const inputToResolve:any = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/file.js'), 'text/javascript', void 0);
const sameOtherInput = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/file.js'), 'text/javascript', void 0);
return editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
let resolvedModelA = resolved;
return editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
return accessor.editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
const resolvedModelA = resolved;
return accessor.editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
assert(resolvedModelA === resolved); // OK: Resolved Model cached globally per input
return editorService.resolveEditorModel(sameOtherInput, true).then(function (otherResolved) {
return accessor.editorService.resolveEditorModel(sameOtherInput, true).then(function (otherResolved) {
assert(otherResolved === resolvedModelA); // OK: Resolved Model cached globally per input
inputToResolve.dispose(false);
return editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
return accessor.editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
assert(resolvedModelA === resolved); // Model is still the same because we had 2 clients
inputToResolve.dispose();
......@@ -99,15 +73,15 @@ suite('Files - FileEditorInput', () => {
resolvedModelA.dispose();
return editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
return accessor.editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
assert(resolvedModelA !== resolved); // Different instance, because input got disposed
let stat = (<any>resolved).versionOnDiskStat;
return editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
return accessor.editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
assert(stat !== (<any>resolved).versionOnDiskStat); // Different stat, because resolve always goes to the server for refresh
stat = (<any>resolved).versionOnDiskStat;
return editorService.resolveEditorModel(inputToResolve, false).then(function (resolved) {
return accessor.editorService.resolveEditorModel(inputToResolve, false).then(function (resolved) {
assert(stat === (<any>resolved).versionOnDiskStat); // Same stat, because not refreshed
done();
......@@ -121,15 +95,8 @@ suite('Files - FileEditorInput', () => {
});
test('Input.matches() - FileEditorInput', function () {
let eventService = new TestEventService();
let contextService = new TestContextService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(ITextFileService, <ITextFileService> instantiationService.createInstance(<any> TestTextFileService));
let fileEditorInput = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/updatefile.js'), 'text/javascript', void 0);
let contentEditorInput2 = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/updatefile.js'), 'text/javascript', void 0);
const fileEditorInput = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/updatefile.js'), 'text/javascript', void 0);
const contentEditorInput2 = instantiationService.createInstance(FileEditorInput, toResource('/foo/bar/updatefile.js'), 'text/javascript', void 0);
assert.strictEqual(fileEditorInput.matches(null), false);
assert.strictEqual(fileEditorInput.matches(fileEditorInput), true);
......@@ -137,33 +104,12 @@ suite('Files - FileEditorInput', () => {
});
test('FileTracker - dispose()', function (done) {
let editorService = new TestEditorService(function () { });
let telemetryService = NullTelemetryService;
let contextService = new TestContextService();
let eventService = new TestEventService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(IFileService, <any>TestFileService);
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, editorService);
instantiationService.stub(IQuickOpenService, new TestQuickOpenService());
instantiationService.stub(IPartService, new TestPartService());
instantiationService.stub(IModeService);
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
instantiationService.stub(IModelService, createMockModelService(instantiationService));
instantiationService.stub(ITelemetryService, telemetryService);
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(ITextFileService, <ITextFileService> instantiationService.createInstance(<any> TestTextFileService));
let tracker = instantiationService.createInstance(FileTracker);
let inputToResolve = instantiationService.createInstance(FileEditorInput, toResource('/fooss5/bar/file2.js'), 'text/javascript', void 0);
let sameOtherInput = instantiationService.createInstance(FileEditorInput, toResource('/fooss5/bar/file2.js'), 'text/javascript', void 0);
return editorService.resolveEditorModel(inputToResolve).then(function (resolved) {
return editorService.resolveEditorModel(sameOtherInput).then(function (resolved) {
const tracker = instantiationService.createInstance(FileTracker);
const inputToResolve = instantiationService.createInstance(FileEditorInput, toResource('/fooss5/bar/file2.js'), 'text/javascript', void 0);
const sameOtherInput = instantiationService.createInstance(FileEditorInput, toResource('/fooss5/bar/file2.js'), 'text/javascript', void 0);
return accessor.editorService.resolveEditorModel(inputToResolve).then(function (resolved) {
return accessor.editorService.resolveEditorModel(sameOtherInput).then(function (resolved) {
tracker.handleDeleteOrMove(toResource('/bar'), []);
assert(!inputToResolve.isDisposed());
assert(!sameOtherInput.isDisposed());
......@@ -179,33 +125,12 @@ suite('Files - FileEditorInput', () => {
});
test('FileEditorInput - dispose() also works for folders', function (done) {
let editorService = new TestEditorService(function () { });
let telemetryService = NullTelemetryService;
let contextService = new TestContextService();
let eventService = new TestEventService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(IFileService, <any>TestFileService);
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, editorService);
instantiationService.stub(IPartService, new TestPartService());
instantiationService.stub(IModeService);
instantiationService.stub(IEditorGroupService, new TestEditorGroupService());
instantiationService.stub(IQuickOpenService, new TestQuickOpenService());
instantiationService.stub(IModelService, createMockModelService(instantiationService));
instantiationService.stub(ITelemetryService, telemetryService);
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(ITextFileService, <ITextFileService> instantiationService.createInstance(<any> TestTextFileService));
let tracker = instantiationService.createInstance(FileTracker);
let inputToResolve = instantiationService.createInstance(FileEditorInput, toResource('/foo6/bar/file.js'), 'text/javascript', void 0);
let sameOtherInput = instantiationService.createInstance(FileEditorInput, toResource('/foo6/bar/file.js'), 'text/javascript', void 0);
return editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
return editorService.resolveEditorModel(sameOtherInput, true).then(function (resolved) {
const tracker = instantiationService.createInstance(FileTracker);
const inputToResolve = instantiationService.createInstance(FileEditorInput, toResource('/foo6/bar/file.js'), 'text/javascript', void 0);
const sameOtherInput = instantiationService.createInstance(FileEditorInput, toResource('/foo6/bar/file.js'), 'text/javascript', void 0);
return accessor.editorService.resolveEditorModel(inputToResolve, true).then(function (resolved) {
return accessor.editorService.resolveEditorModel(sameOtherInput, true).then(function (resolved) {
tracker.handleDeleteOrMove(toResource('/bar'), []);
assert(!inputToResolve.isDisposed());
assert(!sameOtherInput.isDisposed());
......
......@@ -6,58 +6,34 @@
'use strict';
import * as assert from 'assert';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import {TPromise} from 'vs/base/common/winjs.base';
import {TestInstantiationService} from 'vs/test/utils/instantiationTestUtils';
import URI from 'vs/base/common/uri';
import paths = require('vs/base/common/paths');
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import paths = require('vs/base/common/paths');
import {TextFileEditorModel, CACHE} from 'vs/workbench/parts/files/common/editors/textFileEditorModel';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IEventService} from 'vs/platform/event/common/event';
import {IMessageService} from 'vs/platform/message/common/message';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IStorageService} from 'vs/platform/storage/common/storage';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ILifecycleService, NullLifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IFileService} from 'vs/platform/files/common/files';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import PartService = require('vs/workbench/services/part/common/partService');
import {ITextFileService, EventType} from 'vs/workbench/parts/files/common/files';
import {createMockModelService, TestTextFileService, TestFileService, TestPartService, TestEditorService, TestConfigurationService, TestUntitledEditorService, TestStorageService, TestContextService, TestMessageService, TestEventService} from 'vs/test/utils/servicesTestUtils';
import {EventType, ITextFileService} from 'vs/workbench/parts/files/common/files';
import {textFileServiceInstantiationService} from 'vs/test/utils/servicesTestUtils';
function toResource(path) {
return URI.file(paths.join('C:\\', path));
}
let eventService: IEventService;
let textFileService: TestTextFileService;
class ServiceAccessor {
constructor(@IEventService public eventService: IEventService, @ITextFileService public textFileService: ITextFileService) {
}
}
let accessor: ServiceAccessor;
suite('Files - TextFileEditorModel', () => {
let instantiationService: TestInstantiationService;
setup(() => {
instantiationService= new TestInstantiationService();
eventService = new TestEventService();
eventService= <IEventService> instantiationService.stub(IEventService, new TestEventService());
instantiationService.stub(IMessageService, new TestMessageService());
instantiationService.stub(IFileService, <any> TestFileService);
instantiationService.stub(IWorkspaceContextService, new TestContextService());
instantiationService.stub(ITelemetryService);
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IUntitledEditorService, new TestUntitledEditorService());
instantiationService.stub(IWorkbenchEditorService, new TestEditorService());
instantiationService.stub(PartService.IPartService, new TestPartService());
instantiationService.stub(IModeService);
instantiationService.stub(IModelService, createMockModelService(instantiationService));
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IConfigurationService, new TestConfigurationService());
textFileService = <any>instantiationService.createInstance(<any>TestTextFileService);
instantiationService.stub(ITextFileService, textFileService);
instantiationService = textFileServiceInstantiationService();
accessor = instantiationService.createInstance(ServiceAccessor);
});
teardown(() => {
......@@ -65,17 +41,17 @@ suite('Files - TextFileEditorModel', () => {
});
test('Load does not trigger save', function (done) {
let m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index.txt'), 'utf8');
const m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index.txt'), 'utf8');
eventService.addListener2('files:internalFileChanged', () => {
accessor.eventService.addListener2('files:internalFileChanged', () => {
assert.ok(false);
});
eventService.addListener2(EventType.FILE_DIRTY, () => {
accessor.eventService.addListener2(EventType.FILE_DIRTY, () => {
assert.ok(false);
});
eventService.addListener2(EventType.FILE_SAVED, () => {
accessor.eventService.addListener2(EventType.FILE_SAVED, () => {
assert.ok(false);
});
......@@ -89,7 +65,7 @@ suite('Files - TextFileEditorModel', () => {
});
test('Load returns dirty model as long as model is dirty', function (done) {
let m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
const m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
m1.load().then(() => {
m1.textEditorModel.setValue('foo');
......@@ -108,11 +84,11 @@ suite('Files - TextFileEditorModel', () => {
test('Revert', function (done) {
let eventCounter = 0;
eventService.addListener2(EventType.FILE_REVERTED, () => {
accessor.eventService.addListener2(EventType.FILE_REVERTED, () => {
eventCounter++;
});
let m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
const m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
m1.load().then(() => {
m1.textEditorModel.setValue('foo');
......@@ -132,7 +108,7 @@ suite('Files - TextFileEditorModel', () => {
});
test('Conflict Resolution Mode', function (done) {
let m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
const m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
m1.load().then(() => {
m1.setConflictResolutionMode();
......@@ -158,16 +134,16 @@ suite('Files - TextFileEditorModel', () => {
test('Auto Save triggered when model changes', function (done) {
let eventCounter = 0;
let m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index.txt'), 'utf8');
const m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index.txt'), 'utf8');
(<any>m1).autoSaveAfterMillies = 10;
(<any>m1).autoSaveAfterMilliesEnabled = true;
eventService.addListener2(EventType.FILE_DIRTY, () => {
accessor.eventService.addListener2(EventType.FILE_DIRTY, () => {
eventCounter++;
});
eventService.addListener2(EventType.FILE_SAVED, () => {
accessor.eventService.addListener2(EventType.FILE_SAVED, () => {
eventCounter++;
});
......@@ -186,29 +162,29 @@ suite('Files - TextFileEditorModel', () => {
});
test('save() and isDirty() - proper with check for mtimes', function (done) {
let c1 = instantiationService.createInstance(FileEditorInput, toResource('/path/index_async2.txt'), 'text/plain', 'utf8');
let c2 = instantiationService.createInstance(FileEditorInput, toResource('/path/index_async.txt'), 'text/plain', 'utf8');
const c1 = instantiationService.createInstance(FileEditorInput, toResource('/path/index_async2.txt'), 'text/plain', 'utf8');
const c2 = instantiationService.createInstance(FileEditorInput, toResource('/path/index_async.txt'), 'text/plain', 'utf8');
c1.resolve().then((m1: TextFileEditorModel) => {
c2.resolve().then((m2: TextFileEditorModel) => {
m1.textEditorModel.setValue('foo');
let m1Mtime = m1.getLastModifiedTime();
let m2Mtime = m2.getLastModifiedTime();
const m1Mtime = m1.getLastModifiedTime();
const m2Mtime = m2.getLastModifiedTime();
assert.ok(m1Mtime > 0);
assert.ok(m2Mtime > 0);
assert.ok(textFileService.isDirty());
assert.ok(textFileService.isDirty(toResource('/path/index_async2.txt')));
assert.ok(!textFileService.isDirty(toResource('/path/index_async.txt')));
assert.ok(accessor.textFileService.isDirty());
assert.ok(accessor.textFileService.isDirty(toResource('/path/index_async2.txt')));
assert.ok(!accessor.textFileService.isDirty(toResource('/path/index_async.txt')));
m2.textEditorModel.setValue('foo');
assert.ok(textFileService.isDirty(toResource('/path/index_async.txt')));
assert.ok(accessor.textFileService.isDirty(toResource('/path/index_async.txt')));
return TPromise.timeout(10).then(() => {
textFileService.saveAll().then(() => {
assert.ok(!textFileService.isDirty(toResource('/path/index_async.txt')));
assert.ok(!textFileService.isDirty(toResource('/path/index_async2.txt')));
accessor.textFileService.saveAll().then(() => {
assert.ok(!accessor.textFileService.isDirty(toResource('/path/index_async.txt')));
assert.ok(!accessor.textFileService.isDirty(toResource('/path/index_async2.txt')));
assert.ok(m1.getLastModifiedTime() > m1Mtime);
assert.ok(m2.getLastModifiedTime() > m2Mtime);
assert.ok(m1.getLastSaveAttemptTime() > m1Mtime);
......@@ -226,15 +202,15 @@ suite('Files - TextFileEditorModel', () => {
test('Save Participant', function (done) {
let eventCounter = 0;
let m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
const m1 = instantiationService.createInstance(TextFileEditorModel, toResource('/path/index_async.txt'), 'utf8');
eventService.addListener2(EventType.FILE_SAVED, (e) => {
accessor.eventService.addListener2(EventType.FILE_SAVED, (e) => {
assert.equal(m1.getValue(), 'bar');
assert.ok(!m1.isDirty());
eventCounter++;
});
eventService.addListener2(EventType.FILE_SAVING, (e) => {
accessor.eventService.addListener2(EventType.FILE_SAVING, (e) => {
assert.ok(m1.isDirty());
m1.textEditorModel.setValue('bar');
assert.ok(m1.isDirty());
......
......@@ -8,16 +8,12 @@
import {strictEqual, equal} from 'assert';
import {join} from 'vs/base/common/paths';
import URI from 'vs/base/common/uri';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import {FileEditorDescriptor} from 'vs/workbench/parts/files/browser/files';
import {Registry} from 'vs/platform/platform';
import {SyncDescriptor} from 'vs/platform/instantiation/common/descriptors';
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import {Extensions} from 'vs/workbench/common/editor';
import {TestTextFileService, TestEventService, TestContextService} from 'vs/test/utils/servicesTestUtils';
import {IEventService} from 'vs/platform/event/common/event';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {ITextFileService} from 'vs/workbench/parts/files/common/files';
import {textFileServiceInstantiationService} from 'vs/test/utils/servicesTestUtils';
const ExtensionId = Extensions.Editors;
......@@ -27,14 +23,14 @@ class MyOtherClass { }
suite('Files - TextFileEditor', () => {
test('TextFile Editor Registration', function () {
let d1 = new FileEditorDescriptor('ce-id1', 'name', 'vs/workbench/parts/files/browser/tests/contentEditor.test', 'MyClass', ['test-text/html', 'test-text/javascript']);
let d2 = new FileEditorDescriptor('ce-id2', 'name', 'vs/workbench/parts/files/browser/tests/contentEditor.test', 'MyOtherClass', ['test-text/css', 'test-text/javascript']);
const d1 = new FileEditorDescriptor('ce-id1', 'name', 'vs/workbench/parts/files/browser/tests/contentEditor.test', 'MyClass', ['test-text/html', 'test-text/javascript']);
const d2 = new FileEditorDescriptor('ce-id2', 'name', 'vs/workbench/parts/files/browser/tests/contentEditor.test', 'MyOtherClass', ['test-text/css', 'test-text/javascript']);
let oldEditors = Registry.as(ExtensionId).getEditors();
const oldEditors = Registry.as(ExtensionId).getEditors();
Registry.as(ExtensionId).setEditors([]);
let oldEditorCnt = Registry.as(ExtensionId).getEditors().length;
let oldInputCnt = Registry.as(ExtensionId).getEditorInputs().length;
const oldEditorCnt = Registry.as(ExtensionId).getEditors().length;
const oldInputCnt = Registry.as(ExtensionId).getEditorInputs().length;
Registry.as(ExtensionId).registerEditor(d1, new SyncDescriptor(FileEditorInput));
Registry.as(ExtensionId).registerEditor(d2, new SyncDescriptor(FileEditorInput));
......@@ -42,14 +38,7 @@ suite('Files - TextFileEditor', () => {
equal(Registry.as(ExtensionId).getEditors().length, oldEditorCnt + 2);
equal(Registry.as(ExtensionId).getEditorInputs().length, oldInputCnt + 2);
let eventService = new TestEventService();
let contextService = new TestContextService();
let instantiationService = new TestInstantiationService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(ITextFileService, <ITextFileService> instantiationService.createInstance(<any> TestTextFileService));
const instantiationService = textFileServiceInstantiationService();
strictEqual(Registry.as(ExtensionId).getEditor(instantiationService.createInstance(FileEditorInput, URI.file(join('C:\\', '/foo/bar/foobar.html')), 'test-text/html', void 0)), d1);
strictEqual(Registry.as(ExtensionId).getEditor(instantiationService.createInstance(FileEditorInput, URI.file(join('C:\\', '/foo/bar/foobar.js')), 'test-text/javascript', void 0)), d1);
......
......@@ -13,11 +13,11 @@ import {EditorModel} from 'vs/workbench/common/editor';
suite('Files - TextFileEditorModelCache', () => {
test('add, remove, clear', function () {
let cache = new TextFileEditorModelCache();
const cache = new TextFileEditorModelCache();
let m1 = new EditorModel();
let m2 = new EditorModel();
let m3 = new EditorModel();
const m1 = new EditorModel();
const m2 = new EditorModel();
const m3 = new EditorModel();
cache.add(URI.file('/test.html'), <any>m1);
cache.add(URI.file('/some/other.html'), <any>m2);
......
......@@ -26,7 +26,7 @@ function toResource(path) {
suite('Files - View Model', () => {
test('Properties', function () {
let d = new Date().getTime();
const d = new Date().getTime();
let s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
assert.strictEqual(s.isDirectoryResolved, false);
......@@ -42,12 +42,12 @@ suite('Files - View Model', () => {
});
test('Add and Remove Child, check for hasChild', function () {
let d = new Date().getTime();
let s = createStat('/path/to/stat', 'sName', true, false, 8096, d);
const d = new Date().getTime();
const s = createStat('/path/to/stat', 'sName', true, false, 8096, d);
let child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
let child2 = createStat('/path/to/stat/bar.html', 'bar', false, false, 8096, d);
let child4 = createStat('/otherpath/to/other/otherbar.html', 'otherbar.html', false, false, 8096, d);
const child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat('/path/to/stat/bar.html', 'bar', false, false, 8096, d);
const child4 = createStat('/otherpath/to/other/otherbar.html', 'otherbar.html', false, false, 8096, d);
assert(!s.hasChild(child1.name));
assert(!s.hasChild(child2.name));
......@@ -74,12 +74,12 @@ suite('Files - View Model', () => {
});
test('Move', function () {
let d = new Date().getTime();
const d = new Date().getTime();
let s1 = createStat('/', '/', true, false, 8096, d);
let s2 = createStat('/path', 'path', true, false, 8096, d);
let s3 = createStat('/path/to', 'to', true, false, 8096, d);
let s4 = createStat('/path/to/stat', 'stat', false, false, 8096, d);
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', false, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
......@@ -96,9 +96,9 @@ suite('Files - View Model', () => {
assert.strictEqual(s4.resource.fsPath, toResource('/' + s4.name).fsPath);
// Move a subtree with children
let leaf = createStat('/leaf', 'leaf', true, false, 8096, d);
let leafC1 = createStat('/leaf/folder', 'folder', true, false, 8096, d);
let leafCC2 = createStat('/leaf/folder/index.html', 'index.html', true, false, 8096, d);
const leaf = createStat('/leaf', 'leaf', true, false, 8096, d);
const leafC1 = createStat('/leaf/folder', 'folder', true, false, 8096, d);
const leafCC2 = createStat('/leaf/folder/index.html', 'index.html', true, false, 8096, d);
leaf.addChild(leafC1);
leafC1.addChild(leafCC2);
......@@ -110,18 +110,18 @@ suite('Files - View Model', () => {
});
test('Rename', function () {
let d = new Date().getTime();
const d = new Date().getTime();
let s1 = createStat('/', '/', true, false, 8096, d);
let s2 = createStat('/path', 'path', true, false, 8096, d);
let s3 = createStat('/path/to', 'to', true, false, 8096, d);
let s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
s3.addChild(s4);
let s2renamed = createStat('/otherpath', 'otherpath', true, true, 8096, d);
const s2renamed = createStat('/otherpath', 'otherpath', true, true, 8096, d);
s2.rename(s2renamed);
// Verify the paths have changed including children
......@@ -130,22 +130,22 @@ suite('Files - View Model', () => {
assert.strictEqual(s3.resource.fsPath, toResource('/otherpath/to').fsPath);
assert.strictEqual(s4.resource.fsPath, toResource('/otherpath/to/stat').fsPath);
let s4renamed = createStat('/otherpath/to/statother.js', 'statother.js', true, false, 8096, d);
const s4renamed = createStat('/otherpath/to/statother.js', 'statother.js', true, false, 8096, d);
s4.rename(s4renamed);
assert.strictEqual(s4.name, s4renamed.name);
assert.strictEqual(s4.resource.fsPath, s4renamed.resource.fsPath);
});
test('Find', function () {
let d = new Date().getTime();
const d = new Date().getTime();
let s1 = createStat('/', '/', true, false, 8096, d);
let s2 = createStat('/path', 'path', true, false, 8096, d);
let s3 = createStat('/path/to', 'to', true, false, 8096, d);
let s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
let child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
let child2 = createStat('/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
const child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat('/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
......@@ -165,15 +165,15 @@ suite('Files - View Model', () => {
});
test('Find with mixed case', function () {
let d = new Date().getTime();
const d = new Date().getTime();
let s1 = createStat('/', '/', true, false, 8096, d);
let s2 = createStat('/path', 'path', true, false, 8096, d);
let s3 = createStat('/path/to', 'to', true, false, 8096, d);
let s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
const s1 = createStat('/', '/', true, false, 8096, d);
const s2 = createStat('/path', 'path', true, false, 8096, d);
const s3 = createStat('/path/to', 'to', true, false, 8096, d);
const s4 = createStat('/path/to/stat', 'stat', true, false, 8096, d);
let child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
let child2 = createStat('/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
const child1 = createStat('/path/to/stat/foo', 'foo', true, false, 8096, d);
const child2 = createStat('/path/to/stat/foo/bar.html', 'bar.html', false, false, 8096, d);
s1.addChild(s2);
s2.addChild(s3);
......@@ -191,9 +191,9 @@ suite('Files - View Model', () => {
});
test('Validate File Name (For Create)', function () {
let d = new Date().getTime();
let s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
let sChild = createStat('/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
const d = new Date().getTime();
const s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
const sChild = createStat('/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
s.addChild(sChild);
assert(validateFileName(s, null) !== null);
......@@ -218,9 +218,9 @@ suite('Files - View Model', () => {
});
test('Validate File Name (For Rename)', function () {
let d = new Date().getTime();
let s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
let sChild = createStat('/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
const d = new Date().getTime();
const s = createStat('/path/to/stat', 'sName', true, true, 8096, d);
const sChild = createStat('/path/to/stat/alles.klar', 'alles.klar', true, true, 8096, d);
s.addChild(sChild);
assert(validateFileName(s, 'alles.klar') !== null);
......@@ -239,10 +239,10 @@ suite('Files - View Model', () => {
});
test('File Change Event (with stats)', function () {
let d = new Date().toUTCString();
let s1 = new FileStat(toResource('/path/to/sName'), false, false, 'sName', void 0, 8096 /* Size */, d);
let s2 = new FileStat(toResource('/path/to/sName'), false, false, 'sName', void 0, 16000 /* Size */, d);
let s3 = new FileStat(toResource('/path/to/sNameMoved'), false, false, 'sNameMoved', void 0, 8096 /* Size */, d);
const d = new Date().toUTCString();
const s1 = new FileStat(toResource('/path/to/sName'), false, false, 'sName', void 0, 8096 /* Size */, d);
const s2 = new FileStat(toResource('/path/to/sName'), false, false, 'sName', void 0, 16000 /* Size */, d);
const s3 = new FileStat(toResource('/path/to/sNameMoved'), false, false, 'sNameMoved', void 0, 8096 /* Size */, d);
// Got Added
let event = new LocalFileChangeEvent(null, s1);
......@@ -281,10 +281,10 @@ suite('Files - View Model', () => {
});
test('Merge Local with Disk', function () {
let d = new Date().toUTCString();
const d = new Date().toUTCString();
let merge1 = new FileStat(URI.file(join('C:\\', '/path/to')), true, false, 'to', void 0, 8096, d);
let merge2 = new FileStat(URI.file(join('C:\\', '/path/to')), true, false, 'to', void 0, 16000, new Date(0).toUTCString());
const merge1 = new FileStat(URI.file(join('C:\\', '/path/to')), true, false, 'to', void 0, 8096, d);
const merge2 = new FileStat(URI.file(join('C:\\', '/path/to')), true, false, 'to', void 0, 16000, new Date(0).toUTCString());
// Merge Properties
FileStat.mergeLocalWithDisk(merge2, merge1);
......@@ -306,7 +306,7 @@ suite('Files - View Model', () => {
assert.deepEqual(merge1.children[0].parent, merge1, 'Check parent');
// Verify that merge does not replace existing children, but updates properties in that case
let existingChild = merge1.children[0];
const existingChild = merge1.children[0];
FileStat.mergeLocalWithDisk(merge2, merge1);
assert.ok(existingChild === merge1.children[0]);
});
......
......@@ -7,39 +7,25 @@
import * as assert from 'assert';
import {IAction, IActionItem} from 'vs/base/common/actions';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import {Promise, TPromise} from 'vs/base/common/winjs.base';
import paths = require('vs/base/common/paths');
import {IEditorControl} from 'vs/platform/editor/common/editor';
import URI from 'vs/base/common/uri';
import {IModelService} from 'vs/editor/common/services/modelService';
import {IModeService} from 'vs/editor/common/services/modeService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IStorageService} from 'vs/platform/storage/common/storage';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {ILifecycleService, NullLifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IFileService} from 'vs/platform/files/common/files';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import PartService = require('vs/workbench/services/part/common/partService');
import {BaseEditor} from 'vs/workbench/browser/parts/editor/baseEditor';
import {EditorInput, EditorOptions, TextEditorOptions} from 'vs/workbench/common/editor';
import {StringEditorInput} from 'vs/workbench/common/editor/stringEditorInput';
import {StringEditorModel} from 'vs/workbench/common/editor/stringEditorModel';
import {FileEditorInput} from 'vs/workbench/parts/files/common/editors/fileEditorInput';
import {TextFileEditorModel} from 'vs/workbench/parts/files/common/editors/textFileEditorModel';
import {ITextFileService} from 'vs/workbench/parts/files/common/files';
import {createMockModelService, TestTextFileService, TestEventService, TestPartService, TestStorageService, TestConfigurationService, TestContextService, TestWorkspace, TestEditorService} from 'vs/test/utils/servicesTestUtils';
import {textFileServiceInstantiationService} from 'vs/test/utils/servicesTestUtils';
import {Viewlet} from 'vs/workbench/browser/viewlet';
import {IPanel} from 'vs/workbench/common/panel';
import {ITelemetryService, NullTelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IUntitledEditorService, UntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {WorkbenchProgressService, ScopedService} from 'vs/workbench/services/progress/browser/progressService';
import {DelegatingWorkbenchEditorService, WorkbenchEditorService, IEditorPart} from 'vs/workbench/services/editor/browser/editorService';
import {IViewletService} from 'vs/workbench/services/viewlet/common/viewletService';
import {IPanelService} from 'vs/workbench/services/panel/common/panelService';
import {IViewlet} from 'vs/workbench/common/viewlet';
import {Position, Direction, IEditor} from 'vs/platform/editor/common/editor';
import {IEventService} from 'vs/platform/event/common/event';
import {Emitter} from 'vs/base/common/event';
let activeViewlet: Viewlet = <any>{};
......@@ -284,73 +270,7 @@ class TestProgressBar {
suite('Workbench UI Services', () => {
test('WorkbenchEditorService', function () {
const TestFileService = {
resolveContent: function (resource) {
return TPromise.as({
resource: resource,
value: 'Hello Html',
etag: 'index.txt',
mime: 'text/plain',
encoding: 'utf8',
mtime: new Date().getTime(),
name: paths.basename(resource.fsPath)
});
},
resolveStreamContent: function (resource) {
return TPromise.as({
resource: resource,
value: {
on: (event:string, callback:Function): void => {
if (event === 'data') {
callback('Hello Html');
}
if (event === 'end') {
callback();
}
}
},
etag: 'index.txt',
mime: 'text/plain',
encoding: 'utf8',
mtime: new Date().getTime(),
name: paths.basename(resource.fsPath)
});
},
updateContent: function (res) {
return TPromise.timeout(1).then(() => {
return {
resource: res,
etag: 'index.txt',
mime: 'text/plain',
encoding: 'utf8',
mtime: new Date().getTime(),
name: paths.basename(res.fsPath)
};
});
}
};
let editorService = new TestEditorService(function () { });
let eventService = new TestEventService();
let contextService = new TestContextService(TestWorkspace);
let instantiationService= new TestInstantiationService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(ITelemetryService);
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IWorkbenchEditorService, editorService);
instantiationService.stub(PartService.IPartService, new TestPartService());
instantiationService.stub(IModeService);
instantiationService.stub(IModelService, createMockModelService(instantiationService));
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IFileService, <any> TestFileService);
instantiationService.stub(ITextFileService, <ITextFileService>instantiationService.createInstance(<any>TestTextFileService));
let instantiationService = textFileServiceInstantiationService();
let activeInput: EditorInput = instantiationService.createInstance(FileEditorInput, toResource('/something.js'), 'text/javascript', void 0);
......@@ -413,22 +333,7 @@ suite('Workbench UI Services', () => {
});
test('DelegatingWorkbenchEditorService', function () {
let editorService = new TestEditorService(function () { });
let contextService = new TestContextService(TestWorkspace);
let eventService = new TestEventService();
let telemetryService = NullTelemetryService;
let instantiationService = new TestInstantiationService();
instantiationService.stub(IEventService, eventService);
instantiationService.stub(ITelemetryService, telemetryService);
instantiationService.stub(IStorageService, new TestStorageService());
instantiationService.stub(IUntitledEditorService, instantiationService.createInstance(UntitledEditorService));
instantiationService.stub(IWorkbenchEditorService, editorService);
instantiationService.stub(PartService.IPartService, new TestPartService());
instantiationService.stub(ILifecycleService, NullLifecycleService);
instantiationService.stub(IWorkspaceContextService, contextService);
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(ITextFileService, <ITextFileService> instantiationService.createInstance(<any>TestTextFileService));
let instantiationService = textFileServiceInstantiationService();
let activeInput: EditorInput = instantiationService.createInstance(FileEditorInput, toResource('/something.js'), 'text/javascript', void 0);
let testEditorPart = new TestEditorPart();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册