Moved delegate handling to onLoaded / onUnloaded methods and reworked the WebView tests.

This commit is contained in:
Rossen Hristov
2015-04-03 12:56:23 +03:00
parent 956e14eba3
commit 38bc482359
8 changed files with 147 additions and 48 deletions

View File

@ -1,6 +1,7 @@
import TKUnit = require("../../TKUnit"); import TKUnit = require("../../TKUnit");
import helper = require("../helper"); import helper = require("../helper");
import viewModule = require("ui/core/view"); import viewModule = require("ui/core/view");
import page = require("ui/page");
// <snippet module="ui/web-view" title="WebView"> // <snippet module="ui/web-view" title="WebView">
// # WebView // # WebView
@ -28,49 +29,82 @@ var _createWebViewFunc = function (): webViewModule.WebView {
return webView; return webView;
} }
export var testLoadExistingUrl = function (done) { export var testLoadExistingUrl = function () {
helper.buildUIAndRunTest(_createWebViewFunc(), function (views: Array<viewModule.View>) { var newPage: page.Page;
var webView = <webViewModule.WebView>views[0]; var webView = _createWebViewFunc();
// <snippet module="ui/web-view" title="WebView"> var pageFactory = function (): page.Page {
// ### Using WebView, newPage = new page.Page();
// ``` JavaScript newPage.content = webView;
webView.on(webViewModule.knownEvents.loadFinished, function (args: webViewModule.LoadEventData) { return newPage;
var message; };
if (!args.error) {
message = "WebView finished loading " + args.url; helper.navigate(pageFactory);
}
else { var testFinished = false;
message = "Error loading " + args.url + ": " + args.error; var actualUrl;
} var actualError;
//console.log(message);
// <hide> // <snippet module="ui/web-view" title="WebView">
TKUnit.assert(args.url === "https://httpbin.org/html", "args.url should equal https://httpbin.org/html"); // ### Using WebView
TKUnit.assert(args.error === undefined, args.error); // ``` JavaScript
done(); webView.on(webViewModule.knownEvents.loadFinished, function (args: webViewModule.LoadEventData) {
// </hide> // <hide>
}); actualUrl = args.url;
webView.url = "https://httpbin.org/html"; actualError = args.error;
// ``` testFinished = true;
// </snippet> // </hide>
}); var message;
if (!args.error) {
message = "WebView finished loading " + args.url;
}
else {
message = "Error loading " + args.url + ": " + args.error;
}
//console.log(message);
});
webView.url = "https://httpbin.org/html";
TKUnit.wait(2);
helper.goBack();
if (testFinished) {
TKUnit.assert(actualUrl === "https://httpbin.org/html", "args.url should equal https://httpbin.org/html");
TKUnit.assert(actualError === undefined, actualError);
}
else {
TKUnit.assert(false, "TIMEOUT");
}
} }
export var testLoadInvalidUrl = function (done) { export var testLoadInvalidUrl = function () {
helper.buildUIAndRunTest(_createWebViewFunc(), function (views: Array<viewModule.View>) { var newPage: page.Page;
var webView = <webViewModule.WebView>views[0]; var webView = _createWebViewFunc();
var pageFactory = function (): page.Page {
var errorReceived = false; newPage = new page.Page();
webView.on(webViewModule.knownEvents.loadFinished, function (args: webViewModule.LoadEventData) { newPage.content = webView;
if (errorReceived) { return newPage;
return; };
}
helper.navigate(pageFactory);
if (args.error) {
errorReceived = true; var testFinished = false;
done(); var actualError;
}
}); webView.on(webViewModule.knownEvents.loadFinished, function (args: webViewModule.LoadEventData) {
testFinished = true;
webView.url = "kofti://mnogokofti"; actualError = args.error;
}); });
webView.url = "kofti://mnogokofti";
TKUnit.wait(2);
helper.goBack();
if (testFinished) {
TKUnit.assert(actualError !== undefined, "There should be an error.");
}
else {
TKUnit.assert(false, "TIMEOUT");
}
} }

View File

@ -22,9 +22,18 @@ export class ListPicker extends common.ListPicker {
this._ios.dataSource = this._dataSource; this._ios.dataSource = this._dataSource;
this._delegate = ListPickerDelegateImpl.new().initWithOwner(this); this._delegate = ListPickerDelegateImpl.new().initWithOwner(this);
}
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate; this._ios.delegate = this._delegate;
} }
public onUnloaded() {
this._ios.delegate = null;
super.onUnloaded();
}
get ios(): UIPickerView { get ios(): UIPickerView {
return this._ios; return this._ios;
} }

View File

@ -148,7 +148,7 @@ function onSeparatorColorPropertyChanged(data: dependencyObservable.PropertyChan
export class ListView extends common.ListView { export class ListView extends common.ListView {
private _ios: UITableView; private _ios: UITableView;
private _dataSource; private _dataSource;
private _uiTableViewDelegate; private _delegate;
private _heights: Array<number>; private _heights: Array<number>;
private _preparingCell: boolean = false; private _preparingCell: boolean = false;
@ -165,12 +165,21 @@ export class ListView extends common.ListView {
this._dataSource = dataSource; this._dataSource = dataSource;
this._ios.dataSource = this._dataSource; this._ios.dataSource = this._dataSource;
this._uiTableViewDelegate = UITableViewDelegateImpl.new().initWithOwner(this); this._delegate = UITableViewDelegateImpl.new().initWithOwner(this);
this._ios.delegate = this._uiTableViewDelegate;
this._heights = new Array<number>(); this._heights = new Array<number>();
} }
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate;
}
public onUnloaded() {
this._ios.delegate = null;
super.onUnloaded();
}
get ios(): UITableView { get ios(): UITableView {
return this._ios; return this._ios;
} }

View File

@ -96,9 +96,18 @@ export class SearchBar extends common.SearchBar {
this._ios = new UISearchBar(); this._ios = new UISearchBar();
this._delegate = UISearchBarDelegateImpl.new().initWithOwner(this); this._delegate = UISearchBarDelegateImpl.new().initWithOwner(this);
}
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate; this._ios.delegate = this._delegate;
} }
public onUnloaded() {
this._ios.delegate = null;
super.onUnloaded();
}
get ios(): UISearchBar { get ios(): UISearchBar {
return this._ios; return this._ios;
} }

View File

@ -82,7 +82,7 @@ class UINavigationControllerDelegateImpl extends NSObject implements UINavigatio
export class TabView extends common.TabView { export class TabView extends common.TabView {
private _ios: UITabBarControllerImpl; private _ios: UITabBarControllerImpl;
private _tabBarControllerDelegate: UITabBarControllerDelegateImpl; private _delegate: UITabBarControllerDelegateImpl;
private _moreNavigationControllerDelegate: UINavigationControllerDelegateImpl; private _moreNavigationControllerDelegate: UINavigationControllerDelegateImpl;
private _tabBarHeight: number = 0; private _tabBarHeight: number = 0;
private _navBarHeight: number = 0; private _navBarHeight: number = 0;
@ -93,13 +93,23 @@ export class TabView extends common.TabView {
this._ios = UITabBarControllerImpl.new().initWithOwner(this); this._ios = UITabBarControllerImpl.new().initWithOwner(this);
this._tabBarControllerDelegate = UITabBarControllerDelegateImpl.new().initWithOwner(this); this._delegate = UITabBarControllerDelegateImpl.new().initWithOwner(this);
this._ios.delegate = this._tabBarControllerDelegate;
this._moreNavigationControllerDelegate = UINavigationControllerDelegateImpl.new().initWithOwner(this); this._moreNavigationControllerDelegate = UINavigationControllerDelegateImpl.new().initWithOwner(this);
//This delegate is set on the last line of _addTabs method. //This delegate is set on the last line of _addTabs method.
} }
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate;
}
public onUnloaded() {
this._ios.delegate = null;
this._ios.moreNavigationController.delegate = null;
super.onUnloaded();
}
get ios(): UIViewController { get ios(): UIViewController {
return this._ios; return this._ios;
} }
@ -249,4 +259,5 @@ export class TabView extends common.TabView {
view.View.layoutChild(this, child, 0, this._navBarHeight, right, (bottom - this._navBarHeight - this._tabBarHeight)); view.View.layoutChild(this, child, 0, this._navBarHeight, right, (bottom - this._navBarHeight - this._tabBarHeight));
} }
} }
} }

View File

@ -74,9 +74,18 @@ export class TextField extends common.TextField {
this._ios = new UITextField(); this._ios = new UITextField();
this._delegate = UITextFieldDelegateImpl.new().initWithOwner(this); this._delegate = UITextFieldDelegateImpl.new().initWithOwner(this);
}
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate; this._ios.delegate = this._delegate;
} }
public onUnloaded() {
this._ios.delegate = null;
super.onUnloaded();
}
get ios(): UITextField { get ios(): UITextField {
return this._ios; return this._ios;
} }

View File

@ -50,9 +50,18 @@ export class TextView extends common.TextView {
} }
this._delegate = UITextViewDelegateImpl.new().initWithOwner(this); this._delegate = UITextViewDelegateImpl.new().initWithOwner(this);
}
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate; this._ios.delegate = this._delegate;
} }
public onUnloaded() {
this._ios.delegate = null;
super.onUnloaded();
}
get ios(): UITextView { get ios(): UITextView {
return this._ios; return this._ios;
} }

View File

@ -56,9 +56,18 @@ export class WebView extends common.WebView {
this._ios = new UIWebView(); this._ios = new UIWebView();
this._delegate = UIWebViewDelegateImpl.new().initWithOwner(this); this._delegate = UIWebViewDelegateImpl.new().initWithOwner(this);
}
public onLoaded() {
super.onLoaded();
this._ios.delegate = this._delegate; this._ios.delegate = this._delegate;
} }
public onUnloaded() {
this._ios.delegate = null;
super.onUnloaded();
}
get ios(): UIWebView { get ios(): UIWebView {
return this._ios; return this._ios;
} }