[Pkg-mozext-commits] [requestpolicy] 71/100: add mozmill tests: blocking redirects. (issue 493)

David Prévot taffit at moszumanska.debian.org
Fri Dec 12 22:57:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 3d81046870d0de67f02cacd61ed7cc90b320145b
Author: myrdd <myrdd at users.noreply.github.com>
Date:   Thu Nov 6 16:02:39 2014 +0100

    add mozmill tests: blocking redirects. (issue 493)
---
 tests/content/redirect-http-location-header.php    |  3 ++
 tests/content/redirect-http-refresh-header.php     |  3 ++
 ...tml => redirect-js-document-location-auto.html} |  0
 ...tml => redirect-js-document-location-link.html} |  0
 tests/mozmill/lib/rp-utils.js                      | 11 +++++
 tests/mozmill/tests/manifest.ini                   |  1 +
 .../testHTMLAnchorElement/testLinkClick.js         | 13 +-----
 tests/mozmill/tests/testRedirect/manifest.ini      |  4 ++
 .../mozmill/tests/testRedirect/testAutoRedirect.js | 50 ++++++++++++++++++++++
 .../tests/testRedirect/testLinkClickRedirect.js    | 45 +++++++++++++++++++
 10 files changed, 118 insertions(+), 12 deletions(-)

diff --git a/tests/content/redirect-http-location-header.php b/tests/content/redirect-http-location-header.php
new file mode 100644
index 0000000..5b4be1f
--- /dev/null
+++ b/tests/content/redirect-http-location-header.php
@@ -0,0 +1,3 @@
+<?php
+  header('Location: http://www.otherdomain.test');
+?>
diff --git a/tests/content/redirect-http-refresh-header.php b/tests/content/redirect-http-refresh-header.php
new file mode 100644
index 0000000..184ecf4
--- /dev/null
+++ b/tests/content/redirect-http-refresh-header.php
@@ -0,0 +1,3 @@
+<?php
+  header('Refresh: 0; url=http://www.otherdomain.test');
+?>
diff --git a/tests/content/js_document_location_auto.html b/tests/content/redirect-js-document-location-auto.html
similarity index 100%
rename from tests/content/js_document_location_auto.html
rename to tests/content/redirect-js-document-location-auto.html
diff --git a/tests/content/js_document_location_link.html b/tests/content/redirect-js-document-location-link.html
similarity index 100%
rename from tests/content/js_document_location_link.html
rename to tests/content/redirect-js-document-location-link.html
diff --git a/tests/mozmill/lib/rp-utils.js b/tests/mozmill/lib/rp-utils.js
index 314ce12..5b402f3 100644
--- a/tests/mozmill/lib/rp-utils.js
+++ b/tests/mozmill/lib/rp-utils.js
@@ -32,7 +32,18 @@ function getElementById(ancestor, id) {
   return element;
 }
 
+/**
+ * @param {MozMillController} _controller
+ * @return {MozMillElement} The link to click on.
+ */
+function getLink(_controller) {
+  let links = _controller.window.content.document.getElementsByTagName("a");
+  assert.notEqual(links.length, 0, "A link has been found on the test page.");
+  return findElement.Elem(links[0]);
+}
+
 // Export of functions
 exports.waitForTabLoad = waitForTabLoad;
 exports.selectText = selectText;
 exports.getElementById = getElementById;
+exports.getLink = getLink;
diff --git a/tests/mozmill/tests/manifest.ini b/tests/mozmill/tests/manifest.ini
index 92e6990..7bfc351 100644
--- a/tests/mozmill/tests/manifest.ini
+++ b/tests/mozmill/tests/manifest.ini
@@ -2,3 +2,4 @@
 
 [include:testLinks/manifest.ini]
 [include:testPolicy/manifest.ini]
+[include:testRedirect/manifest.ini]
diff --git a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
index 9160c00..299a162 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
+++ b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
@@ -32,7 +32,7 @@ var testLinkClick = function() {
   controller.open(TEST_URL);
   controller.waitForPageLoad();
 
-  let link = getLink();
+  let link = rpUtils.getLink(controller);
   let linkURL = link.getNode().href;
 
   link.click();
@@ -47,14 +47,3 @@ var testLinkClick = function() {
   assert.equal(controller.tabs.activeTab.location.href, linkURL,
       "The location is correct.");
 }
-
-
-/**
- * @return {MozMillElement} The link to click on.
- */
-var getLink = function() {
-  let links = controller.window.content.document.getElementsByTagName("a");
-  assert.notEqual(links.length, 0, "A link has been found on the test page.");
-
-  return findElement.Elem(links[0]);
-}
diff --git a/tests/mozmill/tests/testRedirect/manifest.ini b/tests/mozmill/tests/testRedirect/manifest.ini
new file mode 100644
index 0000000..c680174
--- /dev/null
+++ b/tests/mozmill/tests/testRedirect/manifest.ini
@@ -0,0 +1,4 @@
+[parent:../manifest.ini]
+
+[testAutoRedirect.js]
+[testLinkClickRedirect.js]
diff --git a/tests/mozmill/tests/testRedirect/testAutoRedirect.js b/tests/mozmill/tests/testRedirect/testAutoRedirect.js
new file mode 100644
index 0000000..03215a6
--- /dev/null
+++ b/tests/mozmill/tests/testRedirect/testAutoRedirect.js
@@ -0,0 +1,50 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var {assert, expect} = require("../../../../../../lib/assertions");
+var prefs = require("../../../../../lib/prefs");
+var tabs = require("../../../../../lib/tabs");
+
+var rpConst = require("../../lib/constants");
+
+var testURLs = [
+  "http://www.maindomain.test/redirect-http-location-header.php",
+  "http://www.maindomain.test/redirect-http-refresh-header.php",
+  "http://www.maindomain.test/redirect-js-document-location-auto.html"
+];
+
+
+var setupModule = function(aModule) {
+  aModule.controller = mozmill.getBrowserController();
+  aModule.tabBrowser = new tabs.tabBrowser(aModule.controller);
+  aModule.tabBrowser.closeAllTabs();
+
+  prefs.preferences.setPref(rpConst.PREF_DEFAULT_ALLOW, false);
+}
+
+var teardownModule = function(aModule) {
+  prefs.preferences.clearUserPref(rpConst.PREF_DEFAULT_ALLOW);
+  aModule.tabBrowser.closeAllTabs();
+}
+
+
+var testOpenInCurrentTab = function() {
+  var tabIndex = tabBrowser.selectedIndex;
+
+  var panel = tabBrowser.getTabPanelElement(tabIndex,
+      '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
+
+  for (let testURL of testURLs) {
+    dump("Testing " + testURL + "\n");
+
+    controller.open(testURL);
+    controller.waitForPageLoad();
+
+    assert.ok(panel.exists(), "The redirect has been blocked.");
+
+    tabBrowser.closeAllTabs();
+  }
+}
diff --git a/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js b/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js
new file mode 100644
index 0000000..1a1d010
--- /dev/null
+++ b/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js
@@ -0,0 +1,45 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+var {assert, expect} = require("../../../../../../lib/assertions");
+var prefs = require("../../../../../lib/prefs");
+var tabs = require("../../../../../lib/tabs");
+
+var rpUtils = require("../../lib/rp-utils");
+var rpConst = require("../../lib/constants");
+
+var TEST_URL = "http://www.maindomain.test/redirect-js-document-location-link.html";
+
+
+var setupModule = function(aModule) {
+  aModule.controller = mozmill.getBrowserController();
+  aModule.tabBrowser = new tabs.tabBrowser(aModule.controller);
+  aModule.tabBrowser.closeAllTabs();
+
+  prefs.preferences.setPref(rpConst.PREF_DEFAULT_ALLOW, false);
+}
+
+var teardownModule = function(aModule) {
+  prefs.preferences.clearUserPref(rpConst.PREF_DEFAULT_ALLOW);
+  aModule.tabBrowser.closeAllTabs();
+}
+
+
+var testOpenInCurrentTab = function() {
+  let tabIndex = tabBrowser.selectedIndex;
+
+  controller.open(TEST_URL);
+  controller.waitForPageLoad();
+
+  rpUtils.getLink(controller).click();
+
+  rpUtils.waitForTabLoad(controller, tabBrowser.getTab(0));
+
+  var panel = tabBrowser.getTabPanelElement(tabIndex,
+      '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
+
+  assert.ok(panel.exists(), "The redirect has been blocked.");
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list