Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #31860 from timdream/modal-dialog-prompt
Browse files Browse the repository at this point in the history
Bug 1168600 - Enter on keyboard should confirm window.prompt() dialog, r=albertopq
  • Loading branch information
timdream committed Sep 20, 2015
2 parents e67d319 + eccca2f commit 637e285
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 128 deletions.
247 changes: 126 additions & 121 deletions apps/keyboard/test/marionette/input_test.js
@@ -1,6 +1,9 @@
/* global suite */

'use strict';

var KeyboardTestApp = require('./lib/keyboard_test_app'),
Dialog = require('../../../system/test/marionette/lib/dialog'),
Keyboard = require('./lib/keyboard'),
assert = require('assert');

Expand Down Expand Up @@ -33,177 +36,179 @@ marionette('Input with Keyboard APP', function() {
// create a keyboard test app
keyboardTestApp = new KeyboardTestApp(client);
keyboardTestApp.launch();
keyboardTestApp.textInput.tap();

// Wait for the keyboard pop up and switch to it
systemInputMgmt.waitForKeyboardFrameDisplayed();
systemInputMgmt.switchToActiveKeyboardFrame();
});

test('Type abc', function() {
var inputString = 'abc';
keyboard.type(inputString);

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
suite('<input type="text"> tests', function() {
setup(function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

assert.equal(inputString, keyboardTestApp.textInput.getAttribute('value'));
});
keyboardTestApp.textInput.tap();

test('Type Abc in textarea', function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
// Wait for the keyboard pop up and switch to it
systemInputMgmt.waitForKeyboardFrameDisplayed();
systemInputMgmt.switchToActiveKeyboardFrame();
});

// Focus on a textarea
keyboardTestApp.textInput3.tap();
test('Type abc', function() {
var inputString = 'abc';
keyboard.type(inputString);

client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
var inputString = 'Abc';
keyboard.type(inputString.substring(0, 1));
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

// Make sure it would switch to lower case mode
var shiftKey = keyboard.shiftKey;
client.waitFor(function() {
return (shiftKey.getAttribute('aria-pressed') === 'false');
assert.equal(
inputString, keyboardTestApp.textInput.getAttribute('value'));
});

keyboard.type(inputString.substring(1));

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
test('Type multiple alphabet', function() {
var inputString = 'aGDsaIabcmvljdDFDFDDs śZîd';
keyboard.type(inputString);

assert.equal(inputString, keyboardTestApp.textInput3.getAttribute('value'));
});
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

test('Type multiple alphabet', function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
assert.equal(
inputString, keyboardTestApp.textInput.getAttribute('value'));
});

test('Type number and then alphabet', function() {
var inputString = '123abc';
keyboard.type(inputString);

client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
var inputString = 'aGDsaIabcmvljdDFDFDDs śZîd';
keyboard.type(inputString);
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
assert.equal(
inputString, keyboardTestApp.textInput.getAttribute('value'));
});

assert.equal(inputString, keyboardTestApp.textInput.getAttribute('value'));
});
test('Type alphabet and then number', function() {
var inputString = 'abc123';
keyboard.type(inputString);

test('Type number and then alphabet', function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

assert.equal(
inputString, keyboardTestApp.textInput.getAttribute('value'));
});

client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
var inputString = '123abc';
keyboard.type(inputString);
test('Type symbols', function() {
var inputString = 'aG1 !@#$&*-_/(),.:;"\'?[]{}<>+=`^~|\\%';
keyboard.type(inputString);

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

assert.equal(inputString, keyboardTestApp.textInput.getAttribute('value'));
});
assert.equal(
inputString, keyboardTestApp.textInput.getAttribute('value'));
});

test('Type alphabet and then number', function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
suite('Switch to <textarea>', function() {
setup(function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

// Focus on a textarea
keyboardTestApp.textInput3.tap();

client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
var inputString = 'abc123';
keyboard.type(inputString);
client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
});

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
test('Type Abc', function() {
var inputString = 'Abc';
keyboard.type(inputString.substring(0, 1));

assert.equal(inputString, keyboardTestApp.textInput.getAttribute('value'));
});
// Make sure it would switch to lower case mode
var shiftKey = keyboard.shiftKey;
client.waitFor(function() {
return (shiftKey.getAttribute('aria-pressed') === 'false');
});

test('Type symbols', function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
keyboard.type(inputString.substring(1));

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
var inputString = 'aG1 !@#$&*-_/(),.:;"\'?[]{}<>+=`^~|\\%';
keyboard.type(inputString);
assert.equal(
inputString, keyboardTestApp.textInput3.getAttribute('value'));
});

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
test('Double tapping space bar', function() {
var inputString = 'Aa';
keyboard.type(inputString);

assert.equal(inputString, keyboardTestApp.textInput.getAttribute('value'));
});
// type 2 spaces
var space = keyboard.getKey(' ');
space.tap();
space.tap();

test('Double tapping space bar in textarea', function() {
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

// Focus on a textarea
keyboardTestApp.textInput3.tap();
assert.equal(
'As. ', keyboardTestApp.textInput3.getAttribute('value'));
});

client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
test('tap space bar and then wait for a while before tapping again',
function() {
var inputString = 'Aa';
keyboard.type(inputString);

var inputString = 'Aa';
keyboard.type(inputString);
// type one space and then tap again after a while
var space = keyboard.getKey(' ');
space.tap();

// type 2 spaces
var space = keyboard.getKey(' ');
space.tap();
space.tap();
// The timeout for double tapping is set as 700ms.
client.helper.wait(800);
space.tap();

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);
// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

assert.equal('As. ', keyboardTestApp.textInput3.getAttribute('value'));
assert.equal('As ', keyboardTestApp.textInput3.getAttribute('value'));
});
});
});

test('tap space bar and then wait for a while before tapping again',
function() {
var dialog;

test('type into an window.prompt() dialog and hit enter', function() {
dialog = new Dialog(client);

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

// Focus on a textarea
keyboardTestApp.textInput3.tap();
// Trigger prompt
keyboardTestApp.triggerPromptModalDialog();

// Tap on the prompt input
client.switchToFrame();
systemInputMgmt.switchToActiveKeyboardFrame();
dialog.promptInput.tap();

var inputString = 'Aa';
keyboard.type(inputString);

// type one space and then tap again after a while
var space = keyboard.getKey(' ');
space.tap();

// The timeout for double tapping is set as 700ms.
client.helper.wait(800);
space.tap();
// Type
systemInputMgmt.waitForKeyboardFrameDisplayed();
systemInputMgmt.switchToActiveKeyboardFrame();
keyboard.type('lazy dog.');
keyboard.getKey('\u000d').tap();

// Switch to test app frame.
client.switchToFrame();
client.apps.switchToApp(KeyboardTestApp.ORIGIN);

assert.equal('As ', keyboardTestApp.textInput3.getAttribute('value'));
assert.equal('lazy dog.', keyboardTestApp.promptResult.text());
});
});
3 changes: 3 additions & 0 deletions apps/keyboard/test/marionette/keyboardtestapp/index.html
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<title>Keyboard APP Test</title>
<script defer src="script.js"></script>
</head>
<body>
<div>
Expand All @@ -16,5 +17,7 @@
</div>
<div id="nonInput">
</div>
<button type="button" id="triggerPromptButton">Prompt</button>
<p id="promptResult"></p>
</body>
</html>
9 changes: 9 additions & 0 deletions apps/keyboard/test/marionette/keyboardtestapp/script.js
@@ -0,0 +1,9 @@
'use strict';

document.getElementById('triggerPromptButton').onclick = () => {
// setTimeout is needed so we don't block marionette itself.
window.setTimeout(() => {
var str = window.prompt('The quick brown fox jumps over a', '');
document.getElementById('promptResult').textContent = str;
});
};
2 changes: 2 additions & 0 deletions apps/keyboard/test/marionette/lib/keyboard.js
Expand Up @@ -69,6 +69,8 @@ Keyboard.prototype = {
key == ' ') {
this.switchToPage(0);
this.switchCase(false);
} else if (key === ' ' || key === '\u0008' || key === '\u000d') {
// No need to switch -- should be on every page and every case.
} else {
var index = this.getSymbolPageIndex(key);
this.switchToPage(index);
Expand Down
16 changes: 15 additions & 1 deletion apps/keyboard/test/marionette/lib/keyboard_test_app.js
Expand Up @@ -11,7 +11,9 @@ KeyboardTests.Selector = Object.freeze({
textInput: '#textInput',
textInput2: '#textInput2',
textInput3: '#textInput3',
nonInputArea: '#nonInput'
nonInputArea: '#nonInput',
triggerPromptButton: '#triggerPromptButton',
promptResult: '#promptResult'
});

KeyboardTests.prototype = {
Expand All @@ -31,10 +33,22 @@ KeyboardTests.prototype = {
return this.client.findElement(KeyboardTests.Selector.nonInputArea);
},

get triggerPromptButton() {
return this.client.findElement(KeyboardTests.Selector.triggerPromptButton);
},

get promptResult() {
return this.client.findElement(KeyboardTests.Selector.promptResult);
},

launch: function() {
var client = this.client;
client.apps.launch(KeyboardTests.ORIGIN);
client.apps.switchToApp(KeyboardTests.ORIGIN);
client.helper.waitForElement('body');
},

triggerPromptModalDialog: function() {
this.triggerPromptButton.tap();
}
};

0 comments on commit 637e285

Please sign in to comment.