Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4979)

Unified Diff: chrome/test/data/webui/md_bookmarks/test_store.js

Issue 2839393002: MD Bookmarks: Update TestStore API (Closed)
Patch Set: Bye, curlies Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..749b9bcd3d5b3522dba0de0c71656b1cf6ed188e 100644
--- a/chrome/test/data/webui/md_bookmarks/test_store.js
+++ b/chrome/test/data/webui/md_bookmarks/test_store.js
@@ -2,55 +2,73 @@
// 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);
+ },
+
+ 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,
+ };
+ });
});
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698