зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1396823 - Use unicode-segmentation to iterate graphemes instead of chars r=ato
MozReview-Commit-ID: 8QsOmtXDnGI --HG-- extra : rebase_source : 0af1eb0af8d23346a1b20ac6a04964d974232850
This commit is contained in:
Родитель
a4da46bb89
Коммит
e6f4df94b9
|
@ -2034,6 +2034,7 @@ dependencies = [
|
|||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"unicode-segmentation 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import pytest
|
|||
import time
|
||||
from tests.actions.support.keys import ALL_EVENTS, Keys
|
||||
from tests.actions.support.refine import filter_dict, get_keys, get_events
|
||||
|
||||
from webdriver import error
|
||||
|
||||
@pytest.mark.parametrize("name,expected", ALL_EVENTS.items())
|
||||
def test_webdriver_special_key_sends_keydown(session,
|
||||
|
@ -43,3 +43,37 @@ def test_webdriver_special_key_sends_keydown(session,
|
|||
assert entered_keys == expected["key"]
|
||||
else:
|
||||
assert len(entered_keys) == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
(u"f"),
|
||||
(u"\u0BA8\u0BBF"),
|
||||
(u"\u1100\u1161\u11A8"),
|
||||
])
|
||||
def test_multiple_codepoint_keys_behave_correctly(session,
|
||||
key_reporter,
|
||||
key_chain,
|
||||
value):
|
||||
key_chain \
|
||||
.key_down(value) \
|
||||
.key_up(value) \
|
||||
.perform()
|
||||
|
||||
assert get_keys(key_reporter) == value
|
||||
|
||||
|
||||
@pytest.mark.parametrize("value", [
|
||||
(u"fa"),
|
||||
(u"\u0BA8\u0BBFb"),
|
||||
(u"\u0BA8\u0BBF\u0BA8"),
|
||||
(u"\u1100\u1161\u11A8c")
|
||||
])
|
||||
def test_invalid_multiple_codepoint_keys_fail(session,
|
||||
key_reporter,
|
||||
key_chain,
|
||||
value):
|
||||
with pytest.raises(error.InvalidArgumentException):
|
||||
key_chain \
|
||||
.key_down(value) \
|
||||
.key_up(value) \
|
||||
.perform()
|
|
@ -17,3 +17,4 @@ regex = "0.2"
|
|||
rustc-serialize = "0.3"
|
||||
time = "0.1"
|
||||
url = "1"
|
||||
unicode-segmentation = "1.1.0"
|
|
@ -2,6 +2,7 @@ use command::Parameters;
|
|||
use common::{Nullable, WebElement};
|
||||
use error::{WebDriverResult, WebDriverError, ErrorStatus};
|
||||
use rustc_serialize::json::{ToJson, Json};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
use std::collections::BTreeMap;
|
||||
use std::default::Default;
|
||||
|
||||
|
@ -368,26 +369,26 @@ impl ToJson for KeyAction {
|
|||
}
|
||||
}
|
||||
|
||||
fn validate_key_value(value_str: &str) -> WebDriverResult<char> {
|
||||
let mut chars = value_str.chars();
|
||||
let value = if let Some(c) = chars.next() {
|
||||
c
|
||||
fn validate_key_value(value_str: &str) -> WebDriverResult<String> {
|
||||
let mut graphemes = value_str.graphemes(true);
|
||||
let value = if let Some(g) = graphemes.next() {
|
||||
g
|
||||
} else {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidArgument,
|
||||
"Parameter 'value' was an empty string"))
|
||||
};
|
||||
if chars.next().is_some() {
|
||||
if graphemes.next().is_some() {
|
||||
return Err(WebDriverError::new(
|
||||
ErrorStatus::InvalidArgument,
|
||||
"Parameter 'value' contained multiple characters"))
|
||||
"Parameter 'value' contained multiple graphemes"))
|
||||
};
|
||||
Ok(value)
|
||||
Ok(value.to_string())
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct KeyUpAction {
|
||||
pub value: char
|
||||
pub value: String
|
||||
}
|
||||
|
||||
impl Parameters for KeyUpAction {
|
||||
|
@ -419,7 +420,7 @@ impl ToJson for KeyUpAction {
|
|||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct KeyDownAction {
|
||||
pub value: char
|
||||
pub value: String
|
||||
}
|
||||
|
||||
impl Parameters for KeyDownAction {
|
||||
|
|
|
@ -8,6 +8,7 @@ extern crate regex;
|
|||
extern crate cookie;
|
||||
extern crate time;
|
||||
extern crate url;
|
||||
extern crate unicode_segmentation;
|
||||
|
||||
#[macro_use] pub mod macros;
|
||||
pub mod actions;
|
||||
|
|
Загрузка…
Ссылка в новой задаче