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 identifier for the fetched url stream.
15 #define FETCHED_URL_STREAM_ID 2
17 // The maximum chunk size of stream data.
18 #define STREAM_CHUNK 197
20 const int kNPNEvaluateTimerID
= 100;
21 const int kNPNEvaluateTimerElapse
= 50;
23 namespace NPAPIClient
{
25 ExecuteGetJavascriptUrl2Test::ExecuteGetJavascriptUrl2Test(
26 NPP id
, NPNetscapeFuncs
*host_functions
)
27 : PluginTest(id
, host_functions
),
28 test_started_(false) {
31 NPError
ExecuteGetJavascriptUrl2Test::SetWindow(NPWindow
* pNPWindow
) {
32 #if !defined(OS_MACOSX)
33 if (pNPWindow
->window
== NULL
)
34 return NPERR_NO_ERROR
;
38 std::string url
= SELF_URL
;
39 HostFunctions()->geturlnotify(id(), url
.c_str(), "_self",
40 reinterpret_cast<void*>(SELF_URL_STREAM_ID
));
43 return NPERR_NO_ERROR
;
46 NPError
ExecuteGetJavascriptUrl2Test::NewStream(NPMIMEType type
, NPStream
* stream
,
47 NPBool seekable
, uint16
* stype
) {
49 SetError("NewStream got null stream");
50 return NPERR_INVALID_PARAM
;
53 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream
->notifyData
),
55 unsigned long stream_id
= reinterpret_cast<unsigned long>(stream
->notifyData
);
57 case SELF_URL_STREAM_ID
:
60 SetError("Unexpected NewStream callback");
63 return NPERR_NO_ERROR
;
66 int32
ExecuteGetJavascriptUrl2Test::WriteReady(NPStream
*stream
) {
70 int32
ExecuteGetJavascriptUrl2Test::Write(NPStream
*stream
, int32 offset
, int32 len
,
73 SetError("Write got null stream");
76 if (len
< 0 || len
> STREAM_CHUNK
) {
77 SetError("Write got bogus stream chunk size");
81 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream
->notifyData
),
83 unsigned long stream_id
= reinterpret_cast<unsigned long>(stream
->notifyData
);
85 case SELF_URL_STREAM_ID
:
86 self_url_
.append(static_cast<char*>(buffer
), len
);
89 SetError("Unexpected write callback");
92 // Pretend that we took all the data.
97 NPError
ExecuteGetJavascriptUrl2Test::DestroyStream(NPStream
*stream
, NPError reason
) {
99 SetError("NewStream got null stream");
100 return NPERR_INVALID_PARAM
;
103 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream
->notifyData
),
104 cast_validity_check
);
105 unsigned long stream_id
= reinterpret_cast<unsigned long>(stream
->notifyData
);
107 case SELF_URL_STREAM_ID
:
111 SetError("Unexpected NewStream callback");
114 return NPERR_NO_ERROR
;
117 void ExecuteGetJavascriptUrl2Test::URLNotify(const char* url
, NPReason reason
, void* data
) {
118 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data
),
119 cast_validity_check
);
121 unsigned long stream_id
= reinterpret_cast<unsigned long>(data
);
123 case SELF_URL_STREAM_ID
:
124 if (strcmp(url
, SELF_URL
) != 0)
125 SetError("URLNotify reported incorrect url for SELF_URL");
126 if (self_url_
.empty())
127 SetError("Failed to obtain window location.");
128 SignalTestCompleted();
131 SetError("Unexpected NewStream callback");
136 } // namespace NPAPIClient