Skip to content

Commit

Permalink
Added tests for LastResortWebKitFontWatchRunner and updated tests
Browse files Browse the repository at this point in the history
for FontWatcher and FontWatcherRunner.
  • Loading branch information
jeremiele committed Nov 29, 2011
1 parent 6b14dc3 commit 70c89ab
Show file tree
Hide file tree
Showing 4 changed files with 269 additions and 39 deletions.
31 changes: 18 additions & 13 deletions src-test/core/fontwatchertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ FontWatcherTest.prototype.setUp = function() {
self.testStringCount_++;
self.testStrings_[fontFamily] = opt_fontTestString;
}
this.activeCallback_ = activeCallback;
this.inactiveCallback_ = inactiveCallback;
this.fontFamily_ = fontFamily;
this.fontDescription_ = fontDescription;
};

if (self.fontWatchRunnerActiveFamilies_.indexOf(fontFamily) > -1) {
activeCallback(fontFamily, fontDescription);
webfont.FontWatchRunner.prototype.start = function() {
if (self.fontWatchRunnerActiveFamilies_.indexOf(this.fontFamily_) > -1) {
this.activeCallback_(this.fontFamily_, this.fontDescription_);
} else {
inactiveCallback(fontFamily, fontDescription);
this.inactiveCallback_(this.fontFamily_, this.fontDescription_);
}

};

};

FontWatcherTest.prototype.tearDown = function() {
Expand All @@ -83,7 +87,7 @@ FontWatcherTest.prototype.testWatchOneFontNotLast = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, false);
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, false);

assertEquals(0, this.fontInactiveEventCalled_);
assertEquals(0, this.activeEventCalled_);
Expand All @@ -97,7 +101,7 @@ FontWatcherTest.prototype.testWatchOneFontActive = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, true);
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);

assertEquals(1, this.fontLoadingEventCalled_);
assertEquals(true, this.fontLoading_['fontFamily1 n4']);
Expand All @@ -115,7 +119,7 @@ FontWatcherTest.prototype.testWatchOneFontInactive = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, true);
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);

assertEquals(1, this.fontLoadingEventCalled_);
assertEquals(true, this.fontLoading_['fontFamily1 n4']);
Expand All @@ -133,7 +137,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsActive = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, true);
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);

assertEquals(3, this.fontLoadingEventCalled_);
assertEquals(true, this.fontLoading_['fontFamily1 n4']);
Expand All @@ -155,7 +159,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsInactive = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, true);
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);

assertEquals(3, this.fontLoadingEventCalled_);
assertEquals(true, this.fontLoading_['fontFamily1 n4']);
Expand All @@ -177,7 +181,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsMixed = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, {}, true);
fontWatcher.watch(fontFamilies, {}, {}, webfont.FontWatchRunner, true);

assertEquals(3, this.fontLoadingEventCalled_);
assertEquals(true, this.fontLoading_['fontFamily1 n4']);
Expand Down Expand Up @@ -205,7 +209,7 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithDescriptions = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, fontDescriptions, {}, true);
fontWatcher.watch(fontFamilies, fontDescriptions, {}, webfont.FontWatchRunner, true);

assertEquals(5, this.fontLoadingEventCalled_);
assertEquals(true, this.fontLoading_['fontFamily1 i7']);
Expand Down Expand Up @@ -238,7 +242,8 @@ FontWatcherTest.prototype.testWatchMultipleFontsWithTestStrings = function() {
var fontWatcher = new webfont.FontWatcher(this.fakeDomHelper_, this.fakeEventDispatcher_,
this.fakeFontSizer_, this.fakeAsyncCall_, this.fakeGetTime_);

fontWatcher.watch(fontFamilies, {}, fontTestStrings, true);
fontWatcher.watch(fontFamilies, {}, fontTestStrings, webfont.FontWatchRunner,
true);

assertEquals(2, this.testStringCount_);
assertEquals('testString1', this.testStrings_['fontFamily1']);
Expand Down
55 changes: 36 additions & 19 deletions src-test/core/fontwatchrunnertest.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,12 @@ FontWatchRunnerTest.prototype.testWatchFontAlreadyLoaded = function() {
this.timesToReportChangedWidth_ = 2;
this.timesToGetTimeBeforeTimeout_ = 10;

new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
this.fontDescription_);

fontWatchRunner.start();

assertEquals(1, this.asyncCount_);

Expand All @@ -108,9 +111,12 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadActive = function() {
this.timesToReportChangedWidth_ = 2;
this.timesToGetTimeBeforeTimeout_ = 10;

new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
this.fontDescription_);

fontWatchRunner.start();

assertEquals(4, this.asyncCount_);

Expand All @@ -124,9 +130,12 @@ FontWatchRunnerTest.prototype.testWatchFontWaitForLoadInactive = function() {
this.timesToReportChangedWidth_ = 2;
this.timesToGetTimeBeforeTimeout_ = 5;

new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
this.fontDescription_);

fontWatchRunner.start();

assertEquals(4, this.asyncCount_);

Expand All @@ -148,9 +157,12 @@ FontWatchRunnerTest.prototype.testWatchFontWithInconsistentWidthIsStillInactive
this.timesToReportChangedWidth_ = 1;
this.timesToGetTimeBeforeTimeout_ = 10;

new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
this.fontDescription_);

fontWatchRunner.start();

assertEquals(9, this.asyncCount_);

Expand All @@ -164,9 +176,12 @@ FontWatchRunnerTest.prototype.testDomWithDefaultTestString = function() {
this.timesToReportChangedWidth_ = 2;
this.timesToGetTimeBeforeTimeout_ = 10;

new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
this.fakeGetTime_, this.fontFamily_, this.fontDescription_);
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
this.fontDescription_);

fontWatchRunner.start();

assertEquals(4, this.createElementCalled_);
assertEquals('span', this.createdElements_[0]['name']);
Expand All @@ -187,17 +202,19 @@ FontWatchRunnerTest.prototype.testDomWithDefaultTestString = function() {
assertEquals('BESs', this.createdElements_[3]['innerHtml']);
assertEquals(4, this.insertIntoCalled_);
assertEquals(4, this.removeElementCalled_);

};

FontWatchRunnerTest.prototype.testDomWithNotDefaultTestString = function() {
this.timesToCheckWidthsBeforeChange_ = 3;
this.timesToReportChangedWidth_ = 2;
this.timesToGetTimeBeforeTimeout_ = 10;

new webfont.FontWatchRunner(this.activeCallback_, this.inactiveCallback_,
this.fakeDomHelper_, this.fakeFontSizer_, this.fakeAsyncCall_,
this.fakeGetTime_, this.fontFamily_, this.fontDescription_, 'testString');
var fontWatchRunner = new webfont.FontWatchRunner(this.activeCallback_,
this.inactiveCallback_, this.fakeDomHelper_, this.fakeFontSizer_,
this.fakeAsyncCall_, this.fakeGetTime_, this.fontFamily_,
this.fontDescription_, 'testString');

fontWatchRunner.start();

assertEquals(4, this.createElementCalled_);
assertEquals('span', this.createdElements_[0]['name']);
Expand Down
Loading

0 comments on commit 70c89ab

Please sign in to comment.