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

Side by Side Diff: chrome/browser/ui/webui/options/startup_page_list_browsertest.js

Issue 47033003: Fix "Set pages" drop crash by changing outside drags to simply add a new URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 /**
6 * Fixture for startup pages WebUI tests.
7 * @extends {testing.Test}
8 * @constructor
9 */
10 function StartupPageListWebUITest() {}
11
12 StartupPageListWebUITest.prototype = {
13 __proto__: testing.Test.prototype,
14
15 /**
16 * Browse to the options page & call our preLoad().
17 * @override
18 */
19 browsePreload: 'chrome://settings-frame/startup',
20
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);
26 },
27
28 /** @protected */
arv (Not doing code reviews) 2013/10/29 13:48:03 protected seems strange but ok
Dan Beam 2013/10/29 17:31:31 Ack.
29 getList: function() {
30 return $('startupPagesList');
31 },
32
33 /**
34 * Register a mock handler to ensure expectations are met and options pages
35 * behave correctly.
36 * @override
37 */
38 preLoad: function() {
39 this.makeAndRegisterMockHandler(['addStartupPage',
40 'dragDropStartupPage']);
41 },
42
43 /**
44 * A fake list of startup pages to send to the overlay.
45 * @protected
46 */
47 fakeStartupList: [{title: 'Yahoo!',
48 url: 'http://yahoo.com',
arv (Not doing code reviews) 2013/10/29 13:48:03 { key: value, ... } If the object literal doe
Dan Beam 2013/10/29 17:31:31 Done.
49 tooltip: 'Yahoo! homepage',
50 modelIndex: 0},
51 {title: 'Facebook',
52 url: 'http://facebook.com',
53 tooltip: 'Facebook :: Sign In',
54 modelIndex: 1}],
55 };
56
57 (function() {
58
59 /**
60 * A mock data transfer object for drag/drop events.
61 * @constructor
62 */
63 function MockDataTransfer() {}
64
65 /**
66 * Installs a lazily created MockDataTransfer on event#dataTransfer.
67 * @param {!Event} event An event to modify.
68 */
69 MockDataTransfer.install = function(event) {
70 event.__defineGetter__('dataTransfer', function() {
71 event.dataTransfer_ = event.dataTransfer_ || new MockDataTransfer;
72 return event.dataTransfer_;
73 });
74 };
75
76 MockDataTransfer.prototype = {
77 /**
78 * @type {!Object.<string, string>}
79 * @private
80 */
81 data_: {},
arv (Not doing code reviews) 2013/10/29 13:48:03 No storage on the prototype object please
Dan Beam 2013/10/29 17:31:31 Done.
82
83 /**
84 * The URL data in this mock drop event.
85 * @param {string} type The text of data being set.
86 * @param {string} val The data to set.
87 * @private
arv (Not doing code reviews) 2013/10/29 13:48:03 private does not seem correct. It is never called
Dan Beam 2013/10/29 17:31:31 spurious annotation removed
88 */
89 setData: function(type, val) {
90 this.data_[type] = String(val);
91 },
92
93 /**
94 * Gets data associated with this fake data transfer.
95 * @param {string} type The type of data to get.
96 * @returns {string} The requested type of data or '' if not set.
97 */
98 getData: function(type) {
99 return this.data_[type] || '';
100 },
101 };
102
103 /**
104 * Creates a fake bubbling, cancelable mouse event with a mock data transfer
105 * installed.
106 * @param {string} type A type of mouse event (e.g. 'drop').
107 * @return {!Event} A fake mouse event.
108 */
109 function createMouseEvent(type) {
110 var event = document.createEvent('MouseEvent');
arv (Not doing code reviews) 2013/10/29 13:48:03 Use new MouseEvent(type, {bubbles: true, cancela
Dan Beam 2013/10/29 17:31:31 Done.
111 event.initMouseEvent(type, true, true);
arv (Not doing code reviews) 2013/10/29 13:48:03 initMouseEvent has 15 (or some ridiculous number l
Dan Beam 2013/10/29 17:31:31 Ack.
112 MockDataTransfer.install(event);
113 return event;
114 }
115
116 TEST_F('StartupPageListWebUITest', 'testDropFromOutsideSource', function() {
117 /** @const */ var newPage = 'http://google.com';
arv (Not doing code reviews) 2013/10/29 13:48:03 useless anotation
Dan Beam 2013/10/29 17:31:31 technically all of these are useless without a com
arv (Not doing code reviews) 2013/10/29 19:51:21 Generally I do not see the point in consts for loc
118
119 var mockDropEvent = createMouseEvent('drop');
120 mockDropEvent.dataTransfer.setData('url', newPage);
121
122 this.mockHandler.expects(once()).addStartupPage([newPage, 0]);
123
124 this.getList().items[0].dispatchEvent(mockDropEvent);
125
126 expectTrue(mockDropEvent.defaultPrevented);
127 });
128
129 TEST_F('StartupPageListWebUITest', 'testDropToReorder', function() {
130 // TODO(dbeam): mock4js doesn't handle complex arguments well. Fix this.
131 this.mockHandler.expects(once()).dragDropStartupPage([0, [1].join()]);
132
133 this.getList().selectionModel.selectedIndex = 1;
134 expectEquals(1, this.getList().selectionModel.selectedIndexes.length);
135
136 this.getList().items[0].dispatchEvent(createMouseEvent('drop'));
137 });
138
139 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698