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

Unified Diff: chrome/test/data/webui/extensions/extension_test_util.js

Issue 2101933005: [MD Extensions] Implement keyboard shortcuts page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Michael's Created 4 years, 5 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/extensions/extension_test_util.js
diff --git a/chrome/test/data/webui/extensions/extension_test_util.js b/chrome/test/data/webui/extensions/extension_test_util.js
index 84c66b89bdb0fb190aa971142b3a84df023e9de7..b05e503ee1ae4825a3782cd2b2438b62775e9f30 100644
--- a/chrome/test/data/webui/extensions/extension_test_util.js
+++ b/chrome/test/data/webui/extensions/extension_test_util.js
@@ -29,6 +29,57 @@ cr.define('extension_test_util', function() {
};
/**
+ * A mock to test receiving expected events and verify that they were called
+ * with the proper detail values.
+ */
+ function ListenerMock() {}
+
+ ListenerMock.prototype = {
+ /** @private {Object<{satisfied: boolean, args: !Object}>} */
+ listeners_: {},
+
+ /**
+ * @param {string} eventName
+ * @param {Event} e
+ */
+ onEvent_: function(eventName, e) {
+ assert(this.listeners_.hasOwnProperty(eventName));
+ if (this.listeners_[eventName].satisfied) {
+ // Event was already called and checked. We could always make this
+ // more intelligent by allowing for subsequent calls, removing the
+ // listener, etc, but there's no need right now.
+ return;
+ }
+ var expected = this.listeners_[eventName].args || {};
+ expectDeepEquals(e.detail, expected);
+ this.listeners_[eventName].satisfied = true;
+ },
+
+ /**
+ * Adds an expected event.
+ * @param {!EventTarget} target
+ * @param {string} eventName
+ * @param {Object=} eventArgs If omitted, will check that the details are
michaelpg 2016/07/08 07:12:33 opt_eventArgs
Devlin 2016/07/08 23:14:43 Done.
+ * empty (i.e., {}).
+ */
+ addListener: function(target, eventName, eventArgs) {
+ assert(!this.listeners_.hasOwnProperty(eventName));
+ this.listeners_[eventName] = {args: eventArgs || {}, satisfied: false};
+ target.addEventListener(eventName, this.onEvent_.bind(this, eventName));
+ },
+
+ /** Verifies the expectations set. */
+ verify: function() {
+ var missingEvents = [];
+ for (var key in this.listeners_) {
+ if (!this.listeners_[key].satisfied)
+ missingEvents.push(key);
+ }
+ expectEquals(0, missingEvents.length, JSON.stringify(missingEvents));
+ },
+ }
+
+ /**
* A mock delegate for the item, capable of testing functionality.
* @constructor
* @extends {ClickMock}
@@ -146,6 +197,7 @@ cr.define('extension_test_util', function() {
return {
ClickMock: ClickMock,
+ ListenerMock: ListenerMock,
MockItemDelegate: MockItemDelegate,
isVisible: isVisible,
testVisible: testVisible,

Powered by Google App Engine
This is Rietveld 408576698