Repository: wicket
Updated Branches:
  refs/heads/wicket-7.x 1e4527dad -> 837b6b147


WICKET-6376: allow non-http(s) uris in ajax redirects

Add JS unit tests

(cherry picked from commit 0491709c1ad9720f120ed7ecad21d205c8be5470)


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3c9985ec
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3c9985ec
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3c9985ec

Branch: refs/heads/wicket-7.x
Commit: 3c9985ec5c2ce7526de5fe75afb959ca8849719c
Parents: 1e4527d
Author: Martin Tzvetanov Grigorov <[email protected]>
Authored: Thu Jun 1 00:04:11 2017 +0200
Committer: Martin Tzvetanov Grigorov <[email protected]>
Committed: Thu Jun 1 00:07:05 2017 +0200

----------------------------------------------------------------------
 wicket-core/src/test/js/ajax.js | 108 +++++++++++++++++++++++++++++++++++
 1 file changed, 108 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/3c9985ec/wicket-core/src/test/js/ajax.js
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/js/ajax.js b/wicket-core/src/test/js/ajax.js
index b124290..def9477 100644
--- a/wicket-core/src/test/js/ajax.js
+++ b/wicket-core/src/test/js/ajax.js
@@ -1392,5 +1392,113 @@ jQuery(document).ready(function() {
                        target.off("event1");
                });
 
+               asyncTest('processAjaxResponse, normal HTTP case.', function () 
{
+
+                       expect(2);
+
+                       var originalProcessAjaxResponse = 
Wicket.Ajax.Call.prototype.processAjaxResponse,
+                               originalRedirect = Wicket.Ajax.redirect;
+
+                       Wicket.Ajax.Call.prototype.processAjaxResponse = 
function(data, textStatus, jqXHR, context) {
+                               var mockJqXHR = {
+                                       "readyState": 4,
+                                       getResponseHeader: function 
(headerName) {
+                                               if ('Ajax-Location' === 
headerName) {
+                                                       
Wicket.Ajax.Call.prototype.processAjaxResponse = originalProcessAjaxResponse;
+                                                       return 'http://a.b.c';
+                                               }
+                                               return 
jqXHR.getResponseHeader(headerName);
+                                       }
+                               };
+                               
originalProcessAjaxResponse.call(Wicket.Ajax.Call.prototype, data, textStatus, 
mockJqXHR, context);
+                       };
+
+                       Wicket.Ajax.redirect = function(location) {
+                               Wicket.Ajax.Call.prototype.processAjaxResponse 
= originalProcessAjaxResponse;
+                               Wicket.Ajax.redirect = originalRedirect;
+                               start();
+                               equal(location, 'http://a.b.c', 'Custom HTTP 
address is properly handled');
+                       };
+
+
+                       var attrs = {
+                               u: 'data/ajax/componentId.xml',
+                               c: 'componentId'
+                       };
+
+                       execute(attrs);
+               });
+
+               asyncTest('processAjaxResponse, chrome-extensions case.', 
function () {
+
+                       expect(2);
+
+                       var originalProcessAjaxResponse = 
Wicket.Ajax.Call.prototype.processAjaxResponse,
+                               originalRedirect = Wicket.Ajax.redirect;
+
+                       Wicket.Ajax.Call.prototype.processAjaxResponse = 
function(data, textStatus, jqXHR, context) {
+                               var mockJqXHR = {
+                                       "readyState": 4,
+                                       getResponseHeader: function 
(headerName) {
+                                               if ('Ajax-Location' === 
headerName) {
+                                                       
Wicket.Ajax.Call.prototype.processAjaxResponse = originalProcessAjaxResponse;
+                                                       return 
'chrome-extensions://a.b.c';
+                                               }
+                                               return 
jqXHR.getResponseHeader(headerName);
+                                       }
+                               };
+                               
originalProcessAjaxResponse.call(Wicket.Ajax.Call.prototype, data, textStatus, 
mockJqXHR, context);
+                       };
+
+                       Wicket.Ajax.redirect = function(location) {
+                               Wicket.Ajax.Call.prototype.processAjaxResponse 
= originalProcessAjaxResponse;
+                               Wicket.Ajax.redirect = originalRedirect;
+                               start();
+                               equal(location, 'chrome-extensions://a.b.c', 
'Custom chrome-extensions address is properly handled');
+                       };
+
+                       var attrs = {
+                               u: 'data/ajax/componentId.xml',
+                               c: 'componentId'
+                       };
+
+                       execute(attrs);
+               });
+
+               asyncTest('processAjaxResponse, no scheme case.', function () {
+
+                       expect(2);
+
+                       var originalProcessAjaxResponse = 
Wicket.Ajax.Call.prototype.processAjaxResponse,
+                               originalRedirect = Wicket.Ajax.redirect;
+
+                       Wicket.Ajax.Call.prototype.processAjaxResponse = 
function(data, textStatus, jqXHR, context) {
+                               var mockJqXHR = {
+                                       "readyState": 4,
+                                       getResponseHeader: function 
(headerName) {
+                                               if ('Ajax-Location' === 
headerName) {
+                                                       
Wicket.Ajax.Call.prototype.processAjaxResponse = originalProcessAjaxResponse;
+                                                       return 
'location-without-scheme';
+                                               }
+                                               return 
jqXHR.getResponseHeader(headerName);
+                                       }
+                               };
+                               
originalProcessAjaxResponse.call(Wicket.Ajax.Call.prototype, data, textStatus, 
mockJqXHR, context);
+                       };
+
+                       Wicket.Ajax.redirect = function(location) {
+                               Wicket.Ajax.Call.prototype.processAjaxResponse 
= originalProcessAjaxResponse;
+                               Wicket.Ajax.redirect = originalRedirect;
+                               start();
+                               ok(location.indexOf('location-without-scheme') 
> 0, 'Custom address without scheme is properly handled');
+                       };
+
+                       var attrs = {
+                               u: 'data/ajax/componentId.xml',
+                               c: 'componentId'
+                       };
+
+                       execute(attrs);
+               });
        }
 });

Reply via email to