| 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 cr.define('bookmarks', function() { | 5 cr.define('bookmarks', function() { |
| 6 var TestStore = function(data) { | 6 var TestStore = function(data) { |
| 7 this.data = Object.assign(bookmarks.util.createEmptyState(), data); | 7 this.data = Object.assign(bookmarks.util.createEmptyState(), data); |
| 8 this.lastAction_ = null; | 8 this.lastAction_ = null; |
| 9 this.observers_ = []; | 9 this.observers_ = []; |
| 10 }; | 10 }; |
| 11 | 11 |
| 12 TestStore.prototype = { | 12 TestStore.prototype = { |
| 13 addObserver: function(client) { | 13 addObserver: function(client) { |
| 14 this.observers_.push(client); | 14 this.observers_.push(client); |
| 15 }, | 15 }, |
| 16 | 16 |
| 17 init: function() {}, |
| 18 |
| 17 removeObserver: function(client) {}, | 19 removeObserver: function(client) {}, |
| 18 | 20 |
| 19 isInitialized: function() { | 21 isInitialized: function() { |
| 20 return true; | 22 return true; |
| 21 }, | 23 }, |
| 22 | 24 |
| 23 handleAction: function(action) { | 25 handleAction: function(action) { |
| 24 this.lastAction_ = action; | 26 this.lastAction_ = action; |
| 25 }, | 27 }, |
| 26 | 28 |
| 27 get lastAction() { | 29 get lastAction() { |
| 28 return this.lastAction_; | 30 return this.lastAction_; |
| 29 }, | 31 }, |
| 30 | 32 |
| 31 notifyObservers: function() { | 33 notifyObservers: function() { |
| 32 // TODO(tsergeant): Revisit how state modifications work in UI tests. | 34 // TODO(tsergeant): Revisit how state modifications work in UI tests. |
| 33 // We don't want tests to worry about modifying the whole state tree. | 35 // We don't want tests to worry about modifying the whole state tree. |
| 34 // Instead, we could perform a deep clone in here to ensure that every | 36 // Instead, we could perform a deep clone in here to ensure that every |
| 35 // StoreClient is updated. | 37 // StoreClient is updated. |
| 36 this.observers_.forEach((client) => client.onStateChanged(this.data)); | 38 this.observers_.forEach((client) => client.onStateChanged(this.data)); |
| 37 }, | 39 }, |
| 38 }; | 40 }; |
| 39 | 41 |
| 40 return { | 42 return { |
| 41 TestStore: TestStore, | 43 TestStore: TestStore, |
| 42 }; | 44 }; |
| 43 }); | 45 }); |
| OLD | NEW |