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

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

Issue 2902103002: MD Bookmarks: Disable 'Open in Incognito Window' when Incognito is disabled (Closed)
Patch Set: Add a test Created 3 years, 7 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 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 this.acceptInit_ = false;
14 this.enableReducers_ = false; 14 this.enableReducers_ = false;
15 this.resolverMap_ = new Map();
calamity 2017/05/29 06:52:28 Type annotation?
tsergeant 2017/05/30 00:18:21 Done.
15 }; 16 };
16 17
17 TestStore.prototype = { 18 TestStore.prototype = {
18 __proto__: bookmarks.Store.prototype, 19 __proto__: bookmarks.Store.prototype,
19 20
20 init: function(state) { 21 init: function(state) {
21 if (this.acceptInit_) 22 if (this.acceptInit_)
22 bookmarks.Store.prototype.init.call(this, state); 23 bookmarks.Store.prototype.init.call(this, state);
23 }, 24 },
24 25
(...skipping 22 matching lines...) Expand all
47 * @param {boolean} enabled 48 * @param {boolean} enabled
48 */ 49 */
49 setReducersEnabled: function(enabled) { 50 setReducersEnabled: function(enabled) {
50 this.enableReducers_ = enabled; 51 this.enableReducers_ = enabled;
51 }, 52 },
52 53
53 reduce_: function(action) { 54 reduce_: function(action) {
54 this.lastAction_ = action; 55 this.lastAction_ = action;
55 if (this.enableReducers_) 56 if (this.enableReducers_)
56 bookmarks.Store.prototype.reduce_.call(this, action); 57 bookmarks.Store.prototype.reduce_.call(this, action);
58 if (this.resolverMap_.has(action.name))
59 this.resolverMap_.get(action.name).resolve(action);
57 }, 60 },
58 61
59 /** 62 /**
60 * Notifies UI elements that the store data has changed. When reducers are 63 * Notifies UI elements that the store data has changed. When reducers are
61 * disabled, tests are responsible for manually changing the data to make 64 * disabled, tests are responsible for manually changing the data to make
62 * UI elements update correctly (eg, tests must replace the whole list 65 * UI elements update correctly (eg, tests must replace the whole list
63 * when changing a single element). 66 * when changing a single element).
64 */ 67 */
65 notifyObservers: function() { 68 notifyObservers: function() {
66 this.notifyObservers_(this.data); 69 this.notifyObservers_(this.data);
67 }, 70 },
68 71
69 // Call in order to accept data from an init call to the TestStore once. 72 // Call in order to accept data from an init call to the TestStore once.
70 acceptInitOnce: function() { 73 acceptInitOnce: function() {
71 this.acceptInit_ = true; 74 this.acceptInit_ = true;
72 this.initialized_ = false; 75 this.initialized_ = false;
73 }, 76 },
77
78 /**
79 * Track actions called |name|, allowing that type of action to be waited
80 * for with `waitForAction`.
81 * @param {string} name
82 */
83 expectAction: function(name) {
84 this.resolverMap_.set(name, new PromiseResolver());
85 },
86
87 /**
88 * Returns a Promise that will resolve when an action called |name| is
89 * dispatched. Specifically, it will resolve the first time the action is
90 * seen after `expectAction` is called with that name. To reset the
91 * promise after that, call `expectAction` again.
calamity 2017/05/29 06:52:28 Seems a bit risky to have subsequent calls to wait
tsergeant 2017/05/30 00:18:21 Doing it this way is necessary to support the foll
calamity 2017/06/01 04:07:44 Can you work around the synchronicity issue? (e.g
tsergeant 2017/06/01 05:27:16 Interesting idea to queue up resetting the promise
92 * @param {string} name
93 * @return {!Promise<!Action>}
94 */
95 waitForAction: function(name) {
96 return this.resolverMap_.get(name).promise;
97 },
74 }; 98 };
75 99
76 return { 100 return {
77 TestStore: TestStore, 101 TestStore: TestStore,
78 }; 102 };
79 }); 103 });
80 }); 104 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698