[Pkg-mozext-commits] [requestpolicy] 37/100: add mozmill test for normal link click
David Prévot
taffit at moszumanska.debian.org
Fri Dec 12 22:56:53 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 50fb096697a6ea364d5df924e75034b6ca355e32
Author: myrdd <myrdd at users.noreply.github.com>
Date: Sat Sep 27 11:57:10 2014 +0200
add mozmill test for normal link click
---
tests/mozmill/lib/constants.js | 13 +++++
tests/mozmill/lib/rp-utils.js | 20 +++++++
tests/mozmill/tests/testLinkClicks/manifest.ini | 1 +
.../tests/testLinkClicks/testNormalLinkClick.js | 61 ++++++++++++++++++++++
.../tests/testLinkClicks/testOpenInNewTab.js | 9 ++--
.../tests/testLinkClicks/testOpenInNewWindow.js | 18 +++----
6 files changed, 105 insertions(+), 17 deletions(-)
diff --git a/tests/mozmill/lib/constants.js b/tests/mozmill/lib/constants.js
new file mode 100644
index 0000000..f5ff7d6
--- /dev/null
+++ b/tests/mozmill/lib/constants.js
@@ -0,0 +1,13 @@
+/* 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/. */
+
+
+const PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow";
+
+const REDIRECT_NOTIFICATION_VALUE = "request-policy-meta-redirect";
+
+
+// Export of variables
+exports.PREF_DEFAULT_ALLOW = PREF_DEFAULT_ALLOW;
+exports.REDIRECT_NOTIFICATION_VALUE = REDIRECT_NOTIFICATION_VALUE;
diff --git a/tests/mozmill/lib/rp-utils.js b/tests/mozmill/lib/rp-utils.js
new file mode 100644
index 0000000..9b60f63
--- /dev/null
+++ b/tests/mozmill/lib/rp-utils.js
@@ -0,0 +1,20 @@
+/* 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/. */
+
+/**
+ * @param {MozMillController} _controller
+ * @param {ElemBase} tab
+ */
+function waitForTabLoad(_controller, tab) {
+ // sleep as a workaround because the "busy" attribute is not present
+ // immediately.
+ _controller.sleep(100);
+
+ assert.waitFor(function() {
+ return !tab.getNode().hasAttribute("busy");
+ }, "The tab has loaded");
+}
+
+// Export of functions
+exports.waitForTabLoad = waitForTabLoad;
diff --git a/tests/mozmill/tests/testLinkClicks/manifest.ini b/tests/mozmill/tests/testLinkClicks/manifest.ini
index 3d0e073..2446c79 100644
--- a/tests/mozmill/tests/testLinkClicks/manifest.ini
+++ b/tests/mozmill/tests/testLinkClicks/manifest.ini
@@ -1,4 +1,5 @@
[parent:../manifest.ini]
+[testNormalLinkClick.js]
[testOpenInNewTab.js]
[testOpenInNewWindow.js]
diff --git a/tests/mozmill/tests/testLinkClicks/testNormalLinkClick.js b/tests/mozmill/tests/testLinkClicks/testNormalLinkClick.js
new file mode 100644
index 0000000..8c863b5
--- /dev/null
+++ b/tests/mozmill/tests/testLinkClicks/testNormalLinkClick.js
@@ -0,0 +1,61 @@
+/* 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 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";
+
+
+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 testNormalLinkClick = function() {
+ controller.open(TEST_URL);
+ controller.waitForPageLoad();
+
+ let link = getLink();
+ let linkURL = link.getNode().href;
+
+ link.click();
+
+ rpUtils.waitForTabLoad(controller, tabBrowser.getTab(0));
+
+ var panel = tabBrowser.getTabPanelElement(0,
+ '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
+ assert.ok(false === panel.exists(),
+ "Following the link didn't cause a redirect");
+
+ 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/testLinkClicks/testOpenInNewTab.js b/tests/mozmill/tests/testLinkClicks/testOpenInNewTab.js
index 94baddf..6884fbd 100644
--- a/tests/mozmill/tests/testLinkClicks/testOpenInNewTab.js
+++ b/tests/mozmill/tests/testLinkClicks/testOpenInNewTab.js
@@ -9,9 +9,8 @@ var prefs = require("../../../../../lib/prefs");
var tabs = require("../../../../../lib/tabs");
var utils = require("../../../../../../lib/utils");
-const PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow";
+var rpConst = require("../../lib/constants");
-const REDIRECT_NOTIFICATION_VALUE = "request-policy-meta-redirect";
const TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -21,11 +20,11 @@ var setupModule = function(aModule) {
aModule.tabBrowser = new tabs.tabBrowser(aModule.controller);
aModule.tabBrowser.closeAllTabs();
- prefs.preferences.setPref(PREF_DEFAULT_ALLOW, false);
+ prefs.preferences.setPref(rpConst.PREF_DEFAULT_ALLOW, false);
}
var teardownModule = function(aModule) {
- prefs.preferences.clearUserPref(PREF_DEFAULT_ALLOW);
+ prefs.preferences.clearUserPref(rpConst.PREF_DEFAULT_ALLOW);
utils.closeContentAreaContextMenu(aModule.controller);
aModule.tabBrowser.closeAllTabs();
}
@@ -103,7 +102,7 @@ var assertCorrectLocations = function(linkURL) {
var assertNoRedirects = function() {
for (let index = 0; index < tabBrowser.length; ++index) {
var panel = tabBrowser.getTabPanelElement(index,
- '/{"value":"' + REDIRECT_NOTIFICATION_VALUE + '"}');
+ '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
assert.ok(false === panel.exists(),
"Following the link didn't cause a redirect");
}
diff --git a/tests/mozmill/tests/testLinkClicks/testOpenInNewWindow.js b/tests/mozmill/tests/testLinkClicks/testOpenInNewWindow.js
index 8f8e4aa..ffef45d 100644
--- a/tests/mozmill/tests/testLinkClicks/testOpenInNewWindow.js
+++ b/tests/mozmill/tests/testLinkClicks/testOpenInNewWindow.js
@@ -9,9 +9,9 @@ var prefs = require("../../../../../lib/prefs");
var tabs = require("../../../../../lib/tabs");
var utils = require("../../../../../../lib/utils");
-const PREF_DEFAULT_ALLOW = "extensions.requestpolicy.defaultPolicy.allow";
+var rpUtils = require("../../lib/rp-utils");
+var rpConst = require("../../lib/constants");
-const REDIRECT_NOTIFICATION_VALUE = "request-policy-meta-redirect";
const TEST_URL = "http://www.maindomain.test/link_1.html";
@@ -23,11 +23,11 @@ var setupModule = function(aModule) {
aModule.tabBrowser.closeAllTabs();
aModule.otherTabBrowser = null;
- prefs.preferences.setPref(PREF_DEFAULT_ALLOW, false);
+ prefs.preferences.setPref(rpConst.PREF_DEFAULT_ALLOW, false);
};
var teardownModule = function(aModule) {
- prefs.preferences.clearUserPref(PREF_DEFAULT_ALLOW);
+ prefs.preferences.clearUserPref(rpConst.PREF_DEFAULT_ALLOW);
utils.closeContentAreaContextMenu(aModule.controller);
aModule.tabBrowser.closeAllTabs();
@@ -57,13 +57,7 @@ var testOpenInNewWindow = function () {
return !!otherController;
}, "Newly opened browser window has been found.");
- // sleep as a workaround because the "busy" attribute is not present
- // immediately.
- controller.sleep(100);
-
- assert.waitFor(function() {
- return !otherTabBrowser.getTab(0).getNode().hasAttribute("busy");
- }, "The tab has loaded");
+ rpUtils.waitForTabLoad(controller, otherTabBrowser.getTab(0));
assert.equal(otherController.tabs.activeTab.location.href, linkURL,
"The location in the new window is correct.");
@@ -139,7 +133,7 @@ var assertNoRedirects = function() {
for (let i = 0; i < tabBrowsers.length; ++i) {
var panel = tabBrowsers[i].getTabPanelElement(0,
- '/{"value":"' + REDIRECT_NOTIFICATION_VALUE + '"}');
+ '/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
assert.ok(false === panel.exists(),
"Following the link didn't cause a redirect");
}
--
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