1 // Copyright (c) 2010 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.
8 // This is a NPAPI Plugin Program which is used to test the Browser's NPAPI
9 // host implementation. It is used in conjunction with the npapi_unittest.
11 // As a NPAPI Plugin, you can invoke it by creating a web page of the following
14 // <embed src="content-to-load" type="application/vnd.npapi-test"
18 // src: This is the initial content which will be sent to the plugin.
19 // type: Must be "application/vnd.npapi-test"
20 // name: The testcase to run when invoked
21 // id: The id of the test being run (for testing concurrent plugins)
23 // The Plugin drives the actual test, calling host functions and validating the
24 // Host callbacks which it receives. It is the duty of the plugin to record
27 // To indicate test completion, the plugin expects the containing HTML page to
28 // implement two javascript functions:
29 // onSuccess(string testname);
30 // onFailure(string testname, string results);
31 // The HTML host pages used in this test will then set a document cookie
32 // which the automated test framework can poll for and discover that the
33 // test has completed.
37 // When the PluginClient receives a NPP_New callback from the browser,
38 // it looks at the "name" argument which is passed in. It verifies that
39 // the name matches a known test, and instantiates that test. The test is
40 // a subclass of PluginTest.
44 #include "base/basictypes.h"
50 #if defined(__GNUC__) && __GNUC__ >= 4
51 #define EXPORT __attribute__((visibility ("default")))
56 #include "content/test/plugin/plugin_client.h"
59 BOOL API_CALL
DllMain(HINSTANCE hDll
, DWORD dwReason
, LPVOID lpReserved
) {
65 EXPORT NPError API_CALL
NP_GetEntryPoints(NPPluginFuncs
* pFuncs
) {
66 return NPAPIClient::PluginClient::GetEntryPoints(pFuncs
);
69 EXPORT NPError API_CALL
NP_Shutdown() {
70 return NPAPIClient::PluginClient::Shutdown();
73 #if defined(OS_WIN) || defined(OS_MACOSX)
74 EXPORT NPError API_CALL
NP_Initialize(NPNetscapeFuncs
* npnFuncs
) {
75 return NPAPIClient::PluginClient::Initialize(npnFuncs
);
77 #elif defined(OS_POSIX)
78 EXPORT NPError API_CALL
NP_Initialize(NPNetscapeFuncs
* npnFuncs
,
79 NPPluginFuncs
* nppFuncs
) {
80 NPError error
= NPAPIClient::PluginClient::Initialize(npnFuncs
);
81 if (error
== NPERR_NO_ERROR
) {
82 error
= NP_GetEntryPoints(nppFuncs
);
87 EXPORT NPError API_CALL
NP_GetValue(NPP instance
, NPPVariable variable
,
89 NPError err
= NPERR_NO_ERROR
;
92 case NPPVpluginNameString
:
93 *(static_cast<const char**>(value
)) = "NPAPI Test Plugin";
95 case NPPVpluginDescriptionString
:
96 *(static_cast<const char**>(value
)) =
97 "Simple NPAPI plug-in for Chromium unit tests";
99 case NPPVpluginNeedsXEmbed
:
100 *(static_cast<NPBool
*>(value
)) = true;
103 err
= NPERR_GENERIC_ERROR
;
110 EXPORT
const char* API_CALL
NP_GetMIMEDescription(void) {
111 // The layout test LayoutTests/fast/js/navigator-mimeTypes-length.html
112 // asserts that the number of mimetypes handled by plugins should be
113 // greater than the number of plugins. We specify a mimetype here so
114 // this plugin has at least one.
115 return "application/vnd.npapi-test:npapitest:test npapi";
121 const char* currentTextBreakLocaleID() { return "en_us"; }