| OLD | NEW | 
 | (Empty) | 
|    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 #ifndef WEBKIT_PORT_PLUGINS_TEST_PLUGIN_TEST_H_ |  | 
|    6 #define WEBKIT_PORT_PLUGINS_TEST_PLUGIN_TEST_H_ |  | 
|    7  |  | 
|    8 #include <string> |  | 
|    9  |  | 
|   10 #include "base/string_number_conversions.h" |  | 
|   11 #include "base/string_util.h" |  | 
|   12 #include "third_party/npapi/bindings/npapi.h" |  | 
|   13 #include "third_party/npapi/bindings/nphostapi.h" |  | 
|   14  |  | 
|   15 namespace NPAPIClient { |  | 
|   16  |  | 
|   17 // A PluginTest represents an instance of the plugin, which in |  | 
|   18 // our case is a test case. |  | 
|   19 class PluginTest { |  | 
|   20  public: |  | 
|   21   // Constructor. |  | 
|   22   PluginTest(NPP id, NPNetscapeFuncs *host_functions); |  | 
|   23  |  | 
|   24   // Destructor |  | 
|   25   virtual ~PluginTest() {} |  | 
|   26  |  | 
|   27   // Returns true if the test runs in windowless plugin mode. |  | 
|   28   virtual bool IsWindowless() const { return false; } |  | 
|   29  |  | 
|   30   // |  | 
|   31   // NPAPI Functions |  | 
|   32   // |  | 
|   33   virtual NPError New(uint16 mode, int16 argc, const char* argn[], |  | 
|   34                       const char* argv[], NPSavedData* saved); |  | 
|   35   virtual NPError Destroy(); |  | 
|   36   virtual NPError SetWindow(NPWindow* pNPWindow); |  | 
|   37   virtual NPError NewStream(NPMIMEType type, NPStream* stream, |  | 
|   38                             NPBool seekable, uint16* stype); |  | 
|   39   virtual int32   WriteReady(NPStream *stream); |  | 
|   40   virtual int32   Write(NPStream *stream, int32 offset, int32 len, |  | 
|   41                         void *buffer); |  | 
|   42   virtual NPError DestroyStream(NPStream *stream, NPError reason); |  | 
|   43   virtual void    StreamAsFile(NPStream* stream, const char* fname); |  | 
|   44   virtual void    URLNotify(const char* url, NPReason reason, void* data); |  | 
|   45   virtual int16   HandleEvent(void* event); |  | 
|   46   virtual void    URLRedirectNotify(const char* url, int32_t status, |  | 
|   47                                     void* notify_data); |  | 
|   48   // Returns true if the test has not had any errors. |  | 
|   49   bool Succeeded() { return test_status_.length() == 0; } |  | 
|   50  |  | 
|   51   // Sets an error for the test case.  Appends the msg to the |  | 
|   52   // error that will be returned from the test. |  | 
|   53   void SetError(const std::string &msg); |  | 
|   54  |  | 
|   55   // Expect two string values are equal, and if not, logs an |  | 
|   56   // appropriate error about it. |  | 
|   57   void ExpectStringLowerCaseEqual(const std::string &val1, const std::string &va
     l2) { |  | 
|   58     if (!LowerCaseEqualsASCII(val1, val2.c_str())) { |  | 
|   59       std::string err; |  | 
|   60       err = "Expected Equal for '"; |  | 
|   61       err.append(val1); |  | 
|   62       err.append("' and '"); |  | 
|   63       err.append(val2); |  | 
|   64       err.append("'"); |  | 
|   65       SetError(err); |  | 
|   66     } |  | 
|   67   }; |  | 
|   68  |  | 
|   69   // Expect two values to not be equal, and if they are |  | 
|   70   // logs an appropriate error about it. |  | 
|   71   void ExpectAsciiStringNotEqual(const char *val1, const char *val2) { |  | 
|   72     if (val1 == val2) { |  | 
|   73       std::string err; |  | 
|   74       err = "Expected Not Equal for '"; |  | 
|   75       err.append(val1); |  | 
|   76       err.append("' and '"); |  | 
|   77       err.append(val2); |  | 
|   78       err.append("'"); |  | 
|   79       SetError(err); |  | 
|   80     } |  | 
|   81   } |  | 
|   82   // Expect two integer values are equal, and if not, logs an |  | 
|   83   // appropriate error about it. |  | 
|   84   void ExpectIntegerEqual(int val1, int val2) { |  | 
|   85     if (val1 != val2) { |  | 
|   86       std::string err; |  | 
|   87       err = "Expected Equal for '"; |  | 
|   88       err.append(base::IntToString(val1)); |  | 
|   89       err.append("' and '"); |  | 
|   90       err.append(base::IntToString(val2)); |  | 
|   91       err.append("'"); |  | 
|   92       SetError(err); |  | 
|   93     } |  | 
|   94   } |  | 
|   95  |  | 
|   96  |  | 
|   97  protected: |  | 
|   98   // Signals to the Test that invoked us that the test is |  | 
|   99   // completed.  This is done by forcing the plugin to |  | 
|  100   // set a cookie in the browser window, which the test program |  | 
|  101   // is waiting for.  Note - because this is done by |  | 
|  102   // using javascript, the browser must have the frame |  | 
|  103   // setup before the plugin calls this function.  So plugin |  | 
|  104   // tests MUST NOT call this function prior to having |  | 
|  105   // received the SetWindow() callback from the browser. |  | 
|  106   void SignalTestCompleted(); |  | 
|  107  |  | 
|  108   // Helper function to lookup names in the input array. |  | 
|  109   // If the name is found, returns the value, otherwise |  | 
|  110   // returns NULL. |  | 
|  111   const char *GetArgValue(const char *name, const int16 argc, |  | 
|  112                           const char *argn[], const char *argv[]); |  | 
|  113  |  | 
|  114   // Access to the list of functions provided |  | 
|  115   // by the NPAPI host. |  | 
|  116   NPNetscapeFuncs *HostFunctions() { return host_functions_; } |  | 
|  117  |  | 
|  118   // The NPP Identifier for this plugin instance. |  | 
|  119   NPP id() { return id_; } |  | 
|  120   std::string test_id() const { return test_id_; } |  | 
|  121   std::string test_name() const { return test_name_; } |  | 
|  122   bool test_completed() const { return test_completed_; } |  | 
|  123  private: |  | 
|  124   NPP                       id_; |  | 
|  125   NPNetscapeFuncs *         host_functions_; |  | 
|  126   std::string               test_name_; |  | 
|  127   std::string               test_id_; |  | 
|  128   std::string               test_status_; |  | 
|  129   bool                      test_completed_; |  | 
|  130 }; |  | 
|  131  |  | 
|  132 } // namespace NPAPIClient |  | 
|  133  |  | 
|  134 #endif  // WEBKIT_PORT_PLUGINS_TEST_PLUGIN_TEST_H_ |  | 
| OLD | NEW |