[Pkg-mozext-commits] [requestpolicy] 75/100: rename/tidy up 'metarefresh' files, add <meta> redirect mozmill tests.

David Prévot taffit at moszumanska.debian.org
Fri Dec 12 22:57:01 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 251028a46373c767d1e540bb4fe9fa6284329932
Author: myrdd <myrdd at users.noreply.github.com>
Date:   Fri Nov 7 10:01:28 2014 +0100

    rename/tidy up 'metarefresh' files, add <meta> redirect mozmill tests.
---
 tests/content/destination.html                     |  4 +-
 tests/content/iframe_4_redirect-meta-tag.html      | 14 ++++++
 tests/content/metarefresh_1.html                   | 16 -------
 tests/content/metarefresh_10.html                  | 10 -----
 tests/content/metarefresh_11.html                  | 10 -----
 tests/content/metarefresh_2.html                   | 12 -----
 tests/content/metarefresh_4.html                   | 12 -----
 tests/content/metarefresh_5.html                   | 14 ------
 tests/content/metarefresh_6.html                   | 10 -----
 tests/content/metarefresh_7.html                   | 10 -----
 tests/content/metarefresh_8.html                   | 10 -----
 tests/content/metarefresh_9.html                   | 10 -----
 tests/content/redirect-links.html                  | 33 ++++++++++++++
 tests/content/redirect-meta-tag-01-immediate.html  | 20 +++++++++
 tests/content/redirect-meta-tag-02-delayed.html    | 15 +++++++
 tests/content/redirect-meta-tag-03-multiple.html   | 19 ++++++++
 ...edirect-meta-tag-04-relative-without-slash.html | 14 ++++++
 .../redirect-meta-tag-05-relative-with-slash.html  | 14 ++++++
 .../redirect-meta-tag-06-different-formatting.html | 14 ++++++
 ...t-meta-tag-07-different-formatting-delayed.html | 13 ++++++
 tests/content/redirect-meta-tag-08.html            | 13 ++++++
 tests/content/redirect-meta-tag-09-relative.html   | 10 +++++
 tests/mozmill/lib/rp-utils.js                      | 12 +++--
 .../testHTMLAnchorElement/testOpenInNewTab.js      | 12 +----
 .../testHTMLAnchorElement/testOpenInNewWindow.js   | 11 +----
 .../mozmill/tests/testRedirect/testAutoRedirect.js | 51 ++++++++++++++++++----
 .../tests/testRedirect/testLinkClickRedirect.js    | 48 ++++++++++++++++----
 27 files changed, 275 insertions(+), 156 deletions(-)

diff --git a/tests/content/destination.html b/tests/content/destination.html
index 9032974..ff0c42b 100644
--- a/tests/content/destination.html
+++ b/tests/content/destination.html
@@ -12,8 +12,8 @@
 
   $('body').prepend('<p>' + location.hostname + '</p>');
   if (location.search) {
-    var text = location.search.substr(1);
-    $('body').prepend('<p>' + text + '</p>');
+    var text = decodeURIComponent(location.search.substr(1));
+    $('body').prepend('<p><b>' + text + '<b></p>');
   }
 
   $('body').append('<p>This page makes ' +
diff --git a/tests/content/iframe_4_redirect-meta-tag.html b/tests/content/iframe_4_redirect-meta-tag.html
new file mode 100644
index 0000000..f926d21
--- /dev/null
+++ b/tests/content/iframe_4_redirect-meta-tag.html
@@ -0,0 +1,14 @@
+<html>
+  <head>
+  </head>
+  <body>
+
+    <p>
+      This page doesn't refresh, but the page in the iframe.
+      <br />The iframe src is <tt>redirect-meta-tag-01.html<tt>.
+    </p>
+
+    <iframe src="redirect-meta-tag-01.html" />
+
+</body>
+</html>
diff --git a/tests/content/metarefresh_1.html b/tests/content/metarefresh_1.html
deleted file mode 100644
index 928ff0a..0000000
--- a/tests/content/metarefresh_1.html
+++ /dev/null
@@ -1,16 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0;url=http://www.otherdomain.test/meta_refresh"/>
-</head>
-<body>
-
-<p>Instant refresh meta tag on this page.
-
-<p><a href="file:///home/justin/workspace/csrpolicy/tests/test1.html">try it again</a>
-
-<p>And an iframe with an instant meta refresh.
-
-<p><iframe src="test1a.html"></iframe>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_10.html b/tests/content/metarefresh_10.html
deleted file mode 100644
index 3805462..0000000
--- a/tests/content/metarefresh_10.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0; url='http://code.google.com/p/x-wrt/issues/detail?id=128'">
-</head>
-<body>
-
-<p>Enclosed in ' instead of quotes.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_11.html b/tests/content/metarefresh_11.html
deleted file mode 100644
index 90c1f17..0000000
--- a/tests/content/metarefresh_11.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0; url=subdirectory/">
-</head>
-<body>
-
-<p>Relative path.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_2.html b/tests/content/metarefresh_2.html
deleted file mode 100644
index 1712ba0..0000000
--- a/tests/content/metarefresh_2.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0;url=http://www.otherdomain.test/meta_refresh"/>
-</head>
-<body>
-
-<p>Instant refresh meta tag on this page.
-
-<p><a href="file:///home/justin/workspace/csrpolicy/tests/test1.html">try it again</a>
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_4.html b/tests/content/metarefresh_4.html
deleted file mode 100644
index 57d2a89..0000000
--- a/tests/content/metarefresh_4.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="100;url=http://www.otherdomain.test/meta_refresh"/>
-<meta name="robots" content="index,follow" />
-<meta name="generator" content="blah" />
-</head>
-<body>
-
-Slow meta refresh on this page along with other non-refresh meta tags.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_5.html b/tests/content/metarefresh_5.html
deleted file mode 100644
index 05392ac..0000000
--- a/tests/content/metarefresh_5.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0;url=http://www.otherdomain.test/meta_refresh/1"/>
-<meta http-equiv="refresh" content="1;url=http://www.otherdomain.test/meta_refresh/2"/>
-<meta http-equiv="refresh" content="100;url=http://www.otherdomain.test/meta_refresh/3"/>
-<meta name="robots" content="index,follow" />
-<meta name="generator" content="MindTouch Deki 8.08" />
-</head>
-<body>
-
-Slow meta refresh on this page along with other non-refresh meta tags.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_6.html b/tests/content/metarefresh_6.html
deleted file mode 100644
index 9e5a9b7..0000000
--- a/tests/content/metarefresh_6.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0;url=meta_refresh_relative_url_without_slash"/>
-</head>
-<body>
-
-<p>Instant refresh meta tag on this page to relative url without preceding slash.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_7.html b/tests/content/metarefresh_7.html
deleted file mode 100644
index 74fc9cd..0000000
--- a/tests/content/metarefresh_7.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content="0;url=/meta_refresh_relative_url_with_slash"/>
-</head>
-<body>
-
-<p>Instant refresh meta tag on this page to relative url with preceding slash.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_8.html b/tests/content/metarefresh_8.html
deleted file mode 100644
index fc92c5d..0000000
--- a/tests/content/metarefresh_8.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content=" 0   ;  url = /meta_refresh_relative_url_with_slash     "/>
-</head>
-<body>
-
-<p>Instant refresh meta tag on this page with different formatting of the content attribute.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/metarefresh_9.html b/tests/content/metarefresh_9.html
deleted file mode 100644
index eaaee91..0000000
--- a/tests/content/metarefresh_9.html
+++ /dev/null
@@ -1,10 +0,0 @@
-<html>
-<head>
-<meta http-equiv="refresh" content=" 3   ;  url = /meta_refresh_relative_url_with_slash     "/>
-</head>
-<body>
-
-<p>3 second delayed refresh meta tag on this page with allowed destination.
-
-</body>
-</html>
\ No newline at end of file
diff --git a/tests/content/redirect-links.html b/tests/content/redirect-links.html
new file mode 100644
index 0000000..9f75973
--- /dev/null
+++ b/tests/content/redirect-links.html
@@ -0,0 +1,33 @@
+<html>
+  <head>
+  </head>
+  <body>
+
+  <p>
+    This page contains the links to all redirect test pages that automatically
+    redirect to a different page.
+  </p>
+
+  <p>
+    <a href="redirect-http-location-header.php">link 0</a><br />
+    <a href="redirect-http-refresh-header.php">link 1</a><br />
+    <a href="redirect-js-document-location-auto.html">link 2</a><br />
+    <a href="redirect-meta-tag-01-immediate.html">link 3</a><br />
+    <a href="redirect-meta-tag-02-delayed.html">link 4</a><br />
+    <a href="redirect-meta-tag-03-multiple.html">link 5</a><br />
+    <a href="redirect-meta-tag-08.html">link 6</a><br />
+
+    <a href="redirect-meta-tag-04-relative-without-slash.html"
+       class="redirectShouldBeAllowed">link 7</a><br />
+    <a href="redirect-meta-tag-05-relative-with-slash.html"
+       class="redirectShouldBeAllowed">link 8</a><br />
+    <a href="redirect-meta-tag-06-different-formatting.html"
+       class="redirectShouldBeAllowed">link 9</a><br />
+    <a href="redirect-meta-tag-07-different-formatting-delayed.html"
+       class="redirectShouldBeAllowed">link 10</a><br />
+    <a href="redirect-meta-tag-09-relative.html"
+       class="redirectShouldBeAllowed">link 11</a>
+  </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-01-immediate.html b/tests/content/redirect-meta-tag-01-immediate.html
new file mode 100644
index 0000000..e4d1ce7
--- /dev/null
+++ b/tests/content/redirect-meta-tag-01-immediate.html
@@ -0,0 +1,20 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content="0;url=http://www.otherdomain.test/destination.html?redirect-meta-tag-01%20redirected%20here." />
+  </head>
+  <body>
+
+    <p>
+      This page immediately redirects to a different page using the
+      <tt><meta></tt> tag. If you see this message, the redirect has been
+      blocked.
+    </p>
+
+    <p>
+      <a href="http://www.maindomain.test/redirect-meta-tag-01.html">try it
+      again</a>
+    </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-02-delayed.html b/tests/content/redirect-meta-tag-02-delayed.html
new file mode 100644
index 0000000..1f2695b
--- /dev/null
+++ b/tests/content/redirect-meta-tag-02-delayed.html
@@ -0,0 +1,15 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content="2;url=http://www.otherdomain.test/destination.html?redirect-meta-tag-02%20redirected%20here." />
+    <meta name="robots" content="index,follow" />
+    <meta name="generator" content="blah" />
+  </head>
+  <body>
+
+    <p>
+      Slow meta refresh on this page along with other non-refresh meta tags.
+    </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-03-multiple.html b/tests/content/redirect-meta-tag-03-multiple.html
new file mode 100644
index 0000000..22d34da
--- /dev/null
+++ b/tests/content/redirect-meta-tag-03-multiple.html
@@ -0,0 +1,19 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content="0;url=http://www.otherdomain.test/destination.html?redirect-meta-tag-03%20redirected%20here. Delay: 0" />
+    <meta http-equiv="refresh"
+          content="1;url=http://www.otherdomain.test/destination.html?redirect-meta-tag-03%20redirected%20here. Delay: 1" />
+    <meta http-equiv="refresh"
+          content="100;url=http://www.otherdomain.test/destination.html?redirect-meta-tag-03%20redirected%20here. Delay: 100" />
+    <meta name="robots" content="index,follow" />
+    <meta name="generator" content="MindTouch Deki 8.08" />
+  </head>
+  <body>
+
+    <p>
+      Slow meta refresh on this page along with other non-refresh meta tags.
+    </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-04-relative-without-slash.html b/tests/content/redirect-meta-tag-04-relative-without-slash.html
new file mode 100644
index 0000000..c00676c
--- /dev/null
+++ b/tests/content/redirect-meta-tag-04-relative-without-slash.html
@@ -0,0 +1,14 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content="0;url=destination.html?redirect-meta-tag-04%20redirected%20here.%20The%20refresh%20destination%20was%20a%20relative%20URL%20without%20slash" />
+  </head>
+  <body>
+
+    <p>
+      Instant refresh meta tag on this page to relative url without preceding
+      slash.
+    </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-05-relative-with-slash.html b/tests/content/redirect-meta-tag-05-relative-with-slash.html
new file mode 100644
index 0000000..0bf817c
--- /dev/null
+++ b/tests/content/redirect-meta-tag-05-relative-with-slash.html
@@ -0,0 +1,14 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content="0;url=/destination.html?redirect-meta-tag-05%20redirected%20here.%20The%20refresh%20destination%20was%20a%20relative%20URL%20*with*%20slash" />
+  </head>
+  <body>
+
+    <p>
+      Instant refresh meta tag on this page to relative url *with* preceding
+      slash.
+    </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-06-different-formatting.html b/tests/content/redirect-meta-tag-06-different-formatting.html
new file mode 100644
index 0000000..c86caf4
--- /dev/null
+++ b/tests/content/redirect-meta-tag-06-different-formatting.html
@@ -0,0 +1,14 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content=" 0   ;  url = /destination.html?redirect-meta-tag-06%20redirected%20here.%20The%20refresh%20destination%20was%20a%20relative%20URL%20with%20slash%20and%20formatting%20of%20thecontent%20attribute.     " />
+  </head>
+  <body>
+
+    <p>
+      Instant refresh meta tag on this page with different formatting of the
+      content attribute.
+    </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-07-different-formatting-delayed.html b/tests/content/redirect-meta-tag-07-different-formatting-delayed.html
new file mode 100644
index 0000000..9f43abc
--- /dev/null
+++ b/tests/content/redirect-meta-tag-07-different-formatting-delayed.html
@@ -0,0 +1,13 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content=" 2   ;  url = /destination.html?redirect-meta-tag-07%20redirected%20here.%20The%20refresh%20destination%20was%20a%20relative%20URL%20with%20slash.%20Different%20formatting%20of%20the%20content%20attribute.%20Delayed.     "/>
+  </head>
+  <body>
+
+  <p>
+    2 second delayed refresh meta tag on this page with allowed destination.
+  </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-08.html b/tests/content/redirect-meta-tag-08.html
new file mode 100644
index 0000000..12b004a
--- /dev/null
+++ b/tests/content/redirect-meta-tag-08.html
@@ -0,0 +1,13 @@
+<html>
+  <head>
+    <meta http-equiv="refresh"
+          content="0; url='http://www.otherdomain.test/destination.html?redirect-meta-tag-08%20redirected%20here.%20The%20refresh%20URL%20was%20enclosed%20in%20%26amp%3B%2339%3B%20instead%20of%20quotes.'">
+  </head>
+  <body>
+
+  <p>
+    Enclosed in ' instead of quotes.
+  </p>
+
+  </body>
+</html>
diff --git a/tests/content/redirect-meta-tag-09-relative.html b/tests/content/redirect-meta-tag-09-relative.html
new file mode 100644
index 0000000..94b7785
--- /dev/null
+++ b/tests/content/redirect-meta-tag-09-relative.html
@@ -0,0 +1,10 @@
+<html>
+  <head>
+    <meta http-equiv="refresh" content="0; url=subdirectory/" />
+  </head>
+  <body>
+
+    <p>Relative path.</p>
+
+  </body>
+</html>
diff --git a/tests/mozmill/lib/rp-utils.js b/tests/mozmill/lib/rp-utils.js
index 5b402f3..aa0d9dd 100644
--- a/tests/mozmill/lib/rp-utils.js
+++ b/tests/mozmill/lib/rp-utils.js
@@ -36,10 +36,15 @@ function getElementById(ancestor, id) {
  * @param {MozMillController} _controller
  * @return {MozMillElement} The link to click on.
  */
-function getLink(_controller) {
+function getLink(_controller, i) {
+  i = i || 0;
   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]);
+  assert.ok(links.length >= i, "The page contains at least " + i + " links.");
+  return findElement.Elem(links[i]);
+}
+
+function getNumLinks(_controller) {
+  return _controller.window.content.document.getElementsByTagName("a").length;
 }
 
 // Export of functions
@@ -47,3 +52,4 @@ exports.waitForTabLoad = waitForTabLoad;
 exports.selectText = selectText;
 exports.getElementById = getElementById;
 exports.getLink = getLink;
+exports.getNumLinks = getNumLinks;
diff --git a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
index b876a66..3f7db96 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
+++ b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
@@ -9,6 +9,7 @@ var prefs = require("../../../../../../lib/prefs");
 var tabs = require("../../../../../../lib/tabs");
 var utils = require("../../../../../../../lib/utils");
 
+var rpUtils = require("../../../lib/rp-utils");
 var rpConst = require("../../../lib/constants");
 
 const TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -34,7 +35,7 @@ var testOpenInNewTab = function() {
   controller.open(TEST_URL);
   controller.waitForPageLoad();
 
-  let link = getLink();
+  let link = rpUtils.getLink();
   let linkURL = link.getNode().href;
 
   let i = 1;
@@ -51,15 +52,6 @@ var testOpenInNewTab = function() {
 }
 
 
-/**
- * @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]);
-}
 
 /**
  * Opens the next tab.
diff --git a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewWindow.js b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewWindow.js
index 925f745..a8813c5 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewWindow.js
+++ b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewWindow.js
@@ -38,7 +38,7 @@ var testOpenInNewWindow = function () {
   controller.open(TEST_URL);
   controller.waitForPageLoad();
 
-  let link = getLink();
+  let link = rpUtils.getLink();
   let linkURL = link.getNode().href;
 
   let i = 1;
@@ -77,15 +77,6 @@ var closeWindow = function(_controller) {
 };
 
 
-/**
- * @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]);
-};
 
 /**
  * Opens the next tab.
diff --git a/tests/mozmill/tests/testRedirect/testAutoRedirect.js b/tests/mozmill/tests/testRedirect/testAutoRedirect.js
index 03215a6..3eea50f 100644
--- a/tests/mozmill/tests/testRedirect/testAutoRedirect.js
+++ b/tests/mozmill/tests/testRedirect/testAutoRedirect.js
@@ -10,10 +10,22 @@ 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 testURLPrePath = "http://www.maindomain.test/";
+var urlsWithRedirect = [
+  // [shouldBeAllowed, url]
+  [false, "redirect-http-location-header.php"],
+  [false, "redirect-http-refresh-header.php"],
+  [false, "redirect-js-document-location-auto.html"],
+  [false, "redirect-meta-tag-01-immediate.html"],
+  [false, "redirect-meta-tag-02-delayed.html"],
+  [false, "redirect-meta-tag-03-multiple.html"],
+  [false, "redirect-meta-tag-08.html"],
+
+  [true, "redirect-meta-tag-04-relative-without-slash.html"],
+  [true, "redirect-meta-tag-05-relative-with-slash.html"],
+  [true, "redirect-meta-tag-06-different-formatting.html"],
+  [true, "redirect-meta-tag-07-different-formatting-delayed.html"],
+  [true, "redirect-meta-tag-09-relative.html"]
 ];
 
 
@@ -31,20 +43,43 @@ var teardownModule = function(aModule) {
 }
 
 
-var testOpenInCurrentTab = function() {
+var testAutoRedirect = function() {
   var tabIndex = tabBrowser.selectedIndex;
 
   var panel = tabBrowser.getTabPanelElement(tabIndex,
       '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
 
-  for (let testURL of testURLs) {
-    dump("Testing " + testURL + "\n");
+  for (let [shouldBeAllowed, testURL] of urlsWithRedirect) {
+    testURL = testURLPrePath + testURL;
+    dump("Testing " + testURL + ". The redirect should be " +
+         (shouldBeAllowed ? "allowed" : "blocked") + ".\n");
 
     controller.open(testURL);
     controller.waitForPageLoad();
 
-    assert.ok(panel.exists(), "The redirect has been blocked.");
+    if (shouldBeAllowed) {
+      controller.waitFor(function() {
+          return controller.window.content.document.location.href !== testURL;
+      }, "The URL in the urlbar has changed.");
+      assert.ok(!panel.exists(), "The redirect has been allowed.");
+    } else {
+      assert.ok(panel.exists(), "The redirect has been blocked.");
+      assert.ok(controller.window.content.document.location.href === testURL,
+                "The URL in the urlbar hasn't changed.");
+    }
 
     tabBrowser.closeAllTabs();
+
+    // the following sleep is a workaround against the error:
+    // *************************
+    // A coding exception was thrown in a Promise resolution callback.
+    // See https://developer.mozilla.org/Mozilla/JavaScript_code_modules/Promise.jsm/Promise
+    //
+    // Full message: TypeError: this.options is undefined
+    // Full stack: Capture.prototype.start at resource://gre/modules/BackgroundPageThumbs.jsm:289:19
+    // BackgroundPageThumbs._processCaptureQueue at resource://gre/modules/BackgroundPageThumbs.jsm:222:5
+    // BackgroundPageThumbs.capture at resource://gre/modules/BackgroundPageThumbs.jsm:73:5
+    // (...)
+    controller.sleep(100);
   }
 }
diff --git a/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js b/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js
index 1a1d010..f0d3a3c 100644
--- a/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js
+++ b/tests/mozmill/tests/testRedirect/testLinkClickRedirect.js
@@ -11,7 +11,10 @@ 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 testURLs = [
+  "http://www.maindomain.test/redirect-js-document-location-link.html",
+  "http://www.maindomain.test/redirect-links.html"
+];
 
 
 var setupModule = function(aModule) {
@@ -28,18 +31,45 @@ var teardownModule = function(aModule) {
 }
 
 
-var testOpenInCurrentTab = function() {
+var testLinkClickRedirect = function() {
   let tabIndex = tabBrowser.selectedIndex;
 
-  controller.open(TEST_URL);
-  controller.waitForPageLoad();
+  for (let testURL of testURLs) {
+    dump("Visiting " + testURL + ".\n");
 
-  rpUtils.getLink(controller).click();
+    controller.open(testURL);
+    controller.waitForPageLoad();
 
-  rpUtils.waitForTabLoad(controller, tabBrowser.getTab(0));
+    let len = rpUtils.getNumLinks(controller);
 
-  var panel = tabBrowser.getTabPanelElement(tabIndex,
-      '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
+    for (let i = 0; i < len; ++i) {
+      dump("Testing link " + i + ".\n");
 
-  assert.ok(panel.exists(), "The redirect has been blocked.");
+      controller.open(testURL);
+      controller.waitForPageLoad();
+
+      let link = rpUtils.getLink(controller, i);
+      let classNode = link.getNode().attributes.class;
+      let redirectShouldBeAllowed = classNode ?
+          classNode.nodeValue.indexOf("redirectShouldBeAllowed") >= 0 : false;
+      let url = link.getNode().href;
+      link.click();
+
+      rpUtils.waitForTabLoad(controller, tabBrowser.getTab(0));
+
+      var panel = tabBrowser.getTabPanelElement(tabIndex,
+          '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
+
+      if (redirectShouldBeAllowed) {
+        controller.waitFor(function() {
+            return controller.window.content.document.location.href !== url;
+        }, "The URL in the urlbar has changed.");
+        assert.ok(!panel.exists(), "The redirect has been allowed.");
+      } else {
+        assert.ok(panel.exists(), "The redirect has been blocked.");
+      }
+
+      tabBrowser.closeAllTabs();
+    }
+  }
 }

-- 
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