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

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: testfix Created 4 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/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..8fe44b708ad445f33a8c88bae9c7eb798ccf54e5 100644
--- a/chrome/test/data/webui/extensions/extension_test_util.js
+++ b/chrome/test/data/webui/extensions/extension_test_util.js
@@ -29,6 +29,55 @@ 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 {<string, {satisfied: boolean, args: !Object}} */
michaelpg 2016/07/01 21:39:04 i think you mean: /** @private {Object<{satisfied
Devlin 2016/07/07 00:33:37 Yeah, that thing. ;) Done.
+ 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
+ */
+ addListener: function(target, eventName, eventArgs) {
+ this.listeners_[eventName] = {args: eventArgs || {}, satisfied: false};
michaelpg 2016/07/01 21:39:04 maybe assert eventName not in this.listeners_?
Devlin 2016/07/07 00:33:36 Done.
+ 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 +195,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