Home | History | Annotate | Download | only in ppapi
      1 // Copyright (c) 2012 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 CHROME_TEST_PPAPI_PPAPI_TEST_H_
      6 #define CHROME_TEST_PPAPI_PPAPI_TEST_H_
      7 
      8 #include <list>
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/compiler_specific.h"
     13 #include "chrome/test/base/in_process_browser_test.h"
     14 #include "chrome/test/base/javascript_test_observer.h"
     15 #include "net/test/spawned_test_server/spawned_test_server.h"
     16 
     17 namespace content {
     18 class RenderViewHost;
     19 }
     20 
     21 class PPAPITestMessageHandler : public TestMessageHandler {
     22  public:
     23   PPAPITestMessageHandler();
     24 
     25   MessageResponse HandleMessage(const std::string& json);
     26 
     27   virtual void Reset() OVERRIDE;
     28 
     29   const std::string& message() const {
     30     return message_;
     31   }
     32 
     33  private:
     34   std::string message_;
     35 
     36   DISALLOW_COPY_AND_ASSIGN(PPAPITestMessageHandler);
     37 };
     38 
     39 class PPAPITestBase : public InProcessBrowserTest {
     40  public:
     41   PPAPITestBase();
     42 
     43   // InProcessBrowserTest:
     44   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
     45   virtual void SetUpOnMainThread() OVERRIDE;
     46 
     47   virtual std::string BuildQuery(const std::string& base,
     48                                  const std::string& test_case) = 0;
     49 
     50   // Returns the URL to load for file: tests.
     51   GURL GetTestFileUrl(const std::string& test_case);
     52   void RunTest(const std::string& test_case);
     53   // Run the test and reload. This can test for clean shutdown, including leaked
     54   // instance object vars.
     55   void RunTestAndReload(const std::string& test_case);
     56   void RunTestViaHTTP(const std::string& test_case);
     57   void RunTestWithSSLServer(const std::string& test_case);
     58   void RunTestWithWebSocketServer(const std::string& test_case);
     59   void RunTestIfAudioOutputAvailable(const std::string& test_case);
     60   void RunTestViaHTTPIfAudioOutputAvailable(const std::string& test_case);
     61   std::string StripPrefixes(const std::string& test_name);
     62 
     63  protected:
     64   class InfoBarObserver : public content::NotificationObserver {
     65    public:
     66     InfoBarObserver();
     67     ~InfoBarObserver();
     68 
     69     virtual void Observe(int type,
     70                          const content::NotificationSource& source,
     71                          const content::NotificationDetails& details) OVERRIDE;
     72 
     73     void ExpectInfoBarAndAccept(bool should_accept);
     74 
     75    private:
     76     content::NotificationRegistrar registrar_;
     77     std::list<bool> expected_infobars_;
     78   };
     79 
     80   // Runs the test for a tab given the tab that's already navigated to the
     81   // given URL.
     82   void RunTestURL(const GURL& test_url);
     83   // Gets the URL of the the given |test_case| for the given HTTP test server.
     84   // If |extra_params| is non-empty, it will be appended as URL parameters.
     85   GURL GetTestURL(const net::SpawnedTestServer& http_server,
     86                   const std::string& test_case,
     87                   const std::string& extra_params);
     88 
     89   // Return the document root for the HTTP server on which tests will be run.
     90   // The result is placed in |document_root|. False is returned upon failure.
     91   bool GetHTTPDocumentRoot(base::FilePath* document_root);
     92 };
     93 
     94 // In-process plugin test runner.  See OutOfProcessPPAPITest below for the
     95 // out-of-process version.
     96 class PPAPITest : public PPAPITestBase {
     97  public:
     98   PPAPITest();
     99 
    100   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
    101 
    102   virtual std::string BuildQuery(const std::string& base,
    103                                  const std::string& test_case) OVERRIDE;
    104  protected:
    105   bool in_process_;  // Controls the --ppapi-in-process switch.
    106 };
    107 
    108 // Variant of PPAPITest that runs plugins out-of-process to test proxy
    109 // codepaths.
    110 class OutOfProcessPPAPITest : public PPAPITest {
    111  public:
    112   OutOfProcessPPAPITest();
    113 
    114   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
    115 };
    116 
    117 // NaCl plugin test runner for Newlib runtime.
    118 class PPAPINaClTest : public PPAPITestBase {
    119  public:
    120   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
    121 };
    122 
    123 // NaCl plugin test runner for Newlib runtime.
    124 class PPAPINaClNewlibTest : public PPAPINaClTest {
    125  public:
    126   virtual std::string BuildQuery(const std::string& base,
    127                                  const std::string& test_case) OVERRIDE;
    128 };
    129 
    130 // NaCl plugin test runner for GNU-libc runtime.
    131 class PPAPINaClGLibcTest : public PPAPINaClTest {
    132  public:
    133   virtual std::string BuildQuery(const std::string& base,
    134                                  const std::string& test_case) OVERRIDE;
    135 };
    136 
    137 // NaCl plugin test runner for the PNaCl + Newlib runtime.
    138 class PPAPINaClPNaClTest : public PPAPINaClTest {
    139  public:
    140   virtual std::string BuildQuery(const std::string& base,
    141                                  const std::string& test_case) OVERRIDE;
    142 };
    143 
    144 class PPAPINaClTestDisallowedSockets : public PPAPITestBase {
    145  public:
    146   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
    147 
    148   virtual std::string BuildQuery(const std::string& base,
    149                                  const std::string& test_case) OVERRIDE;
    150 };
    151 
    152 class PPAPIBrokerInfoBarTest : public OutOfProcessPPAPITest {
    153  public:
    154   // PPAPITestBase override:
    155   virtual void SetUpOnMainThread() OVERRIDE;
    156 };
    157 
    158 #endif  // CHROME_TEST_PPAPI_PPAPI_TEST_H_
    159