diff --git a/src/session.js b/src/session.js index 12f645c03..f579917d8 100644 --- a/src/session.js +++ b/src/session.js @@ -186,12 +186,12 @@ ghostdriver.Session = function(desiredCapabilities) { } if (k.indexOf(_capsPageBlacklistPref) === 0) { const pageBlacklist = []; - const len = desiredCapabilities[k].length; - for(var i = 0; i < len; i++) { + const pageBlacklistLength = desiredCapabilities[k].length; + for(var i = 0; i < pageBlacklistLength; i++) { pageBlacklist.push(new RegExp(desiredCapabilities[k][i])); } _pageBlacklistFilter = function(url, net) { - for(var i = 0; i < len; i++) { + for(var i = 0; i < pageBlacklistLength; i++) { if(url.search(pageBlacklist[i]) !== -1) { net.abort(); _log.debug("blacklist abort " + url); @@ -201,17 +201,18 @@ ghostdriver.Session = function(desiredCapabilities) { } if (k.indexOf(_capsPageWhitelistPref) === 0) { const pageWhitelist = []; - const len2 = desiredCapabilities[k].length; - for(var i = 0; i < len; i++) { + const pageWhitelistLength = desiredCapabilities[k].length; + for(var i = 0; i < pageWhitelistLength; i++) { pageWhitelist.push(new RegExp(desiredCapabilities[k][i])); } _pageWhitelistFilter = function(url, net) { - for(var i = 0; i < len2; i++) { - if(url.search(pageWhitelist[i]) === -1) { - net.abort(); - _log.debug("whitelist abort " + url); + for(var i = 0; i < pageWhitelistLength; i++) { + if(url.search(pageWhitelist[i]) !== -1) { + return; } } + net.abort(); + _log.debug("whitelist abort " + url); } } if (k.indexOf(_capsPageSettingsProxyPref) === 0) { diff --git a/test/java/src/test/java/BlacklistWhitelistTest.java b/test/java/src/test/java/BlacklistWhitelistTest.java new file mode 100644 index 000000000..513239918 --- /dev/null +++ b/test/java/src/test/java/BlacklistWhitelistTest.java @@ -0,0 +1,57 @@ +/* +This file is part of the GhostDriver by Ivan De Marino . + +Copyright (c) 2017, Jason Gowan +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +package ghostdriver; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.openqa.selenium.WebDriver; + +import java.util.Arrays; + +public class BlacklistWhitelistTest extends BaseTest { + @BeforeClass + public static void setBlacklistWhitelistCapabilities() { + sCaps.setCapability( + "phantomjs.page.blacklist", + Arrays.asList("png$") + ); + sCaps.setCapability( + "phantomjs.page.whitelist", + Arrays.asList("^https:..github.com", "^https:..assets-cdn.github.com") + ); + } + + @Test + public void testBlacklistWhitelistCapabilities() { + WebDriver d = getDriver(); + + d.get("https://github.com"); + // need some way to verify + } + +}