Skip to content

Instantly share code, notes, and snippets.

@vijaysingh-axway
Last active April 3, 2020 16:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaysingh-axway/2b9931d0dea0fb491425c6d1592c3120 to your computer and use it in GitHub Desktop.
Save vijaysingh-axway/2b9931d0dea0fb491425c6d1592c3120 to your computer and use it in GitHub Desktop.
app.js file having test cases of WebView
var items =
[
{
title : 'Webview events (beforeload, load, progress, redirect)',
message : 'In log it should print the values',
functionName : Test0
},
{
title : 'Webview events (error)',
message : 'In log it should print the error.',
functionName : Test1
},
{
title : 'Webview events (sslerror)',
message : 'It should show ssl error alert.',
functionName : Test2
},
{
title : 'Webview events (blacklisturl)',
message : 'It should show blacklisturl error alert.',
functionName : Test3
},
{
title : 'Webview events (Ti.App and Ti.API)',
message : 'On click of Trigger button, Ti.App and Ti.API events logged.',
functionName : Test4
},
{
title : 'Webview methods (sethtml(), message event )',
message : 'On click of button it should set custom html',
functionName : Test5
},
{
title : 'Webview methods ( evalJS() )',
message : 'Will show text on evaluating "document.body.innerText.toString()"',
functionName : Test6
},
{
title : 'Webview methods (canGoBack, canGoForward, goBack,goForward)',
message : 'Should do/alert the right stuff',
functionName : Test7
},
{
title : 'Webview methods (reload)',
message : 'Should reload the page.',
functionName : Test8
},
{
title :'Webview methods (stopLoading)',
message : 'Should stop loading of the page.',
functionName : Test9
},
{
title : 'Webview methods (repaint)',
message : 'Should repaint the page.',
functionName : Test10
},
{
title :'Webview methods (basicAuthentication)',
message : 'Should load successfully.',
functionName : Test11
},
{
title : 'Webview properties (allowsLinkPreview)',
message : 'Need device supporting 3D touch.',
functionName : Test12
},
{
title : 'Webview properties (data)',
message : 'Should load file.',
functionName : Test13
},
{
title : 'Webview properties (hideLoadIndicator, loading)',
message : 'No loader visible. Loading should show result.',
functionName : Test14
},
{
title : 'Webview properties (ignoreSslError)',
message : 'Should load successfully.',
functionName : Test15
},
{
title : 'Webview properties (zoomLevel)',
message : 'Page should be zoomed',
functionName : Test16
},
{
title : 'Webview properties (requestHeaders)',
message : 'In alert should show the outer html.',
functionName : Test17
},
{
title : 'Webview properties (userAgent)',
message : 'In alert should show userAgent as - testUserAgent',
functionName : Test18
},
{
title : 'Webview properties (willHandleTouches)',
message : 'Alert should show on click on webview',
functionName : Test19
},
{
title : 'Webview properties (allowedURLSchemes, handleurl)',
message : 'It should open google page in safari',
functionName : Test20
},
{
title : 'Webview properties (title, backForwardList, cachePolicy, selectionGranularity)',
message : 'On click of buttons respective value should show in alert.',
functionName : Test21
},
{
title : 'Webview Configuration properties (selectionGranularity, preferences)',
message : 'Google page should load with fontsize 20.',
functionName : Test22
},
{
title : 'Webview method (startListeningToProperties)',
message : 'Title event should fire and should show in log',
functionName : Test23
},
{
title : 'Webview method (takeSnapshot)',
message : 'Image should show on click of button',
functionName : Test24
},
{
title : 'Webview method (addUserScript)',
message : 'Event should fire and should show alert',
functionName : Test25
},
{
title : 'Cookie support for webview',
message : 'Add delete etc should work.',
functionName : Test26
},
{
title : 'Webview play video (TIMOB-26490)',
message : 'On closing window it should stop video playing',
functionName : Test27
},
];
var rows = [];
for (var i = 0; i < items.length; i++) {
var data = items[i];
rows.push({ properties: {title:data.title, height: 60, subtitle: data.message, backgroundColor: 'white'}, template:Ti.UI.LIST_ITEM_TEMPLATE_SUBTITLE});
}
var win = Ti.UI.createWindow({
title: 'TEST',
backgroundColor: 'white',
layout: 'vertical'
});
var ls = Ti.UI.createListSection({
items: rows,
sectionHeaderTitle: 'Section header',
});
var lv = Ti.UI.createListView({
top: 20,
sections: [ls],
});
lv.addEventListener('itemclick', function(e) {
Ti.API.info('click at index: ' + e.itemIndex);
var clickedItem = items[e.itemIndex];
clickedItem.functionName();
});
win.add(lv);
win.open();
function Test0() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var progress = Ti.UI.createProgressBar({
min: 0.0,
max: 1.0,
top: 0,
width: Ti.UI.FILL
});
var webview = Ti.UI.createWebView({
url: 'https://httpbin.org/redirect/1'
});
webview.addEventListener('beforeload', function(e) {
Ti.API.warn('\n\n\nBEFORELOAD!!');
Ti.API.warn(e);
});
webview.addEventListener('load', function(e) {
Ti.API.warn('\n\n\nLOADED');
alert('LOADED')
});
webview.addEventListener("progress", function(e) {
if (e.value >= 1.0) {
progress.setValue(0.0);
progress.visible && progress.hide();
} else {
progress.setValue(e.value);
!progress.visible && progress.show();
}
});
webview.addEventListener('redirect', function(e) {
Ti.API.warn('\n\n\nREDIRECT');
});
win.add(webview);
win.add(progress);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test1() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://google.xcom'
});
webview.addEventListener('error', function(e) {
alert('ERROR LOADING PAGE');
Ti.API.error(e);
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test2() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://httpbin.org/basic-auth/user/password'
});
webview.addEventListener('sslerror', function(e) {
alert('SSL ERROR!!');
Ti.API.error(e);
});
webview.addEventListener('load', function(e) {
alert('LOADED SUCCESSFULLY');
Ti.API.info(e);
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test3() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://google.com',
blacklistedURLs: ['https://google.com']
});
webview.addEventListener('blacklisturl', function(e) {
alert('Blacklisted URL!!');
Ti.API.error(e);
});
webview.addEventListener('load', function(e) {
alert('LOADED SUCCESSFULLY');
Ti.API.info(e);
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test4() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var webView = Ti.UI.createWebView({
url: 'test.html',
});
Ti.App.addEventListener('eventToTitanium', function(e) {
Ti.API.info(e);
Ti.App.fireEvent('eventToJs', {message:'Titanium'});
});
Ti.App.addEventListener('backEventToTitanium', function(e) {
Ti.API.info(e);
alert('EVENT RECIEVED FROM Ti.App');
});
win.add(webView);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test5 () {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button,
backgroundColor: 'white'
});
var webview = Ti.UI.createWebView({
top: 60,
url: 'https://google.com'
});
var msgButton = Ti.UI.createButton({
top: 10,
title: 'Post message',
visible: false
});
msgButton.addEventListener('click', function(e) {
webview.evalJS('invokeMyJSMethod({message: \'Titanium rocks!\'})');
});
var htmlButton = Ti.UI.createButton({
top: 10,
title: 'Set custom HTML',
});
htmlButton.addEventListener('click', function(e) {
webview.setHtml("<!DOCTYPE html><html><head><title>Local HTML</title></head><body><p style='font-size: 72px, color: red;'>Hello world!</p><script type=\"text/javascript\">function invokeMyJSMethod(e) {alert('Hello from your HTML file: ' + e.message);} window.webkit.messageHandlers.Ti.postMessage({message: 'Titanium rocks!'});</script></body></html>", {
mimeType: 'text/html'
})
msgButton.visible = true;
htmlButton.visible = false;
});
webview.addEventListener("message", function(e) {
Ti.API.info('-- did receive message')
Ti.API.info(e.body.message);
});
win.add(msgButton);
win.add(webview);
win.add(htmlButton);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test6(){
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://google.com'
});
webview.addEventListener('load', function(e) {
alert(webview.evalJS('document.body.innerText.toString()'));
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test7() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor : 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 130,
url: 'https://google.com'
});
var htmlButton1 = Ti.UI.createButton({
left : 20,
top : 20,
title: 'Can Go Back ?',
});
htmlButton1.addEventListener('click', function(e) {
alert(webview.canGoBack().toString());
});
var htmlButton2 = Ti.UI.createButton({
right : 20,
top : 20,
title: 'Can Go Forward ?',
});
htmlButton2.addEventListener('click', function(e) {
alert(webview.canGoForward().toString());
});
var htmlButton3 = Ti.UI.createButton({
left : 20,
top: 70,
title: 'Go Back',
});
htmlButton3.addEventListener('click', function(e) {
if (webview.canGoBack()) {
webview.goBack();
} else {
alert('First click on any link to open next page.');
}
});
var htmlButton4 = Ti.UI.createButton({
right: 20,
top: 70,
title: 'Go Forward',
});
htmlButton4.addEventListener('click', function(e) {
if (webview.canGoForward()) {
webview.goForward();
} else {
alert('Either you are on last page or you have not open any next page.');
}
});
win.add(htmlButton1);
win.add(htmlButton2);
win.add(htmlButton3);
win.add(htmlButton4);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test8() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 50,
url: 'https://google.com'
});
var htmlButton = Ti.UI.createButton({
top : 10,
title: 'Reload',
});
htmlButton.addEventListener('click', function(e) {
webview.reload();
});
win.add(htmlButton);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test9() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 60,
url: 'https://google.com'
});
var htmlButton = Ti.UI.createButton({
top : 10,
title: 'Stop loading',
});
htmlButton.addEventListener('click', function(e) {
webview.stopLoading();
});
win.add(htmlButton);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test10() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 60,
url: 'https://google.com'
});
var htmlButton = Ti.UI.createButton({
top : 10,
title: 'Repaint',
});
htmlButton.addEventListener('click', function(e) {
webview.repaint();
});
win.add(htmlButton);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test11() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://httpbin.org/basic-auth/user/password',
basicAuthentication: {'username': 'user', 'password' : 'password'}
});
win.add(webview);
webview.addEventListener('sslerror', function(e) {
alert('SSL ERROR!!');
Ti.API.error(e);
});
webview.addEventListener('load', function(e) {
alert('LOADED SUCCESSFULLY');
Ti.API.info(e);
});
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test12() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://google.com',
allowsLinkPreview: true
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test13() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var blob = Ti.Filesystem.getFile('app.js').read();
var webview = Ti.UI.createWebView({
data: blob
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test14() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 60,
url: 'https://google.com',
hideLoadIndicator: true
});
var htmlButton = Ti.UI.createButton({
top : 10,
title: 'Is loading ?',
});
htmlButton.addEventListener('click', function(e) {
alert(webview.loading.toString());
});
win.add(htmlButton);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test15() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://httpbin.org/basic-auth/user/password',
ignoreSslError : true
});
webview.addEventListener('sslerror', function(e) {
alert('SSL ERROR!!');
Ti.API.error(e);
});
webview.addEventListener('load', function(e) {
alert('LOADED SUCCESSFULLY');
Ti.API.info(e);
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test16() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button,
backgroundColor: 'white'
});
var webview = Ti.UI.createWebView({
url: 'https://www.google.com',
top: 60
});
win.add(webview);
var htmlButton = Ti.UI.createButton({
top : 10,
title: 'Set zoom level 2.0',
});
htmlButton.addEventListener('click', function(e) {
webview.zoomLevel = 2.0;
Ti.API.info(webview.zoomLevel);
});
win.add(htmlButton);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test17() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button,
backgroundColor: 'white'
});
var webview = Ti.UI.createWebView({
requestHeaders: {
'TEST123': 'HELLO',
'User-Agent': 'TI ROCKS'
},
url: 'https://httpbin.org/headers'
});
webview.addEventListener('load', function(e) {
webview.evalJS('document.documentElement.outerHTML.toString()', function(e) {
alert(e);
});
});
win.add(webview);
win.open();
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test18 () {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button,
backgroundColor: 'white'
});
var webview = Ti.UI.createWebView({
userAgent: 'testUserAgent',
url: 'https://www.google.com'
});
webview.addEventListener('load', function(e) {
webview.evalJS('navigator.userAgent', function(e) {
alert(e);
});
});
win.add(webview);
win.open();
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test19 () {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button,
backgroundColor: 'white'
});
var webview = Ti.UI.createWebView({
url: 'https://www.google.com',
willHandleTouches : true
});
webview.addEventListener('click', function(e) {
alert('CLICK EVENT FIRED');
});
win.add(webview);
win.open();
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test20() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
rightNavButton: button,
backgroundColor: 'white'
});
var webview = Ti.UI.createWebView({
url: 'https://www.google.com',
allowedURLSchemes: ['https', 'http']
});
win.add(webview);
webview.addEventListener('handleurl', function(e) {
var handler = e.handler;
Ti.Platform.openURL(e.url);
handler.invoke(Ti.UI.iOS.ACTION_POLICY_CANCEL);
});
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test21() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 90,
url: 'https://google.com',
cachePolicy: Ti.UI.iOS.CACHE_POLICY_RELOAD_IGNORING_LOCAL_CACHE_DATA,
allowsBackForwardNavigationGestures: true
});
var button1 = Ti.UI.createButton({
top : 10,
left : 10,
title: 'Title',
});
button1.addEventListener('click', function(e) {
alert(webview.title);
});
var button2 = Ti.UI.createButton({
top : 10,
left: 60,
title: 'Back Forward List',
});
button2.addEventListener('click', function(e) {
alert(webview.backForwardList.toString());
});
var button3 = Ti.UI.createButton({
top : 10,
left : 200,
title: 'Cache Policy',
});
button3.addEventListener('click', function(e) {
alert(webview.cachePolicy.toString());
});
var button4 = Ti.UI.createButton({
top : 50,
left : 10,
title: 'Selection Granularity',
});
button4.addEventListener('click', function(e) {
alert(webview.selectionGranularity.toString());
});
var button5 = Ti.UI.createButton({
top : 50,
left : 160,
title: 'Back Forward Navigation Gesture',
});
button5.addEventListener('click', function(e) {
alert(webview.allowsBackForwardNavigationGestures.toString());
});
win.add(button1);
win.add(button2);
win.add(button3);
win.add(button4);
win.add(button5);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test22() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var pool = Ti.UI.iOS.createWebViewProcessPool();
var config = Ti.UI.iOS.createWebViewConfiguration({
allowsPictureInPictureMediaPlaback: true,
suppressesIncrementalRendering: true,
allowsAirPlayMediaPayback: true,
allowsPictureInPictureMediaPlaback: true,
selectionGranularity: Ti.UI.iOS.SELECTION_GRANULARITY_CHARACTER,
preferences: {
minimumFontSize : 20,
},
processPool: pool
});
var webview = Ti.UI.createWebView({
top: 60,
url: 'https://google.com',
configuration: config
});
var button1 = Ti.UI.createButton({
top : 10,
left : 10,
title: 'Selection Granularity',
});
button1.addEventListener('click', function(e) {
alert(webview.selectionGranularity.toString());
});
win.add(button1);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test23() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url: 'https://google.com',
});
webview.startListeningToProperties(['title']);
webview.addEventListener('title', function(e){
Ti.API.info('\n\n Title is : -' +e.value);
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
setTimeout(function(e) {
webview.stopListeningToProperties(['title']);
webview.setUrl('https://www.apple.com');
}, 5000);
}
function Test24() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var imageView = Ti.UI.createImageView({
top:0,
width: 70,
height: 70
});
var webview = Ti.UI.createWebView({
top: 90,
url: 'https://google.com',
});
var button1 = Ti.UI.createButton({
top : 10,
left : 10,
title: 'Take Snapshot',
});
button1.addEventListener('click', function(e) {
webview.takeSnapshot(function(e){
imageView.setImage(e.snapshot);
});
});
win.add(button1);
win.add(imageView);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test25() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
top: 60,
url: 'https://www.google.com'// "<!DOCTYPE html><html><head><title>Local HTML</title></head><body><p style='font-size: 72px, color: red;'>Hello world!</p><script type=\"text/javascript\"></script></body></html>"
});
webview.addEventListener("message", function(e) {
Ti.API.info('-- did receive message')
alert(e.body.message);
});
webview.addUserScript({
source: 'window.webkit.messageHandlers.TiTest.postMessage({message: \'Titanium rocks!\'});',
mainFrameOnly: true,
injectionTime: Ti.UI.iOS.INJECTION_TIME_DOCUMENT_START
});
webview.addScriptMessageHandler('TiTest');
var button1 = Ti.UI.createButton({
top : 10,
left : 10,
title: 'Reload',
});
button1.addEventListener('click', function(e) {
webview.reload();
setTimeout(function(e) {
webview.removeScriptMessageHandler('TiTest');
Ti.API.info('After reload message event should not fire');
}, 2000);
});
win.add(button1);
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test26() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var button1 = Ti.UI.createButton({
top: 40,
left: 20,
title: 'AddCookie'
});
var button2 = Ti.UI.createButton({
top: 40,
left: 220,
title: 'GetAllCookie'
});
var button3 = Ti.UI.createButton({
top: 80,
left: 20,
title: 'DeleteCookie'
});
var button4 = Ti.UI.createButton({
top: 80,
left: 120,
title: 'GetCookie For AppcDomain'
});
win.add(button1);
win.add(button2);
win.add(button3);
win.add(button4);
var webview = Ti.UI.createWebView({
top: 120,
url: "http://httpbin.org/cookies"
});
webview.addEventListener('load', function(e) {
Ti.API.warn('\n\n\nLOADED');
//var array = webview.getAllHTTPCookies();
});
win.add(webview);
button1.addEventListener('click', function(e){
var cookie1 = Titanium.Network.createCookie({
name: 'CookieOne',
value: 'CookieOneValue',
domain: 'httpbin.org',
path: '/cookies',
version: 0,
expiryDate: new Date(2020, 1, 1)
});
webview.addHTTPCookie(cookie1);
var cookie2 = Titanium.Network.createCookie({
name: 'CookieTwo',
value: 'CookieTwoValue',
domain: 'httpbin.org',
path: '/cookies',
version: 1,
expiryDate: new Date(2020, 1, 1)
});
webview.addHTTPCookie(cookie2);
var cookie3 = Titanium.Network.createCookie({
name: 'Cookie1Google',
value: 'Cookie1GoogleValue',
domain: 'google.com',
path: '/cookies',
version: 1,
expiryDate: new Date(2020, 1, 1)
});
webview.addHTTPCookie(cookie3);
var cookie4 = Titanium.Network.createCookie({
name: 'Cookie1Appcelerator',
value: 'Cookie1GoogleValue',
domain: 'appcelerator.com',
path: '/cookies',
version: 1,
expiryDate: new Date(2020, 1, 1)
});
webview.addHTTPCookie(cookie4);
});
button2.addEventListener('click', function(e){
var array = webview.getAllHTTPCookies();
Ti.API.info('No of cookies are: \n' +array.length);
});
button3.addEventListener('click', function(e){
//webview.removeAllHTTPCookies();
webview.removeHTTPCookie('google.com', '/cookies', null);
var array = webview.getAllHTTPCookies();
Ti.API.info('After deletion no of cookies are: \n' +array.length);
});
button4.addEventListener('click', function(e){
var array = webview.getHTTPCookiesForDomain('appcelerator.com');
Ti.API.info('No of cookies for appc domain are: \n' +array.length);
});
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
function Test27() {
var button = Ti.UI.createButton({ title: 'close' });
var win = Ti.UI.createWindow({
backgroundColor: 'white',
rightNavButton: button
});
var webview = Ti.UI.createWebView({
url : 'https://vimeo.com/album/5202279',
top : 50
});
win.add(webview);
button.addEventListener('click', function(e){
navWin.close();
});
var navWin = Ti.UI.iOS.createNavigationWindow({window: win});
navWin.open();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment