[Temporary] try resources/ahem.js

BUG=392046
[email protected]

Review URL: https://codereview.chromium.org/1207173002

git-svn-id: svn://svn.chromium.org/blink/trunk@197801 bbb929c8-8fbe-4397-9dbb-9b2b20218538
diff --git a/third_party/WebKit/LayoutTests/resources/ahem.js b/third_party/WebKit/LayoutTests/resources/ahem.js
new file mode 100644
index 0000000..156b248
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/resources/ahem.js
@@ -0,0 +1,19 @@
+// A test using Ahem font includes this file to ensure that the
+// font is loaded before window.onload fires and test finishes.
+// Note: this doesn't work if the test doesn't contain any visible
+// element with 'font-family: Ahem' style.
+(function() {
+  var scripts = document.getElementsByTagName('script');
+  var src = scripts[scripts.length - 1].src;
+  var lastSlash = src.lastIndexOf('/');
+  var relativePath = src.substr(0, lastSlash);
+
+  window.addEventListener('DOMContentLoad', function() {
+    var style = document.createElement('style');
+    style.appendChild(document.createTextNode(
+      '@font-face { font-family: Ahem; src: url(' + relativePath + '/Ahem.ttf'));
+    document.head.appendChild(style);
+    // Force a layout to start loading the font.
+    document.documentElement.offsetTop;
+  }, true);
+}());