Add a check so setting src on async image multiple times wont mismatch imageSource

This commit is contained in:
Panayot Cankov
2016-06-09 15:58:39 +03:00
parent 55398d6320
commit f8ee993934
4 changed files with 36 additions and 4 deletions

View File

@ -16,5 +16,5 @@ set timeout 600
#spawn (adb logcat | tee ./__TESTRESULT__.txt)
log_file -noappend $outfile
eval spawn $cmd
expect "=== ALL TESTS COMPLETE ==="
expect "Tests EOF!"
send \003

View File

@ -153,17 +153,20 @@ function printRunTestStats() {
testFileContent = testFileContent.concat(testCases);
// DO NOT CHANGE THE FIRST ROW! Used as an indicator for test run pass detection.
let finalMessage = `=== ALL TESTS COMPLETE ===\n` +
let finalMessage = `\n=== ALL TESTS COMPLETE ===\n` +
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
`DURATION: ${totalTime} ms`;
`DURATION: ${totalTime} ms\n`;
TKUnit.write(finalMessage, messageType.info);
for (j = 0; j < failedTestInfo.length; j++) {
let failureMessage = failedTestInfo[j];
TKUnit.write(failureMessage, messageType.error);
finalMessage += "\n" + failureMessage;
}
// DO NOT CHANGE THE FIRST ROW! Used as an indicator for test run pass detection.
TKUnit.write(`Tests EOF!`, messageType.info);
testFileContent.push("</testsuite>");
testFileContent.push("</testsuites>");

View File

@ -2,6 +2,8 @@
import {StackLayout} from "ui/layouts/stack-layout";
import {GridLayout} from "ui/layouts/grid-layout";
import {isIOS} from "platform";
import {PropertyChangeData} from "data/observable";
// import {target} from "../../TKUnit";
import TKUnit = require("../../TKUnit");
@ -133,6 +135,28 @@ export var test_SettingImageSrcToDataURIAsync = function (done) {
runImageTest(done, image, image.src)
}
// NOTE: This tests that setting multiple times src will not show the imageSource of a previous src value.
// It however will never be reliable as to properly detect failure we need to use somewhat large timeout
// waiting for imageSource to be set to the wrong value.
export var __test_SettingImageSrcTwiceMustNotMismatch = function(done) {
var image = new Image();
image.on("propertyChange", (args: PropertyChangeData) => {
if (args.propertyName === "isLoading" && args.value === false) {
setTimeout(() => {
if (image.imageSource) {
done(new Error("Images source set from previous async src setting"));
} else {
done();
}
}, 50); /* Slow! */
}
});
image.loadMode = "async";
image.src = "~/logo.png";
image.src = null;
// At somepoint image.imageSource was set to "~/logo.png";
}
export var test_SettingStretch_AspectFit = function () {
// >> img-set-stretch
var image = new ImageModule.Image();

View File

@ -97,6 +97,9 @@ export class Image extends view.View implements definition.Image {
var source = new imageSource.ImageSource();
var imageLoaded = () => {
if (value !== this.src) {
return;
}
this.imageSource = source;
this._setValue(Image.isLoadingProperty, false);
}
@ -143,9 +146,11 @@ export class Image extends view.View implements definition.Image {
else if (value instanceof imageSource.ImageSource) {
// Support binding the imageSource trough the src property
this.imageSource = value;
this._setValue(Image.isLoadingProperty, false);
}
else {
this.imageSource = imageSource.fromNativeSource(value);
this._setValue(Image.isLoadingProperty, false);
}
}
}