Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / chrome / test / data / nacl / ppapi / ppp_instance / ppapi_ppp_instance.js
blob142d98d46419f8c1a27796753b32e44abffaaa6d
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 function startsWith(str, prefix) {
6 return (str.indexOf(prefix) === 0);
9 function setupTests(tester, plugin) {
10 //////////////////////////////////////////////////////////////////////////////
11 // Test Helpers
12 //////////////////////////////////////////////////////////////////////////////
13 var numMessages = 0;
14 function addTestListeners(numListeners, test, testFunction, runCheck) {
15 var messageListener = test.wrap(function(message) {
16 if (!startsWith(message.data, testFunction)) return;
17 test.log(message.data);
18 numMessages++;
19 plugin.removeEventListener('message', messageListener, false);
20 test.assertEqual(message.data, testFunction + ':PASSED');
21 if (runCheck) test.assert(runCheck());
22 if (numMessages < numListeners) {
23 plugin.addEventListener('message', messageListener, false);
24 } else {
25 numMessages = 0;
26 test.pass();
28 });
29 plugin.addEventListener('message', messageListener, false);
32 function addTestListener(test, testFunction, runCheck) {
33 return addTestListeners(1, test, testFunction, runCheck);
36 //////////////////////////////////////////////////////////////////////////////
37 // Tests
38 //////////////////////////////////////////////////////////////////////////////
40 tester.addTest('PPP_Instance::DidCreate', function() {
41 assertEqual(plugin.lastError, '');
42 });
44 tester.addAsyncTest('PPP_Instance::DidChangeView', function(test) {
45 // The .cc file hardcodes an expected 15x20 size.
46 plugin.width = 15;
47 plugin.height = 20;
48 addTestListener(test, 'DidChangeView');
49 });
51 // This test does not appear to be reliable on the bots.
52 // http://crbug.com/329511
54 tester.addAsyncTest('PPP_Instance::DidChangeFocus', function(test) {
55 // TODO(polina): How can I simulate focusing on Windows?
56 // For now just pass explicitely.
57 if (startsWith(navigator.platform, 'Win')) {
58 test.log('skipping test on ' + navigator.platform);
59 test.pass();
60 return;
62 addTestListeners(2, test, 'DidChangeFocus');
63 plugin.tabIndex = 0;
64 plugin.focus();
65 plugin.blur();
66 });
69 // PPP_Instance::HandleDocumentLoad is only used with full-frame plugins.
70 // This is tested in tests/ppapi_browser/extension_mime_handler/
72 // PPP_Instance::DidDestroy is never invoked in the untrusted code.
73 // We could wait for a crash event from it, but CallOnMainThread semantics
74 // on shutdown are still buggy, so it might never come even if the function
75 // triggered. Plus waiting for something not to happen makes the test flaky.