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. 4 5 #include "content/test/plugin/plugin_private_test.h" 6 7 #include "base/basictypes.h" 8 #include "base/strings/string_util.h" 9 #include "content/test/plugin/plugin_client.h" 10 11 namespace NPAPIClient { 12 13 PrivateTest::PrivateTest(NPP id, NPNetscapeFuncs *host_functions) 14 : PluginTest(id, host_functions) { 15 } 16 17 NPError PrivateTest::New(uint16 mode, int16 argc, 18 const char* argn[], const char* argv[], 19 NPSavedData* saved) { 20 PluginTest::New(mode, argc, argn, argv, saved); 21 22 NPBool private_mode = 0; 23 NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions(); 24 NPError result = browser->getvalue( 25 id(), NPNVprivateModeBool, &private_mode); 26 if (result != NPERR_NO_ERROR) { 27 SetError("Failed to read NPNVprivateModeBool value."); 28 } else { 29 NPIdentifier location = HostFunctions()->getstringidentifier("location"); 30 NPIdentifier href = HostFunctions()->getstringidentifier("href"); 31 32 NPObject *window_obj = NULL; 33 HostFunctions()->getvalue(id(), NPNVWindowNPObject, &window_obj); 34 35 NPVariant location_var; 36 HostFunctions()->getproperty(id(), window_obj, location, &location_var); 37 38 NPVariant href_var; 39 HostFunctions()->getproperty(id(), NPVARIANT_TO_OBJECT(location_var), href, 40 &href_var); 41 std::string href_str(href_var.value.stringValue.UTF8Characters, 42 href_var.value.stringValue.UTF8Length); 43 bool private_expected = href_str.find("?private") != href_str.npos; 44 if (private_mode != static_cast<NPBool>(private_expected)) 45 SetError("NPNVprivateModeBool returned incorrect value."); 46 47 HostFunctions()->releasevariantvalue(&href_var); 48 HostFunctions()->releasevariantvalue(&location_var); 49 HostFunctions()->releaseobject(window_obj); 50 } 51 52 SignalTestCompleted(); 53 54 return NPERR_NO_ERROR; 55 } 56 57 } // namespace NPAPIClient 58