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