blob: 89008dbd54b39958fd563c6527f782047c3adbc3 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2011 Software Freedom Conservancy. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<title>richtext_test.html</title>
<script src="../test/test_bootstrap.js"></script>
<script>
var DEMO = window.location.href.indexOf('Demo=true') != -1;
goog.require('goog.userAgent');
goog.require('webdriver.Builder');
goog.require('webdriver.Key');
goog.require('webdriver.testing.jsunit');
</script>
<iframe name="testFrame" id="testFame"></iframe>
<div id="editable" contenteditable="true"
style="border:1px solid black; height:20px; width: 100%;"></div>
<script>
var MODIFER_KEY = goog.userAgent.MAC ?
webdriver.Key.COMMAND : webdriver.Key.CONTROL;
var driver;
function setUpPage() {
var testFrameWindow = window.frames[0];
testFrameWindow.document.designMode = 'on';
}
function setUp() {
driver = new webdriver.Builder().build();
driver.switchTo().defaultContent();
// WebDriver simulates user actions as closely as possible. If we set
// body.innerHTML to an empty string, the body will have no height and
// WebDriver will not let us type on it (just like a user wouldn't be able
// to). Set the innerHTML to a single BR tag so it has enough for us to
// type on.
if (!goog.userAgent.IE) {
driver.switchTo().frame(0);
driver.executeScript('document.body.innerHTML = "<br/" + ">"');
driver.switchTo().defaultContent();
}
driver.executeScript(
'document.getElementById("editable").innerHTML = "<br/" + ">"');
}
function slowDownForDemo() {
if (DEMO) {
driver.sleep(500);
}
}
function runTypingTest(target) {
target.sendKeys('abc123');
assertThat(target.getText(), equals('abc123'));
slowDownForDemo();
target.sendKeys(MODIFER_KEY, 'ax');
assertThat(target.getText(), equals(''));
slowDownForDemo();
target.sendKeys(MODIFER_KEY, 'v');
assertThat(target.getText(), matchesRegex(/abc123\s?/));
slowDownForDemo();
}
function testCutAndPaste_designModeDoc() {
if (goog.userAgent.IE) {
G_testRunner.testCase.saveMessage('Skipping test; is IE');
return;
}
driver.switchTo().frame('testFrame');
runTypingTest(driver.findElement(By.xpath('//body')));
}
function testCutAndPaste_contentEditable() {
runTypingTest(driver.findElement(By.id('editable')));
}
</script>