| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_ | 5 #ifndef CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_ |
| 6 #define CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_ | 6 #define CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 #include "content/public/test/javascript_test_observer.h" | 11 #include "content/public/test/javascript_test_observer.h" |
| 12 | 12 |
| 13 // A helper base class that decodes structured automation messages of the form: | 13 // A helper base class that decodes structured automation messages of the form: |
| 14 // {"type": type_name, ...} | 14 // {"type": type_name, ...} |
| 15 class StructuredMessageHandler : public content::TestMessageHandler { | 15 class StructuredMessageHandler : public content::TestMessageHandler { |
| 16 public: | 16 public: |
| 17 virtual MessageResponse HandleMessage(const std::string& json) override; | 17 MessageResponse HandleMessage(const std::string& json) override; |
| 18 | 18 |
| 19 // This method provides a higher-level interface for handling JSON messages | 19 // This method provides a higher-level interface for handling JSON messages |
| 20 // from the DOM automation controler. Instead of handling a string | 20 // from the DOM automation controler. Instead of handling a string |
| 21 // containing a JSON-encoded object, this specialization of TestMessageHandler | 21 // containing a JSON-encoded object, this specialization of TestMessageHandler |
| 22 // decodes the string into a dictionary. This makes it easier to send and | 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 | 23 // receive structured messages. It is assumed the dictionary will always have |
| 24 // a "type" field that indicates the nature of message. | 24 // a "type" field that indicates the nature of message. |
| 25 virtual MessageResponse HandleStructuredMessage( | 25 virtual MessageResponse HandleStructuredMessage( |
| 26 const std::string& type, | 26 const std::string& type, |
| 27 base::DictionaryValue* msg) = 0; | 27 base::DictionaryValue* msg) = 0; |
| 28 | 28 |
| 29 protected: | 29 protected: |
| 30 // The structured message is missing an expected field. | 30 // The structured message is missing an expected field. |
| 31 MessageResponse MissingField( | 31 MessageResponse MissingField( |
| 32 const std::string& type, | 32 const std::string& type, |
| 33 const std::string& field) WARN_UNUSED_RESULT; | 33 const std::string& field) WARN_UNUSED_RESULT; |
| 34 | 34 |
| 35 // Something went wrong while decoding the message. | 35 // Something went wrong while decoding the message. |
| 36 MessageResponse InternalError(const std::string& reason) WARN_UNUSED_RESULT; | 36 MessageResponse InternalError(const std::string& reason) WARN_UNUSED_RESULT; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 // A simple structured message handler for tests that load nexes. | 39 // A simple structured message handler for tests that load nexes. |
| 40 class LoadTestMessageHandler : public StructuredMessageHandler { | 40 class LoadTestMessageHandler : public StructuredMessageHandler { |
| 41 public: | 41 public: |
| 42 LoadTestMessageHandler(); | 42 LoadTestMessageHandler(); |
| 43 | 43 |
| 44 void Log(const std::string& type, const std::string& message); | 44 void Log(const std::string& type, const std::string& message); |
| 45 | 45 |
| 46 virtual MessageResponse HandleStructuredMessage( | 46 MessageResponse HandleStructuredMessage(const std::string& type, |
| 47 const std::string& type, | 47 base::DictionaryValue* msg) override; |
| 48 base::DictionaryValue* msg) override; | |
| 49 | 48 |
| 50 bool test_passed() const { | 49 bool test_passed() const { |
| 51 return test_passed_; | 50 return test_passed_; |
| 52 } | 51 } |
| 53 | 52 |
| 54 private: | 53 private: |
| 55 bool test_passed_; | 54 bool test_passed_; |
| 56 | 55 |
| 57 DISALLOW_COPY_AND_ASSIGN(LoadTestMessageHandler); | 56 DISALLOW_COPY_AND_ASSIGN(LoadTestMessageHandler); |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 class NaClBrowserTestBase : public InProcessBrowserTest { | 59 class NaClBrowserTestBase : public InProcessBrowserTest { |
| 61 public: | 60 public: |
| 62 NaClBrowserTestBase(); | 61 NaClBrowserTestBase(); |
| 63 virtual ~NaClBrowserTestBase(); | 62 virtual ~NaClBrowserTestBase(); |
| 64 | 63 |
| 65 virtual void SetUpCommandLine(base::CommandLine* command_line) override; | 64 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 66 | 65 |
| 67 virtual void SetUpOnMainThread() override; | 66 void SetUpOnMainThread() override; |
| 68 | 67 |
| 69 // What variant are we running - newlib, glibc, pnacl, etc? | 68 // 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 | 69 // 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. | 70 // also be used to affect the behavior of the test. |
| 72 virtual base::FilePath::StringType Variant() = 0; | 71 virtual base::FilePath::StringType Variant() = 0; |
| 73 | 72 |
| 74 // Where are the files for this class of test located on disk? | 73 // Where are the files for this class of test located on disk? |
| 75 virtual bool GetDocumentRoot(base::FilePath* document_root); | 74 virtual bool GetDocumentRoot(base::FilePath* document_root); |
| 76 | 75 |
| 77 virtual bool IsAPnaclTest(); | 76 virtual bool IsAPnaclTest(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 bool full_url = false); | 101 bool full_url = false); |
| 103 | 102 |
| 104 private: | 103 private: |
| 105 bool StartTestServer(); | 104 bool StartTestServer(); |
| 106 | 105 |
| 107 scoped_ptr<net::SpawnedTestServer> test_server_; | 106 scoped_ptr<net::SpawnedTestServer> test_server_; |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 class NaClBrowserTestNewlib : public NaClBrowserTestBase { | 109 class NaClBrowserTestNewlib : public NaClBrowserTestBase { |
| 111 public: | 110 public: |
| 112 virtual base::FilePath::StringType Variant() override; | 111 base::FilePath::StringType Variant() override; |
| 113 }; | 112 }; |
| 114 | 113 |
| 115 class NaClBrowserTestGLibc : public NaClBrowserTestBase { | 114 class NaClBrowserTestGLibc : public NaClBrowserTestBase { |
| 116 public: | 115 public: |
| 117 virtual base::FilePath::StringType Variant() override; | 116 base::FilePath::StringType Variant() override; |
| 118 }; | 117 }; |
| 119 | 118 |
| 120 class NaClBrowserTestPnacl : public NaClBrowserTestBase { | 119 class NaClBrowserTestPnacl : public NaClBrowserTestBase { |
| 121 public: | 120 public: |
| 122 virtual base::FilePath::StringType Variant() override; | 121 base::FilePath::StringType Variant() override; |
| 123 | 122 |
| 124 virtual bool IsAPnaclTest() override; | 123 bool IsAPnaclTest() override; |
| 125 }; | 124 }; |
| 126 | 125 |
| 127 class NaClBrowserTestPnaclNonSfi : public NaClBrowserTestBase { | 126 class NaClBrowserTestPnaclNonSfi : public NaClBrowserTestBase { |
| 128 public: | 127 public: |
| 129 virtual void SetUpCommandLine(base::CommandLine* command_line) override; | 128 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 130 virtual base::FilePath::StringType Variant() override; | 129 base::FilePath::StringType Variant() override; |
| 131 }; | 130 }; |
| 132 | 131 |
| 133 class NaClBrowserTestNonSfiMode : public NaClBrowserTestBase { | 132 class NaClBrowserTestNonSfiMode : public NaClBrowserTestBase { |
| 134 public: | 133 public: |
| 135 virtual void SetUpCommandLine(base::CommandLine* command_line) override; | 134 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 136 virtual base::FilePath::StringType Variant() override; | 135 base::FilePath::StringType Variant() override; |
| 137 }; | 136 }; |
| 138 | 137 |
| 139 // A NaCl browser test only using static files. | 138 // A NaCl browser test only using static files. |
| 140 class NaClBrowserTestStatic : public NaClBrowserTestBase { | 139 class NaClBrowserTestStatic : public NaClBrowserTestBase { |
| 141 public: | 140 public: |
| 142 virtual base::FilePath::StringType Variant() override; | 141 base::FilePath::StringType Variant() override; |
| 143 virtual bool GetDocumentRoot(base::FilePath* document_root) override; | 142 bool GetDocumentRoot(base::FilePath* document_root) override; |
| 144 }; | 143 }; |
| 145 | 144 |
| 146 // A NaCl browser test that loads from an unpacked chrome extension. | 145 // A NaCl browser test that loads from an unpacked chrome extension. |
| 147 // The directory of the unpacked extension files is determined by | 146 // The directory of the unpacked extension files is determined by |
| 148 // the tester's document root. | 147 // the tester's document root. |
| 149 class NaClBrowserTestNewlibExtension : public NaClBrowserTestNewlib { | 148 class NaClBrowserTestNewlibExtension : public NaClBrowserTestNewlib { |
| 150 public: | 149 public: |
| 151 virtual void SetUpCommandLine(base::CommandLine* command_line) override; | 150 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 152 }; | 151 }; |
| 153 | 152 |
| 154 class NaClBrowserTestGLibcExtension : public NaClBrowserTestGLibc { | 153 class NaClBrowserTestGLibcExtension : public NaClBrowserTestGLibc { |
| 155 public: | 154 public: |
| 156 virtual void SetUpCommandLine(base::CommandLine* command_line) override; | 155 void SetUpCommandLine(base::CommandLine* command_line) override; |
| 157 }; | 156 }; |
| 158 | 157 |
| 159 // PNaCl tests take a long time on windows debug builds | 158 // PNaCl tests take a long time on windows debug builds |
| 160 // and sometimes time out. Disable until it is made faster: | 159 // and sometimes time out. Disable until it is made faster: |
| 161 // https://code.google.com/p/chromium/issues/detail?id=177555 | 160 // https://code.google.com/p/chromium/issues/detail?id=177555 |
| 162 #if (defined(OS_WIN) && !defined(NDEBUG)) | 161 #if (defined(OS_WIN) && !defined(NDEBUG)) |
| 163 # define MAYBE_PNACL(test_name) DISABLED_##test_name | 162 # define MAYBE_PNACL(test_name) DISABLED_##test_name |
| 164 #else | 163 #else |
| 165 # define MAYBE_PNACL(test_name) test_name | 164 # define MAYBE_PNACL(test_name) test_name |
| 166 #endif | 165 #endif |
| (...skipping 25 matching lines...) Expand all Loading... |
| 192 | 191 |
| 193 #define NACL_BROWSER_TEST_F(suite, name, body) \ | 192 #define NACL_BROWSER_TEST_F(suite, name, body) \ |
| 194 IN_PROC_BROWSER_TEST_F(suite##Newlib, name) \ | 193 IN_PROC_BROWSER_TEST_F(suite##Newlib, name) \ |
| 195 body \ | 194 body \ |
| 196 IN_PROC_BROWSER_TEST_F(suite##GLibc, MAYBE_GLIBC(name)) \ | 195 IN_PROC_BROWSER_TEST_F(suite##GLibc, MAYBE_GLIBC(name)) \ |
| 197 body \ | 196 body \ |
| 198 IN_PROC_BROWSER_TEST_F(suite##Pnacl, MAYBE_PNACL(name)) \ | 197 IN_PROC_BROWSER_TEST_F(suite##Pnacl, MAYBE_PNACL(name)) \ |
| 199 body | 198 body |
| 200 | 199 |
| 201 #endif // CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_ | 200 #endif // CHROME_TEST_NACL_NACL_BROWSERTEST_UTIL_H_ |
| OLD | NEW |