Home | History | Annotate | Download | only in plugin
      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 <stdlib.h>
      6 
      7 #include "content/test/plugin/plugin_arguments_test.h"
      8 
      9 #include "base/basictypes.h"
     10 #include "base/strings/string_util.h"
     11 #include "base/strings/stringprintf.h"
     12 
     13 namespace NPAPIClient {
     14 
     15 PluginArgumentsTest::PluginArgumentsTest(NPP id,
     16                                          NPNetscapeFuncs *host_functions)
     17   : PluginTest(id, host_functions) {
     18 }
     19 
     20 NPError PluginArgumentsTest::New(uint16 mode, int16 argc,
     21                                  const char* argn[], const char* argv[],
     22                                  NPSavedData* saved) {
     23   // mode:  should be the string either "NP_EMBED" or "NP_FULL",
     24   //        depending on the mode passed in.
     25   // count: the count of "val" arguments.  If the value is
     26   //        2, then we'll find arguments "val1" and "val2".  If
     27   //        the value is 0, then there will be no "val" arguments.
     28   // size:  each val string will be this size * the value's
     29   //        index.  E.g if size is "10", val1 will be 10bytes,
     30   //        and val2 will be 20bytes.
     31   const char *mode_string = GetArgValue("mode", argc, argn, argv);
     32   ExpectAsciiStringNotEqual(mode_string, (const char *)NULL);
     33   if (mode_string != NULL) {
     34     std::string mode_dep_string = mode_string;
     35     if (mode == NP_EMBED)
     36       ExpectStringLowerCaseEqual(mode_dep_string, "np_embed");
     37     else if (mode == NP_FULL)
     38       ExpectStringLowerCaseEqual(mode_dep_string, "np_full");
     39   }
     40 
     41   const char *count_string = GetArgValue("count", argc, argn, argv);
     42   if (count_string != NULL) {
     43     int max_args = atoi(count_string);
     44 
     45     const char *size_string = GetArgValue("size", argc, argn, argv);
     46     ExpectAsciiStringNotEqual(size_string, (const char *)NULL);
     47     if (size_string != NULL) {
     48       int size = atoi(size_string);
     49 
     50       for (int index = 1; index <= max_args; index++) {
     51         std::string arg_name = base::StringPrintf("%s%d", "val", index);
     52         const char *val_string = GetArgValue(arg_name.c_str(), argc, argn,
     53                                              argv);
     54         ExpectAsciiStringNotEqual(val_string, (const char*)NULL);
     55         if (val_string != NULL)
     56           ExpectIntegerEqual((int)strlen(val_string), (index*size));
     57       }
     58     }
     59   }
     60 
     61   return PluginTest::New(mode, argc, argn, argv, saved);
     62 }
     63 
     64 NPError PluginArgumentsTest::SetWindow(NPWindow* pNPWindow) {
     65   // This test just tests the arguments.  We're done now.
     66   this->SignalTestCompleted();
     67 
     68   return NPERR_NO_ERROR;
     69 }
     70 
     71 }  // namespace NPAPIClient
     72