|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information.
|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 | import * as assert from 'assert';
|
| 6 | +import { DeferredPromise } from 'vs/base/common/async'; |
6 | 7 | import { DisposableStore } from 'vs/base/common/lifecycle';
|
7 | 8 | import { URI } from 'vs/base/common/uri';
|
8 | 9 | import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
@@ -73,4 +74,77 @@ suite('ContextKeyService', () => {
|
73 | 74 | const expr = ContextKeyExpr.in('notebookCellResource', 'jupyter.runByLineCells');
|
74 | 75 | assert.deepStrictEqual(contextKeyService.contextMatchesRules(expr), true);
|
75 | 76 | });
|
| 77 | + |
| 78 | + test('suppress update event from parent when one key is overridden by child', () => { |
| 79 | + const root = new ContextKeyService(new TestConfigurationService()); |
| 80 | + const child = root.createScoped(document.createElement('div')); |
| 81 | + |
| 82 | + root.createKey('testA', 1); |
| 83 | + child.createKey('testA', 4); |
| 84 | + |
| 85 | + let fired = false; |
| 86 | + const event = child.onDidChangeContext(e => fired = true); |
| 87 | + root.setContext('testA', 10); |
| 88 | + assert.strictEqual(fired, false, 'Should not fire event when overridden key is updated in parent'); |
| 89 | + event.dispose(); |
| 90 | + }); |
| 91 | + |
| 92 | + test('suppress update event from parent when all keys are overridden by child', () => { |
| 93 | + const root = new ContextKeyService(new TestConfigurationService()); |
| 94 | + const child = root.createScoped(document.createElement('div')); |
| 95 | + |
| 96 | + root.createKey('testA', 1); |
| 97 | + root.createKey('testB', 2); |
| 98 | + root.createKey('testC', 3); |
| 99 | + |
| 100 | + child.createKey('testA', 4); |
| 101 | + child.createKey('testB', 5); |
| 102 | + child.createKey('testD', 6); |
| 103 | + |
| 104 | + let fired = false; |
| 105 | + const event = child.onDidChangeContext(e => fired = true); |
| 106 | + root.bufferChangeEvents(() => { |
| 107 | + root.setContext('testA', 10); |
| 108 | + root.setContext('testB', 20); |
| 109 | + root.setContext('testD', 30); |
| 110 | + }); |
| 111 | + |
| 112 | + assert.strictEqual(fired, false, 'Should not fire event when overridden key is updated in parent'); |
| 113 | + event.dispose(); |
| 114 | + }); |
| 115 | + |
| 116 | + test('pass through update event from parent when one key is not overridden by child', () => { |
| 117 | + const root = new ContextKeyService(new TestConfigurationService()); |
| 118 | + const child = root.createScoped(document.createElement('div')); |
| 119 | + |
| 120 | + root.createKey('testA', 1); |
| 121 | + root.createKey('testB', 2); |
| 122 | + root.createKey('testC', 3); |
| 123 | + |
| 124 | + child.createKey('testA', 4); |
| 125 | + child.createKey('testB', 5); |
| 126 | + child.createKey('testD', 6); |
| 127 | + |
| 128 | + const def = new DeferredPromise(); |
| 129 | + child.onDidChangeContext(e => { |
| 130 | + try { |
| 131 | + assert.ok(e.affectsSome(new Set(['testA'])), 'testA changed'); |
| 132 | + assert.ok(e.affectsSome(new Set(['testB'])), 'testB changed'); |
| 133 | + assert.ok(e.affectsSome(new Set(['testC'])), 'testC changed'); |
| 134 | + } catch (err) { |
| 135 | + def.error(err); |
| 136 | + return; |
| 137 | + } |
| 138 | + |
| 139 | + def.complete(undefined); |
| 140 | + }); |
| 141 | + |
| 142 | + root.bufferChangeEvents(() => { |
| 143 | + root.setContext('testA', 10); |
| 144 | + root.setContext('testB', 20); |
| 145 | + root.setContext('testC', 30); |
| 146 | + }); |
| 147 | + |
| 148 | + return def.p; |
| 149 | + }); |
76 | 150 | });
|
0 commit comments