Skip to content

Commit f8ee993

Browse files
committed
Add a check so setting src on async image multiple times wont mismatch imageSource
1 parent 55398d6 commit f8ee993

4 files changed

Lines changed: 36 additions & 4 deletions

File tree

expect.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ set timeout 600
1616
#spawn (adb logcat | tee ./__TESTRESULT__.txt)
1717
log_file -noappend $outfile
1818
eval spawn $cmd
19-
expect "=== ALL TESTS COMPLETE ==="
19+
expect "Tests EOF!"
2020
send \003

tests/app/testRunner.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,20 @@ function printRunTestStats() {
153153

154154
testFileContent = testFileContent.concat(testCases);
155155

156-
// DO NOT CHANGE THE FIRST ROW! Used as an indicator for test run pass detection.
157-
let finalMessage = `=== ALL TESTS COMPLETE ===\n` +
156+
let finalMessage = `\n=== ALL TESTS COMPLETE ===\n` +
158157
`${(allTests.length - failedTestCount)} OK, ${failedTestCount} failed\n` +
159-
`DURATION: ${totalTime} ms`;
158+
`DURATION: ${totalTime} ms\n`;
160159
TKUnit.write(finalMessage, messageType.info);
160+
161161
for (j = 0; j < failedTestInfo.length; j++) {
162162
let failureMessage = failedTestInfo[j];
163163
TKUnit.write(failureMessage, messageType.error);
164164
finalMessage += "\n" + failureMessage;
165165
}
166166

167+
// DO NOT CHANGE THE FIRST ROW! Used as an indicator for test run pass detection.
168+
TKUnit.write(`Tests EOF!`, messageType.info);
169+
167170
testFileContent.push("</testsuite>");
168171
testFileContent.push("</testsuites>");
169172

tests/app/ui/image/image-tests.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import {StackLayout} from "ui/layouts/stack-layout";
33
import {GridLayout} from "ui/layouts/grid-layout";
44
import {isIOS} from "platform";
5+
import {PropertyChangeData} from "data/observable";
6+
57
// import {target} from "../../TKUnit";
68

79
import TKUnit = require("../../TKUnit");
@@ -133,6 +135,28 @@ export var test_SettingImageSrcToDataURIAsync = function (done) {
133135
runImageTest(done, image, image.src)
134136
}
135137

138+
// NOTE: This tests that setting multiple times src will not show the imageSource of a previous src value.
139+
// It however will never be reliable as to properly detect failure we need to use somewhat large timeout
140+
// waiting for imageSource to be set to the wrong value.
141+
export var __test_SettingImageSrcTwiceMustNotMismatch = function(done) {
142+
var image = new Image();
143+
image.on("propertyChange", (args: PropertyChangeData) => {
144+
if (args.propertyName === "isLoading" && args.value === false) {
145+
setTimeout(() => {
146+
if (image.imageSource) {
147+
done(new Error("Images source set from previous async src setting"));
148+
} else {
149+
done();
150+
}
151+
}, 50); /* Slow! */
152+
}
153+
});
154+
image.loadMode = "async";
155+
image.src = "~/logo.png";
156+
image.src = null;
157+
// At somepoint image.imageSource was set to "~/logo.png";
158+
}
159+
136160
export var test_SettingStretch_AspectFit = function () {
137161
// >> img-set-stretch
138162
var image = new ImageModule.Image();

tns-core-modules/ui/image/image-common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ export class Image extends view.View implements definition.Image {
9797

9898
var source = new imageSource.ImageSource();
9999
var imageLoaded = () => {
100+
if (value !== this.src) {
101+
return;
102+
}
100103
this.imageSource = source;
101104
this._setValue(Image.isLoadingProperty, false);
102105
}
@@ -143,9 +146,11 @@ export class Image extends view.View implements definition.Image {
143146
else if (value instanceof imageSource.ImageSource) {
144147
// Support binding the imageSource trough the src property
145148
this.imageSource = value;
149+
this._setValue(Image.isLoadingProperty, false);
146150
}
147151
else {
148152
this.imageSource = imageSource.fromNativeSource(value);
153+
this._setValue(Image.isLoadingProperty, false);
149154
}
150155
}
151156
}

0 commit comments

Comments
 (0)