Bug 1257481 - move browserDrop.js tests into test_browser_drop.xul, r=enndeakin
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Tue, 22 Mar 2016 21:04:37 +0000
changeset 290861 ccd1d2db9f2932b491d445fe83739131ccf18f89
parent 290860 d6acac6649a37bfda6c6c8cb6cde9972bb56ffbb
child 290862 12ff599ce0e24302de55a4f1ae4c82acbc96b53a
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersenndeakin
bugs1257481
milestone48.0a1
Bug 1257481 - move browserDrop.js tests into test_browser_drop.xul, r=enndeakin MozReview-Commit-ID: AyWry0UjYMD
toolkit/content/tests/browser/browser.ini
toolkit/content/tests/browser/browser_browserDrop.js
toolkit/content/tests/chrome/window_browser_drop.xul
--- a/toolkit/content/tests/browser/browser.ini
+++ b/toolkit/content/tests/browser/browser.ini
@@ -1,16 +1,14 @@
 [DEFAULT]
 support-files =
   head.js
   file_contentTitle.html
   audio.ogg
 [browser_autoscroll_disabled.js]
-[browser_browserDrop.js]
-skip-if = buildapp == 'mulet' || e10s # Relies on drop to be handled in the parent process
 [browser_bug295977_autoscroll_overflow.js]
 [browser_bug594509.js]
 [browser_bug982298.js]
 [browser_bug1198465.js]
 [browser_contentTitle.js]
 [browser_default_image_filename.js]
 [browser_f7_caret_browsing.js]
 skip-if = e10s
@@ -43,9 +41,9 @@ support-files =
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 [browser_mute.js]
 [browser_mute2.js]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 [browser_quickfind_editable.js]
 [browser_saveImageURL.js]
 support-files =
   image.jpg
-  image_page.html
\ No newline at end of file
+  image_page.html
deleted file mode 100644
--- a/toolkit/content/tests/browser/browser_browserDrop.js
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/ */
-
-function test() {
-  waitForExplicitFinish();
-
-  let newTab = gBrowser.selectedTab = gBrowser.addTab();
-  registerCleanupFunction(function () {
-    gBrowser.removeTab(newTab);
-  });
-
-  let scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
-                     getService(Ci.mozIJSSubScriptLoader);
-  let ChromeUtils = {};
-  scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js", ChromeUtils);
-
-  let browser = gBrowser.selectedBrowser;
-
-  var linkHandlerActivated = 0;
-  // Don't worry about clobbering the droppedLinkHandler, since we're closing
-  // this tab after the test anyways
-  browser.droppedLinkHandler = function dlh(e, url, name) {
-    linkHandlerActivated++;
-    ok(!/(javascript|data)/i.test(url), "javascript link should not be dropped");
-  }
-
-  var receivedDropCount = 0;
-  function dropListener() {
-    receivedDropCount++;
-    if (receivedDropCount == triggeredDropCount) {
-      // Wait for the browser's system-phase event handler to run.
-      executeSoon(function () {
-        is(linkHandlerActivated, validDropCount,
-           "link handler was called correct number of times");
-        finish();
-      })
-    }
-  }
-  browser.addEventListener("drop", dropListener, false);
-  registerCleanupFunction(function () {
-    browser.removeEventListener("drop", dropListener, false);
-  });
-
-  var triggeredDropCount = 0;
-  var validDropCount = 0;
-  function drop(text, valid) {
-    triggeredDropCount++;
-    if (valid)
-      validDropCount++;
-    executeSoon(function () {
-      ChromeUtils.synthesizeDrop(browser, browser, [[{type: "text/plain", data: text}]], "copy", window);
-    });
-  }
-
-  drop("mochi.test/first", true);
-  drop("javascript:'bad'");
-  drop("jAvascript:'also bad'");
-  drop("mochi.test/second", true);
-  drop("data:text/html,bad");
-  drop("mochi.test/third", true);
-}
--- a/toolkit/content/tests/chrome/window_browser_drop.xul
+++ b/toolkit/content/tests/chrome/window_browser_drop.xul
@@ -9,17 +9,16 @@
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"/>
 
 <script>
 <![CDATA[
 
-let lastLink, lastLinkName;
 Components.utils.import("resource://testing-common/ContentTask.jsm");
 
 function doDropAndStopLoad(browser, data, shouldExpectStateChange) {
   ContentTask.setTestScope(window); // Need this so is/isnot/ok are available inside the contenttask
   return ContentTask.spawn(browser, {data, shouldExpectStateChange}, function*({data, shouldExpectStateChange}) {
     let { interfaces: Ci, utils: Cu } = Components;
     Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
@@ -71,52 +70,69 @@ function doDropAndStopLoad(browser, data
     if (!gotLoad) {
       wp.removeProgressListener(progressListener);
     }
     return [uri, nameReturned];
   });
 }
 
 function expectLink(browser, expectedLink, expectedName, data, testid, onbody=false) {
+  let lastLink = "";
+  let lastLinkName = "";
   function dropOnBrowserSync() {
+    browser.droppedLinkHandler = function(event, link, linkname) {
+      info(`droppedLinkHandler called, received link ${link} and linkname ${linkname}`);
+      if (!expectedLink && !expectedName) {
+        ok(false, "droppedLinkHandler called for URI " + link + " which we didn't expect.");
+      }
+      lastLink = link;
+      lastLinkName = linkname;
+    };
+
     let dropEl = onbody ? browser.contentDocument.body : browser;
     synthesizeDrop(dropEl, dropEl, data, "", dropEl.ownerDocument.defaultView);
     return Promise.resolve([lastLink, lastLinkName]);
   }
   let dropInfoReceived;
-  lastLink = lastLinkName = "";
   if (browser.isRemoteBrowser) {
     dropInfoReceived = doDropAndStopLoad(browser, data[0][0], !!expectedLink);
   } else {
     dropInfoReceived = dropOnBrowserSync();
   }
   return dropInfoReceived.then(([uri, linkname]) => {
     is(uri, expectedLink, testid + " link");
     is(linkname, expectedName, testid + " name");
   });
 }
 
 function* dropLinksOnBrowser(browser, type) {
-  browser.droppedLinkHandler = function(event, link, linkname) {
-    info(`droppedLinkHandler called, received link ${link} and linkname ${linkname}`);
-    lastLink = link;
-    lastLinkName = linkname;
-  };
   yield expectLink(browser, "http://www.mozilla.org/", "http://www.mozilla.org/",
                    [ [ { type: "text/plain", data: "http://www.mozilla.org/" } ] ],
                    "text/plain drop on browser " + type);
   yield expectLink(browser, "", "",
                    [ [ { type: "text/link", data: "http://www.mozilla.org/" } ] ],
                    "text/link drop on browser " + type);
   yield expectLink(browser, "http://www.example.com/", "http://www.example.com/",
                    [ [ { type: "text/uri-list", data: "http://www.example.com/\nhttp://www.mozilla.org" } ] ],
                    "text/uri-list drop on browser " + type);
   yield expectLink(browser, "http://www.example.com/", "Example.com",
                    [ [ { type: "text/x-moz-url", data: "http://www.example.com/\nExample.com" } ] ],
                    "text/x-moz-url drop on browser " + type);
+
+  // Dropping javascript or data: URLs should fail:
+  yield expectLink(browser, "", "",
+                   [ [ { type: "text/plain", data: "javascript:'bad'" } ] ],
+                   "text/plain javascript url drop on browser " + type);
+  yield expectLink(browser, "", "",
+                   [ [ { type: "text/plain", data: "jAvascript:'also bad'" } ] ],
+                   "text/plain mixed-case javascript url drop on browser " + type);
+  yield expectLink(browser, "", "",
+                   [ [ { type: "text/plain", data: "data:text/html,bad" } ] ],
+                   "text/plain data url drop on browser " + type);
+
   // dropping a chrome url should fail as we don't have a source node set,
   // defaulting to a source of file:///
   yield expectLink(browser, "", "",
                    [ [ { type: "text/x-moz-url", data: "chrome://browser/content/browser.xul" } ] ],
                    "text/x-moz-url chrome url drop on browser " + type);
 
   if (browser.type == "content") {
     yield ContentTask.spawn(browser, null, function() {