Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / startup_page_list_browsertest.js
blob25e5fd4ee7b049ff11454f2972e1d8787e823de0
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * Fixture for startup pages WebUI tests.
7 * @extends {testing.Test}
8 * @constructor
9 */
10 function StartupPageListWebUITest() {}
12 StartupPageListWebUITest.prototype = {
13 __proto__: testing.Test.prototype,
15 /**
16 * Browse to the options page & call our preLoad().
17 * @override
19 browsePreload: 'chrome://settings-frame/startup',
21 /** @override */
22 setUp: function() {
23 StartupOverlay.updateStartupPages(this.fakeStartupList);
24 // 1 item for entering data, 1+ from |this.fakeStartupList|.
25 assertGE(this.getList().items.length, 2);
28 /**
29 * Returns the list to be tested.
30 * @return {Element} The start-up pages list.
31 * @protected
33 getList: function() {
34 return $('startupPagesList');
37 /**
38 * Register a mock handler to ensure expectations are met and options pages
39 * behave correctly.
40 * @override
42 preLoad: function() {
43 this.makeAndRegisterMockHandler(['addStartupPage',
44 'dragDropStartupPage']);
47 /**
48 * A fake list of startup pages to send to the overlay.
49 * @protected
51 fakeStartupList: [
53 title: 'Yahoo!',
54 url: 'http://yahoo.com',
55 tooltip: 'Yahoo! homepage',
56 modelIndex: 0
59 title: 'Facebook',
60 url: 'http://facebook.com',
61 tooltip: 'Facebook :: Sign In',
62 modelIndex: 1
67 (function() {
69 /**
70 * A mock data transfer object for drag/drop events.
71 * @constructor
73 function MockDataTransfer() {
74 /**
75 * The data this dataTransfer object knows about.
76 * @type {!Object.<string, string>}
77 * @private
79 this.data_ = {};
82 /**
83 * Installs a lazily created MockDataTransfer on event#dataTransfer.
84 * @param {!Event} event An event to modify.
86 MockDataTransfer.install = function(event) {
87 event.__defineGetter__('dataTransfer', function() {
88 event.dataTransfer_ = event.dataTransfer_ || new MockDataTransfer;
89 return event.dataTransfer_;
90 });
93 MockDataTransfer.prototype = {
94 /**
95 * The URL data in this mock drop event.
96 * @param {string} type The text of data being set.
97 * @param {*} val The data to set. Will be stringified.
99 setData: function(type, val) {
100 this.data_[type] = String(val);
104 * Gets data associated with this fake data transfer.
105 * @param {string} type The type of data to get.
106 * @return {string} The requested type of data or '' if not set.
108 getData: function(type) {
109 return this.data_[type] || '';
114 * Creates a fake bubbling, cancelable mouse event with a mock data transfer
115 * installed.
116 * @param {string} type A type of mouse event (e.g. 'drop').
117 * @return {!Event} A fake mouse event.
119 function createMouseEvent(type) {
120 var event = new MouseEvent(type, {bubbles: true, cancelable: true});
121 MockDataTransfer.install(event);
122 return event;
125 TEST_F('StartupPageListWebUITest', 'testDropFromOutsideSource', function() {
126 /** @const */ var NEW_PAGE = 'http://google.com';
128 var mockDropEvent = createMouseEvent('drop');
129 mockDropEvent.dataTransfer.setData('url', NEW_PAGE);
131 this.mockHandler.expects(once()).addStartupPage([NEW_PAGE, 0]);
133 this.getList().items[0].dispatchEvent(mockDropEvent);
135 expectTrue(mockDropEvent.defaultPrevented);
138 TEST_F('StartupPageListWebUITest', 'testDropToReorder', function() {
139 // TODO(dbeam): mock4js doesn't handle complex arguments well. Fix this.
140 this.mockHandler.expects(once()).dragDropStartupPage([0, [1].join()]);
142 this.getList().selectionModel.selectedIndex = 1;
143 expectEquals(1, this.getList().selectionModel.selectedIndexes.length);
145 this.getList().items[0].dispatchEvent(createMouseEvent('drop'));
148 }());