OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /* | 5 /* |
6 * Copyright (C) 2011 Apple Inc. All rights reserved. | 6 * Copyright (C) 2011 Apple Inc. All rights reserved. |
7 * | 7 * |
8 * Redistribution and use in source and binary forms, with or without | 8 * Redistribution and use in source and binary forms, with or without |
9 * modification, are permitted provided that the following conditions | 9 * modification, are permitted provided that the following conditions |
10 * are met: | 10 * are met: |
(...skipping 30 matching lines...) Expand all Loading... |
41 // Test that evaluating JavaScript using NPN_GetURL will a stream with result of
the evaluation. | 41 // Test that evaluating JavaScript using NPN_GetURL will a stream with result of
the evaluation. |
42 class GetURLWithJavaScriptURL : public PluginTest { | 42 class GetURLWithJavaScriptURL : public PluginTest { |
43 public: | 43 public: |
44 GetURLWithJavaScriptURL(NPP npp, const string& identifier) | 44 GetURLWithJavaScriptURL(NPP npp, const string& identifier) |
45 : PluginTest(npp, identifier) | 45 : PluginTest(npp, identifier) |
46 , m_didFail(false) | 46 , m_didFail(false) |
47 { | 47 { |
48 } | 48 } |
49 | 49 |
50 private: | 50 private: |
51 virtual NPError NPP_New(NPMIMEType pluginType, | 51 NPError NPP_New(NPMIMEType pluginType, |
52 uint16_t mode, | 52 uint16_t mode, |
53 int16_t argc, | 53 int16_t argc, |
54 char* argn[], | 54 char* argn[], |
55 char* argv[], | 55 char* argv[], |
56 NPSavedData* saved) override { | 56 NPSavedData* saved) override { |
57 NPN_GetURL(javaScriptURL, 0); | 57 NPN_GetURL(javaScriptURL, 0); |
58 return NPERR_NO_ERROR; | 58 return NPERR_NO_ERROR; |
59 } | 59 } |
60 | 60 |
61 virtual NPError NPP_NewStream(NPMIMEType type, NPStream* stream, NPBool seek
able, uint16_t* stype) override | 61 NPError NPP_NewStream(NPMIMEType type, |
62 { | 62 NPStream* stream, |
| 63 NPBool seekable, |
| 64 uint16_t* stype) override { |
63 stream->pdata = this; | 65 stream->pdata = this; |
64 | 66 |
65 if (strcmp(stream->url, javaScriptURL)) | 67 if (strcmp(stream->url, javaScriptURL)) |
66 m_didFail = true; | 68 m_didFail = true; |
67 | 69 |
68 if (stream->end != strlen(javaScriptResult)) | 70 if (stream->end != strlen(javaScriptResult)) |
69 m_didFail = true; | 71 m_didFail = true; |
70 | 72 |
71 *stype = NP_NORMAL; | 73 *stype = NP_NORMAL; |
72 return NPERR_NO_ERROR; | 74 return NPERR_NO_ERROR; |
73 } | 75 } |
74 | 76 |
75 virtual NPError NPP_DestroyStream(NPStream* stream, NPReason reason) overrid
e | 77 NPError NPP_DestroyStream(NPStream* stream, NPReason reason) override { |
76 { | |
77 if (stream->pdata != this) | 78 if (stream->pdata != this) |
78 m_didFail = true; | 79 m_didFail = true; |
79 | 80 |
80 if (reason != NPRES_DONE) | 81 if (reason != NPRES_DONE) |
81 m_didFail = true; | 82 m_didFail = true; |
82 | 83 |
83 if (m_data.size() != stream->end) | 84 if (m_data.size() != stream->end) |
84 m_didFail = true; | 85 m_didFail = true; |
85 | 86 |
86 m_data.push_back('\0'); | 87 m_data.push_back('\0'); |
87 | 88 |
88 if (strcmp(&m_data[0], javaScriptResult)) | 89 if (strcmp(&m_data[0], javaScriptResult)) |
89 m_didFail = true; | 90 m_didFail = true; |
90 | 91 |
91 if (!m_didFail) | 92 if (!m_didFail) |
92 executeScript("testSucceeded()"); | 93 executeScript("testSucceeded()"); |
93 else | 94 else |
94 executeScript("notifyDone()"); | 95 executeScript("notifyDone()"); |
95 | 96 |
96 return NPERR_NO_ERROR; | 97 return NPERR_NO_ERROR; |
97 } | 98 } |
98 | 99 |
99 virtual int32_t NPP_WriteReady(NPStream* stream) override | 100 int32_t NPP_WriteReady(NPStream* stream) override { |
100 { | |
101 if (stream->pdata != this) | 101 if (stream->pdata != this) |
102 m_didFail = true; | 102 m_didFail = true; |
103 | 103 |
104 return 2; | 104 return 2; |
105 } | 105 } |
106 | 106 |
107 virtual int32_t NPP_Write(NPStream* stream, int32_t offset, int32_t len, voi
d* buffer) override | 107 int32_t NPP_Write(NPStream* stream, |
108 { | 108 int32_t offset, |
| 109 int32_t len, |
| 110 void* buffer) override { |
109 if (stream->pdata != this) | 111 if (stream->pdata != this) |
110 m_didFail = true; | 112 m_didFail = true; |
111 | 113 |
112 m_data.insert(m_data.end(), static_cast<char*>(buffer), static_cast<char
*>(buffer) + len); | 114 m_data.insert(m_data.end(), static_cast<char*>(buffer), static_cast<char
*>(buffer) + len); |
113 return len; | 115 return len; |
114 } | 116 } |
115 | 117 |
116 vector<char> m_data; | 118 vector<char> m_data; |
117 bool m_didFail; | 119 bool m_didFail; |
118 }; | 120 }; |
119 | 121 |
120 static PluginTest::Register<GetURLWithJavaScriptURL> getURLWithJavaScriptURLDest
royingPlugin("get-url-with-javascript-url"); | 122 static PluginTest::Register<GetURLWithJavaScriptURL> getURLWithJavaScriptURLDest
royingPlugin("get-url-with-javascript-url"); |
OLD | NEW |