Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve font watching #66

Merged
merged 71 commits into from Jan 30, 2013
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
d059cd4
Removed the test for the webkit font fallback bug in favour of a bett…
Nov 7, 2012
c282155
Added an accurate model of the broken way webkit used to handle fallb…
Nov 7, 2012
6e8bbc3
Changed FontWatchRunner to take an extra argument indicating the pres…
Nov 7, 2012
9fca6e7
Fixed formatting.
Nov 7, 2012
b337386
Added test for when the fallback font and the loaded font have the sa…
Nov 7, 2012
9b294c3
Fixed type annotations on core/fontwatcher.
Nov 13, 2012
bb209f9
Changed the fontwatchrunner to test both width and height of the test…
Nov 13, 2012
2e27db4
Patched up the Google lastresortwebkitfontwatchrunner to match the ch…
Nov 13, 2012
58e03c9
Added two tests for checking both the width and height when monitorin…
Nov 13, 2012
2dcd257
Changed the behaviour of the timeout when the Webkit bug is present. …
Nov 13, 2012
3351efc
Added a test for detecting the Webkit fallback bug where it does not …
Nov 13, 2012
56ebd35
Renamed the null-font from __test__ to __webfontloader_test__ so it i…
Nov 13, 2012
b5a1055
Only test for the Webkit fallback bug when the user is using Webkit.
Nov 13, 2012
3db8e8a
Refactored the font measurements so that we do not have duplicated CS…
Nov 14, 2012
3d19789
Added test for the case where the font fails to load and the Webkit b…
Nov 14, 2012
100f848
Extracted size comparison method.
Nov 14, 2012
318223f
Rewrote the FontWatchRunner check_ method to correctly handle all cas…
Nov 14, 2012
6fd8ca6
FontRuler no longer automatically inserts itself into the DOM. This o…
Nov 15, 2012
247f0f0
Renamed requestFontA/B to fontRulerA/B.
Nov 15, 2012
f4ef7ef
Re-use the same two FontRuler instances for both the initial measurem…
Nov 15, 2012
63e3160
Renamed lastObservedSizeA/B to webkitFallbackSizeA/B.
Nov 15, 2012
584b78b
Renamed hasBug => hasWebkitFallbackBug and hasFallbackBug => checkWeb…
Nov 15, 2012
2049d04
Renamed fakeUserAgent_ to userAgent_.
Nov 15, 2012
c652d82
Added documentation to the Webkit fallback bug detection code.
Nov 15, 2012
10080df
Fixed type annotations and made fontDescription explicitly optional.
Nov 15, 2012
1bfcb1b
Fixed google/lastresortwebkitfontwatchrunner.js so it works with the …
Nov 15, 2012
07173c8
Added tests to exercise the webkit fallback bug detection code.
Nov 15, 2012
2db3b2b
Updated gemspec.
Nov 15, 2012
c4924b9
Moved inserting the ruler adjacent to the measurement call.
Nov 16, 2012
2da24c4
Changed FontRuler so that the element is created on instantiation but…
Nov 19, 2012
1fe77f4
Prevent a race condition where a WebKit version with the bug loads a …
Nov 21, 2012
79205af
Fixed a small bug that causes null to be inserted when there is no fo…
Nov 21, 2012
d86aa64
Merged in new font watching strategy. Google lastresortwebkitfontwatc…
Nov 30, 2012
a8854de
Fixed lastresortwebkitfontwatchrunnertest.
bramstein Dec 4, 2012
8b4c6c6
Insert the null web font just before the measurement is taken
Dec 5, 2012
4e829cc
Don't detect or pay attention to last resort sizes unless webkit bug …
Dec 5, 2012
ff13db6
Fix whitespace (tab to spaces) in DomHelper
Dec 5, 2012
74c05dc
Initial code to combine bug and last resort size detection (needs tes…
Dec 5, 2012
7bfb60d
Chrome console complains about font/truetype MIME type
Dec 5, 2012
baf2882
Added missing semicolon.
bramstein Dec 5, 2012
3b47f35
Fixed tests.
bramstein Dec 5, 2012
7d7edc3
Added test for insertNullFontStyle.
bramstein Dec 5, 2012
cb67d5f
Merge branch 'master' into bs-improve-font-watching
Dec 6, 2012
e2dde82
Only detect webkit fallback bug for older versions that may have it
Dec 6, 2012
f822fd7
First pass at moving browser information into a separate object.
bramstein Dec 12, 2012
bb49f9a
Merge branch 'master' into bs-improve-font-watching
bramstein Dec 17, 2012
1e66382
Merge branch 'master' into bs-extend-user-agent-browser-info
bramstein Dec 17, 2012
cd93994
Changed BrowserInfo enum to a real class.
bramstein Dec 17, 2012
a0063b5
UserAgent parameters are not optional.
bramstein Dec 17, 2012
8770cb9
Removed UserAgent.isSupportingWebFont method.
bramstein Dec 17, 2012
dc89a06
Merge branch 'bs-extend-user-agent-browser-info' into bs-improve-font…
bramstein Dec 17, 2012
d86e4f8
Cleaned up version number parsing.
bramstein Dec 19, 2012
ecd7c41
Hardcoded detection of the webkit fallback bug and the android font s…
bramstein Jan 3, 2013
2bd7b2a
Added tests for browserinfo bugs and did some minor renaming.
bramstein Jan 3, 2013
311945b
Rewrote font watching strategy and updated tests.
bramstein Jan 3, 2013
cc988ec
Removed NullFont methods.
bramstein Jan 3, 2013
edc12d1
Removed Android web font loading bug detection code.
bramstein Jan 3, 2013
98a84b0
Rewrote detection code to use generic font family sizes to detect the…
bramstein Jan 7, 2013
624cef8
Fixed incorrect indexing of the generic font family lookup.
bramstein Jan 7, 2013
40c7ead
Added Apple Color Emoji to the generic (last resort) font families. A…
bramstein Jan 8, 2013
05a4eb6
Fixed FontWatchRunner tests.
bramstein Jan 8, 2013
2acec0b
Fixed lastresortwebkitfontwatchrunnertest.js.
bramstein Jan 8, 2013
8a52b5a
Renamed genericFontFamilySizes to lastResortSizes.
bramstein Jan 9, 2013
42dc224
Removed old nullFontStyle shim.
bramstein Jan 9, 2013
ddcef48
Added clarifying comment about Apple Color Emoji.
bramstein Jan 9, 2013
fef9a9a
Export BrowserInfo.prototype.hasWebKitFallbackBug.
bramstein Jan 14, 2013
06cf21d
Introduced webfont.Size object.
bramstein Jan 21, 2013
75c67f7
Added option to configure metric compatible fonts that are checked fo…
bramstein Jan 21, 2013
df91723
Attempt at clearing up FontWatchRunner.prototype.check_ logic.
bramstein Jan 21, 2013
5e98f12
Merged in master.
bramstein Jan 24, 2013
77c5e3b
Fixed broken test after merging in master.
bramstein Jan 30, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src-test/core/fonttest.js
Expand Up @@ -10,7 +10,8 @@ FontTest.prototype.setUp = function() {
return document.createElement(name);
},
insertInto: function() {},
removeElement: function() {}
removeElement: function() {},
setStyle: function() {}
};
this.fontModuleLoader_ = new webfont.FontModuleLoader();
};
Expand Down
95 changes: 84 additions & 11 deletions src-test/core/fontwatchertest.js
Expand Up @@ -35,9 +35,21 @@ FontWatcherTest.prototype.setUp = function() {
}
};

this.fakeDomHelper_ = {
createElement: function(name, attrs, innerHtml) {
var element = document.createElement(name);
return element;
},
insertInto: function() {},
removeElement: function() {},
setStyle: function() {}
};

this.userAgent_ = new webfont.UserAgent('Firefox', '3.6', 'Gecko', '1.9.2', 'Macintosh', '10.6', undefined, true);

this.fakeFontSizer_ = {
getWidth: function() {
fail('Fake getWidth should not be called.');
getSize: function() {
fail('Fake getSize should not be called.');
}
};

Expand All @@ -55,7 +67,7 @@ FontWatcherTest.prototype.setUp = function() {
this.testStringCount_ = 0;
this.testStrings_ = {};
webfont.FontWatchRunner = function(activeCallback, inactiveCallback, domHelper,
fontSizer, asyncCall, getTime, fontFamily, fontDescription, opt_fontTestString) {
fontSizer, asyncCall, getTime, fontFamily, fontDescription, hasWebkitFallbackBug, opt_fontTestString) {
if (opt_fontTestString) {
self.testStringCount_++;
self.testStrings_[fontFamily] = opt_fontTestString;
Expand Down Expand Up @@ -84,7 +96,7 @@ FontWatcherTest.prototype.testWatchOneFontNotLast = function() {
var fontFamilies = [ 'fontFamily1' ];
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1' ];

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, false);
Expand All @@ -98,7 +110,7 @@ FontWatcherTest.prototype.testWatchOneFontActive = function() {
var fontFamilies = [ 'fontFamily1' ];
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1' ];

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
Expand All @@ -116,7 +128,7 @@ FontWatcherTest.prototype.testWatchOneFontInactive = function() {
var fontFamilies = [ 'fontFamily1' ];
this.fontWatchRunnerActiveFamilies_ = [];

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
Expand All @@ -134,7 +146,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsActive = function() {
var fontFamilies = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
Expand All @@ -156,7 +168,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsInactive = function() {
var fontFamilies = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
this.fontWatchRunnerActiveFamilies_ = [];

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
Expand All @@ -178,7 +190,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsMixed = function() {
var fontFamilies = [ 'fontFamily1', 'fontFamily2', 'fontFamily3' ];
this.fontWatchRunnerActiveFamilies_ = [ 'fontFamily1', 'fontFamily3' ];

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);
Expand Down Expand Up @@ -206,7 +218,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithDescriptions = function() {
'fontFamily3': ['n4', 'i4', 'n7']
};

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, fontDescriptions, {}, webfont.FontWatchRunner, true);
Expand Down Expand Up @@ -239,7 +251,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithTestStrings = function() {
'fontFamily4': null
};

var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
var fontWatcher = new webfont.FontWatcher(this.userAgent_, this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, fontTestStrings, webfont.FontWatchRunner,
Expand All @@ -249,3 +261,64 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithTestStrings = function() {
assertEquals('testString1', this.testStrings_['fontFamily1']);
assertEquals('testString3', this.testStrings_['fontFamily3']);
};

FontWatcherTest.prototype.testWebkitBugDetectionOnlyOnWebkit = function() {
var createElementCalled = false;
var fakeDomHelper = {
createElement: function() {
createElementCalled = true;
}
};
var fontWatcher = new webfont.FontWatcher(this.userAgent_, fakeDomHelper, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

assertEquals(false, fontWatcher.hasWebkitFallbackBug_);
assertEquals(false, createElementCalled);
};

FontWatcherTest.prototype.testWebkitFallbackBugDetectionWithBug = function() {
var userAgent = new webfont.UserAgent('Chrome', '18.0.1271.64', 'AppleWebKit', '537.11', 'Macintosh', '10.6', undefined, true);
var isInitial = true;
var fakeFontSizer = {
getSize: function(el) {
if (isInitial) {
isInitial = false;
// Monospace
return {
width: 1,
height: 1
};
} else {
// Something not monospace
return {
width: 2,
height: 2
};
}
}
};

var fontWatcher = new webfont.FontWatcher(userAgent, this.fakeDomHelper_, this.fakeEventDispatcher_,
fakeFontSizer, this.fakeAsyncCall_, this.fakeGetTime_);

assertEquals(true, fontWatcher.hasWebkitFallbackBug_);
};

FontWatcherTest.prototype.testWebkitFallbackBugDetectionWithoutBug = function() {
var userAgent = new webfont.UserAgent('Chrome', '23.0.1271.64', 'AppleWebKit', '537.11', 'Macintosh', '10.6', undefined, true);
var isInitial = true;
var fakeFontSizer = {
getSize: function(el) {
// Monospace
return {
width: 1,
height: 1
};
}
};

var fontWatcher = new webfont.FontWatcher(userAgent, this.fakeDomHelper_, this.fakeEventDispatcher_,
fakeFontSizer, this.fakeAsyncCall_, this.fakeGetTime_);

assertEquals(false, fontWatcher.hasWebkitFallbackBug_);
};