1 // Copyright (c) 2011 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 tester.addAsyncTest('PPP_Instance::DidChangeFocus', function(test) {
52 // TODO(polina): How can I simulate focusing on Windows?
53 // For now just pass explicitely.
54 if (startsWith(navigator.platform, 'Win')) {
55 test.log('skipping test on ' + navigator.platform);
59 addTestListeners(2, test, 'DidChangeFocus');
65 // PPP_Instance::HandleDocumentLoad is only used with full-frame plugins.
66 // This is tested in tests/ppapi_browser/extension_mime_handler/
68 // PPP_Instance::DidDestroy is never invoked in the untrusted code.
69 // We could wait for a crash event from it, but CallOnMainThread semantics
70 // on shutdown are still buggy, so it might never come even if the function
71 // triggered. Plus waiting for something not to happen makes the test flaky.