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.
6 * Fixture for startup pages WebUI tests.
7 * @extends {testing.Test}
10 function StartupPageListWebUITest() {}
12 StartupPageListWebUITest
.prototype = {
13 __proto__
: testing
.Test
.prototype,
16 * Browse to the options page & call our preLoad().
19 browsePreload
: 'chrome://settings-frame/startup',
23 StartupOverlay
.updateStartupPages(this.fakeStartupList
);
24 // 1 item for entering data, 1+ from |this.fakeStartupList|.
25 assertGE(this.getList().items
.length
, 2);
29 * Returns the list to be tested.
30 * @return {Element} The start-up pages list.
34 return $('startupPagesList');
38 * Register a mock handler to ensure expectations are met and options pages
43 this.makeAndRegisterMockHandler(['addStartupPage',
44 'dragDropStartupPage']);
48 * A fake list of startup pages to send to the overlay.
54 url
: 'http://yahoo.com',
55 tooltip
: 'Yahoo! homepage',
60 url
: 'http://facebook.com',
61 tooltip
: 'Facebook :: Sign In',
70 * A mock data transfer object for drag/drop events.
73 function MockDataTransfer() {
75 * The data this dataTransfer object knows about.
76 * @type {!Object.<string, string>}
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_
;
93 MockDataTransfer
.prototype = {
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
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
);
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'));