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 //////////////////////////////////////////////////////////////////////////////
12 //////////////////////////////////////////////////////////////////////////////
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);
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);
29 plugin.addEventListener('message', messageListener, false);
32 function addTestListener(test, testFunction, runCheck) {
33 return addTestListeners(1, test, testFunction, runCheck);
36 //////////////////////////////////////////////////////////////////////////////
38 //////////////////////////////////////////////////////////////////////////////
40 tester.addTest('PPP_Instance::DidCreate', function() {
41 assertEqual(plugin.lastError, '');
44 tester.addAsyncTest('PPP_Instance::DidChangeView', function(test) {
45 // The .cc file hardcodes an expected 15x20 size.
48 addTestListener(test, 'DidChangeView');
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);
62 addTestListeners(2, test, 'DidChangeFocus');
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.