Files
cappuccino/Tests/Manual/CrossOriginTest/AppController.j
T
Andrew Hankinson 642dc36c41 Test: Cross Origin Manual Test
This commit adds a manual testing application for checking Cross-origin behaviour in different browsers. A README file included in this application provides details on how to run the tests.
2014-12-09 16:07:43 -05:00

79 lines
2.3 KiB
Plaintext

/*
* AppController.j
* CrossOriginTest
*
* Created by You on December 5, 2014.
* Copyright 2014, Your Company All rights reserved.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
var corsServer = "http://localhost:8001";
@implementation AppController : CPObject
{
@outlet CPWindow theWindow;
@outlet CPButton theButton;
@outlet CPButton setsWithCredentials;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
// In this case, we want the window from Cib to become our full browser window
[theWindow setFullPlatformWindow:YES];
}
-(void)connection:(CPURLConnection)connection didReceiveResponse:(CPHTTPURLResponse)response
{
console.log("Response received");
}
-(void)connection:(CPURLConnection)connection didReceiveData:(CPString)data
{
var wc = ([[connection originalRequest] withCredentials]) ? "YES" : "NO"
console.log("CPURLConnection was sent with credentials? " + wc + " Response: " + data);
}
- (@action)stateOfWithCredentials:(id)aSender
{
console.log([setsWithCredentials state]);
}
- (@action)testCappuccinoRequest:(id)aSender
{
var req = [CPURLRequest requestWithURL:[CPURL URLWithString:corsServer + @"/resp.json"]];
[req setValue:@"no-cache" forHTTPHeaderField:@"Pragma"];
[req setValue:@"no-store, no-cache, must-revalidate, post-check=0, pre-check=0" forHTTPHeaderField:@"Cache-Control"];
[req setWithCredentials:[setsWithCredentials state]];
[[CPURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];
}
- (@action)testNativeRequest:(id)aSender
{
var wc = ([setsWithCredentials state]) ? true : false;
var req = new XMLHttpRequest();
function reqListener ()
{
console.log("Native XHR was sent with credentials? " + wc + " Response: " + this.responseText);
}
req.onload = reqListener;
req.withCredentials = wc;
req.open("GET", corsServer + "/resp.json", true);
req.setRequestHeader("Pragma", "no-cache");
req.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
req.send();
}
@end