15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/* 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright (C) 2011 Apple Inc. All rights reserved. 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * modification, are permitted provided that the following conditions 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * are met: 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * THE POSSIBILITY OF SUCH DAMAGE. 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "PluginTest.h" 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string.h> 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <vector> 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using namespace std; 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char *javaScriptURL = "javascript:'Hello, ' + 'World!'"; 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char *javaScriptResult = "Hello, World!"; 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Test that evaluating a javascript: URL will send a stream with the result of the evaluation. 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Test that evaluating JavaScript using NPN_GetURL will a stream with result of the evaluation. 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class GetURLWithJavaScriptURL : public PluginTest { 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public: 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) GetURLWithJavaScriptURL(NPP npp, const string& identifier) 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : PluginTest(npp, identifier) 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) , m_didFail(false) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)private: 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual NPError NPP_New(NPMIMEType pluginType, 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) uint16_t mode, 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int16_t argc, 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) char* argn[], 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) char* argv[], 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPSavedData* saved) OVERRIDE { 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPN_GetURL(javaScriptURL, 0); 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_NO_ERROR; 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual NPError NPP_NewStream(NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype) OVERRIDE 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) stream->pdata = this; 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (strcmp(stream->url, javaScriptURL)) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (stream->end != strlen(javaScriptResult)) 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *stype = NP_NORMAL; 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_NO_ERROR; 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual NPError NPP_DestroyStream(NPStream* stream, NPReason reason) OVERRIDE 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (stream->pdata != this) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (reason != NPRES_DONE) 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (m_data.size() != stream->end) 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_data.push_back('\0'); 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (strcmp(&m_data[0], javaScriptResult)) 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!m_didFail) 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) executeScript("testSucceeded()"); 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) else 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) executeScript("notifyDone()"); 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_NO_ERROR; 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual int32_t NPP_WriteReady(NPStream* stream) OVERRIDE 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (stream->pdata != this) 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return 2; 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual int32_t NPP_Write(NPStream* stream, int32_t offset, int32_t len, void* buffer) OVERRIDE 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (stream->pdata != this) 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_didFail = true; 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_data.insert(m_data.end(), static_cast<char*>(buffer), static_cast<char*>(buffer) + len); 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return len; 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) vector<char> m_data; 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool m_didFail; 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static PluginTest::Register<GetURLWithJavaScriptURL> getURLWithJavaScriptURLDestroyingPlugin("get-url-with-javascript-url"); 121