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.
5 #include "content/test/plugin/plugin_get_javascript_url2_test.h"
7 #include "base/basictypes.h"
10 #define SELF_URL "javascript:window.location+\"\""
11 // The identifier for the self url stream.
12 #define SELF_URL_STREAM_ID 1
14 // The maximum chunk size of stream data.
15 #define STREAM_CHUNK 197
17 namespace NPAPIClient
{
19 ExecuteGetJavascriptUrl2Test::ExecuteGetJavascriptUrl2Test(
20 NPP id
, NPNetscapeFuncs
*host_functions
)
21 : PluginTest(id
, host_functions
),
22 test_started_(false) {
25 NPError
ExecuteGetJavascriptUrl2Test::SetWindow(NPWindow
* pNPWindow
) {
26 #if !defined(OS_MACOSX)
27 if (pNPWindow
->window
== NULL
)
28 return NPERR_NO_ERROR
;
32 std::string url
= SELF_URL
;
33 HostFunctions()->geturlnotify(id(), url
.c_str(), "_self",
34 reinterpret_cast<void*>(SELF_URL_STREAM_ID
));
37 return NPERR_NO_ERROR
;
40 NPError
ExecuteGetJavascriptUrl2Test::NewStream(NPMIMEType type
, NPStream
* stream
,
41 NPBool seekable
, uint16
* stype
) {
43 SetError("NewStream got null stream");
44 return NPERR_INVALID_PARAM
;
47 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream
->notifyData
),
49 unsigned long stream_id
= reinterpret_cast<unsigned long>(stream
->notifyData
);
51 case SELF_URL_STREAM_ID
:
54 SetError("Unexpected NewStream callback");
57 return NPERR_NO_ERROR
;
60 int32
ExecuteGetJavascriptUrl2Test::WriteReady(NPStream
*stream
) {
64 int32
ExecuteGetJavascriptUrl2Test::Write(NPStream
*stream
, int32 offset
, int32 len
,
67 SetError("Write got null stream");
70 if (len
< 0 || len
> STREAM_CHUNK
) {
71 SetError("Write got bogus stream chunk size");
75 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream
->notifyData
),
77 unsigned long stream_id
= reinterpret_cast<unsigned long>(stream
->notifyData
);
79 case SELF_URL_STREAM_ID
:
80 self_url_
.append(static_cast<char*>(buffer
), len
);
83 SetError("Unexpected write callback");
86 // Pretend that we took all the data.
91 NPError
ExecuteGetJavascriptUrl2Test::DestroyStream(NPStream
*stream
, NPError reason
) {
93 SetError("NewStream got null stream");
94 return NPERR_INVALID_PARAM
;
97 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream
->notifyData
),
99 unsigned long stream_id
= reinterpret_cast<unsigned long>(stream
->notifyData
);
101 case SELF_URL_STREAM_ID
:
105 SetError("Unexpected NewStream callback");
108 return NPERR_NO_ERROR
;
111 void ExecuteGetJavascriptUrl2Test::URLNotify(const char* url
, NPReason reason
, void* data
) {
112 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data
),
113 cast_validity_check
);
115 unsigned long stream_id
= reinterpret_cast<unsigned long>(data
);
117 case SELF_URL_STREAM_ID
:
118 if (strcmp(url
, SELF_URL
) != 0)
119 SetError("URLNotify reported incorrect url for SELF_URL");
120 if (self_url_
.empty())
121 SetError("Failed to obtain window location.");
122 SignalTestCompleted();
125 SetError("Unexpected NewStream callback");
130 } // namespace NPAPIClient