| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 suiteSetup(function() { | 5 suiteSetup(function() { |
| 6 cr.define('bookmarks', function() { | 6 cr.define('bookmarks', function() { |
| 7 var TestStore = function(data) { | 7 var TestStore = function(data) { |
| 8 bookmarks.Store.call(this); | 8 bookmarks.Store.call(this); |
| 9 this.data_ = Object.assign(bookmarks.util.createEmptyState(), data); | 9 this.data_ = Object.assign(bookmarks.util.createEmptyState(), data); |
| 10 this.initialized_ = true; | 10 this.initialized_ = true; |
| 11 | 11 |
| 12 this.lastAction_ = null; | 12 this.lastAction_ = null; |
| 13 this.acceptInit_ = false; | 13 /** @type {?PromiseResolver} */ |
| 14 this.initPromise_ = null; |
| 14 this.enableReducers_ = false; | 15 this.enableReducers_ = false; |
| 15 /** @type {!Map<string, !PromiseResolver>} */ | 16 /** @type {!Map<string, !PromiseResolver>} */ |
| 16 this.resolverMap_ = new Map(); | 17 this.resolverMap_ = new Map(); |
| 17 }; | 18 }; |
| 18 | 19 |
| 19 TestStore.prototype = { | 20 TestStore.prototype = { |
| 20 __proto__: bookmarks.Store.prototype, | 21 __proto__: bookmarks.Store.prototype, |
| 21 | 22 |
| 22 /** @override */ | 23 /** @override */ |
| 23 init: function(state) { | 24 init: function(state) { |
| 24 if (this.acceptInit_) | 25 if (this.initPromise_) { |
| 25 bookmarks.Store.prototype.init.call(this, state); | 26 bookmarks.Store.prototype.init.call(this, state); |
| 27 this.initPromise_.resolve(); |
| 28 } |
| 26 }, | 29 }, |
| 27 | 30 |
| 28 get lastAction() { | 31 get lastAction() { |
| 29 return this.lastAction_; | 32 return this.lastAction_; |
| 30 }, | 33 }, |
| 31 | 34 |
| 32 resetLastAction() { | 35 resetLastAction() { |
| 33 this.lastAction_ = null; | 36 this.lastAction_ = null; |
| 34 }, | 37 }, |
| 35 | 38 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 /** | 73 /** |
| 71 * Notifies UI elements that the store data has changed. When reducers are | 74 * Notifies UI elements that the store data has changed. When reducers are |
| 72 * disabled, tests are responsible for manually changing the data to make | 75 * disabled, tests are responsible for manually changing the data to make |
| 73 * UI elements update correctly (eg, tests must replace the whole list | 76 * UI elements update correctly (eg, tests must replace the whole list |
| 74 * when changing a single element). | 77 * when changing a single element). |
| 75 */ | 78 */ |
| 76 notifyObservers: function() { | 79 notifyObservers: function() { |
| 77 this.notifyObservers_(this.data); | 80 this.notifyObservers_(this.data); |
| 78 }, | 81 }, |
| 79 | 82 |
| 80 // Call in order to accept data from an init call to the TestStore once. | 83 /** |
| 84 * Call in order to accept data from an init call to the TestStore once. |
| 85 * @return {Promise} Promise which resolves when the store is initialized. |
| 86 */ |
| 81 acceptInitOnce: function() { | 87 acceptInitOnce: function() { |
| 82 this.acceptInit_ = true; | 88 this.initPromise_ = new PromiseResolver(); |
| 83 this.initialized_ = false; | 89 this.initialized_ = false; |
| 90 return this.initPromise_.promise; |
| 84 }, | 91 }, |
| 85 | 92 |
| 86 /** | 93 /** |
| 87 * Track actions called |name|, allowing that type of action to be waited | 94 * Track actions called |name|, allowing that type of action to be waited |
| 88 * for with `waitForAction`. | 95 * for with `waitForAction`. |
| 89 * @param {string} name | 96 * @param {string} name |
| 90 */ | 97 */ |
| 91 expectAction: function(name) { | 98 expectAction: function(name) { |
| 92 this.resolverMap_.set(name, new PromiseResolver()); | 99 this.resolverMap_.set(name, new PromiseResolver()); |
| 93 }, | 100 }, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 108 return action; | 115 return action; |
| 109 }); | 116 }); |
| 110 }, | 117 }, |
| 111 }; | 118 }; |
| 112 | 119 |
| 113 return { | 120 return { |
| 114 TestStore: TestStore, | 121 TestStore: TestStore, |
| 115 }; | 122 }; |
| 116 }); | 123 }); |
| 117 }); | 124 }); |
| OLD | NEW |