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

Side by Side Diff: chrome/test/data/webui/md_bookmarks/test_store.js

Issue 2776993002: [MD Bookmarks] Persist collapsed folders between page loads. (Closed)
Patch Set: address comments, add test 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 unified diff | Download patch
OLDNEW
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 this.acceptInit_ = false;
10 }; 11 };
11 12
12 TestStore.prototype = { 13 TestStore.prototype = {
13 addObserver: function(client) { 14 addObserver: function(client) {
14 this.observers_.push(client); 15 this.observers_.push(client);
15 }, 16 },
16 17
17 init: function() {}, 18 init: function(state) {
19 if (this.acceptInit_)
20 this.data = state;
21 },
18 22
19 removeObserver: function(client) {}, 23 removeObserver: function(client) {},
20 24
21 isInitialized: function() { 25 isInitialized: function() {
22 return true; 26 return true;
23 }, 27 },
24 28
25 handleAction: function(action) { 29 handleAction: function(action) {
26 this.lastAction_ = action; 30 this.lastAction_ = action;
27 }, 31 },
28 32
29 get lastAction() { 33 get lastAction() {
30 return this.lastAction_; 34 return this.lastAction_;
31 }, 35 },
32 36
33 notifyObservers: function() { 37 notifyObservers: function() {
34 // TODO(tsergeant): Revisit how state modifications work in UI tests. 38 // TODO(tsergeant): Revisit how state modifications work in UI tests.
35 // We don't want tests to worry about modifying the whole state tree. 39 // We don't want tests to worry about modifying the whole state tree.
36 // Instead, we could perform a deep clone in here to ensure that every 40 // Instead, we could perform a deep clone in here to ensure that every
37 // StoreClient is updated. 41 // StoreClient is updated.
38 this.observers_.forEach((client) => client.onStateChanged(this.data)); 42 this.observers_.forEach((client) => client.onStateChanged(this.data));
39 }, 43 },
44
45 // Call in order to accept data from an init call to the TestStore.
46 acceptInit: function() {
47 this.acceptInit_ = true;
48 },
40 }; 49 };
41 50
42 return { 51 return {
43 TestStore: TestStore, 52 TestStore: TestStore,
44 }; 53 };
45 }); 54 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698