Add very simple loading test for non-SFI NaCl.
[chromium-blink-merge.git] / chrome / test / nacl / nacl_browsertest_util.h
blobac47c351c5c99ec04ab91fe7cf12ea87935d149e
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.
5 #ifndef CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_
6 #define CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/javascript_test_observer.h"
13 // A helper base class that decodes structured automation messages of the form:
14 // {"type": type_name, ...}
15 class StructuredMessageHandler : public TestMessageHandler {
16 public:
17 virtual MessageResponse HandleMessage(const std::string& json) OVERRIDE;
19 // This method provides a higher-level interface for handling JSON messages
20 // from the DOM automation controler. Instead of handling a string
21 // containing a JSON-encoded object, this specialization of TestMessageHandler
22 // decodes the string into a dictionary. This makes it easier to send and
23 // receive structured messages. It is assumed the dictionary will always have
24 // a "type" field that indicates the nature of message.
25 virtual MessageResponse HandleStructuredMessage(
26 const std::string& type,
27 base::DictionaryValue* msg) = 0;
29 protected:
30 // The structured message is missing an expected field.
31 MessageResponse MissingField(
32 const std::string& type,
33 const std::string& field) WARN_UNUSED_RESULT;
35 // Something went wrong while decoding the message.
36 MessageResponse InternalError(const std::string& reason) WARN_UNUSED_RESULT;
39 // A simple structured message handler for tests that load nexes.
40 class LoadTestMessageHandler : public StructuredMessageHandler {
41 public:
42 LoadTestMessageHandler();
44 void Log(const std::string& type, const std::string& message);
46 virtual MessageResponse HandleStructuredMessage(
47 const std::string& type,
48 base::DictionaryValue* msg) OVERRIDE;
50 bool test_passed() const {
51 return test_passed_;
54 private:
55 bool test_passed_;
57 DISALLOW_COPY_AND_ASSIGN(LoadTestMessageHandler);
60 class NaClBrowserTestBase : public InProcessBrowserTest {
61 public:
62 NaClBrowserTestBase();
63 virtual ~NaClBrowserTestBase();
65 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
67 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
69 // What variant are we running - newlib, glibc, pnacl, etc?
70 // This is used to compute what directory we're pulling data from, but it can
71 // also be used to affect the behavior of the test.
72 virtual base::FilePath::StringType Variant() = 0;
74 // Where are the files for this class of test located on disk?
75 virtual bool GetDocumentRoot(base::FilePath* document_root);
77 virtual bool IsAPnaclTest();
79 virtual bool IsPnaclDisabled();
81 // Map a file relative to the variant directory to a URL served by the test
82 // web server.
83 GURL TestURL(const base::FilePath::StringType& url_fragment);
85 // Load a URL and listen to automation events with a given handler.
86 // Returns true if the test glue function correctly. (The handler should
87 // seperately indicate if the test failed.)
88 bool RunJavascriptTest(const GURL& url, TestMessageHandler* handler);
90 // Run a simple test that checks that a nexe loads correctly. Useful for
91 // setting up other tests, such as checking that UMA data was logged.
92 void RunLoadTest(const base::FilePath::StringType& test_file);
94 // Run a test that was originally written to use NaCl's integration testing
95 // jig. These tests were originally driven by NaCl's SCons build in the
96 // nacl_integration test stage on the Chrome waterfall. Changes in the
97 // boundaries between the Chrome and NaCl repos have resulted in many of
98 // these tests having a stronger affinity with the Chrome repo. This method
99 // provides a compatibility layer to simplify turning nacl_integration tests
100 // into browser tests.
101 void RunNaClIntegrationTest(const base::FilePath::StringType& url_fragment);
103 private:
104 bool StartTestServer();
106 scoped_ptr<net::SpawnedTestServer> test_server_;
109 class NaClBrowserTestNewlib : public NaClBrowserTestBase {
110 public:
111 virtual base::FilePath::StringType Variant() OVERRIDE;
114 class NaClBrowserTestGLibc : public NaClBrowserTestBase {
115 public:
116 virtual base::FilePath::StringType Variant() OVERRIDE;
119 class NaClBrowserTestPnacl : public NaClBrowserTestBase {
120 public:
121 virtual base::FilePath::StringType Variant() OVERRIDE;
123 virtual bool IsAPnaclTest() OVERRIDE;
126 // Class used to test that when --disable-pnacl is specified the PNaCl mime
127 // type is not available.
128 class NaClBrowserTestPnaclDisabled : public NaClBrowserTestBase {
129 public:
130 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
132 virtual base::FilePath::StringType Variant() OVERRIDE;
134 virtual bool IsAPnaclTest() OVERRIDE;
136 virtual bool IsPnaclDisabled() OVERRIDE;
139 class NaClBrowserTestNonSfiMode : public NaClBrowserTestBase {
140 public:
141 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
142 virtual base::FilePath::StringType Variant() OVERRIDE;
145 // A NaCl browser test only using static files.
146 class NaClBrowserTestStatic : public NaClBrowserTestBase {
147 public:
148 virtual base::FilePath::StringType Variant() OVERRIDE;
149 virtual bool GetDocumentRoot(base::FilePath* document_root) OVERRIDE;
152 // PNaCl tests take a long time on windows debug builds
153 // and sometimes time out. Disable until it is made faster:
154 // https://code.google.com/p/chromium/issues/detail?id=177555
155 #if (defined(OS_WIN) && !defined(NDEBUG))
156 #define MAYBE_PNACL(test_name) DISABLED_##test_name
157 #else
158 #define MAYBE_PNACL(test_name) test_name
159 #endif
161 #if defined(ARCH_CPU_ARM_FAMILY)
163 // There is no support for Glibc on ARM NaCl.
164 #define NACL_BROWSER_TEST_F(suite, name, body) \
165 IN_PROC_BROWSER_TEST_F(suite##Newlib, name) \
166 body
168 #else
170 // Otherwise, we have Glibc, Newlib and Pnacl tests
171 #define NACL_BROWSER_TEST_F(suite, name, body) \
172 IN_PROC_BROWSER_TEST_F(suite##Newlib, name) \
173 body \
174 IN_PROC_BROWSER_TEST_F(suite##GLibc, name) \
175 body \
176 IN_PROC_BROWSER_TEST_F(suite##Pnacl, MAYBE_PNACL(name)) \
177 body
179 #endif
181 #endif // CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_