Bug 930843 part.1 Add test for checking isTrust attribute value of DOMActivate event r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Sat, 22 Aug 2015 13:02:39 +0900
changeset 291520 2518b11aca2618c587702399b5fc9749f27e02ea
parent 291519 8a5579a007a9e78fe78bd83b4dce4a2a3dc53bf3
child 291521 6eaeb32125f4ce179182e8742e0cb43c6251ebc8
push idunknown
push userunknown
push dateunknown
reviewerssmaug
bugs930843
milestone43.0a1
Bug 930843 part.1 Add test for checking isTrust attribute value of DOMActivate event r=smaug
dom/events/test/mochitest.ini
dom/events/test/test_dom_activate_event.html
--- a/dom/events/test/mochitest.ini
+++ b/dom/events/test/mochitest.ini
@@ -188,8 +188,9 @@ skip-if = buildapp == 'b2g' || e10s
 [test_bug1096146.html]
 support-files =
   bug1096146_embedded.html
 [test_offsetxy.html]
 skip-if = toolkit == 'android' || buildapp == 'b2g' || buildapp == 'mulet'
 [test_eventhandler_scoping.html]
 [test_bug1013412.html]
 skip-if = buildapp == 'b2g' # no wheel events on b2g
+[test_dom_activate_event.html]
new file mode 100644
--- /dev/null
+++ b/dom/events/test/test_dom_activate_event.html
@@ -0,0 +1,89 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Test DOMActivate event</title>
+  <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>
+<p id="display">
+<a id="a" href="#dummy">link</a>
+<button id="button">button</button>
+<input id="checkbox" type="checkbox">
+<input id="radio" type="radio">
+<input id="submit" type="submit">
+<input id="ibutton" type="button">
+<input id="reset" type="reset">
+</p>
+<div id="content" style="display: none">
+  
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+SimpleTest.waitForExplicitFinish();
+SimpleTest.waitForFocus(runTests);
+
+function runIsTrustedTestCausedByTrustedClick(aElement, aNextTest)
+{
+  const kDescription = "runIsTrustedTestCausedByTrustedClick(aElement.id=" + aElement.id + "): ";
+  var DOMActivateFired = false;
+  aElement.addEventListener("DOMActivate", function (aEvent) {
+    DOMActivateFired = true;
+    ok(aEvent.isTrusted, kDescription + "DOMActivate event should be trusted event");
+    aElement.removeEventListener("DOMActivate", arguments.callee);
+    aNextTest();
+  });
+  aElement.addEventListener("click", function (aEvent) {
+    ok(aEvent.isTrusted, kDescription + "click event should be trusted event");
+    aElement.removeEventListener("click", arguments.callee);
+  });
+  synthesizeMouseAtCenter(aElement, {});
+}
+
+function runIsTrustedTestCausedByUntrustedClick(aElement, aNextTest)
+{
+  const kDescription = "runIsTrustedTestCausedByUntrustedClick(aElement.id=" + aElement.id + "): ";
+  var DOMActivateFired = false;
+  aElement.addEventListener("DOMActivate", function (aEvent) {
+    DOMActivateFired = true;
+    ok(aEvent.isTrusted,
+       kDescription + "DOMActivate event should be trusted event even if it's caused by untrusted event");
+    aElement.removeEventListener("DOMActivate", arguments.callee);
+    aNextTest();
+  });
+  aElement.addEventListener("click", function (aEvent) {
+    ok(!aEvent.isTrusted, kDescription + "click event should be untrusted event");
+    aElement.removeEventListener("click", arguments.callee);
+  });
+  var click = new MouseEvent("click", { button: 0 });
+  aElement.dispatchEvent(click);
+}
+
+function runTests()
+{
+  // XXX Don't add indentation here. If you add indentation, the diff will be
+  //     complicated when somebody adds new tests.
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("a"), function () {
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("button"), function () {
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("checkbox"), function () {
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("radio"), function () {
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("submit"), function () {
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("ibutton"), function () {
+  runIsTrustedTestCausedByTrustedClick(document.getElementById("reset"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("a"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("button"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("checkbox"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("radio"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("submit"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("ibutton"), function () {
+  runIsTrustedTestCausedByUntrustedClick(document.getElementById("reset"), function () {
+    SimpleTest.finish();
+  });});});});});});});});});});});});});});
+}
+
+</script>
+</pre>
+</body>
+</html>