| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/glue/plugins/test/plugin_geturl_test.h" | 5 #include "webkit/glue/plugins/test/plugin_geturl_test.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 npn_evaluate_context_(false) { | 39 npn_evaluate_context_(false) { |
| 40 } | 40 } |
| 41 | 41 |
| 42 NPError PluginGetURLTest::New(uint16 mode, int16 argc, const char* argn[], | 42 NPError PluginGetURLTest::New(uint16 mode, int16 argc, const char* argn[], |
| 43 const char* argv[], NPSavedData* saved) { | 43 const char* argv[], NPSavedData* saved) { |
| 44 const char* page_not_found_url = GetArgValue("page_not_found_url", argc, | 44 const char* page_not_found_url = GetArgValue("page_not_found_url", argc, |
| 45 argn, argv); | 45 argn, argv); |
| 46 if (page_not_found_url) { | 46 if (page_not_found_url) { |
| 47 page_not_found_url_ = page_not_found_url; | 47 page_not_found_url_ = page_not_found_url; |
| 48 expect_404_response_ = true; | 48 expect_404_response_ = true; |
| 49 } else { | 49 } |
| 50 const char* fail_write_url = GetArgValue("fail_write_url", argc, | 50 |
| 51 argn, argv); | 51 const char* fail_write_url = GetArgValue("fail_write_url", argc, |
| 52 if (fail_write_url) { | 52 argn, argv); |
| 53 fail_write_url_ = fail_write_url; | 53 if (fail_write_url) { |
| 54 } | 54 fail_write_url_ = fail_write_url; |
| 55 } |
| 56 |
| 57 const char* referrer_target_url = GetArgValue("ref_target", argc, |
| 58 argn, argv); |
| 59 if (referrer_target_url) { |
| 60 referrer_target_url_ = referrer_target_url; |
| 55 } | 61 } |
| 56 | 62 |
| 57 return PluginTest::New(mode, argc, argn, argv, saved); | 63 return PluginTest::New(mode, argc, argn, argv, saved); |
| 58 } | 64 } |
| 59 | 65 |
| 60 NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) { | 66 NPError PluginGetURLTest::SetWindow(NPWindow* pNPWindow) { |
| 61 if (!tests_started_) { | 67 if (!tests_started_) { |
| 62 tests_started_ = true; | 68 tests_started_ = true; |
| 63 | 69 |
| 64 tests_in_progress_++; | 70 tests_in_progress_++; |
| 65 | 71 |
| 66 if (expect_404_response_) { | 72 if (expect_404_response_) { |
| 67 HostFunctions()->geturl(id(), page_not_found_url_.c_str(), NULL); | 73 HostFunctions()->geturl(id(), page_not_found_url_.c_str(), NULL); |
| 68 return NPERR_NO_ERROR; | 74 return NPERR_NO_ERROR; |
| 69 } else if (!fail_write_url_.empty()) { | 75 } else if (!fail_write_url_.empty()) { |
| 70 HostFunctions()->geturl(id(), fail_write_url_.c_str(), NULL); | 76 HostFunctions()->geturl(id(), fail_write_url_.c_str(), NULL); |
| 71 return NPERR_NO_ERROR; | 77 return NPERR_NO_ERROR; |
| 78 } else if (!referrer_target_url_.empty()) { |
| 79 HostFunctions()->pushpopupsenabledstate(id(), true); |
| 80 HostFunctions()->geturl(id(), referrer_target_url_.c_str(), "_blank"); |
| 81 HostFunctions()->poppopupsenabledstate(id()); |
| 82 return NPERR_NO_ERROR; |
| 72 } | 83 } |
| 73 | 84 |
| 74 std::string url = SELF_URL; | 85 std::string url = SELF_URL; |
| 75 HostFunctions()->geturlnotify(id(), url.c_str(), NULL, | 86 HostFunctions()->geturlnotify(id(), url.c_str(), NULL, |
| 76 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); | 87 reinterpret_cast<void*>(SELF_URL_STREAM_ID)); |
| 77 | 88 |
| 78 tests_in_progress_++; | 89 tests_in_progress_++; |
| 79 std::string bogus_url = BOGUS_URL; | 90 std::string bogus_url = BOGUS_URL; |
| 80 HostFunctions()->geturlnotify(id(), bogus_url.c_str(), NULL, | 91 HostFunctions()->geturlnotify(id(), bogus_url.c_str(), NULL, |
| 81 reinterpret_cast<void*>(BOGUS_URL_STREAM_ID)); | 92 reinterpret_cast<void*>(BOGUS_URL_STREAM_ID)); |
| 82 } | 93 } |
| 83 return NPERR_NO_ERROR; | 94 return NPERR_NO_ERROR; |
| 84 } | 95 } |
| 85 | 96 |
| 86 NPError PluginGetURLTest::NewStream(NPMIMEType type, NPStream* stream, | 97 NPError PluginGetURLTest::NewStream(NPMIMEType type, NPStream* stream, |
| 87 NPBool seekable, uint16* stype) { | 98 NPBool seekable, uint16* stype) { |
| 88 if (stream == NULL) { | 99 if (stream == NULL) { |
| 89 SetError("NewStream got null stream"); | 100 SetError("NewStream got null stream"); |
| 90 return NPERR_INVALID_PARAM; | 101 return NPERR_INVALID_PARAM; |
| 91 } | 102 } |
| 92 | 103 |
| 93 if (test_completed()) { | 104 if (test_completed()) { |
| 94 return PluginTest::NewStream(type, stream, seekable, stype); | 105 return PluginTest::NewStream(type, stream, seekable, stype); |
| 95 } | 106 } |
| 96 | 107 |
| 108 if (!referrer_target_url_.empty()) { |
| 109 return NPERR_NO_ERROR; |
| 110 } |
| 111 |
| 97 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 112 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 98 cast_validity_check); | 113 cast_validity_check); |
| 99 | 114 |
| 100 if (expect_404_response_) { | 115 if (expect_404_response_) { |
| 101 NPObject *window_obj = NULL; | 116 NPObject *window_obj = NULL; |
| 102 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); | 117 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); |
| 103 if (!window_obj) { | 118 if (!window_obj) { |
| 104 SetError("Failed to get NPObject for plugin instance2"); | 119 SetError("Failed to get NPObject for plugin instance2"); |
| 105 SignalTestCompleted(); | 120 SignalTestCompleted(); |
| 106 return NPERR_NO_ERROR; | 121 return NPERR_NO_ERROR; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 break; | 168 break; |
| 154 } | 169 } |
| 155 return NPERR_NO_ERROR; | 170 return NPERR_NO_ERROR; |
| 156 } | 171 } |
| 157 | 172 |
| 158 int32 PluginGetURLTest::WriteReady(NPStream *stream) { | 173 int32 PluginGetURLTest::WriteReady(NPStream *stream) { |
| 159 if (test_completed()) { | 174 if (test_completed()) { |
| 160 return PluginTest::WriteReady(stream); | 175 return PluginTest::WriteReady(stream); |
| 161 } | 176 } |
| 162 | 177 |
| 178 if (!referrer_target_url_.empty()) { |
| 179 return STREAM_CHUNK; |
| 180 } |
| 181 |
| 163 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 182 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 164 cast_validity_check); | 183 cast_validity_check); |
| 165 unsigned long stream_id = reinterpret_cast<unsigned long>( | 184 unsigned long stream_id = reinterpret_cast<unsigned long>( |
| 166 stream->notifyData); | 185 stream->notifyData); |
| 167 if (stream_id == BOGUS_URL_STREAM_ID) | 186 if (stream_id == BOGUS_URL_STREAM_ID) |
| 168 SetError("Received WriteReady for BOGUS_URL"); | 187 SetError("Received WriteReady for BOGUS_URL"); |
| 169 | 188 |
| 170 return STREAM_CHUNK; | 189 return STREAM_CHUNK; |
| 171 } | 190 } |
| 172 | 191 |
| 173 int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, | 192 int32 PluginGetURLTest::Write(NPStream *stream, int32 offset, int32 len, |
| 174 void *buffer) { | 193 void *buffer) { |
| 175 if (test_completed()) { | 194 if (test_completed()) { |
| 176 return PluginTest::Write(stream, offset, len, buffer); | 195 return PluginTest::Write(stream, offset, len, buffer); |
| 177 } | 196 } |
| 178 | 197 |
| 179 if (!fail_write_url_.empty()) { | 198 if (!fail_write_url_.empty()) { |
| 180 SignalTestCompleted(); | 199 SignalTestCompleted(); |
| 181 return -1; | 200 return -1; |
| 182 } | 201 } |
| 183 | 202 |
| 203 if (!referrer_target_url_.empty()) { |
| 204 return len; |
| 205 } |
| 206 |
| 184 if (stream == NULL) { | 207 if (stream == NULL) { |
| 185 SetError("Write got null stream"); | 208 SetError("Write got null stream"); |
| 186 return -1; | 209 return -1; |
| 187 } | 210 } |
| 188 if (len < 0 || len > STREAM_CHUNK) { | 211 if (len < 0 || len > STREAM_CHUNK) { |
| 189 SetError("Write got bogus stream chunk size"); | 212 SetError("Write got bogus stream chunk size"); |
| 190 return -1; | 213 return -1; |
| 191 } | 214 } |
| 192 | 215 |
| 193 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), | 216 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 260 |
| 238 if (expect_404_response_) { | 261 if (expect_404_response_) { |
| 239 if (npn_evaluate_context_) { | 262 if (npn_evaluate_context_) { |
| 240 SetError("Received destroyStream in the context of NPN_Evaluate."); | 263 SetError("Received destroyStream in the context of NPN_Evaluate."); |
| 241 } | 264 } |
| 242 | 265 |
| 243 SignalTestCompleted(); | 266 SignalTestCompleted(); |
| 244 return NPERR_NO_ERROR; | 267 return NPERR_NO_ERROR; |
| 245 } | 268 } |
| 246 | 269 |
| 270 if (!referrer_target_url_.empty()) { |
| 271 return NPERR_NO_ERROR; |
| 272 } |
| 273 |
| 247 unsigned long stream_id = | 274 unsigned long stream_id = |
| 248 reinterpret_cast<unsigned long>(stream->notifyData); | 275 reinterpret_cast<unsigned long>(stream->notifyData); |
| 249 switch (stream_id) { | 276 switch (stream_id) { |
| 250 case SELF_URL_STREAM_ID: | 277 case SELF_URL_STREAM_ID: |
| 251 // don't care | 278 // don't care |
| 252 break; | 279 break; |
| 253 case FETCHED_URL_STREAM_ID: | 280 case FETCHED_URL_STREAM_ID: |
| 254 { | 281 { |
| 255 char read_buffer[STREAM_CHUNK]; | 282 char read_buffer[STREAM_CHUNK]; |
| 256 size_t bytes = fread(read_buffer, 1, sizeof(read_buffer), test_file_); | 283 size_t bytes = fread(read_buffer, 1, sizeof(read_buffer), test_file_); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 default: | 351 default: |
| 325 SetError("Unexpected NewStream callback"); | 352 SetError("Unexpected NewStream callback"); |
| 326 break; | 353 break; |
| 327 } | 354 } |
| 328 | 355 |
| 329 if (tests_in_progress_ == 0) | 356 if (tests_in_progress_ == 0) |
| 330 SignalTestCompleted(); | 357 SignalTestCompleted(); |
| 331 } | 358 } |
| 332 | 359 |
| 333 } // namespace NPAPIClient | 360 } // namespace NPAPIClient |
| OLD | NEW |