Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: webkit/glue/plugins/test/plugin_get_javascript_url2_test.cc

Issue 6012002: Move the NPAPI files from webkit/glue/plugins to webkit/plugins/npapi and put... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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.
4
5 #include "webkit/glue/plugins/test/plugin_get_javascript_url2_test.h"
6
7 #include "base/basictypes.h"
8
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
13
14 // The identifier for the fetched url stream.
15 #define FETCHED_URL_STREAM_ID 2
16
17 // The maximum chunk size of stream data.
18 #define STREAM_CHUNK 197
19
20 const int kNPNEvaluateTimerID = 100;
21 const int kNPNEvaluateTimerElapse = 50;
22
23 namespace NPAPIClient {
24
25 ExecuteGetJavascriptUrl2Test::ExecuteGetJavascriptUrl2Test(
26 NPP id, NPNetscapeFuncs *host_functions)
27 : PluginTest(id, host_functions),
28 test_started_(false) {
29 }
30
31 NPError ExecuteGetJavascriptUrl2Test::SetWindow(NPWindow* pNPWindow) {
32 if (pNPWindow->window == NULL)
33 return NPERR_NO_ERROR;
34
35 if (!test_started_) {
36 std::string url = SELF_URL;
37 HostFunctions()->geturlnotify(id(), url.c_str(), "_self",
38 reinterpret_cast<void*>(SELF_URL_STREAM_ID));
39 test_started_ = true;
40 }
41 return NPERR_NO_ERROR;
42 }
43
44 NPError ExecuteGetJavascriptUrl2Test::NewStream(NPMIMEType type, NPStream* strea m,
45 NPBool seekable, uint16* stype) {
46 if (stream == NULL) {
47 SetError("NewStream got null stream");
48 return NPERR_INVALID_PARAM;
49 }
50
51 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
52 cast_validity_check);
53 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
54 switch (stream_id) {
55 case SELF_URL_STREAM_ID:
56 break;
57 default:
58 SetError("Unexpected NewStream callback");
59 break;
60 }
61 return NPERR_NO_ERROR;
62 }
63
64 int32 ExecuteGetJavascriptUrl2Test::WriteReady(NPStream *stream) {
65 return STREAM_CHUNK;
66 }
67
68 int32 ExecuteGetJavascriptUrl2Test::Write(NPStream *stream, int32 offset, int32 len,
69 void *buffer) {
70 if (stream == NULL) {
71 SetError("Write got null stream");
72 return -1;
73 }
74 if (len < 0 || len > STREAM_CHUNK) {
75 SetError("Write got bogus stream chunk size");
76 return -1;
77 }
78
79 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
80 cast_validity_check);
81 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
82 switch (stream_id) {
83 case SELF_URL_STREAM_ID:
84 self_url_.append(static_cast<char*>(buffer), len);
85 break;
86 default:
87 SetError("Unexpected write callback");
88 break;
89 }
90 // Pretend that we took all the data.
91 return len;
92 }
93
94
95 NPError ExecuteGetJavascriptUrl2Test::DestroyStream(NPStream *stream, NPError re ason) {
96 if (stream == NULL) {
97 SetError("NewStream got null stream");
98 return NPERR_INVALID_PARAM;
99 }
100
101 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
102 cast_validity_check);
103 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
104 switch (stream_id) {
105 case SELF_URL_STREAM_ID:
106 // don't care
107 break;
108 default:
109 SetError("Unexpected NewStream callback");
110 break;
111 }
112 return NPERR_NO_ERROR;
113 }
114
115 void ExecuteGetJavascriptUrl2Test::URLNotify(const char* url, NPReason reason, v oid* data) {
116 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data),
117 cast_validity_check);
118
119 unsigned long stream_id = reinterpret_cast<unsigned long>(data);
120 switch (stream_id) {
121 case SELF_URL_STREAM_ID:
122 if (strcmp(url, SELF_URL) != 0)
123 SetError("URLNotify reported incorrect url for SELF_URL");
124 if (self_url_.empty())
125 SetError("Failed to obtain window location.");
126 SignalTestCompleted();
127 break;
128 default:
129 SetError("Unexpected NewStream callback");
130 break;
131 }
132 }
133
134 } // namespace NPAPIClient
OLDNEW
« no previous file with comments | « webkit/glue/plugins/test/plugin_get_javascript_url2_test.h ('k') | webkit/glue/plugins/test/plugin_get_javascript_url_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698