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

This commit is contained in:
Tim Chien 2014-05-23 03:14:00 +02:00
Родитель db892a8095
Коммит fde26509c2
4 изменённых файлов: 82 добавлений и 44 удалений

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

@ -41,7 +41,7 @@ function runTest() {
appId: SpecialPowers.Ci.nsIScriptSecurityManager.NO_APP_ID,
isInBrowserElement: true
}
}], createFrames);
}], SimpleTest.waitForFocus.bind(SimpleTest, createFrames));
}
var gFrames = [];
@ -51,29 +51,55 @@ 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() {
// "Expected" lost of focus since the test is finished.
if (input.value === '#0#1hello') {
return;
}
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.loadFrameScript('data:,(' + encodeURIComponent(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 +143,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 +181,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 +207,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]