Fix native image recreated on layout even if the view is not resized

This commit is contained in:
Panayot Cankov
2015-12-03 16:53:25 +02:00
parent a2d21d8f19
commit d61ab801e9
5 changed files with 104 additions and 15 deletions

View File

@ -144,17 +144,41 @@ function log(): void {
TKUnit.write(testsName + " COMPLETED for " + duration + " BACKSTACK DEPTH: " + topmost().backStack.length, messageType.info);
}
export var runAll = function (moduleName?: string) {
export var runAll = function (testSelector?: string) {
if (running) {
// TODO: We may schedule pending run requests
return;
}
var singleModuleName, singleTestName;
if (testSelector) {
var pair = testSelector.split(".");
singleModuleName = pair[0];
if (singleModuleName) {
if (singleModuleName.length === 0) {
singleModuleName = undefined;
} else {
singleModuleName = singleModuleName.toLowerCase();
}
}
singleTestName = pair[1];
if (singleTestName) {
if (singleTestName.length === 0) {
singleTestName = undefined;
} else {
singleTestName = singleTestName.toLowerCase();
}
}
}
console.log("TESTS: " + singleModuleName + " " + singleTestName);
var totalSuccess = 0;
var totalFailed: Array<TKUnit.TestFailure> = [];
testsQueue.push(new TestInfo(function () { running = true; }));
for (var name in allTests) {
if (moduleName && (moduleName.toLowerCase() !== name.toLowerCase())) {
if (singleModuleName && (singleModuleName !== name.toLowerCase())) {
continue;
}
@ -170,8 +194,11 @@ export var runAll = function (moduleName?: string) {
testsQueue.push(new TestInfo(test.setUpModule, test));
}
for (var testName in test) {
if (singleTestName && (singleTestName !== testName.toLowerCase())) {
continue;
}
var testFunction = test[testName];
if ((typeof (testFunction) === "function") && (testName.substring(0, 4) == "test")) {
if (test.setUp) {

View File

@ -1,6 +1,12 @@
import commonTests = require("./view-tests-common");
import view = require("ui/core/view");
import grid = require("ui/layouts/grid-layout");
import color = require("color");
import helper = require("../helper");
import page = require("ui/page");
import TKUnit = require("../../TKUnit");
global.moduleMerge(commonTests, exports);
export function getNativeBorderWidth(v: view.View): number {
@ -27,4 +33,55 @@ export function checkNativeBackgroundColor(v: view.View): boolean {
export function checkNativeBackgroundImage(v: view.View): boolean {
return (<UIView>v.ios).backgroundColor !== undefined;
}
}
export function testBackgroundInternalChangedOnceOnResize() {
var layout = new grid.GridLayout();
layout.className = "myClass";
layout.backgroundColor = new color.Color(255, 255, 0, 0);
var pageFactory = () => {
var root = new page.Page();
root.css = ".myClass { background-image: url('~/tests/logo.png') }";
root.content = layout;
return root;
}
helper.navigate(pageFactory);
try {
var sizeChangedCount = 0;
function trackCount() {
var result = sizeChangedCount;
sizeChangedCount = 0;
return result;
}
var base = (<any>layout.style)._applyStyleProperty;
(<any>layout.style)._applyStyleProperty = function(property) {
base.apply(layout.style, arguments);
if (property.name === "_backgroundInternal") {
++sizeChangedCount;
}
}
layout.requestLayout();
layout.layout(0, 0, 200, 200);
TKUnit.assertEqual(trackCount(), 1, "Expected background to be re-applied at most once when the view is layed-out on 0 0 200 200.");
layout.requestLayout();
layout.layout(50, 50, 250, 250);
TKUnit.assertEqual(trackCount(), 0, "Expected background to NOT change when view is layed-out from 0 0 200 200 to 50 50 250 250.");
layout.requestLayout();
layout.layout(0, 0, 250, 250);
TKUnit.assertEqual(trackCount(), 1, "Expected background to be re-applied at most once when the view is layed-out from 50 50 250 250 to 0 0 250 250.");
}
finally {
helper.goBack();
}
}