Chromium Code Reviews| Index: chrome/test/data/webui/md_bookmarks/test_store.js |
| diff --git a/chrome/test/data/webui/md_bookmarks/test_store.js b/chrome/test/data/webui/md_bookmarks/test_store.js |
| index 36041011cdfa3a390ca3fcd4dbdf9e950413473c..41968bcc90e11a77a80fc975de7fefca5eb0b4d6 100644 |
| --- a/chrome/test/data/webui/md_bookmarks/test_store.js |
| +++ b/chrome/test/data/webui/md_bookmarks/test_store.js |
| @@ -2,55 +2,74 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -cr.define('bookmarks', function() { |
| - var TestStore = function(data) { |
| - this.data = Object.assign(bookmarks.util.createEmptyState(), data); |
| - this.lastAction_ = null; |
| - this.observers_ = []; |
| - this.acceptInit_ = false; |
| - }; |
| - |
| - TestStore.prototype = { |
| - addObserver: function(client) { |
| - this.observers_.push(client); |
| - }, |
| - |
| - init: function(state) { |
| - if (this.acceptInit_) { |
| - this.data = state; |
| - this.acceptInit_ = false; |
| - } |
| - }, |
| - |
| - removeObserver: function(client) {}, |
| - |
| - isInitialized: function() { |
| - return true; |
| - }, |
| - |
| - handleAction: function(action) { |
| - this.lastAction_ = action; |
| - }, |
| - |
| - get lastAction() { |
| - return this.lastAction_; |
| - }, |
| - |
| - notifyObservers: function() { |
| - // TODO(tsergeant): Revisit how state modifications work in UI tests. |
| - // We don't want tests to worry about modifying the whole state tree. |
| - // Instead, we could perform a deep clone in here to ensure that every |
| - // StoreClient is updated. |
| - this.observers_.forEach((client) => client.onStateChanged(this.data)); |
| - }, |
| - |
| - // Call in order to accept data from an init call to the TestStore once. |
| - acceptInitOnce: function() { |
| - this.acceptInit_ = true; |
| - }, |
| - }; |
| - |
| - return { |
| - TestStore: TestStore, |
| - }; |
| +suiteSetup(function() { |
| + cr.define('bookmarks', function() { |
| + var TestStore = function(data) { |
| + bookmarks.Store.call(this); |
| + this.data_ = Object.assign(bookmarks.util.createEmptyState(), data); |
| + this.initialized_ = true; |
| + |
| + this.lastAction_ = null; |
| + this.acceptInit_ = false; |
| + this.enableReducers_ = false; |
| + }; |
| + |
| + TestStore.prototype = { |
| + __proto__: bookmarks.Store.prototype, |
| + |
| + init: function(state) { |
| + if (this.acceptInit_) { |
| + bookmarks.Store.prototype.init.call(this, state); |
| + } |
|
calamity
2017/04/27 04:23:53
nit: no curlies.
tsergeant
2017/04/27 04:48:16
Done.
|
| + }, |
| + |
| + get lastAction() { |
| + return this.lastAction_; |
| + }, |
| + |
| + get data() { |
| + return this.data_; |
| + }, |
| + |
| + set data(newData) { |
| + this.data_ = newData; |
| + }, |
| + |
| + /** |
| + * Enable or disable calling bookmarks.reduceAction for each action. |
| + * With reducers disabled (the default), TestStore is a stub which |
| + * requires state be managed manually (suitable for unit tests). With |
| + * reducers enabled, TestStore becomes a proxy for observing actions |
| + * (suitable for integration tests). |
| + * @param {boolean} enabled |
| + */ |
| + setReducersEnabled: function(enabled) { |
| + this.enableReducers_ = enabled; |
| + }, |
| + |
| + reduce_: function(action) { |
| + this.lastAction_ = action; |
| + if (this.enableReducers_) |
| + bookmarks.Store.prototype.reduce_.call(this, action); |
| + }, |
| + |
| + notifyObservers: function() { |
| + // TODO(tsergeant): Revisit how state modifications work in UI tests. |
| + // We don't want tests to worry about modifying the whole state tree. |
| + // Instead, we could perform a deep clone in here to ensure that every |
| + // StoreClient is updated. |
| + this.notifyObservers_(this.data); |
| + }, |
| + |
| + // Call in order to accept data from an init call to the TestStore once. |
| + acceptInitOnce: function() { |
| + this.acceptInit_ = true; |
| + this.initialized_ = false; |
| + }, |
| + }; |
| + |
| + return { |
| + TestStore: TestStore, |
| + }; |
| + }); |
| }); |