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

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: nits + latest master 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..003c69a9eb43da9345e7d966bfc482ccdbfb4d84 100644
--- a/chrome/test/data/webui/extensions/extension_test_util.js
+++ b/chrome/test/data/webui/extensions/extension_test_util.js
@@ -29,6 +29,60 @@ 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() {
+ this.listeners_ = {};
+ }
+
+ ListenerMock.prototype = {
+ /** @private {Object<{satisfied: boolean, args: !Object}>} */
+ listeners_: undefined,
+
+ /**
+ * @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=} opt_eventArgs If omitted, will check that the details
+ * are empty (i.e., {}).
+ */
+ addListener: function(target, eventName, opt_eventArgs) {
+ assert(!this.listeners_.hasOwnProperty(eventName));
+ this.listeners_[eventName] =
+ {args: opt_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 +200,7 @@ cr.define('extension_test_util', function() {
return {
ClickMock: ClickMock,
+ ListenerMock: ListenerMock,
MockItemDelegate: MockItemDelegate,
isVisible: isVisible,
testVisible: testVisible,
« no previous file with comments | « chrome/test/data/webui/extensions/extension_shortcut_input_test.js ('k') | chrome/test/data/webui/test_api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698