Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 PPAPI_TESTS_TEST_CASE_H_ | 5 #ifndef PPAPI_TESTS_TEST_CASE_H_ |
| 6 #define PPAPI_TESTS_TEST_CASE_H_ | 6 #define PPAPI_TESTS_TEST_CASE_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
| 13 #include "ppapi/cpp/dev/scrollbar_dev.h" | 13 #include "ppapi/cpp/dev/scrollbar_dev.h" |
| 14 | |
| 15 #if (defined __native_client__) | |
| 14 #include "ppapi/cpp/var.h" | 16 #include "ppapi/cpp/var.h" |
| 17 #else | |
| 18 #include "ppapi/cpp/private/var_private.h" | |
| 19 #endif | |
| 15 | 20 |
| 16 struct PPB_Testing_Dev; | 21 struct PPB_Testing_Dev; |
| 17 class TestingInstance; | 22 class TestingInstance; |
| 18 | 23 |
| 19 namespace pp { | 24 namespace pp { |
| 20 namespace deprecated { | 25 namespace deprecated { |
| 21 class ScriptableObject; | 26 class ScriptableObject; |
| 22 } | 27 } |
| 23 } | 28 } |
| 24 | 29 |
| 25 // Individual classes of tests derive from this generic test case. | 30 // Individual classes of tests derive from this generic test case. |
| 26 class TestCase { | 31 class TestCase { |
| 27 public: | 32 public: |
| 28 explicit TestCase(TestingInstance* instance); | 33 explicit TestCase(TestingInstance* instance); |
| 29 virtual ~TestCase(); | 34 virtual ~TestCase(); |
| 30 | 35 |
| 31 // Optionally override to do testcase specific initialization. | 36 // Optionally override to do testcase specific initialization. |
| 32 virtual bool Init() { return true; } | 37 virtual bool Init() { return true; } |
| 33 | 38 |
| 34 // Override to implement the test. It will be called after the plugin is | 39 // Override to implement the test. It will be called after the plugin is |
| 35 // first displayed. | 40 // first displayed. |
| 36 virtual void RunTest() = 0; | 41 virtual void RunTest() = 0; |
| 37 | 42 |
| 38 static std::string MakeFailureMessage(const char* file, int line, | 43 static std::string MakeFailureMessage(const char* file, int line, |
| 39 const char* cmd); | 44 const char* cmd); |
| 40 | 45 |
| 46 #if !(defined __native_client__) | |
| 41 // Returns the scriptable test object for the current test, if any. | 47 // Returns the scriptable test object for the current test, if any. |
| 42 // Internally, this uses CreateTestObject which each test overrides. | 48 // Internally, this uses CreateTestObject which each test overrides. |
| 43 pp::Var GetTestObject(); | 49 pp::VarPrivate GetTestObject(); |
| 50 #endif | |
| 44 | 51 |
| 45 // A function that is invoked whenever HandleMessage is called on the | 52 // A function that is invoked whenever HandleMessage is called on the |
| 46 // associated TestingInstance. Default implementation does nothing. TestCases | 53 // associated TestingInstance. Default implementation does nothing. TestCases |
| 47 // that want to handle incoming postMessage events should override this | 54 // that want to handle incoming postMessage events should override this |
| 48 // method. | 55 // method. |
| 49 virtual void HandleMessage(const pp::Var& message_data); | 56 virtual void HandleMessage(const pp::Var& message_data); |
| 50 | 57 |
| 51 protected: | 58 protected: |
| 59 #if !(defined __native_client__) | |
| 52 // Overridden by each test to supply a ScriptableObject corresponding to the | 60 // Overridden by each test to supply a ScriptableObject corresponding to the |
| 53 // test. There can only be one object created for all test in a given class | 61 // test. There can only be one object created for all test in a given class |
| 54 // so be sure your object is designed to be re-used. | 62 // so be sure your object is designed to be re-used. |
| 55 // | 63 // |
| 56 // This object should be created on the heap. Ownership will be passed to the | 64 // This object should be created on the heap. Ownership will be passed to the |
| 57 // caller. Return NULL if there is no supported test object (the default). | 65 // caller. Return NULL if there is no supported test object (the default). |
| 58 virtual pp::deprecated::ScriptableObject* CreateTestObject(); | 66 virtual pp::deprecated::ScriptableObject* CreateTestObject(); |
| 67 #endif | |
| 59 | 68 |
| 60 // Initializes the testing interface. | 69 // Initializes the testing interface. |
| 61 bool InitTestingInterface(); | 70 bool InitTestingInterface(); |
| 62 | 71 |
| 63 // Makes sure the test is run over HTTP. | 72 // Makes sure the test is run over HTTP. |
| 64 bool EnsureRunningOverHTTP(); | 73 bool EnsureRunningOverHTTP(); |
| 65 | 74 |
| 66 // Pointer to the instance that owns us. | 75 // Pointer to the instance that owns us. |
| 67 TestingInstance* instance_; | 76 TestingInstance* instance_; |
| 68 | 77 |
| 69 // NULL unless InitTestingInterface is called. | 78 // NULL unless InitTestingInterface is called. |
| 70 const PPB_Testing_Dev* testing_interface_; | 79 const PPB_Testing_Dev* testing_interface_; |
| 71 | 80 |
| 72 // Force asynchronous completion of any operation taking a callback. | 81 // Force asynchronous completion of any operation taking a callback. |
| 73 bool force_async_; | 82 bool force_async_; |
| 74 | 83 |
| 75 private: | 84 private: |
| 76 // Holds the test object, if any was retrieved from CreateTestObject. | 85 // Holds the test object, if any was retrieved from CreateTestObject. |
| 77 pp::Var test_object_; | 86 pp::VarPrivate test_object_; |
|
cstefansen
2011/07/07 18:03:09
#if !(defined __native_client__) ?
dmichael (off chromium)
2011/07/07 21:17:59
Good catch, done.
| |
| 78 }; | 87 }; |
| 79 | 88 |
| 80 // This class is an implementation detail. | 89 // This class is an implementation detail. |
| 81 class TestCaseFactory { | 90 class TestCaseFactory { |
| 82 public: | 91 public: |
| 83 typedef TestCase* (*Method)(TestingInstance* instance); | 92 typedef TestCase* (*Method)(TestingInstance* instance); |
| 84 | 93 |
| 85 TestCaseFactory(const char* name, Method method) | 94 TestCaseFactory(const char* name, Method method) |
| 86 : next_(head_), | 95 : next_(head_), |
| 87 name_(name), | 96 name_(name), |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) | 151 #define ASSERT_FALSE(cmd) ASSERT_TRUE(!(cmd)) |
| 143 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) | 152 #define ASSERT_EQ(a, b) ASSERT_TRUE((a) == (b)) |
| 144 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) | 153 #define ASSERT_NE(a, b) ASSERT_TRUE((a) != (b)) |
| 145 | 154 |
| 146 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ | 155 #define ASSERT_DOUBLE_EQ(a, b) ASSERT_TRUE( \ |
| 147 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) | 156 std::fabs((a)-(b)) <= std::numeric_limits<double>::epsilon()) |
| 148 | 157 |
| 149 #define PASS() return std::string() | 158 #define PASS() return std::string() |
| 150 | 159 |
| 151 #endif // PPAPI_TESTS_TEST_CASE_H_ | 160 #endif // PPAPI_TESTS_TEST_CASE_H_ |
| OLD | NEW |