|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium; |
| 19 | + |
| 20 | +import static org.hamcrest.Matchers.anyOf; |
| 21 | +import static org.hamcrest.Matchers.equalTo; |
| 22 | +import static org.junit.Assert.assertEquals; |
| 23 | +import static org.junit.Assert.assertThat; |
| 24 | +import static org.junit.Assume.assumeFalse; |
| 25 | +import static org.openqa.selenium.testing.Ignore.Driver.CHROME; |
| 26 | +import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT; |
| 27 | +import static org.openqa.selenium.testing.Ignore.Driver.IE; |
| 28 | +import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE; |
| 29 | +import static org.openqa.selenium.testing.Ignore.Driver.SAFARI; |
| 30 | +import static org.openqa.selenium.testing.TestUtilities.getEffectivePlatform; |
| 31 | +import static org.openqa.selenium.testing.TestUtilities.isFirefox; |
| 32 | + |
| 33 | +import org.junit.After; |
| 34 | +import org.junit.Test; |
| 35 | +import org.openqa.selenium.testing.Ignore; |
| 36 | +import org.openqa.selenium.testing.JUnit4TestBase; |
| 37 | +import org.openqa.selenium.testing.JavascriptEnabled; |
| 38 | +import org.openqa.selenium.testing.NotYetImplemented; |
| 39 | + |
| 40 | +public class ContentEditableTest extends JUnit4TestBase { |
| 41 | + |
| 42 | + @After |
| 43 | + public void switchToDefaultContent() { |
| 44 | + driver.switchTo().defaultContent(); |
| 45 | + } |
| 46 | + |
| 47 | + @JavascriptEnabled |
| 48 | + @Ignore(value = {SAFARI, MARIONETTE}, reason = "Safari: cannot type on contentEditable with synthetic events") |
| 49 | + @Test |
| 50 | + public void testTypingIntoAnIFrameWithContentEditableOrDesignModeSet() { |
| 51 | + driver.get(pages.richTextPage); |
| 52 | + |
| 53 | + driver.switchTo().frame("editFrame"); |
| 54 | + WebElement element = driver.switchTo().activeElement(); |
| 55 | + element.sendKeys("Fishy"); |
| 56 | + |
| 57 | + driver.switchTo().defaultContent(); |
| 58 | + WebElement trusted = driver.findElement(By.id("istrusted")); |
| 59 | + WebElement id = driver.findElement(By.id("tagId")); |
| 60 | + |
| 61 | + assertThat(trusted.getText(), anyOf( |
| 62 | + equalTo("[true]"), |
| 63 | + // Chrome does not set a trusted flag. |
| 64 | + equalTo("[n/a]"), |
| 65 | + equalTo("[]"))); |
| 66 | + assertThat(id.getText(), anyOf(equalTo("[frameHtml]"), equalTo("[theBody]"))); |
| 67 | + } |
| 68 | + |
| 69 | + @JavascriptEnabled |
| 70 | + @NotYetImplemented(HTMLUNIT) |
| 71 | + @Test |
| 72 | + @Ignore(MARIONETTE) |
| 73 | + public void testNonPrintableCharactersShouldWorkWithContentEditableOrDesignModeSet() { |
| 74 | + assumeFalse("FIXME: Fails in Firefox on Linux with synthesized events", |
| 75 | + isFirefox(driver) && |
| 76 | + (getEffectivePlatform().is(Platform.LINUX) || getEffectivePlatform().is(Platform.MAC))); |
| 77 | + |
| 78 | + driver.get(pages.richTextPage); |
| 79 | + |
| 80 | + driver.switchTo().frame("editFrame"); |
| 81 | + WebElement element = driver.switchTo().activeElement(); |
| 82 | + element.sendKeys("Dishy", Keys.BACK_SPACE, Keys.LEFT, Keys.LEFT); |
| 83 | + element.sendKeys(Keys.LEFT, Keys.LEFT, "F", Keys.DELETE, Keys.END, "ee!"); |
| 84 | + |
| 85 | + assertEquals("Fishee!", element.getText()); |
| 86 | + } |
| 87 | + |
| 88 | + @Ignore(value = {SAFARI, HTMLUNIT}, reason = "Untested browsers;" + |
| 89 | + " Safari: cannot type on contentEditable with synthetic events", |
| 90 | + issues = {3127}) |
| 91 | + @Test |
| 92 | + public void testShouldBeAbleToTypeIntoEmptyContentEditableElement() { |
| 93 | + driver.get(pages.readOnlyPage); |
| 94 | + WebElement editable = driver.findElement(By.id("content-editable-blank")); |
| 95 | + |
| 96 | + editable.sendKeys("cheese"); |
| 97 | + |
| 98 | + assertThat(editable.getText(), equalTo("cheese")); |
| 99 | + } |
| 100 | + |
| 101 | + @Ignore(value = {CHROME, IE, SAFARI, HTMLUNIT, MARIONETTE}) |
| 102 | + @Test |
| 103 | + public void testShouldBeAbleToTypeIntoContentEditableElementWithExistingValue() { |
| 104 | + driver.get(pages.readOnlyPage); |
| 105 | + WebElement editable = driver.findElement(By.id("content-editable")); |
| 106 | + |
| 107 | + String initialText = editable.getText(); |
| 108 | + editable.sendKeys(", edited"); |
| 109 | + |
| 110 | + assertThat(editable.getText(), equalTo(initialText + ", edited")); |
| 111 | + } |
| 112 | + |
| 113 | + @Ignore(value = {IE, SAFARI, HTMLUNIT, MARIONETTE}, |
| 114 | + reason = "Untested browsers;" + |
| 115 | + " Safari: cannot type on contentEditable with synthetic events", |
| 116 | + issues = {3127}) |
| 117 | + @Test |
| 118 | + public void testShouldBeAbleToTypeIntoTinyMCE() { |
| 119 | + driver.get(appServer.whereIs("tinymce.html")); |
| 120 | + driver.switchTo().frame("mce_0_ifr"); |
| 121 | + |
| 122 | + WebElement editable = driver.findElement(By.id("tinymce")); |
| 123 | + |
| 124 | + editable.clear(); |
| 125 | + editable.sendKeys("cheese"); // requires focus on OS X |
| 126 | + |
| 127 | + assertThat(editable.getText(), equalTo("cheese")); |
| 128 | + } |
| 129 | + |
| 130 | + @Ignore(value = {IE, SAFARI, HTMLUNIT, MARIONETTE}, |
| 131 | + reason = "Untested browsers;" + |
| 132 | + " Safari: cannot type on contentEditable with synthetic events", |
| 133 | + issues = {3127}) |
| 134 | + @Test |
| 135 | + public void testShouldAppendToTinyMCE() { |
| 136 | + driver.get(appServer.whereIs("tinymce.html")); |
| 137 | + driver.switchTo().frame("mce_0_ifr"); |
| 138 | + |
| 139 | + WebElement editable = driver.findElement(By.id("tinymce")); |
| 140 | + |
| 141 | + editable.sendKeys(" and cheese"); // requires focus on OS X |
| 142 | + |
| 143 | + assertThat(editable.getText(), equalTo("Initial content and cheese")); |
| 144 | + } |
| 145 | + |
| 146 | +} |
0 commit comments