Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / test / plugin / plugin_get_javascript_url2_test.cc
bloba3c7c1a16ef833039f429c16a5a92ef6aad4b26d
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 identifier for the fetched url stream.
15 #define FETCHED_URL_STREAM_ID 2
17 // The maximum chunk size of stream data.
18 #define STREAM_CHUNK 197
20 const int kNPNEvaluateTimerID = 100;
21 const int kNPNEvaluateTimerElapse = 50;
23 namespace NPAPIClient {
25 ExecuteGetJavascriptUrl2Test::ExecuteGetJavascriptUrl2Test(
26 NPP id, NPNetscapeFuncs *host_functions)
27 : PluginTest(id, host_functions),
28 test_started_(false) {
31 NPError ExecuteGetJavascriptUrl2Test::SetWindow(NPWindow* pNPWindow) {
32 #if !defined(OS_MACOSX)
33 if (pNPWindow->window == NULL)
34 return NPERR_NO_ERROR;
35 #endif
37 if (!test_started_) {
38 std::string url = SELF_URL;
39 HostFunctions()->geturlnotify(id(), url.c_str(), "_self",
40 reinterpret_cast<void*>(SELF_URL_STREAM_ID));
41 test_started_ = true;
43 return NPERR_NO_ERROR;
46 NPError ExecuteGetJavascriptUrl2Test::NewStream(NPMIMEType type, NPStream* stream,
47 NPBool seekable, uint16* stype) {
48 if (stream == NULL) {
49 SetError("NewStream got null stream");
50 return NPERR_INVALID_PARAM;
53 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
54 cast_validity_check);
55 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
56 switch (stream_id) {
57 case SELF_URL_STREAM_ID:
58 break;
59 default:
60 SetError("Unexpected NewStream callback");
61 break;
63 return NPERR_NO_ERROR;
66 int32 ExecuteGetJavascriptUrl2Test::WriteReady(NPStream *stream) {
67 return STREAM_CHUNK;
70 int32 ExecuteGetJavascriptUrl2Test::Write(NPStream *stream, int32 offset, int32 len,
71 void *buffer) {
72 if (stream == NULL) {
73 SetError("Write got null stream");
74 return -1;
76 if (len < 0 || len > STREAM_CHUNK) {
77 SetError("Write got bogus stream chunk size");
78 return -1;
81 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
82 cast_validity_check);
83 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
84 switch (stream_id) {
85 case SELF_URL_STREAM_ID:
86 self_url_.append(static_cast<char*>(buffer), len);
87 break;
88 default:
89 SetError("Unexpected write callback");
90 break;
92 // Pretend that we took all the data.
93 return len;
97 NPError ExecuteGetJavascriptUrl2Test::DestroyStream(NPStream *stream, NPError reason) {
98 if (stream == NULL) {
99 SetError("NewStream got null stream");
100 return NPERR_INVALID_PARAM;
103 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(stream->notifyData),
104 cast_validity_check);
105 unsigned long stream_id = reinterpret_cast<unsigned long>(stream->notifyData);
106 switch (stream_id) {
107 case SELF_URL_STREAM_ID:
108 // don't care
109 break;
110 default:
111 SetError("Unexpected NewStream callback");
112 break;
114 return NPERR_NO_ERROR;
117 void ExecuteGetJavascriptUrl2Test::URLNotify(const char* url, NPReason reason, void* data) {
118 COMPILE_ASSERT(sizeof(unsigned long) <= sizeof(data),
119 cast_validity_check);
121 unsigned long stream_id = reinterpret_cast<unsigned long>(data);
122 switch (stream_id) {
123 case SELF_URL_STREAM_ID:
124 if (strcmp(url, SELF_URL) != 0)
125 SetError("URLNotify reported incorrect url for SELF_URL");
126 if (self_url_.empty())
127 SetError("Failed to obtain window location.");
128 SignalTestCompleted();
129 break;
130 default:
131 SetError("Unexpected NewStream callback");
132 break;
136 } // namespace NPAPIClient