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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 /** @fileoverview Common utilities for extension ui tests. */ 5 /** @fileoverview Common utilities for extension ui tests. */
6 cr.define('extension_test_util', function() { 6 cr.define('extension_test_util', function() {
7 /** 7 /**
8 * A mock to test that clicking on an element calls a specific method. 8 * A mock to test that clicking on an element calls a specific method.
9 * @constructor 9 * @constructor
10 */ 10 */
(...skipping 11 matching lines...) Expand all
22 var mock = new MockController(); 22 var mock = new MockController();
23 var mockMethod = mock.createFunctionMock(this, callName); 23 var mockMethod = mock.createFunctionMock(this, callName);
24 MockMethod.prototype.addExpectation.apply( 24 MockMethod.prototype.addExpectation.apply(
25 mockMethod, opt_expectedArgs); 25 mockMethod, opt_expectedArgs);
26 MockInteractions.tap(element); 26 MockInteractions.tap(element);
27 mock.verifyMocks(); 27 mock.verifyMocks();
28 }, 28 },
29 }; 29 };
30 30
31 /** 31 /**
32 * A mock to test receiving expected events and verify that they were called
33 * with the proper detail values.
34 */
35 function ListenerMock() {
36 this.listeners_ = {};
37 }
38
39 ListenerMock.prototype = {
40 /** @private {Object<{satisfied: boolean, args: !Object}>} */
41 listeners_: undefined,
42
43 /**
44 * @param {string} eventName
45 * @param {Event} e
46 */
47 onEvent_: function(eventName, e) {
48 assert(this.listeners_.hasOwnProperty(eventName));
49 if (this.listeners_[eventName].satisfied) {
50 // Event was already called and checked. We could always make this
51 // more intelligent by allowing for subsequent calls, removing the
52 // listener, etc, but there's no need right now.
53 return;
54 }
55 var expected = this.listeners_[eventName].args || {};
56 expectDeepEquals(e.detail, expected);
57 this.listeners_[eventName].satisfied = true;
58 },
59
60 /**
61 * Adds an expected event.
62 * @param {!EventTarget} target
63 * @param {string} eventName
64 * @param {Object=} opt_eventArgs If omitted, will check that the details
65 * are empty (i.e., {}).
66 */
67 addListener: function(target, eventName, opt_eventArgs) {
68 assert(!this.listeners_.hasOwnProperty(eventName));
69 this.listeners_[eventName] =
70 {args: opt_eventArgs || {}, satisfied: false};
71 target.addEventListener(eventName, this.onEvent_.bind(this, eventName));
72 },
73
74 /** Verifies the expectations set. */
75 verify: function() {
76 var missingEvents = [];
77 for (var key in this.listeners_) {
78 if (!this.listeners_[key].satisfied)
79 missingEvents.push(key);
80 }
81 expectEquals(0, missingEvents.length, JSON.stringify(missingEvents));
82 },
83 }
84
85 /**
32 * A mock delegate for the item, capable of testing functionality. 86 * A mock delegate for the item, capable of testing functionality.
33 * @constructor 87 * @constructor
34 * @extends {ClickMock} 88 * @extends {ClickMock}
35 * @implements {extensions.ItemDelegate} 89 * @implements {extensions.ItemDelegate}
36 */ 90 */
37 function MockItemDelegate() {} 91 function MockItemDelegate() {}
38 92
39 MockItemDelegate.prototype = { 93 MockItemDelegate.prototype = {
40 __proto__: ClickMock.prototype, 94 __proto__: ClickMock.prototype,
41 95
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 function testIronIcons(e) { 193 function testIronIcons(e) {
140 e.querySelectorAll('* /deep/ iron-icon').forEach(function(icon) { 194 e.querySelectorAll('* /deep/ iron-icon').forEach(function(icon) {
141 var svg = icon.$$('svg'); 195 var svg = icon.$$('svg');
142 expectTrue(!!svg && svg.innerHTML != '', 196 expectTrue(!!svg && svg.innerHTML != '',
143 'icon "' + icon.icon + '" is not present'); 197 'icon "' + icon.icon + '" is not present');
144 }); 198 });
145 } 199 }
146 200
147 return { 201 return {
148 ClickMock: ClickMock, 202 ClickMock: ClickMock,
203 ListenerMock: ListenerMock,
149 MockItemDelegate: MockItemDelegate, 204 MockItemDelegate: MockItemDelegate,
150 isVisible: isVisible, 205 isVisible: isVisible,
151 testVisible: testVisible, 206 testVisible: testVisible,
152 createExtensionInfo: createExtensionInfo, 207 createExtensionInfo: createExtensionInfo,
153 testIronIcons: testIronIcons, 208 testIronIcons: testIronIcons,
154 }; 209 };
155 }); 210 });
OLDNEW
« 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