Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
Adding manual test for chrome.identity
Browse files Browse the repository at this point in the history
  • Loading branch information
mmocny committed Feb 27, 2014
1 parent e34de5f commit 08f2d17
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 8 deletions.
Binary file removed chrome-apps-api-tests/assets/icons/icon128.png
Binary file not shown.
Binary file removed chrome-apps-api-tests/assets/icons/icon16.png
Binary file not shown.
Binary file removed chrome-apps-api-tests/assets/icons/icon48.png
Binary file not shown.
1 change: 1 addition & 0 deletions chrome-apps-api-tests/index.html
Expand Up @@ -39,6 +39,7 @@
<!-- Manual Test scripts -->
<script type="text/javascript" src="tests/manual/manual.chrome.embed.js"></script>
<script type="text/javascript" src="tests/manual/manual.chrome.fileSystem.js"></script>
<script type="text/javascript" src="tests/manual/manual.chrome.identity.js"></script>
<script type="text/javascript" src="tests/manual/manual.chrome.idle.js"></script>
<script type="text/javascript" src="tests/manual/manual.chrome.notifications.js"></script>
<script type="text/javascript" src="tests/manual/manual.chrome.power.js"></script>
Expand Down
24 changes: 18 additions & 6 deletions chrome-apps-api-tests/manifest.json
@@ -1,14 +1,13 @@
{
"name": "Chrome Apps Api Tests",
"description": "New style tests, shared with cordova",
"description": "Auto and Manual testing of chrome APIs, for desktop and mobile",
"manifest_version": 2,
"minimum_chrome_version": "23",
"version": "0.1.1",
"version": "0.2.0",
"offline_enabled": true,
"icons": {
"16": "assets/icons/icon16.png",
"48": "assets/icons/icon48.png",
"128": "assets/icons/icon128.png"
"16": "assets/icon-128x128.png",
"128": "assets/icon-128x128.png"
},
"app": {
"background": {
Expand All @@ -33,6 +32,19 @@
"http://127.0.0.1/*",
"https://www.googleapis.com/*"
],
"default_locale": "fr"
"default_locale": "fr",

"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCq7U5RoVWf4rUqCS+VDN1lNffuc1BfodrsjUBv6BDeqRust5ePjbsDBzmW6aUjgwhb38WIJNihOqLl7HRYlG4F25FjiK+GUwM3zCfZFgJpKmakuofpSEmkkoniHTcuqGKpQn2o9j5lPom7iM0Dq2LdN+WTDc0qe0/2Ndp3SH+A0QIDAQAB",

"oauth2": {
"client_id": "545713885199-6h5bad5od8r86prjv5t2r8oudkivc5ph.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/calendar.readonly",
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/gcm_for_chrome",
"https://www.googleapis.com/auth/gcm_for_chrome.readonly"
]
}
}
10 changes: 8 additions & 2 deletions chrome-apps-api-tests/manifest.mobile.json
@@ -1,5 +1,11 @@
{
"packageId": "org.chromium.apps.ChromeAppsApiTests",
"versionCode": 1,
"CFBundleVersion": '1.1.1',
"versionCode": 2,
"CFBundleVersion": '0.2.0',

"senderId": "429153676186", // pushMessaging
"incoming_sync_delay": { // syncFileSystem
"initial": 2000,
"maximum": 64000
}
}
158 changes: 158 additions & 0 deletions chrome-apps-api-tests/tests/manual/manual.chrome.identity.js
@@ -0,0 +1,158 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

registerManualTests('chrome.identity', function(rootEl, addButton) {
function hitEndpoint(endpoint, callback) {
var onGetAuthTokenSuccess = function(token) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
callback(JSON.parse(xhr.responseText));
} else {
console.log('Failed with status ' + xhr.status + '.');
console.log('Response text: ' + JSON.stringify(xhr.responseText));
}
}
};
xhr.open('GET', endpoint);
xhr.setRequestHeader('Authorization', 'Bearer ' + token);
xhr.send(null);
};

chrome.identity.getAuthToken({ interactive: true }, onGetAuthTokenSuccess);
}

addButton('Get auth token', function() {
var callback = function(token) {
if (!token) {
console.log('Failed to get a token. lastError = ' + JSON.stringify(chrome.runtime.lastError));
} else {
console.log('Token: ' + token);
}
};

chrome.identity.getAuthToken({ interactive: true }, callback);
});

addButton('Remove cached auth token', function() {
var onRemoveCachedAuthTokenSuccess = function() {
console.log('Token removed from cache.');
};

var onInitialGetAuthTokenSuccess = function(token) {
console.log('Removing token ' + token + ' from cache.');

// Remove the token!
chrome.identity.removeCachedAuthToken({ token: token }, onRemoveCachedAuthTokenSuccess);
};

// First, we need to get the existing auth token.
chrome.identity.getAuthToken({ interactive: true }, onInitialGetAuthTokenSuccess);
});

addButton('Revoke auth token', function() {
var onRevokeAuthTokenSuccess = function() {
console.log('Token revoked.');
};

var onInitialGetAuthTokenSuccess = function(token) {
console.log('Revoking token ' + token + '.');

// Revoke the token!
chrome.identity.revokeAuthToken({ token: token }, onRevokeAuthTokenSuccess);
};

// First, we need to get the existing auth token.
chrome.identity.getAuthToken({ interactive: true }, onInitialGetAuthTokenSuccess);
});

addButton('Get name via Google\'s User Info API', function() {
hitEndpoint('https://www.googleapis.com/oauth2/v3/userinfo', function(response) {
console.log('Name: ' + response.name);
});
});

addButton('Get name via Google\'s Drive API', function() {
hitEndpoint('https://www.googleapis.com/drive/v2/about', function(response) {
console.log('Name: ' + response.name);
});
});

addButton('Get files via Google\'s Drive API', function() {
hitEndpoint('https://www.googleapis.com/drive/v2/files', function(response) {
var fileCount = response.items.length;
var cappedCount = (fileCount <= 3) ? fileCount : 3;
console.log('Files (' + cappedCount + ' of ' + fileCount + '):');
for (var i = 0; i < cappedCount; i++) {
console.log(' ' + response.items[i].title);
}
});
});

addButton('Get calendars via Google\'s Calendar API', function() {
hitEndpoint('https://www.googleapis.com/calendar/v3/users/me/calendarList', function(response) {
var calendarCount = response.items.length;
var cappedCount = (calendarCount <= 3) ? calendarCount : 3;
console.log('Calendars (' + cappedCount + ' of ' + calendarCount + '):');
for (var i = 0; i < cappedCount; i++) {
console.log(' ' + response.items[i].summary);
}
});
});

addButton('Get playlists via Google\'s YouTube API', function() {
hitEndpoint('https://www.googleapis.com/youtube/v3/playlists?part=snippet&mine=true', function(response) {
var playlistCount = response.items.length;
var cappedCount = (playlistCount <= 3) ? playlistCount : 3;
console.log('Playlists (' + cappedCount + ' of ' + playlistCount + '):');
for (var i = 0; i < cappedCount; i++) {
console.log(' ' + response.items[i].snippet.title);
}
});
});

addButton('Launch Google web auth flow', function() {
console.log('launchWebAuthFlow (google.com): Waiting for callback');

var webAuthDetails = {
interactive: true,
url: 'https://accounts.google.com/o/oauth2/auth?client_id=545713885199-pq7ffbv68ktqpv6qlg0nu62dh0f3n1f8.apps.googleusercontent.com&redirect_uri=' + chrome.identity.getRedirectURL() + '&response_type=token&scope=https%3A%2F%2Fwww.googleapis.com/auth/userinfo.profile'
};

var onLaunchWebAuthFlowSuccess = function(url) {
if (!url) {
console.log('Failed to get a token. lastError = ' + JSON.stringify(chrome.runtime.lastError));
} else {
console.log('Resulting URL: ' + url);
}
};

chrome.identity.launchWebAuthFlow(webAuthDetails, onLaunchWebAuthFlowSuccess);
});

addButton('Launch Facebook web auth flow', function() {
var FACEBOOK_PERMISSIONS='email';
var FACEBOOK_APP_ID='218307504870310';
var APPURL='https://'+chrome.runtime.id+'.chromiumapp.org/';
var FACEBOOK_LOGIN_SUCCESS_URL= 'http://www.any.do/facebook_proxy/login_success?redirect='+encodeURIComponent(APPURL);
var FACEBOOK_OAUTH_URL = 'http://www.facebook.com/dialog/oauth?display=popup&scope='+FACEBOOK_PERMISSIONS+'&client_id='+FACEBOOK_APP_ID+'&redirect_uri='+FACEBOOK_LOGIN_SUCCESS_URL;

var webAuthDetails = {
interactive: true,
url:FACEBOOK_OAUTH_URL,
};

var onLaunchWebAuthFlowSuccess = function(url) {
if (!url) {
console.log('Failed to get a token. lastError = ' + JSON.stringify(chrome.runtime.lastError));
} else {
console.log('Resulting URL: ' + url);
}
};

chrome.identity.launchWebAuthFlow(webAuthDetails, onLaunchWebAuthFlowSuccess);
});
});

0 comments on commit 08f2d17

Please sign in to comment.