[Pkg-mozext-commits] [requestpolicy] 39/100: new mozmill tests: follow text-selection links
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 34451749d55d7048651e01248cd030e9f1be0387
Author: myrdd <myrdd at users.noreply.github.com>
Date: Sun Sep 28 14:54:26 2014 +0200
new mozmill tests: follow text-selection links
---
tests/link_1.html | 4 +-
tests/mozmill/lib/rp-utils.js | 9 ++
tests/mozmill/tests/testLinks/manifest.ini | 1 +
.../testHTMLAnchorElement/testLinkClick.js | 3 +-
.../testHTMLAnchorElement/testOpenInNewTab.js | 2 +-
.../tests/testLinks/testTextSelection/manifest.ini | 5 +
.../testOpenInCurrentTab.js} | 34 +++---
.../testOpenInNewTab.js | 63 +++-------
.../testTextSelection/testOpenInNewWindow.js | 132 +++++++++++++++++++++
9 files changed, 179 insertions(+), 74 deletions(-)
diff --git a/tests/link_1.html b/tests/link_1.html
index 4614ed4..4707dd8 100644
--- a/tests/link_1.html
+++ b/tests/link_1.html
@@ -16,11 +16,11 @@
<br /><br />
<div style="margin : 100px 0 0 100px">
-http://www.otherdomain.test
+<span id="text_url_1">http://www.otherdomain.test/destination.html</span>
</div>
<div style="margin : 100px 0 0 100px">
-http://www.otherdomain.test/
+<span id="text_url_2">http://www.otherdomain.test</span>
</div>
</body>
diff --git a/tests/mozmill/lib/rp-utils.js b/tests/mozmill/lib/rp-utils.js
index 9b60f63..249dacd 100644
--- a/tests/mozmill/lib/rp-utils.js
+++ b/tests/mozmill/lib/rp-utils.js
@@ -16,5 +16,14 @@ function waitForTabLoad(_controller, tab) {
}, "The tab has loaded");
}
+function selectText(_tabBrowser, text) {
+ var findBar = _tabBrowser.findBar;
+ findBar.open();
+ findBar.search(text);
+ findBar.value = "";
+ findBar.close(true);
+}
+
// Export of functions
exports.waitForTabLoad = waitForTabLoad;
+exports.selectText = selectText;
diff --git a/tests/mozmill/tests/testLinks/manifest.ini b/tests/mozmill/tests/testLinks/manifest.ini
index 9bfbaef..51af283 100644
--- a/tests/mozmill/tests/testLinks/manifest.ini
+++ b/tests/mozmill/tests/testLinks/manifest.ini
@@ -1,3 +1,4 @@
[parent:../manifest.ini]
[include:testHTMLAnchorElement/manifest.ini]
+[include:testTextSelection/manifest.ini]
diff --git a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
index 3076a35..9160c00 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
+++ b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
@@ -7,7 +7,6 @@
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");
@@ -29,7 +28,7 @@ var teardownModule = function(aModule) {
}
-var testNormalLinkClick = function() {
+var testLinkClick = function() {
controller.open(TEST_URL);
controller.waitForPageLoad();
diff --git a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
index f3534fe..b876a66 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
+++ b/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
@@ -30,7 +30,7 @@ var teardownModule = function(aModule) {
}
-var testOpenInBackgroundTab = function() {
+var testOpenInNewTab = function() {
controller.open(TEST_URL);
controller.waitForPageLoad();
diff --git a/tests/mozmill/tests/testLinks/testTextSelection/manifest.ini b/tests/mozmill/tests/testLinks/testTextSelection/manifest.ini
new file mode 100644
index 0000000..493f115
--- /dev/null
+++ b/tests/mozmill/tests/testLinks/testTextSelection/manifest.ini
@@ -0,0 +1,5 @@
+[parent:../manifest.ini]
+
+[testOpenInCurrentTab.js]
+[testOpenInNewTab.js]
+[testOpenInNewWindow.js]
diff --git a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js b/tests/mozmill/tests/testLinks/testTextSelection/testOpenInCurrentTab.js
similarity index 63%
copy from tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
copy to tests/mozmill/tests/testLinks/testTextSelection/testOpenInCurrentTab.js
index 3076a35..39bc337 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testLinkClick.js
+++ b/tests/mozmill/tests/testLinks/testTextSelection/testOpenInCurrentTab.js
@@ -7,7 +7,6 @@
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");
@@ -29,33 +28,28 @@ var teardownModule = function(aModule) {
}
-var testNormalLinkClick = function() {
+var testOpenInCurrentTab = function() {
+ var tabIndex = tabBrowser.selectedIndex;
+
controller.open(TEST_URL);
controller.waitForPageLoad();
- let link = getLink();
- let linkURL = link.getNode().href;
+ let textURL = findElement.ID(controller.window.document, "text_url_1");
+ let textURLValue = textURL.getNode().textContent;
+
+ rpUtils.selectText(tabBrowser, textURLValue);
- link.click();
+ // perform right-click and entry selection
+ var contextMenu = controller.getMenu("#contentAreaContextMenu");
+ contextMenu.select("#context-openlinkincurrent", textURL);
- rpUtils.waitForTabLoad(controller, tabBrowser.getTab(0));
+ rpUtils.waitForTabLoad(controller, tabBrowser.getTab(tabIndex));
- var panel = tabBrowser.getTabPanelElement(0,
+ var panel = tabBrowser.getTabPanelElement(tabIndex,
'/{"value":"' + rpConst.REDIRECT_NOTIFICATION_VALUE + '"}');
assert.ok(false === panel.exists(),
- "Following the link didn't cause a redirect");
+ "Following the URL didn't cause a redirect");
- assert.equal(controller.tabs.activeTab.location.href, linkURL,
+ assert.equal(controller.tabs.activeTab.location.href, textURLValue,
"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/testLinks/testHTMLAnchorElement/testOpenInNewTab.js b/tests/mozmill/tests/testLinks/testTextSelection/testOpenInNewTab.js
similarity index 59%
copy from tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
copy to tests/mozmill/tests/testLinks/testTextSelection/testOpenInNewTab.js
index f3534fe..e8710ef 100644
--- a/tests/mozmill/tests/testLinks/testHTMLAnchorElement/testOpenInNewTab.js
+++ b/tests/mozmill/tests/testLinks/testTextSelection/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";
@@ -16,7 +17,6 @@ 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();
@@ -30,61 +30,27 @@ var teardownModule = function(aModule) {
}
-var testOpenInBackgroundTab = function() {
+var testOpenInNewTab = function() {
+ var tabIndex = tabBrowser.selectedIndex;
+
controller.open(TEST_URL);
controller.waitForPageLoad();
- let link = getLink();
- let linkURL = link.getNode().href;
+ let textURL = findElement.ID(controller.window.document, "text_url_1");
+ let textURLValue = textURL.getNode().textContent;
- let i = 1;
- while (true === openNextTab(i, link)) {
- // Check that i+1 tabs are open
- assert.waitFor(function () {
- return tabBrowser.length === (i + 1);
- }, "Tab " + (i + 1) + " opened.");
- ++i;
- }
-
- assertCorrectLocations(linkURL);
- assertNoRedirects();
-}
+ rpUtils.selectText(tabBrowser, textURLValue);
+ // perform right-click and entry selection
+ var contextMenu = controller.getMenu("#contentAreaContextMenu");
+ contextMenu.select("#context-openlinkintab", textURL);
-/**
- * @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.");
+ assert.waitFor(() => { return tabBrowser.length == 2; }, "New Tab opened.");
- return findElement.Elem(links[0]);
-}
+ rpUtils.waitForTabLoad(controller, tabBrowser.getTab(tabIndex));
-/**
- * Opens the next tab.
- * @return {boolean}
- * true if a new tab has been opened.
- * false if no tab needs to open anymore.
- */
-var openNextTab = function(i, link) {
- switch (i) {
- case 1:
- // Open another tab by middle-clicking on the link
- tabBrowser.openTab({method: "middleClick", target: link});
- return true;
- break;
-
- case 2:
- // Open link via context menu in a new tab:
- tabBrowser.openTab({method: "contextMenu", target: link});
- return true;
- break;
-
- default:
- return false;
- break;
- }
+ assertNoRedirects();
+ assertCorrectLocations(textURLValue);
}
var assertCorrectLocations = function(linkURL) {
@@ -95,7 +61,6 @@ var assertCorrectLocations = function(linkURL) {
}
}
-
/**
* Assert that the link clicks have not been detected as redirects.
*/
diff --git a/tests/mozmill/tests/testLinks/testTextSelection/testOpenInNewWindow.js b/tests/mozmill/tests/testLinks/testTextSelection/testOpenInNewWindow.js
new file mode 100644
index 0000000..ef57594
--- /dev/null
+++ b/tests/mozmill/tests/testLinks/testTextSelection/testOpenInNewWindow.js
@@ -0,0 +1,132 @@
+/* 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.otherController = null;
+
+ aModule.tabBrowser = new tabs.tabBrowser(aModule.controller);
+ aModule.tabBrowser.closeAllTabs();
+ aModule.otherTabBrowser = null;
+
+ prefs.preferences.setPref(rpConst.PREF_DEFAULT_ALLOW, false);
+};
+
+var teardownModule = function(aModule) {
+ prefs.preferences.clearUserPref(rpConst.PREF_DEFAULT_ALLOW);
+ utils.closeContentAreaContextMenu(aModule.controller);
+ aModule.tabBrowser.closeAllTabs();
+
+ closeWindow(aModule.otherController);
+};
+
+var testOpenInNewWindow = function () {
+ controller.open(TEST_URL);
+ controller.waitForPageLoad();
+
+ let textURL = findElement.ID(controller.window.document, "text_url_1");
+ let textURLValue = textURL.getNode().textContent;
+
+ rpUtils.selectText(tabBrowser, textURLValue);
+
+ let i = 1;
+ while (true === openNextWindow(i, textURL)) {
+ assert.waitFor(function () {
+ // Make sure that we work on the correct window
+ var windows = mozmill.utils.getWindows("navigator:browser");
+ for (var j = 0; j < windows.length; ++j) {
+ if (windows[j] !== controller.window) {
+ otherController = new mozmill.controller.MozMillController(windows[j]);
+ otherTabBrowser = new tabs.tabBrowser(otherController);
+ break;
+ }
+ }
+
+ return !!otherController;
+ }, "Newly opened browser window has been found.");
+
+ rpUtils.waitForTabLoad(controller, otherTabBrowser.getTab(0));
+
+ assert.equal(otherController.tabs.activeTab.location.href, textURLValue,
+ "The location in the new window is correct.");
+
+ assertNoRedirects();
+ closeWindow(otherController);
+ otherController = null;
+ otherTabBrowser = null;
+ ++i;
+ }
+};
+
+var closeWindow = function(_controller) {
+ if (_controller && _controller.window) {
+ _controller.window.close();
+ }
+};
+
+
+/**
+ * Opens the next tab.
+ * @return {boolean}
+ * true if a new tab has been opened.
+ * false if no tab needs to open anymore.
+ */
+var openNextWindow = function(i, textURL) {
+ var contextMenuItemID;
+
+ switch (i) {
+ case 1:
+ // Context Menu: Open Link in New Window
+ contextMenuItemID = "#context-openlink";
+ break;
+
+ case 2:
+ // Context Menu: Open Link in New Private Window
+ contextMenuItemID = "#context-openlinkprivate";
+ break;
+
+ default:
+ return false;
+ break;
+ }
+
+ // There seems to be a bug in Mozmill: the right-click is not performed the
+ // second time. The workaround seems to be to wait for some miliseconds before
+ // continuing. I set the timeout to 100 ms. If this time is still not enough
+ // for anybody, simply increase it.
+ // It seemed that this bug has to do with the focus. However, the
+ // HTMLElement.blur() function doesn't work for <a> Elements.
+ controller.sleep(100);
+
+ var contextMenu = controller.getMenu("#contentAreaContextMenu");
+ contextMenu.select(contextMenuItemID, textURL);
+ return true;
+};
+
+/**
+ * Assert that the link clicks have not been detected as redirects.
+ */
+var assertNoRedirects = function() {
+ var tabBrowsers = [tabBrowser, otherTabBrowser];
+
+ for (let i = 0; i < tabBrowsers.length; ++i) {
+ var panel = tabBrowsers[i].getTabPanelElement(0,
+ '/{"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