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