From 7cf417a123574f27028223e342ba59093c995732 Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Tue, 8 Dec 2015 10:54:11 +0200 Subject: [PATCH 1/2] Made two memory leak tests async so that GC could be triggered. --- apps/tests/weak-event-listener-tests.ts | 32 ++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/apps/tests/weak-event-listener-tests.ts b/apps/tests/weak-event-listener-tests.ts index 25d00e649..7d8949948 100644 --- a/apps/tests/weak-event-listener-tests.ts +++ b/apps/tests/weak-event-listener-tests.ts @@ -94,7 +94,7 @@ export function test_handlerIsCalled_WithTargetAsThis() { TKUnit.assert(callbackCalled, "Handler not called."); } -export function test_listnerDoesNotRetainTarget() { +export function test_listnerDoesNotRetainTarget(done) { var source = new observable.Observable(); var target = new Target(); @@ -102,12 +102,22 @@ export function test_listnerDoesNotRetainTarget() { var targetRef = new WeakRef(target); target = undefined; - helper.forceGC(); - TKUnit.assert(!targetRef.get(), "Target should be released after GC"); + TKUnit.waitUntilReady(() => { + helper.forceGC(); + return !targetRef.get(); + }); + + try { + TKUnit.assert(!targetRef.get(), "Target should be released after GC"); + done(null); + } + catch (e) { + done(e); + } } -export function test_listnerDoesNotRetainSource() { +export function test_listnerDoesNotRetainSource(done) { var source = new observable.Observable(); var target = new Target(); @@ -115,9 +125,19 @@ export function test_listnerDoesNotRetainSource() { var sourceRef = new WeakRef(source); source = undefined; - helper.forceGC(); - TKUnit.assert(!sourceRef.get(), "Source should be released after GC"); + TKUnit.waitUntilReady(() => { + helper.forceGC(); + return !sourceRef.get(); + }); + + try { + TKUnit.assert(!sourceRef.get(), "Source should be released after GC"); + done(null); + } + catch (e) { + done(e); + } } export function test_handlerIsDetached_WhenAllListenersAreRemoved() { From d1d6c2221ca34590b126b546f1056781e8d57fdd Mon Sep 17 00:00:00 2001 From: Hristo Hristov Date: Tue, 8 Dec 2015 14:31:55 +0200 Subject: [PATCH 2/2] Fixed android unit-tests --- ui/styling/stylers.android.ts | 51 ++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/ui/styling/stylers.android.ts b/ui/styling/stylers.android.ts index e50634d79..42d03f21a 100644 --- a/ui/styling/stylers.android.ts +++ b/ui/styling/stylers.android.ts @@ -26,6 +26,10 @@ var ignorePropertyHandler = new stylersCommon.StylePropertyChangedHandler( var _defaultBackgrounds = new Map(); function onBackgroundOrBorderPropertyChanged(v: view.View) { + if (!btn) { + btn = require("ui/button"); + } + var nativeView = v._nativeView; if (!nativeView) { return; @@ -39,9 +43,6 @@ function onBackgroundOrBorderPropertyChanged(v: view.View) { if (!(bkg instanceof background.ad.BorderDrawable)) { bkg = new background.ad.BorderDrawable(); let viewClass = types.getClass(v); - if (!btn) { - btn = require("ui/button"); - } if (!(v instanceof btn.Button) && !_defaultBackgrounds.has(viewClass)) { _defaultBackgrounds.set(viewClass, nativeView.getBackground()); } @@ -81,10 +82,10 @@ function onBackgroundOrBorderPropertyChanged(v: view.View) { var density = utils.layout.getDisplayDensity(); nativeView.setPadding( - (borderWidth + v.style.paddingLeft) * density, - (borderWidth + v.style.paddingTop) * density, - (borderWidth + v.style.paddingRight) * density, - (borderWidth + v.style.paddingBottom) * density + Math.round((borderWidth + v.style.paddingLeft) * density), + Math.round((borderWidth + v.style.paddingTop) * density), + Math.round((borderWidth + v.style.paddingRight) * density), + Math.round((borderWidth + v.style.paddingBottom) * density) ); } @@ -119,7 +120,7 @@ export class DefaultStyler implements definition.stylers.Styler { //minWidth methods private static setMinWidthProperty(view: view.View, newValue: any) { - (view._nativeView).setMinimumWidth(newValue * utils.layout.getDisplayDensity()); + (view._nativeView).setMinimumWidth(Math.round(newValue * utils.layout.getDisplayDensity())); } private static resetMinWidthProperty(view: view.View, nativeValue: any) { @@ -128,7 +129,7 @@ export class DefaultStyler implements definition.stylers.Styler { //minHeight methods private static setMinHeightProperty(view: view.View, newValue: any) { - (view._nativeView).setMinimumHeight(newValue * utils.layout.getDisplayDensity()); + (view._nativeView).setMinimumHeight(Math.round(newValue * utils.layout.getDisplayDensity())); } private static resetMinHeightProperty(view: view.View, nativeValue: any) { @@ -148,10 +149,10 @@ export class DefaultStyler implements definition.stylers.Styler { var nativeView: android.view.View = view._nativeView; var lp = DefaultStyler.getNativeLayoutParams(nativeView); - lp.leftMargin = params.leftMargin * utils.layout.getDisplayDensity(); - lp.topMargin = params.topMargin * utils.layout.getDisplayDensity(); - lp.rightMargin = params.rightMargin * utils.layout.getDisplayDensity(); - lp.bottomMargin = params.bottomMargin * utils.layout.getDisplayDensity(); + lp.leftMargin = Math.round(params.leftMargin * utils.layout.getDisplayDensity()); + lp.topMargin = Math.round(params.topMargin * utils.layout.getDisplayDensity()); + lp.rightMargin = Math.round(params.rightMargin * utils.layout.getDisplayDensity()); + lp.bottomMargin = Math.round(params.bottomMargin * utils.layout.getDisplayDensity()); var width = params.width * utils.layout.getDisplayDensity(); var height = params.height * utils.layout.getDisplayDensity(); @@ -218,8 +219,8 @@ export class DefaultStyler implements definition.stylers.Styler { } lp.gravity = gravity; - lp.width = width; - lp.height = height; + lp.width = Math.round(width); + lp.height = Math.round(height); nativeView.setLayoutParams(lp); } @@ -240,19 +241,19 @@ export class DefaultStyler implements definition.stylers.Styler { private static setPaddingProperty(view: view.View, newValue: style.Thickness) { var density = utils.layout.getDisplayDensity(); - var left = (newValue.left + view.borderWidth) * density; - var top = (newValue.top + view.borderWidth) * density; - var right = (newValue.right + view.borderWidth) * density; - var bottom = (newValue.bottom + view.borderWidth) * density; + var left = Math.round((newValue.left + view.borderWidth) * density); + var top = Math.round((newValue.top + view.borderWidth) * density); + var right = Math.round((newValue.right + view.borderWidth) * density); + var bottom = Math.round((newValue.bottom + view.borderWidth) * density); (view._nativeView).setPadding(left, top, right, bottom); } private static resetPaddingProperty(view: view.View, nativeValue: style.Thickness) { var density = utils.layout.getDisplayDensity(); - var left = (nativeValue.left + view.borderWidth) * density; - var top = (nativeValue.top + view.borderWidth) * density; - var right = (nativeValue.right + view.borderWidth) * density; - var bottom = (nativeValue.bottom + view.borderWidth) * density; + var left = Math.round((nativeValue.left + view.borderWidth) * density); + var top = Math.round((nativeValue.top + view.borderWidth) * density); + var right = Math.round((nativeValue.right + view.borderWidth) * density); + var bottom = Math.round((nativeValue.bottom + view.borderWidth) * density); (view._nativeView).setPadding(left, top, right, bottom); } @@ -308,7 +309,7 @@ export class ImageStyler implements definition.stylers.Styler { if (!view._nativeView) { return; } - var val = newValue * utils.layout.getDisplayDensity(); + var val = Math.round(newValue * utils.layout.getDisplayDensity()); (view._nativeView).setCornerRadius(val); onBackgroundOrBorderPropertyChanged(view); } @@ -327,7 +328,7 @@ export class ImageStyler implements definition.stylers.Styler { return; } - var val = newValue * utils.layout.getDisplayDensity(); + var val = Math.round(newValue * utils.layout.getDisplayDensity()); (view._nativeView).setBorderWidth(val); onBackgroundOrBorderPropertyChanged(view); }