| 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_get_javascript_url_test.h" | 5 #include "webkit/glue/plugins/test/plugin_get_javascript_url_test.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" |
| 7 | 8 |
| 8 // url for "self". | 9 // url for "self". |
| 9 #define SELF_URL "javascript:window.location+\"\"" | 10 #define SELF_URL "javascript:window.location+\"\"" |
| 10 // The identifier for the self url stream. | 11 // The identifier for the self url stream. |
| 11 #define SELF_URL_STREAM_ID 1 | 12 #define SELF_URL_STREAM_ID 1 |
| 12 | 13 |
| 13 // The identifier for the fetched url stream. | 14 // The identifier for the fetched url stream. |
| 14 #define FETCHED_URL_STREAM_ID 2 | 15 #define FETCHED_URL_STREAM_ID 2 |
| 15 | 16 |
| 16 // The maximum chunk size of stream data. | 17 // The maximum chunk size of stream data. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 31 test_started_ = true; | 32 test_started_ = true; |
| 32 } | 33 } |
| 33 return NPERR_NO_ERROR; | 34 return NPERR_NO_ERROR; |
| 34 } | 35 } |
| 35 | 36 |
| 36 NPError ExecuteGetJavascriptUrlTest::NewStream(NPMIMEType type, NPStream* stream
, | 37 NPError ExecuteGetJavascriptUrlTest::NewStream(NPMIMEType type, NPStream* stream
, |
| 37 NPBool seekable, uint16* stype) { | 38 NPBool seekable, uint16* stype) { |
| 38 if (stream == NULL) | 39 if (stream == NULL) |
| 39 SetError("NewStream got null stream"); | 40 SetError("NewStream got null stream"); |
| 40 | 41 |
| 41 unsigned long stream_id = PtrToUlong(stream->notifyData); | 42 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 43 cast_validity_check); |
| 44 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData); |
| 42 switch (stream_id) { | 45 switch (stream_id) { |
| 43 case SELF_URL_STREAM_ID: | 46 case SELF_URL_STREAM_ID: |
| 44 break; | 47 break; |
| 45 default: | 48 default: |
| 46 SetError("Unexpected NewStream callback"); | 49 SetError("Unexpected NewStream callback"); |
| 47 break; | 50 break; |
| 48 } | 51 } |
| 49 return NPERR_NO_ERROR; | 52 return NPERR_NO_ERROR; |
| 50 } | 53 } |
| 51 | 54 |
| 52 int32 ExecuteGetJavascriptUrlTest::WriteReady(NPStream *stream) { | 55 int32 ExecuteGetJavascriptUrlTest::WriteReady(NPStream *stream) { |
| 53 return STREAM_CHUNK; | 56 return STREAM_CHUNK; |
| 54 } | 57 } |
| 55 | 58 |
| 56 int32 ExecuteGetJavascriptUrlTest::Write(NPStream *stream, int32 offset, int32 l
en, | 59 int32 ExecuteGetJavascriptUrlTest::Write(NPStream *stream, int32 offset, int32 l
en, |
| 57 void *buffer) { | 60 void *buffer) { |
| 58 if (stream == NULL) | 61 if (stream == NULL) |
| 59 SetError("Write got null stream"); | 62 SetError("Write got null stream"); |
| 60 if (len < 0 || len > STREAM_CHUNK) | 63 if (len < 0 || len > STREAM_CHUNK) |
| 61 SetError("Write got bogus stream chunk size"); | 64 SetError("Write got bogus stream chunk size"); |
| 62 | 65 |
| 63 unsigned long stream_id = PtrToUlong(stream->notifyData); | 66 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 67 cast_validity_check); |
| 68 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData); |
| 64 switch (stream_id) { | 69 switch (stream_id) { |
| 65 case SELF_URL_STREAM_ID: | 70 case SELF_URL_STREAM_ID: |
| 66 self_url_.append(static_cast<char*>(buffer), len); | 71 self_url_.append(static_cast<char*>(buffer), len); |
| 67 break; | 72 break; |
| 68 default: | 73 default: |
| 69 SetError("Unexpected write callback"); | 74 SetError("Unexpected write callback"); |
| 70 break; | 75 break; |
| 71 } | 76 } |
| 72 // Pretend that we took all the data. | 77 // Pretend that we took all the data. |
| 73 return len; | 78 return len; |
| 74 } | 79 } |
| 75 | 80 |
| 76 | 81 |
| 77 NPError ExecuteGetJavascriptUrlTest::DestroyStream(NPStream *stream, NPError rea
son) { | 82 NPError ExecuteGetJavascriptUrlTest::DestroyStream(NPStream *stream, NPError rea
son) { |
| 78 if (stream == NULL) | 83 if (stream == NULL) |
| 79 SetError("NewStream got null stream"); | 84 SetError("NewStream got null stream"); |
| 80 | 85 |
| 81 unsigned long stream_id = PtrToUlong(stream->notifyData); | 86 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData), |
| 87 cast_validity_check); |
| 88 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData); |
| 82 switch (stream_id) { | 89 switch (stream_id) { |
| 83 case SELF_URL_STREAM_ID: | 90 case SELF_URL_STREAM_ID: |
| 84 // don't care | 91 // don't care |
| 85 break; | 92 break; |
| 86 default: | 93 default: |
| 87 SetError("Unexpected NewStream callback"); | 94 SetError("Unexpected NewStream callback"); |
| 88 break; | 95 break; |
| 89 } | 96 } |
| 90 return NPERR_NO_ERROR; | 97 return NPERR_NO_ERROR; |
| 91 } | 98 } |
| 92 | 99 |
| 93 void ExecuteGetJavascriptUrlTest::URLNotify(const char* url, NPReason reason, vo
id* data) { | 100 void ExecuteGetJavascriptUrlTest::URLNotify(const char* url, NPReason reason, vo
id* data) { |
| 94 unsigned long stream_id = PtrToUlong(data); | 101 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data), |
| 102 cast_validity_check); |
| 103 unsigned long stream_id = reinterpret_cast<unsigned long>(data); |
| 95 switch (stream_id) { | 104 switch (stream_id) { |
| 96 case SELF_URL_STREAM_ID: | 105 case SELF_URL_STREAM_ID: |
| 97 if (strcmp(url, SELF_URL) != 0) | 106 if (strcmp(url, SELF_URL) != 0) |
| 98 SetError("URLNotify reported incorrect url for SELF_URL"); | 107 SetError("URLNotify reported incorrect url for SELF_URL"); |
| 99 if (self_url_.empty()) | 108 if (self_url_.empty()) |
| 100 SetError("Failed to obtain window location."); | 109 SetError("Failed to obtain window location."); |
| 101 SignalTestCompleted(); | 110 SignalTestCompleted(); |
| 102 break; | 111 break; |
| 103 default: | 112 default: |
| 104 SetError("Unexpected NewStream callback"); | 113 SetError("Unexpected NewStream callback"); |
| 105 break; | 114 break; |
| 106 } | 115 } |
| 107 } | 116 } |
| 108 | 117 |
| 109 } // namespace NPAPIClient | 118 } // namespace NPAPIClient |
| 110 | 119 |
| OLD | NEW |