Bug 377624 - [Test Part] "Implement the accept attribute for the form and file upload controls form "image/*"" [r=sicking, feedback=ehsan]
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 19 May 2010 22:28:08 -0400
changeset 42485 cec477f51801
parent 42484 103d84b4b399
child 42486 1711cfd31e7d
push id13361
push userCallek@gmail.com
push dateThu, 20 May 2010 02:31:41 +0000
treeherdermozilla-central@c46b625c886e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs377624
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
Bug 377624 - [Test Part] "Implement the accept attribute for the form and file upload controls form "image/*"" [r=sicking, feedback=ehsan]
content/html/content/test/Makefile.in
content/html/content/test/test_bug377624.html
layout/forms/test/Makefile.in
layout/forms/test/test_bug377624.html
--- a/content/html/content/test/Makefile.in
+++ b/content/html/content/test/Makefile.in
@@ -170,12 +170,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug565538.html \
 		test_bug456229.html \
 		test_bug546995-1.html \
 		test_bug546995-2.html \
 		test_bug546995-3.html \
 		test_bug546995-4.html \
 		test_bug546995-5.html \
 		file_bug546995.html \
+		test_bug377624.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/html/content/test/test_bug377624.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=377624
+-->
+<head>
+  <title>Test for Bug 377624</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377624">Mozilla Bug 377624</a>
+<p id="display"></p>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 377624 **/
+
+var input = document.createElement('input');
+ok("accept" in input, "'accept' is a valid input property");
+
+</script>
+</pre>
+</body>
+</html>
--- a/layout/forms/test/Makefile.in
+++ b/layout/forms/test/Makefile.in
@@ -64,12 +64,13 @@ include $(topsrcdir)/config/rules.mk
 		test_bug542914.html \
 		test_bug536567.html \
 		     bug536567_subframe.html \
 		test_bug549170.html \
 		test_bug562447.html \
 		test_bug563642.html \
 		test_bug564115.html \
 		bug564115_window.html \
+		test_bug377624.html \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/layout/forms/test/test_bug377624.html
@@ -0,0 +1,174 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=377624
+-->
+<head>
+  <title>Test for Bug 377624</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body onload="runTests();">
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=377624">Mozilla Bug 377624</a>
+<p id="display"></p>
+<div id="content">
+  <input id='i' type='file' accept="image/*">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 377624 **/
+
+SimpleTest.waitForExplicitFinish();
+
+netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
+const Cu = Components.utils;
+
+const FILE_PICKER_CID = "@mozilla.org/filepicker;1";
+const FILE_PICKER_ID = Components.ID(Cc[FILE_PICKER_CID].number);
+const FILE_PICKER_DESCRIPTION = "File Picker Test Service";
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+function FilePickerService()
+{
+}
+
+FilePickerService.prototype = {
+  _obs: Cc["@mozilla.org/observer-service;1"].
+        getService(Ci.nsIObserverService),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFilePicker]),
+
+  // constants
+  modeOpen: 0,
+  modeSave: 1,
+  modeGetFolder: 2,
+  modeOpenMultiple: 3,
+  returnOK: 0,
+  returnCancel: 1,
+  returnReplace: 2,
+  filterAll: 1,
+  filterHTML: 2,
+  filterText: 4,
+  filterImages: 8,
+  filterXML: 16,
+  filterXUL: 32,
+  filterApps: 64,
+
+  // properties
+  defaultExtension: "",
+  defaultString: "",
+  get displayDirectory() { return null; },
+  set displayDirectory(val) { },
+  file: null,
+  get files() { return null; },
+  get fileURL() { return null; },
+  filterIndex: 0,
+
+  // methods
+  appendFilter: function(val)
+  {
+    this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTER", val);
+  },
+
+  appendFilters: function(val)
+  {
+    this._obs.notifyObservers(null, "TEST_FILEPICKER_APPENDFILTERS", val);
+  },
+
+  init: function() {},
+
+  show: function()
+  {
+    this._obs.notifyObservers(null, "TEST_FILEPICKER_SHOW", this.filterIndex);
+    return this.returnOK;
+  }
+};
+
+factory = {
+  createInstance: function(aOuter, aIid) {
+    if (aOuter != null)
+      throw Cr.NS_ERROR_NO_AGGREGATION;
+    return new FilePickerService().QueryInterface(aIid);
+  }
+};
+
+document.getElementById('i').addEventListener("focus", function (aEvent) {
+    aEvent.target.removeEventListener("focus", arguments.callee, false);
+    synthesizeKey('VK_SPACE', {});
+  }, false);
+
+function runTests()
+{
+  var i = document.getElementById('i');
+
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+  Cm.registerFactory(FILE_PICKER_ID,
+                     FILE_PICKER_DESCRIPTION,
+                     FILE_PICKER_CID,
+                     factory);
+
+  var obs = Cc["@mozilla.org/observer-service;1"].
+            getService(Ci.nsIObserverService);
+
+  var observer = {
+    observe: function(aSubject, aTopic, aData) {
+      switch (aTopic) {
+        case "TEST_FILEPICKER_APPENDFILTER":
+          this.appendFilterCalled = true;
+          break;
+        case "TEST_FILEPICKER_APPENDFILTERS":
+          this.filters.push(aData);
+          break;
+        case "TEST_FILEPICKER_SHOW":
+          this.shown = true;
+          this.filterIndex = aData;
+
+          SimpleTest.executeSoon(function () {
+            netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+
+            ok(observer.shown, "File picker show method should have been called");
+            ok(!observer.appendFilterCalled, "appendFilter should not have been called");
+            is(observer.filters.length, 1, "AppendFilters should have been called once");
+            is(observer.filters[0], FilePickerService.prototype.filterAll +
+               FilePickerService.prototype.filterImages,
+              "All and Images filters should have been added");
+            is(observer.filterIndex, 1,
+               "File picker should show the second filter index (first is zero)");
+
+            obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTER", false);
+            obs.removeObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
+            obs.removeObserver(observer, "TEST_FILEPICKER_SHOW", false);
+            Cm.unregisterFactory(FILE_PICKER_ID, factory);
+
+            SimpleTest.finish();
+          } );
+          break;
+      }
+    },
+    shown: false,
+    appendFilterCalled: false,
+    filters: [],
+    filterIndex: 0
+  };
+
+  obs.addObserver(observer, "TEST_FILEPICKER_APPENDFILTER", false);
+  obs.addObserver(observer, "TEST_FILEPICKER_APPENDFILTERS", false);
+  obs.addObserver(observer, "TEST_FILEPICKER_SHOW", false);
+
+  // We are simulating a focus then a SPACE key press to open the file picker.
+  // We were not able to do this with |synthesizeMouse|.
+  i.focus();
+}
+
+</script>
+</pre>
+</body>
+</html>