Skip to content

Commit

Permalink
Merge branch 'master' into bs-custom-timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram Stein committed Feb 28, 2013
2 parents 70d6536 + 34e2789 commit a00449c
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 115 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v1.2.1 (February 26, 2013)
* Fix the possibility of test strings wrapping to a new line and thereby breaking font watching.
* Change the FontWatchRunner to not create DOM elements until it is started.
* Fix the possibility of extraneous whitespace in class names.
* Add a cache buster parameter to the Monotype/Fonts.com module.
* Fix the case where there are no fonts to load. Webfontloader will now fire the inactive event correctly.
* Test suite now uses the active browser to test font watching in addition to the mocked font watching tests.
* Test suite is now using Jasmine instead of JSTestDriver.

v1.2.0 (January 30, 2013)
* Improved font watching for browsers with the WebKit web font fallback bug
* Improved font watching in general by comparing both width and height
Expand Down
11 changes: 10 additions & 1 deletion docs/EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,16 @@ not supplied.
### Browser Support

Every web browser has varying levels of support for fonts linked via
@font-face.
@font-face. Support for web fonts is determined using the browser user agent
string. The user agent string may claim to support a web font format
when it in fact does not. This is especially noticable on mobile browsers
with a "Desktop" mode, which usually identify as Chrome on Linux.
In this case a web font provider may decide to send WOFF fonts to the
device because the real desktop Chrome supports it, while the mobile
browser does not. The WebFont Loader is not designed to handle these
cases and it chooses to believe the user agent string. Web font providers
may or may not build on top of the basic WebFont Loader functionality
to handle these special cases individually.

> If WebFont Loader determines that the current browser does not support
`@font-face`, the `Inactive` event will be triggered.
Expand Down
2 changes: 1 addition & 1 deletion lib/webfontloader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'webfontloader/modules'

module WebFontLoader
VERSION = '1.2.0'
VERSION = '1.2.1'

ProjectRoot = File.expand_path(File.dirname(__FILE__) + "/..")

Expand Down
4 changes: 2 additions & 2 deletions spec/core/font_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('WebFont', function () {
userAgent = null;

beforeEach(function () {
userAgent = new UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, new BrowserInfo(true, false));
userAgent = new UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, new BrowserInfo(true, false, false));
fontModuleLoader = new FontModuleLoader();
});

Expand Down Expand Up @@ -190,7 +190,7 @@ describe('WebFont', function () {
testModule = null;

beforeEach(function () {
font = new WebFont(window, fontModuleLoader, function (func, timeout) { func(); }, new UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, new BrowserInfo(false, false)));
font = new WebFont(window, fontModuleLoader, function (func, timeout) { func(); }, new UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, new BrowserInfo(false, false, false)));
font.addModule('test', function (conf, domHelper) {
testModule = new function () {
this.conf = conf;
Expand Down
2 changes: 1 addition & 1 deletion spec/core/fontwatcher_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('FontWatcher', function () {
activeFontFamilies = [];

beforeEach(function () {
userAgent = new UserAgent('Firefox', '3.6', 'Gecko', '1.9.3', 'Macintosh', '10.6', undefined, new BrowserInfo(true, false));
userAgent = new UserAgent('Firefox', '3.6', 'Gecko', '1.9.3', 'Macintosh', '10.6', undefined, new BrowserInfo(true, false, false));
activeFontFamilies = [];
testStrings = jasmine.createSpy('testStrings');
timeout = jasmine.createSpy('timeout');
Expand Down
52 changes: 39 additions & 13 deletions spec/core/fontwatchrunner_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe('FontWatchRunner', function () {
var FontWatchRunner = webfont.FontWatchRunner,
BrowserInfo = webfont.BrowserInfo,
UserAgentParser = webfont.UserAgentParser,
Size = webfont.Size,
DomHelper = webfont.DomHelper,
Expand All @@ -14,6 +15,7 @@ describe('FontWatchRunner', function () {
FALLBACK_SIZE_B = new Size(2, 2),
LAST_RESORT_SIZE = new Size(4, 4),

browserInfo = new BrowserInfo(true, false, false),
setupSizes = [FALLBACK_SIZE_A, FALLBACK_SIZE_B, LAST_RESORT_SIZE],
actualSizes = [],
fakeGetSizeCount = 0,
Expand Down Expand Up @@ -85,7 +87,7 @@ describe('FontWatchRunner', function () {
];

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, false);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, browserInfo);

fontWatchRunner.start();

Expand All @@ -102,7 +104,7 @@ describe('FontWatchRunner', function () {
];

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, false);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, browserInfo);

fontWatchRunner.start();
expect(asyncCount).toEqual(3);
Expand All @@ -121,7 +123,7 @@ describe('FontWatchRunner', function () {
];

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, false);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, browserInfo);

fontWatchRunner.start();

Expand All @@ -130,14 +132,20 @@ describe('FontWatchRunner', function () {
});

describe('WebKit fallback bug', function () {
var fallbackBugBrowserInfo = null;

beforeEach(function () {
fallbackBugBrowserInfo = new BrowserInfo(true, true, false);
});

it('should ignore fallback size and call active', function () {
actualSizes = [
LAST_RESORT_SIZE, LAST_RESORT_SIZE,
TARGET_SIZE, TARGET_SIZE
];

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, true);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, fallbackBugBrowserInfo);

fontWatchRunner.start();

Expand All @@ -154,7 +162,7 @@ describe('FontWatchRunner', function () {
timesToGetTimeBeforeTimeout = 2;

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, true);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, fallbackBugBrowserInfo);

fontWatchRunner.start();

Expand All @@ -172,7 +180,7 @@ describe('FontWatchRunner', function () {
timesToGetTimeBeforeTimeout = 3;

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, true);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, fallbackBugBrowserInfo);

fontWatchRunner.start();

Expand All @@ -189,7 +197,7 @@ describe('FontWatchRunner', function () {
timesToGetTimeBeforeTimeout = 2;

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, true,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, fallbackBugBrowserInfo,
0, { 'My Other Family': true });

fontWatchRunner.start();
Expand All @@ -215,6 +223,24 @@ describe('FontWatchRunner', function () {
});
});

describe('webkit metrics bug', function () {
it('should correctly call active even though the height is different', function () {
actualSizes = [
FALLBACK_SIZE_A, FALLBACK_SIZE_B,
new Size(1, 2), new Size(2, 3), // Same as FALLBACK_SIZE_A and FALLBACK_SIZE_B except that the height is different.
TARGET_SIZE, TARGET_SIZE
];

var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, new BrowserInfo(true, false, true));

fontWatchRunner.start();

expect(asyncCount).toEqual(2);
expect(activeCallback).toHaveBeenCalledWith('My Family', 'n4');
});
});

describe('real browser testing', function () {
var fontSizer = null,
asyncCall = null,
Expand Down Expand Up @@ -244,7 +270,7 @@ describe('FontWatchRunner', function () {
it('should fail to load a null font', function () {
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fontSizer, asyncCall, getTime, '__webfontloader_test__', '',
userAgent.getBrowserInfo().hasWebKitFallbackBug(), 500);
userAgent.getBrowserInfo(), 500);

runs(function () {
fontWatchRunner.start();
Expand All @@ -262,7 +288,7 @@ describe('FontWatchRunner', function () {
it('should load font succesfully', function () {
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fontSizer, asyncCall, getTime, 'SourceSansA', '',
userAgent.getBrowserInfo().hasWebKitFallbackBug(), 500),
userAgent.getBrowserInfo(), 500),
ruler = new FontRuler(domHelper, fontSizer, 'abcdef'),
activeSize = null,
originalSize = null,
Expand Down Expand Up @@ -303,7 +329,7 @@ describe('FontWatchRunner', function () {
it('should attempt to load a non-existing font', function () {
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fontSizer, asyncCall, getTime, 'Elena', '',
userAgent.getBrowserInfo().hasWebKitFallbackBug(), 500);
userAgent.getBrowserInfo(), 500);

runs(function () {
fontWatchRunner.start();
Expand All @@ -321,7 +347,7 @@ describe('FontWatchRunner', function () {
it('should load even if @font-face is inserted after watching has started', function () {
var fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fontSizer, asyncCall, getTime, 'SourceSansB', '',
userAgent.getBrowserInfo().hasWebKitFallbackBug(), 500),
userAgent.getBrowserInfo(), 500),
ruler = new FontRuler(domHelper, fontSizer, 'abcdef'),
activeSize = null,
originalSize = null,
Expand Down Expand Up @@ -379,7 +405,7 @@ describe('FontWatchRunner', function () {
];

fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, false);
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily, fontDescription, browserInfo);

fontWatchRunner.start();

Expand All @@ -393,7 +419,7 @@ describe('FontWatchRunner', function () {

fontWatchRunner = new FontWatchRunner(activeCallback, inactiveCallback,
domHelper, fakeFontSizer, fakeAsyncCall, fakeGetTime, fontFamily,
fontDescription, false, 0, {}, 'TestString');
fontDescription, browserInfo, 0, {}, 'TestString');

fontWatchRunner.start();

Expand Down
Loading

0 comments on commit a00449c

Please sign in to comment.