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>}
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 // Disabled due to: crbug.com/419370
126 TEST_F('StartupPageListWebUITest', 'DISABLED_testDropFromOutsideSource',
128 /** @const */ var NEW_PAGE = 'http://google.com';
130 var mockDropEvent = createMouseEvent('drop');
131 mockDropEvent.dataTransfer.setData('url', NEW_PAGE);
133 this.mockHandler.expects(once()).addStartupPage([NEW_PAGE, 0]);
135 this.getList().items[0].dispatchEvent(mockDropEvent);
137 expectTrue(mockDropEvent.defaultPrevented);
140 // Disabled due to: crbug.com/419370
141 TEST_F('StartupPageListWebUITest', 'DISABLED_testDropToReorder', function() {
142 // TODO(dbeam): mock4js doesn't handle complex arguments well. Fix this.
143 this.mockHandler.expects(once()).dragDropStartupPage([0, [1].join()]);
145 this.getList().selectionModel.selectedIndex = 1;
146 expectEquals(1, this.getList().selectionModel.selectedIndexes.length);
148 this.getList().items[0].dispatchEvent(createMouseEvent('drop'));