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

Side by Side Diff: chrome/browser/resources/md_bookmarks/toast_manager.js

Issue 2926763005: [MD Bookmarks] Refactor window timer mocking. (Closed)
Patch Set: address comments Created 3 years, 6 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 /** 5 /**
6 * @fileoverview Element which shows toasts. 6 * @fileoverview Element which shows toasts.
7 */ 7 */
8 cr.define('bookmarks', function() { 8 cr.define('bookmarks', function() {
9 9
10 var ToastManager = Polymer({ 10 var ToastManager = Polymer({
11 is: 'bookmarks-toast-manager', 11 is: 'bookmarks-toast-manager',
12 12
13 properties: { 13 properties: {
14 duration: { 14 duration: {
15 type: Number, 15 type: Number,
16 value: 0, 16 value: 0,
17 }, 17 },
18 18
19 /** @private */ 19 /** @private */
20 open_: { 20 open_: {
21 type: Boolean, 21 type: Boolean,
22 reflectToAttribute: true, 22 reflectToAttribute: true,
23 }, 23 },
24 24
25 /** @private */ 25 /** @private */
26 showUndo_: Boolean, 26 showUndo_: Boolean,
27 }, 27 },
28 28
29 /** @private {function(number)} */ 29 /** @private {bookmarks.TimerProxy} */
30 clearTimeout_: window.clearTimeout.bind(window), 30 timerProxy_: new bookmarks.TimerProxy(),
31
32 /** @private {function((Function|null|string), number)} */
33 setTimeout_: window.setTimeout.bind(window),
34 31
35 /** @private {number|null} */ 32 /** @private {number|null} */
36 hideTimeout_: null, 33 hideTimeoutId_: null,
37 34
38 /** @override */ 35 /** @override */
39 attached: function() { 36 attached: function() {
40 assert(ToastManager.instance_ == null); 37 assert(ToastManager.instance_ == null);
41 ToastManager.instance_ = this; 38 ToastManager.instance_ = this;
42 }, 39 },
43 40
44 /** @override */ 41 /** @override */
45 detached: function() { 42 detached: function() {
46 ToastManager.instance_ = null; 43 ToastManager.instance_ = null;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 * @param {boolean} showUndo Whether the undo button should be shown. 79 * @param {boolean} showUndo Whether the undo button should be shown.
83 * @private 80 * @private
84 */ 81 */
85 showInternal_: function(showUndo) { 82 showInternal_: function(showUndo) {
86 this.open_ = true; 83 this.open_ = true;
87 this.showUndo_ = showUndo; 84 this.showUndo_ = showUndo;
88 85
89 if (!this.duration) 86 if (!this.duration)
90 return; 87 return;
91 88
92 if (this.hideTimeout_ != null) { 89 if (this.hideTimeoutId_ != null)
93 this.clearTimeout_(this.hideTimeout_); 90 this.timerProxy_.clearTimeout(this.hideTimeoutId_);
94 this.hideTimeout_ = null;
95 }
96 91
97 this.hideTimeout_ = this.setTimeout_(function() { 92 this.hideTimeoutId_ = this.timerProxy_.setTimeout(function() {
98 this.open_ = false; 93 this.open_ = false;
99 this.hideTimeout_ = null; 94 this.hideTimeoutId_ = null;
100 }.bind(this), this.duration); 95 }.bind(this), this.duration);
101 }, 96 },
102 97
103 hide: function() { 98 hide: function() {
104 this.open_ = false; 99 this.open_ = false;
105 }, 100 },
106 101
107 /** @private */ 102 /** @private */
108 onUndoTap_: function() { 103 onUndoTap_: function() {
109 // Will hide the toast. 104 // Will hide the toast.
110 this.fire('command-undo'); 105 this.fire('command-undo');
111 }, 106 },
112 }); 107 });
113 108
114 /** @private {?bookmarks.ToastManager} */ 109 /** @private {?bookmarks.ToastManager} */
115 ToastManager.instance_ = null; 110 ToastManager.instance_ = null;
116 111
117 /** @return {!bookmarks.ToastManager} */ 112 /** @return {!bookmarks.ToastManager} */
118 ToastManager.getInstance = function() { 113 ToastManager.getInstance = function() {
119 return assert(ToastManager.instance_); 114 return assert(ToastManager.instance_);
120 }; 115 };
121 116
122 return { 117 return {
123 ToastManager: ToastManager, 118 ToastManager: ToastManager,
124 }; 119 };
125 }); 120 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/timer_proxy.js ('k') | chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698