Commit a89290b0 authored by Zentaro Kavanagh's avatar Zentaro Kavanagh Committed by Commit Bot

Diagnostics: Support observable with multiple responses

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I98fc3ffa4818417fc02a92407dbf35eff8c8f601
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2424715
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809871}
parent 4a985723
......@@ -383,6 +383,56 @@ suite('FakeObservablesTest', () => {
observables.trigger('ObserveFoo_OnFooUpdated');
return resolver.promise;
});
test('TwoResults', () => {
observables.register('ObserveFoo_OnFooUpdated');
/** @type !Array<string> */
const expected = ['bar1', 'bar2'];
observables.setObservableData('ObserveFoo_OnFooUpdated', expected);
// The first call will get 'bar1', and the second 'bar2'.
let resolver = new PromiseResolver();
const expectedCallCount = 2;
let callCount = 0;
observables.observe('ObserveFoo_OnFooUpdated', (foo) => {
assertEquals(expected[callCount % expected.length], foo);
callCount++;
if (callCount === expectedCallCount) {
resolver.resolve();
}
});
// Trigger the observer twice.
observables.trigger('ObserveFoo_OnFooUpdated');
observables.trigger('ObserveFoo_OnFooUpdated');
return resolver.promise;
});
test('ObservableDataWraps', () => {
observables.register('ObserveFoo_OnFooUpdated');
/** @type !Array<string> */
const expected = ['bar1', 'bar2'];
observables.setObservableData('ObserveFoo_OnFooUpdated', expected);
// With 3 calls and 2 observable values the response should cycle
// 'bar1', 'bar2', 'bar1'
let resolver = new PromiseResolver();
const expectedCallCount = 3;
let callCount = 0;
observables.observe('ObserveFoo_OnFooUpdated', (foo) => {
assertEquals(expected[callCount % expected.length], foo);
callCount++;
if (callCount === expectedCallCount) {
resolver.resolve();
}
});
// Trigger the observer three times.
observables.trigger('ObserveFoo_OnFooUpdated');
observables.trigger('ObserveFoo_OnFooUpdated');
observables.trigger('ObserveFoo_OnFooUpdated');
return resolver.promise;
});
});
......
......@@ -37,9 +37,6 @@ class FakeObservableState {
/** @param {!Array<!T>} observations */
setObservableData(observations) {
// TODO(zentaro): Fully support multiple observations.
assert(observations.length == 1);
this.observations_ = observations;
this.index_ = 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment