1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* Fixture for startup pages WebUI tests.
* @extends {testing.Test}
* @constructor
*/
function StartupPageListWebUITest() {}
StartupPageListWebUITest.prototype = {
__proto__: testing.Test.prototype,
/**
* Browse to the options page & call our preLoad().
* @override
*/
browsePreload: 'chrome://settings-frame/startup',
/** @override */
setUp: function() {
StartupOverlay.updateStartupPages(this.fakeStartupList);
// 1 item for entering data, 1+ from |this.fakeStartupList|.
assertGE(this.getList().items.length, 2);
},
/**
* Returns the list to be tested.
* @return {Element} The start-up pages list.
* @protected
*/
getList: function() {
return $('startupPagesList');
},
/**
* Register a mock handler to ensure expectations are met and options pages
* behave correctly.
* @override
*/
preLoad: function() {
this.makeAndRegisterMockHandler(['addStartupPage',
'dragDropStartupPage']);
},
/**
* A fake list of startup pages to send to the overlay.
* @protected
*/
fakeStartupList: [
{
title: 'Yahoo!',
url: 'http://yahoo.com',
tooltip: 'Yahoo! homepage',
modelIndex: 0
},
{
title: 'Facebook',
url: 'http://facebook.com',
tooltip: 'Facebook :: Sign In',
modelIndex: 1
}
],
};
(function() {
/**
* A mock data transfer object for drag/drop events.
* @constructor
*/
function MockDataTransfer() {
/**
* The data this dataTransfer object knows about.
* @type {!Object<string>}
* @private
*/
this.data_ = {};
}
/**
* Installs a lazily created MockDataTransfer on event#dataTransfer.
* @param {!Event} event An event to modify.
*/
MockDataTransfer.install = function(event) {
event.__defineGetter__('dataTransfer', function() {
event.dataTransfer_ = event.dataTransfer_ || new MockDataTransfer;
return event.dataTransfer_;
});
};
MockDataTransfer.prototype = {
/**
* The URL data in this mock drop event.
* @param {string} type The text of data being set.
* @param {*} val The data to set. Will be stringified.
*/
setData: function(type, val) {
this.data_[type] = String(val);
},
/**
* Gets data associated with this fake data transfer.
* @param {string} type The type of data to get.
* @return {string} The requested type of data or '' if not set.
*/
getData: function(type) {
return this.data_[type] || '';
},
};
/**
* Creates a fake bubbling, cancelable mouse event with a mock data transfer
* installed.
* @param {string} type A type of mouse event (e.g. 'drop').
* @return {!Event} A fake mouse event.
*/
function createMouseEvent(type) {
var event = new MouseEvent(type, {bubbles: true, cancelable: true});
MockDataTransfer.install(event);
return event;
}
// Disabled due to: crbug.com/419370
TEST_F('StartupPageListWebUITest', 'DISABLED_testDropFromOutsideSource',
function() {
/** @const */ var NEW_PAGE = 'http://google.com';
var mockDropEvent = createMouseEvent('drop');
mockDropEvent.dataTransfer.setData('url', NEW_PAGE);
this.mockHandler.expects(once()).addStartupPage([NEW_PAGE, 0]);
this.getList().items[0].dispatchEvent(mockDropEvent);
expectTrue(mockDropEvent.defaultPrevented);
});
// Disabled due to: crbug.com/419370
TEST_F('StartupPageListWebUITest', 'DISABLED_testDropToReorder', function() {
// TODO(dbeam): mock4js doesn't handle complex arguments well. Fix this.
this.mockHandler.expects(once()).dragDropStartupPage([0, [1].join()]);
this.getList().selectionModel.selectedIndex = 1;
expectEquals(1, this.getList().selectionModel.selectedIndexes.length);
this.getList().items[0].dispatchEvent(createMouseEvent('drop'));
});
}());
|