Bug 983490 - Better progress control for setInputMethodActive() test. r=yxl

This commit is contained in:
Tim Chien 2014-05-22 01:14:00 +02:00
Родитель d0a5ea9350
Коммит 9c976d87e8
4 изменённых файлов: 75 добавлений и 42 удалений

Просмотреть файл

@ -51,29 +51,50 @@ function createFrames() {
// Create two input method iframes.
let loadendCount = 0;
let countLoadend = function() {
ok(this.setInputMethodActive, 'Can access setInputMethodActive.');
if (this === gInputFrame) {
// The frame script running in the frame where the input is hosted.
let appFrameScript = function appFrameScript() {
let input = content.document.body.firstElementChild;
input.oninput = function() {
sendAsyncMessage('test:InputMethod:oninput', this.value);
sendAsyncMessage('test:InputMethod:oninput', {
from: 'input',
value: this.value
});
};
/*
* Bug 957213. Sometimes we need to refocus the input field to avoid
* intermittent test failure.
*/
content.setInterval(function() {
input.focus();
}, 500);
input.onblur = function() {
sendAsyncMessage('test:InputMethod:oninput', {
from: 'input',
error: true,
value: 'Unexpected lost of focus on the input frame!'
});
};
input.focus();
}
// Inject frame script to receive input.
let mm = SpecialPowers.getBrowserFrameMessageManager(gInputFrame);
mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
mm.addMessageListener("test:InputMethod:oninput", next);
} else {
ok(this.setInputMethodActive, 'Can access setInputMethodActive.');
// The frame script running in the input method frames.
let appFrameScript = function appFrameScript() {
content.addEventListener("message", function(evt) {
sendAsyncMessage('test:InputMethod:imFrameMessage', {
from: 'im',
value: evt.data
});
});
}
// Inject frame script to receive message.
let mm = SpecialPowers.getBrowserFrameMessageManager(this);
mm.loadFrameScript('data:,(' + appFrameScript.toString() + ')();', false);
mm.addMessageListener("test:InputMethod:imFrameMessage", next);
}
loadendCount++;
@ -117,19 +138,35 @@ function startTest() {
};
}
var gTimerId = null;
var gCount = 0;
function next(msg) {
gCount++;
let wrappedMsg = SpecialPowers.wrap(msg);
let value = wrappedMsg.data;
let from = wrappedMsg.data.from;
let value = wrappedMsg.data.value;
if (wrappedMsg.data.error) {
ok(false, wrappedMsg.data.value);
return;
}
gCount++;
// The texts sent from the first and the second input method are '#0' and
// '#1' respectively.
switch (gCount) {
case 1:
is(from, 'im', 'Message sequence unexpected (1).');
is(value, '#0true', 'First frame should get the context first.');
// Do nothing and wait for the input to show up in input frame.
break;
case 2:
is(from, 'input', 'Message sequence unexpected (2).');
is(value, '#0hello',
'Failed to get correct input from the first iframe.');
let req1 = gFrames[1].setInputMethodActive(true);
req1.onsuccess = function() {
ok(true, 'setInputMethodActive succeeded (1).');
@ -139,15 +176,23 @@ function next(msg) {
};
break;
case 2:
is(value, '#0#1hello',
'Failed to get correct input from the second iframe.');
// Do nothing and wait for the next input from the second iframe.
case 3:
is(from, 'im', 'Message sequence unexpected (3).');
is(value, '#0false', 'First frame should have the context removed.');
// Do nothing and wait for the second frame to get the context;
break;
case 3:
is(value, '#0#1#1hello',
case 4:
is(from, 'im', 'Message sequence unexpected (4).');
is(value, '#1true', 'Second frame should get the context.');
// Do nothing and wait for the input to show up in input frame.
break;
case 5:
is(from, 'input', 'Message sequence unexpected (5).');
is(value, '#0#1hello',
'Failed to get correct input from the second iframe.');
// Receive the second input from the second iframe.
// Deactive the second iframe.
let req3 = gFrames[1].setInputMethodActive(false);
@ -157,18 +202,12 @@ function next(msg) {
req3.onerror = function() {
ok(false, 'setInputMethodActive(false) failed (3): ' + this.error.name);
};
// Wait for a short while to ensure the second iframe is not active any
// more.
gTimerId = setTimeout(function() {
ok(true, 'Successfully deactivate the second iframe.');
tearDown();
}, 1000);
break;
case 4:
ok(false, 'Failed to deactivate the second iframe in time.');
clearTimeout(gTimerId);
case 6:
is(from, 'im', 'Message sequence unexpected (6).');
is(value, '#1false', 'Second frame should have the context removed.');
tearDown();
break;
}

Просмотреть файл

@ -4,23 +4,17 @@
<script>
var im = navigator.mozInputMethod;
if (im) {
var intervalId = null;
// Automatically append location hash to current input field.
im.oninputcontextchange = function() {
var ctx = im.inputcontext;
// Report back to parent frame on status of ctx gotten.
window.postMessage(window.location.hash + !!ctx, '*');
// If there is a context, send out the hash.
if (ctx) {
dump('inputcontext is received for input method ' + location.hash + '\n');
intervalId = setInterval(function() {
dump('sending text in input method ' + location.hash + '\n');
ctx.replaceSurroundingText(location.hash);
}, 500);
} else {
dump('inputcontext is removed for input method ' + location.hash + '\n');
clearInterval(intervalId);
ctx.replaceSurroundingText(location.hash);
}
};
}
</script>
<p>This frame representing the input method frame.</p>
<p>This frame represents the input method frame.</p>
</body>
</html>

Просмотреть файл

@ -66,7 +66,7 @@ skip-if = (toolkit == 'gonk' && !debug)
skip-if = toolkit == 'android' || (toolkit == 'gonk' && !debug) #TIMED_OUT, bug 766586
[test_browserElement_oop_SendEvent.html]
[test_browserElement_oop_SetInputMethodActive.html]
skip-if = true # Bug 983490, bug 987928
skip-if = (os == "android")
[test_browserElement_oop_SetVisible.html]
[test_browserElement_oop_SetVisibleFrames.html]
[test_browserElement_oop_SetVisibleFrames2.html]

Просмотреть файл

@ -170,7 +170,7 @@ skip-if = toolkit == 'android' || (toolkit == 'gonk' && !debug) # android(TIMED_
[test_browserElement_inproc_SendEvent.html]
# The setInputMethodActive() tests will timed out on Android
[test_browserElement_inproc_SetInputMethodActive.html]
skip-if = true # Bug 983490, bug 987928
skip-if = (os == "android")
[test_browserElement_inproc_SetVisible.html]
[test_browserElement_inproc_SetVisibleFrames.html]
[test_browserElement_inproc_SetVisibleFrames2.html]