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

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

Issue 2926763005: [MD Bookmarks] Refactor window timer mocking. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/webui/md_bookmarks/test_timer_proxy.js
diff --git a/chrome/test/data/webui/md_bookmarks/test_timer_proxy.js b/chrome/test/data/webui/md_bookmarks/test_timer_proxy.js
new file mode 100644
index 0000000000000000000000000000000000000000..bf5c5768fb70bbbbdd97c63feeba259d194bad4f
--- /dev/null
+++ b/chrome/test/data/webui/md_bookmarks/test_timer_proxy.js
@@ -0,0 +1,68 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+suiteSetup(function() {
+ cr.define('bookmarks', function() {
+ var TestTimerProxy = function(data) {
+ bookmarks.TimerProxy.call(this);
+
+ this.immediatelyResolveTimeouts = true;
+
+ this.timeoutIds_ = 0;
+
+ /** @private {Object<number, Function>} */
tsergeant 2017/06/13 06:48:43 We can do better than Object: !Map<number, !Funct
calamity 2017/06/16 02:59:26 Done.
+ this.activeTimeouts_ = new Map();
+ };
+
+ TestTimerProxy.prototype = {
+ __proto__: bookmarks.TimerProxy.prototype,
+
+ /**
+ * @param {Function|string} fn
+ * @param {number=} delay
+ * @return {number}
+ * @override
+ */
+ setTimeout: function(fn, delay) {
+ if (this.immediatelyResolveTimeouts)
+ fn();
+ else
+ this.activeTimeouts_[this.timeoutIds_] = fn;
+
+ return this.timeoutIds_++;
tsergeant 2017/06/13 06:48:43 Optional: You could use cr.createUid() here, since
calamity 2017/06/16 02:59:26 My ids start fighting with other uids which make m
tsergeant 2017/06/16 03:54:22 Oh, sure, I forgot that you were hardcoding the va
+ },
+
+ /**
+ * @param {number|undefined?} id
+ * @override
+ */
+ clearTimeout: function(id) {
+ this.activeTimeouts_.delete(id);
+ },
+
+ /**
+ * Run the function associated with a timeout id and clear it from the
+ * active timeouts.
+ * @param {number} id
+ */
+ runTimeoutFn: function(id) {
+ this.activeTimeouts_[id]();
+ this.clearTimeout(id);
+ },
+
+ /**
+ * Returns whether a given timeout id has been run or cleared.
tsergeant 2017/06/13 06:48:43 This sentence is a little tough to read. How about
calamity 2017/06/16 02:59:26 Done.
+ * @param {number} id
+ * @return {boolean}
+ */
+ hasTimeout: function(id) {
+ return this.activeTimeouts_.has(id);
+ },
+ };
+
+ return {
+ TestTimerProxy: TestTimerProxy,
+ };
+ });
+});

Powered by Google App Engine
This is Rietveld 408576698