Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Commit

Permalink
include unwanted urls just once
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderadam committed Jan 22, 2014
1 parent 310da07 commit a23cfab
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/capybara/poltergeist/client/browser.coffee
Expand Up @@ -318,7 +318,7 @@ class Poltergeist.Browser
this.sendResponse(true)

blocked_urls: ->
@page.blockedUrls()
this.sendResponse(@page.blockedUrls())

clear_blocked_urls: ->
@page.clearBlockedUrls()
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/poltergeist/client/compiled/browser.js
Expand Up @@ -428,7 +428,7 @@ Poltergeist.Browser = (function() {
};

Browser.prototype.blocked_urls = function() {
return this.page.blockedUrls();
return this.sendResponse(this.page.blockedUrls());
};

Browser.prototype.clear_blocked_urls = function() {
Expand Down
8 changes: 6 additions & 2 deletions lib/capybara/poltergeist/client/compiled/web_page.js
@@ -1,4 +1,5 @@
var __slice = [].slice;
var __slice = [].slice,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

Poltergeist.WebPage = (function() {
var command, delegate, _fn, _fn1, _i, _j, _len, _len1, _ref, _ref1,
Expand Down Expand Up @@ -119,9 +120,12 @@ Poltergeist.WebPage = (function() {
};

WebPage.prototype.onResourceRequestedNative = function(requestData, networkRequest) {
var _ref2;
if (this.hasOwnProperty('evalOnResourceRequested') && !this.evalOnResourceRequested(requestData)) {
this._blockedUrls || (this._blockedUrls = []);
this._blockedUrls.push(requestData.url);
if (_ref2 = requestData.url, __indexOf.call(this._blockedUrls, _ref2) < 0) {
this._blockedUrls.push(requestData.url);
}
networkRequest.abort();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/poltergeist/client/web_page.coffee
Expand Up @@ -74,7 +74,7 @@ class Poltergeist.WebPage
onResourceRequestedNative: (requestData, networkRequest) ->
if this.hasOwnProperty('evalOnResourceRequested') && !this.evalOnResourceRequested(requestData)
@_blockedUrls ||= []
@_blockedUrls.push requestData.url
@_blockedUrls.push requestData.url unless requestData.url in @_blockedUrls
networkRequest.abort()
return

Expand Down
2 changes: 2 additions & 0 deletions spec/integration/driver_spec.rb
Expand Up @@ -714,6 +714,8 @@ def create_screenshot(file, *args)
JS
@session.visit('/poltergeist/resource_requested_test')
expect(@session.status_code).to eq(200)

expect(@driver.browser.blocked_urls.first).to end_with('unwanted')
expect(@session).to have_content('We are loading some unwanted action here')
@session.within_frame 'framename' do
expect(@session.html).not_to include('We shouldn\'t see this.')
Expand Down

0 comments on commit a23cfab

Please sign in to comment.