From 3f61d63e72c57f318807e06409084bf04fa08ded Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Mon, 4 Jan 2016 10:36:14 +0100 Subject: [PATCH 1/2] Add failing test for FontCacheTask::add_web_font This test tries to add a web font to the `FontCacheTask`. The added web font corresponds to the following CSS font definition: ``` @font-face { font-family: "test family"; src: local(test font face); } ``` This test fails, since `FontCacheTask` tries to get the value for the key "test font face" from `self.web_families`, but previously initialized a value for the key "test family". --- components/servo/Cargo.lock | 2 ++ tests/unit/gfx/Cargo.toml | 6 ++++++ tests/unit/gfx/font_cache_task.rs | 21 +++++++++++++++++++++ tests/unit/gfx/lib.rs | 3 +++ 4 files changed, 32 insertions(+) create mode 100644 tests/unit/gfx/font_cache_task.rs diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 3d6d7e60012..23691286c60 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -650,6 +650,8 @@ name = "gfx_tests" version = "0.0.1" dependencies = [ "gfx 0.0.1", + "ipc-channel 0.1.0 (git+https://github.com/servo/ipc-channel)", + "style 0.0.1", ] [[package]] diff --git a/tests/unit/gfx/Cargo.toml b/tests/unit/gfx/Cargo.toml index 24e43ff3def..55ec4c14504 100644 --- a/tests/unit/gfx/Cargo.toml +++ b/tests/unit/gfx/Cargo.toml @@ -10,3 +10,9 @@ doctest = false [dependencies.gfx] path = "../../../components/gfx" + +[dependencies.ipc-channel] +git = "https://github.com/servo/ipc-channel" + +[dependencies.style] +path = "../../../components/style" diff --git a/tests/unit/gfx/font_cache_task.rs b/tests/unit/gfx/font_cache_task.rs new file mode 100644 index 00000000000..54cc417acb0 --- /dev/null +++ b/tests/unit/gfx/font_cache_task.rs @@ -0,0 +1,21 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use gfx::font_cache_task::FontCacheTask; +use ipc_channel::ipc; +use style::computed_values::font_family::FontFamily; +use style::font_face::Source; + +#[test] +fn test_local_web_font() { + let (inp_chan, _) = ipc::channel().unwrap(); + let (out_chan, out_receiver) = ipc::channel().unwrap(); + let font_cache_task = FontCacheTask::new(inp_chan); + let family_name = FontFamily::FamilyName(From::from("test family")); + let variant_name = FontFamily::FamilyName(From::from("test font face")); + + font_cache_task.add_web_font(family_name, Source::Local(variant_name), out_chan); + + assert_eq!(out_receiver.recv().unwrap(), ()); +} diff --git a/tests/unit/gfx/lib.rs b/tests/unit/gfx/lib.rs index 9a5040b6fe1..3bac7b06edc 100644 --- a/tests/unit/gfx/lib.rs +++ b/tests/unit/gfx/lib.rs @@ -3,5 +3,8 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ extern crate gfx; +extern crate ipc_channel; +extern crate style; +#[cfg(test)] mod font_cache_task; #[cfg(test)] mod text_util; From 40696457299e66e58522875838e99961ed9bdf1e Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Sun, 3 Jan 2016 18:23:03 +0100 Subject: [PATCH 2/2] Don't shadow family_name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The argument to `local()` is not a font family, but the name of a »single font face within a larger family« according to http://www.w3.org/TR/css3-fonts/#src-desc. The previous implementation of `FontCache::run` would panic if the argument to `local()` would not be the name of a font family present in `self.web_families`. That happened since `FontCacheTask` tried to use the argument to `local()` as a key for `self.web_families`, although it previously correctly initialized a value for the `family` field of the `AddWebFont` command. --- components/gfx/font_cache_task.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/gfx/font_cache_task.rs b/components/gfx/font_cache_task.rs index cfa53a3d119..bba52ade3cb 100644 --- a/components/gfx/font_cache_task.rs +++ b/components/gfx/font_cache_task.rs @@ -152,7 +152,7 @@ impl FontCache { let family_name = LowercaseString::new(family.name()); if !self.web_families.contains_key(&family_name) { let templates = FontTemplates::new(); - self.web_families.insert(family_name, templates); + self.web_families.insert(family_name.clone(), templates); } match src { @@ -208,10 +208,10 @@ impl FontCache { } }); } - Source::Local(ref family) => { - let family_name = LowercaseString::new(family.name()); + Source::Local(ref font) => { + let font_face_name = LowercaseString::new(font.name()); let templates = &mut self.web_families.get_mut(&family_name).unwrap(); - for_each_variation(&family_name, |path| { + for_each_variation(&font_face_name, |path| { templates.add_template(Atom::from(&*path), None); }); result.send(()).unwrap();