Skip to content

Commit d1aca9d

Browse files
committed
Enable WebFonts cache-aware timeout adaption
Enable the feature by default, but with a FeatureList kill-switch. Bug: 570205 Change-Id: I003c21871ab71e47a863707b9709a39d76883635 Reviewed-on: https://chromium-review.googlesource.com/c/1429820 Reviewed-by: Karan Bhatia <karandeepb@chromium.org> Reviewed-by: Yutaka Hirano <yhirano@chromium.org> Reviewed-by: Kunihiko Sakamoto <ksakamoto@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org> Cr-Original-Commit-Position: refs/heads/master@{#626969}(cherry picked from commit 67bee39) Reviewed-on: https://chromium-review.googlesource.com/c/1446263 Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org> Cr-Commit-Position: refs/branch-heads/3683@{#85} Cr-Branched-From: e510299-refs/heads/master@{#625896}
1 parent 4234539 commit d1aca9d

File tree

8 files changed

+92
-21
lines changed

8 files changed

+92
-21
lines changed

chrome/test/data/extensions/api_test/webrequest/framework.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function navigateAndWait(url, callback) {
132132
chrome.tabs.update(tabId, {url: url});
133133
}
134134

135-
// data: array of extected events, each one is a dictionary:
135+
// data: array of expected events, each one is a dictionary:
136136
// { label: "<unique identifier>",
137137
// event: "<webrequest event type>",
138138
// details: { <expected details of the webrequest event> },
@@ -345,14 +345,25 @@ function captureEvent(name, details, callback) {
345345
delete details.responseHeaders;
346346
}
347347

348+
// Check if the equivalent event is already captured, and issue a unique
349+
// |eventCount| to identify each.
350+
var eventCount = 0;
351+
capturedEventData.forEach(function (event) {
352+
if (deepEq(event.event, name) && deepEq(event.details, details)) {
353+
eventCount++;
354+
// update |details| for the next match.
355+
details.eventCount = eventCount;
356+
}
357+
});
358+
348359
// find |details| in expectedEventData
349360
var found = false;
350361
var label = undefined;
351362
expectedEventData.forEach(function (exp) {
352363
if (deepEq(exp.event, name) && deepEq(exp.details, details)) {
353364
if (found) {
354-
chrome.test.fail("Received event twice '" + name + "':" +
355-
JSON.stringify(details));
365+
chrome.test.fail("Duplicated expectation entry '" + exp.label +
366+
"' should be identified by |eventCount|: " + JSON.stringify(details));
356367
} else {
357368
found = true;
358369
label = exp.label;

chrome/test/data/extensions/api_test/webrequest/test_types.js

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ runTests([
255255
url: getFontURL(),
256256
tabId: 1,
257257
initiator: getDomain(initiators.WEB_INITIATED)
258-
},
258+
}
259259
},
260260
{ label: 'onSendHeaders',
261261
event: 'onSendHeaders',
@@ -264,7 +264,49 @@ runTests([
264264
url: getFontURL(),
265265
tabId: 1,
266266
initiator: getDomain(initiators.WEB_INITIATED)
267-
},
267+
}
268+
},
269+
{ label: 'onErrorOccurred',
270+
event: 'onErrorOccurred',
271+
details: {
272+
type: 'font',
273+
url: getFontURL(),
274+
tabId: 1,
275+
initiator: getDomain(initiators.WEB_INITIATED),
276+
error: 'net::ERR_CACHE_MISS',
277+
fromCache: false,
278+
}
279+
},
280+
{ label: 'onBeforeRequest-1',
281+
event: 'onBeforeRequest',
282+
details: {
283+
eventCount: 1,
284+
type: 'font',
285+
url: getFontURL(),
286+
frameUrl: 'unknown frame URL',
287+
tabId: 1,
288+
initiator: getDomain(initiators.WEB_INITIATED)
289+
}
290+
},
291+
{ label: 'onBeforeSendHeaders-1',
292+
event: 'onBeforeSendHeaders',
293+
details: {
294+
eventCount: 1,
295+
type: 'font',
296+
url: getFontURL(),
297+
tabId: 1,
298+
initiator: getDomain(initiators.WEB_INITIATED)
299+
}
300+
},
301+
{ label: 'onSendHeaders-1',
302+
event: 'onSendHeaders',
303+
details: {
304+
eventCount: 1,
305+
type: 'font',
306+
url: getFontURL(),
307+
tabId: 1,
308+
initiator: getDomain(initiators.WEB_INITIATED)
309+
}
268310
},
269311
{ label: 'onHeadersReceived',
270312
event: 'onHeadersReceived',
@@ -275,7 +317,7 @@ runTests([
275317
statusLine: 'HTTP/1.1 200 OK',
276318
statusCode: 200,
277319
initiator: getDomain(initiators.WEB_INITIATED)
278-
},
320+
}
279321
},
280322
{ label: 'onResponseStarted',
281323
event: 'onResponseStarted',
@@ -288,7 +330,7 @@ runTests([
288330
statusLine: 'HTTP/1.1 200 OK',
289331
statusCode: 200,
290332
initiator: getDomain(initiators.WEB_INITIATED)
291-
},
333+
}
292334
},
293335
{ label: 'onCompleted',
294336
event: 'onCompleted',
@@ -301,10 +343,12 @@ runTests([
301343
statusLine: 'HTTP/1.1 200 OK',
302344
statusCode: 200,
303345
initiator: getDomain(initiators.WEB_INITIATED)
304-
},
346+
}
305347
}],
306348
[['onBeforeRequest', 'onBeforeSendHeaders', 'onSendHeaders',
307-
'onHeadersReceived', 'onResponseStarted', 'onCompleted']],
349+
'onErrorOccurred', 'onBeforeRequest-1', 'onBeforeSendHeaders-1',
350+
'onSendHeaders-1', 'onHeadersReceived', 'onResponseStarted',
351+
'onCompleted']],
308352
{urls: [getFontURL()]});
309353

310354
// Load a page to be sure webRequest listeners are set up.

third_party/blink/common/features.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,9 @@ const base::Feature kDecodeLossyWebPImagesToYUV{
180180
const base::Feature kAlwaysAccelerateCanvas{"AlwaysAccelerateCanvas",
181181
base::FEATURE_DISABLED_BY_DEFAULT};
182182

183+
// Enables cache-aware WebFonts loading. See https://crbug.com/570205.
184+
const base::Feature kWebFontsCacheAwareTimeoutAdaption{
185+
"WebFontsCacheAwareTimeoutAdaption", base::FEATURE_ENABLED_BY_DEFAULT};
186+
183187
} // namespace features
184188
} // namespace blink

third_party/blink/public/common/features.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ BLINK_COMMON_EXPORT extern const char
6060
BLINK_COMMON_EXPORT extern const base::Feature kDecodeLossyWebPImagesToYUV;
6161
BLINK_COMMON_EXPORT extern const base::Feature kAlwaysAccelerateCanvas;
6262

63+
BLINK_COMMON_EXPORT extern const base::Feature
64+
kWebFontsCacheAwareTimeoutAdaption;
65+
6366
} // namespace features
6467
} // namespace blink
6568

third_party/blink/renderer/core/css/css_font_face_src_value.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include "third_party/blink/renderer/core/css/css_font_face_src_value.h"
2727

28+
#include "base/feature_list.h"
29+
#include "third_party/blink/public/common/features.h"
2830
#include "third_party/blink/public/platform/web_url_request.h"
2931
#include "third_party/blink/renderer/core/css/css_markup.h"
3032
#include "third_party/blink/renderer/core/css/style_sheet_contents.h"
@@ -88,8 +90,10 @@ FontResource& CSSFontFaceSrcValue::Fetch(ExecutionContext* context,
8890
ResourceLoaderOptions options;
8991
options.initiator_info.name = fetch_initiator_type_names::kCSS;
9092
FetchParameters params(resource_request, options);
91-
if (RuntimeEnabledFeatures::WebFontsCacheAwareTimeoutAdaptationEnabled())
93+
if (base::FeatureList::IsEnabled(
94+
features::kWebFontsCacheAwareTimeoutAdaption)) {
9295
params.SetCacheAwareLoadingEnabled(kIsCacheAwareLoadingEnabled);
96+
}
9397
params.SetContentSecurityCheck(should_check_content_security_policy_);
9498
const SecurityOrigin* security_origin = context->GetSecurityOrigin();
9599

third_party/blink/renderer/core/loader/resource/font_resource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class CORE_EXPORT FontResource final : public Resource {
106106
TaskHandle font_load_long_limit_;
107107

108108
friend class MemoryCache;
109-
FRIEND_TEST_ALL_PREFIXES(FontResourceTest, CacheAwareFontLoading);
109+
FRIEND_TEST_ALL_PREFIXES(CacheAwareFontResourceTest, CacheAwareFontLoading);
110110
};
111111

112112
DEFINE_RESOURCE_TYPE_CASTS(Font);

third_party/blink/renderer/core/loader/resource/font_resource_test.cc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include "third_party/blink/renderer/core/loader/resource/font_resource.h"
66

7+
#include "base/test/scoped_feature_list.h"
78
#include "testing/gtest/include/gtest/gtest.h"
9+
#include "third_party/blink/public/common/features.h"
810
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom-shared.h"
911
#include "third_party/blink/public/platform/platform.h"
1012
#include "third_party/blink/public/platform/web_url_loader_mock_factory.h"
@@ -36,6 +38,18 @@ class FontResourceTest : public testing::Test {
3638
}
3739
};
3840

41+
class CacheAwareFontResourceTest : public FontResourceTest {
42+
public:
43+
void SetUp() override {
44+
scoped_feature_list_.InitAndEnableFeature(
45+
features::kWebFontsCacheAwareTimeoutAdaption);
46+
FontResourceTest::SetUp();
47+
}
48+
49+
private:
50+
base::test::ScopedFeatureList scoped_feature_list_;
51+
};
52+
3953
// Tests if ResourceFetcher works fine with FontResource that requires defered
4054
// loading supports.
4155
TEST_F(FontResourceTest,
@@ -98,16 +112,13 @@ TEST_F(FontResourceTest,
98112
}
99113

100114
// Tests if cache-aware font loading works correctly.
101-
TEST_F(FontResourceTest, CacheAwareFontLoading) {
115+
TEST_F(CacheAwareFontResourceTest, CacheAwareFontLoading) {
102116
KURL url("http://127.0.0.1:8000/font.woff");
103117
ResourceResponse response(url);
104118
response.SetHTTPStatusCode(200);
105119
Platform::Current()->GetURLLoaderMockFactory()->RegisterURL(
106120
url, WrappedResourceResponse(response), "");
107121

108-
RuntimeEnabledFeatures::Backup features_backup;
109-
RuntimeEnabledFeatures::SetWebFontsCacheAwareTimeoutAdaptationEnabled(true);
110-
111122
std::unique_ptr<DummyPageHolder> dummy_page_holder =
112123
DummyPageHolder::Create(IntSize(800, 600));
113124
Document& document = dummy_page_holder->GetDocument();
@@ -166,8 +177,6 @@ TEST_F(FontResourceTest, CacheAwareFontLoading) {
166177

167178
Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
168179
GetMemoryCache()->Remove(&resource);
169-
170-
features_backup.Restore();
171180
}
172181

173182
} // namespace blink

third_party/blink/renderer/platform/runtime_enabled_features.json5

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,10 +1395,6 @@
13951395
name: "WebBluetoothScanning",
13961396
status: "test",
13971397
},
1398-
{
1399-
name: "WebFontsCacheAwareTimeoutAdaptation",
1400-
status: "experimental",
1401-
},
14021398
{
14031399
name: "WebGL2ComputeContext",
14041400
status: "experimental",

0 commit comments

Comments
 (0)