Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / content / test / plugin / plugin_get_javascript_url2_test.cc
blobe9ab4451e40f8dd6313616f34913fc78d4d3adf1
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"
9 // url for "self".
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;
29 #endif
31 if (!test_started_) {
32 std::string url = SELF_URL;
33 HostFunctions()->geturlnotify(id(), url.c_str(), "_self",
34 reinterpret_cast<void*>(SELF_URL_STREAM_ID));
35 test_started_ = true;
37 return NPERR_NO_ERROR;
40 NPError ExecuteGetJavascriptUrl2Test::NewStream(NPMIMEType type, NPStream* stream,
41 NPBool seekable, uint16* stype) {
42 if (stream == NULL) {
43 SetError("NewStream got null stream");
44 return NPERR_INVALID_PARAM;
47 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
48 cast_validity_check);
49 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
50 switch (stream_id) {
51 case SELF_URL_STREAM_ID:
52 break;
53 default:
54 SetError("Unexpected NewStream callback");
55 break;
57 return NPERR_NO_ERROR;
60 int32 ExecuteGetJavascriptUrl2Test::WriteReady(NPStream *stream) {
61 return STREAM_CHUNK;
64 int32 ExecuteGetJavascriptUrl2Test::Write(NPStream *stream, int32 offset, int32 len,
65 void *buffer) {
66 if (stream == NULL) {
67 SetError("Write got null stream");
68 return -1;
70 if (len < 0 || len > STREAM_CHUNK) {
71 SetError("Write got bogus stream chunk size");
72 return -1;
75 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
76 cast_validity_check);
77 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
78 switch (stream_id) {
79 case SELF_URL_STREAM_ID:
80 self_url_.append(static_cast<char*>(buffer), len);
81 break;
82 default:
83 SetError("Unexpected write callback");
84 break;
86 // Pretend that we took all the data.
87 return len;
91 NPError ExecuteGetJavascriptUrl2Test::DestroyStream(NPStream *stream, NPError reason) {
92 if (stream == NULL) {
93 SetError("NewStream got null stream");
94 return NPERR_INVALID_PARAM;
97 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
98 cast_validity_check);
99 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
100 switch (stream_id) {
101 case SELF_URL_STREAM_ID:
102 // don't care
103 break;
104 default:
105 SetError("Unexpected NewStream callback");
106 break;
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);
116 switch (stream_id) {
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();
123 break;
124 default:
125 SetError("Unexpected NewStream callback");
126 break;
130 } // namespace NPAPIClient