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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/startup_page_list_browsertest.js
diff --git a/chrome/browser/ui/webui/options/startup_page_list_browsertest.js b/chrome/browser/ui/webui/options/startup_page_list_browsertest.js
new file mode 100644
index 0000000000000000000000000000000000000000..0cf7b7c0798af1c79d6a4b6da49eb1b25f64c4ef
--- /dev/null
+++ b/chrome/browser/ui/webui/options/startup_page_list_browsertest.js
@@ -0,0 +1,148 @@
+// 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}
+ * @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, 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.
+ * @returns {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;
+}
+
+TEST_F('StartupPageListWebUITest', '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);
+});
+
+TEST_F('StartupPageListWebUITest', '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'));
+});
+
+}());

Powered by Google App Engine
This is Rietveld 408576698