This repository has been archived by the owner on Nov 23, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test framework, testcases, and update README on testing
- Loading branch information
Showing
10 changed files
with
614 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "test/qunit"] | ||
path = test/qunit | ||
url = git://github.com/jquery/qunit.git | ||
[submodule "test/sinon"] | ||
path = test/sinon | ||
url = git://github.com/cjohansen/Sinon.JS.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>google-oauth2-web-client tests</title> | ||
<link rel="stylesheet" href="qunit/qunit/qunit.css"> | ||
</head> | ||
<body> | ||
<div id="qunit"></div> | ||
<script src="qunit/qunit/qunit.js"></script> | ||
|
||
<!-- sinon --> | ||
<script src="sinon/lib/sinon.js"></script> | ||
<script src="sinon/lib/sinon/spy.js"></script> | ||
|
||
<!-- script to test --> | ||
<script src="../src/google-oauth2.js"></script> | ||
|
||
<!-- testinit --> | ||
<script src="testinit.js"></script> | ||
|
||
<!-- test scripts --> | ||
<script src="unit/basics.js"></script> | ||
<script src="unit/initiation.js"></script> | ||
<script src="integration/interactive.js"></script> | ||
<script src="integration/immediate.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
module('Immediate login integration'); | ||
|
||
test('successful login should trigger onlogin callback', function () { | ||
var client_id = localhost_client_id; | ||
|
||
var returnValue = window.GO2.init({ | ||
client_id: client_id, | ||
scope: localhost_scope, | ||
redirect_uri: localhost_redirect_uri | ||
}); | ||
equal(returnValue, true, 'init() returns true.'); | ||
|
||
window.GO2.login(false, true); | ||
|
||
stop(); | ||
|
||
window.GO2.onlogin = function (token) { | ||
window.GO2.onlogin = null; | ||
ok(!!token, 'Got token from onlogin: ' + token); | ||
|
||
start(); | ||
}; | ||
}); | ||
|
||
test('when logged in, GO2.getAccessToken() should return the token', function () { | ||
var token = window.GO2.getAccessToken(); | ||
ok(!!token, 'Pass with token:' + token); | ||
}); | ||
|
||
test('GO2.logout() should trigger onlogout callback', function () { | ||
stop(); | ||
|
||
window.GO2.onlogout = function () { | ||
window.GO2.onlogout = null; | ||
ok(true, 'Passed!'); | ||
|
||
start(); | ||
}; | ||
window.GO2.logout(); | ||
}); | ||
|
||
test('when logged out, GO2.getAccessToken() should not return the token', function () { | ||
var token = window.GO2.getAccessToken(); | ||
ok(!token, 'Not getting token.'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
module('Interactive login integration'); | ||
|
||
test('successful login should trigger onlogin callback', function () { | ||
var client_id = localhost_client_id; | ||
|
||
var returnValue = window.GO2.init({ | ||
client_id: client_id, | ||
scope: localhost_scope, | ||
redirect_uri: localhost_redirect_uri | ||
}); | ||
equal(returnValue, true, 'init() returns true.'); | ||
|
||
window.GO2.login(); | ||
|
||
stop(); | ||
window.GO2.onlogin = function (token) { | ||
window.GO2.onlogin = null; | ||
ok(!!token, 'Got token from onlogin: ' + token); | ||
|
||
start(); | ||
}; | ||
}); | ||
|
||
test('when logged in, GO2.getAccessToken() should return the token', function () { | ||
var token = window.GO2.getAccessToken(); | ||
ok(!!token, 'Pass with token:' + token); | ||
}); | ||
|
||
test('GO2.logout() should trigger onlogout callback', function () { | ||
stop(); | ||
|
||
window.GO2.onlogout = function () { | ||
window.GO2.onlogout = null; | ||
ok(true, 'Passed!'); | ||
|
||
start(); | ||
}; | ||
window.GO2.logout(); | ||
}); | ||
|
||
test('when logged out, GO2.getAccessToken() should not return the token', function () { | ||
var token = window.GO2.getAccessToken(); | ||
ok(!token, 'Not getting token.'); | ||
}); |
Submodule qunit
added at
900f72
Submodule sinon
added at
4fa7a7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
var localhost_client_id = '519733320959.apps.googleusercontent.com'; | ||
var localhost_scope = ['https://www.googleapis.com/auth/userinfo.profile', | ||
'https://www.googleapis.com/auth/userinfo.email']; | ||
var localhost_redirect_uri = 'http://127-0-0-1.org.uk:8009/test/'; | ||
|
||
// The fake one allows Google to show an error page without log us in automatically | ||
var fake_client_id = 'not-valid.apps.googleusercontent.com'; | ||
|
||
var apiUrl = 'https://accounts.google.com/o/oauth2/auth'; | ||
var defaultScope = 'https://www.googleapis.com/auth/plus.me'; | ||
|
||
function splitUrlArgs(urlArgs) { | ||
var urlArgKeys = []; | ||
var urlArgValues = []; | ||
|
||
urlArgs.split('&').forEach(function (keyValue) { | ||
var kv = keyValue.split('='); | ||
urlArgKeys.push(kv.shift()); | ||
urlArgValues.push(decodeURIComponent(kv.join(''))); | ||
}); | ||
|
||
return { | ||
keys: urlArgKeys, | ||
values: urlArgValues | ||
}; | ||
} | ||
|
||
test('Testing environment test', function () { | ||
var win = window.open(''); | ||
equal(typeof win, 'object', 'Popup blocker is not in-effect'); | ||
if (win && win.close) | ||
win.close(); | ||
|
||
equal(window.location.href.substr(0, localhost_redirect_uri.length), localhost_redirect_uri, | ||
'Integration will work; test is running on presumed URL.'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
module('Basics'); | ||
|
||
test('GO2 object exists', function () { | ||
equal(typeof window.GO2, 'object', 'Passed!'); | ||
}); | ||
|
||
test('GO2.init function exists', function () { | ||
equal(typeof window.GO2.init, 'function', 'Passed!'); | ||
}); | ||
|
||
test('GO2.login function exists', function () { | ||
equal(typeof window.GO2.login, 'function', 'Passed!'); | ||
}); | ||
|
||
test('GO2.logout function exists', function () { | ||
equal(typeof window.GO2.logout, 'function', 'Passed!'); | ||
}); | ||
|
||
test('GO2.getAccessToken function exists', function () { | ||
equal(typeof window.GO2.getAccessToken, 'function', 'Passed!'); | ||
}); |
Oops, something went wrong.