diff options
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/test_broker.cc | 46 | ||||
-rw-r--r-- | ppapi/tests/test_broker.h | 29 | ||||
-rw-r--r-- | ppapi/tests/test_char_set.cc | 17 | ||||
-rw-r--r-- | ppapi/tests/test_char_set.h | 1 | ||||
-rw-r--r-- | ppapi/tests/test_cursor_control.cc | 37 | ||||
-rw-r--r-- | ppapi/tests/test_cursor_control.h | 29 |
6 files changed, 158 insertions, 1 deletions
diff --git a/ppapi/tests/test_broker.cc b/ppapi/tests/test_broker.cc new file mode 100644 index 0000000..b1d5b02 --- /dev/null +++ b/ppapi/tests/test_broker.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/tests/test_broker.h" + +#include "ppapi/c/pp_errors.h" +#include "ppapi/c/trusted/ppb_broker_trusted.h" +#include "ppapi/cpp/module.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(Broker); + +TestBroker::TestBroker(TestingInstance* instance) + : TestCase(instance), + broker_interface_(NULL) { +} + +bool TestBroker::Init() { + broker_interface_ = static_cast<PPB_BrokerTrusted const*>( + pp::Module::Get()->GetBrowserInterface(PPB_BROKER_TRUSTED_INTERFACE)); + return !!broker_interface_; +} + +void TestBroker::RunTest() { + RUN_TEST(Create); +} + +std::string TestBroker::TestCreate() { + // Very simplistic test to make sure we can create a broker interface. + PP_Resource broker = broker_interface_->CreateTrusted( + instance_->pp_instance()); + ASSERT_TRUE(broker); + + ASSERT_FALSE(broker_interface_->IsBrokerTrusted(0)); + ASSERT_TRUE(broker_interface_->IsBrokerTrusted(broker)); + + // Test getting the handle for an invalid resource. + int32_t handle; + ASSERT_TRUE(broker_interface_->GetHandle(0, &handle) == PP_ERROR_BADRESOURCE); + + // Connect hasn't been called so this should fail. + ASSERT_TRUE(broker_interface_->GetHandle(broker, &handle) == PP_ERROR_FAILED); + + PASS(); +} diff --git a/ppapi/tests/test_broker.h b/ppapi/tests/test_broker.h new file mode 100644 index 0000000..4cef9e5 --- /dev/null +++ b/ppapi/tests/test_broker.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_TESTS_TEST_BROKER_H_ +#define PPAPI_TESTS_TEST_BROKER_H_ + +#include <string> +#include <vector> + +#include "ppapi/tests/test_case.h" + +struct PPB_BrokerTrusted; + +class TestBroker : public TestCase { + public: + TestBroker(TestingInstance* instance); + + // TestCase implementation. + virtual bool Init(); + virtual void RunTest(); + + private: + std::string TestCreate(); + + const struct PPB_BrokerTrusted* broker_interface_; +}; + +#endif // PPAPI_TESTS_TEST_BROKER_H_ diff --git a/ppapi/tests/test_char_set.cc b/ppapi/tests/test_char_set.cc index acc381f..dc417a0 100644 --- a/ppapi/tests/test_char_set.cc +++ b/ppapi/tests/test_char_set.cc @@ -16,7 +16,7 @@ TestCharSet::TestCharSet(TestingInstance* instance) } bool TestCharSet::Init() { - char_set_interface_ = reinterpret_cast<struct PPB_CharSet_Dev const*>( + char_set_interface_ = static_cast<PPB_CharSet_Dev const*>( pp::Module::Get()->GetBrowserInterface(PPB_CHAR_SET_DEV_INTERFACE)); return !!char_set_interface_; } @@ -24,6 +24,7 @@ bool TestCharSet::Init() { void TestCharSet::RunTest() { RUN_TEST(UTF16ToCharSet); RUN_TEST(CharSetToUTF16); + RUN_TEST(GetDefaultCharSet); } std::string TestCharSet::TestUTF16ToCharSet() { @@ -155,6 +156,20 @@ std::string TestCharSet::TestCharSetToUTF16() { PASS(); } +std::string TestCharSet::TestGetDefaultCharSet() { + // Test invalid instance. + pp::Var result(pp::Var::PassRef(), char_set_interface_->GetDefaultCharSet(0)); + ASSERT_TRUE(result.is_undefined()); + + // Just make sure the default char set is a nonempty string. + result = pp::Var(pp::Var::PassRef(), + char_set_interface_->GetDefaultCharSet(instance_->pp_instance())); + ASSERT_TRUE(result.is_string()); + ASSERT_FALSE(result.AsString().empty()); + + PASS(); +} + std::vector<uint16_t> TestCharSet::UTF8ToUTF16(const std::string& utf8) { uint32_t result_len = 0; uint16_t* result = char_set_interface_->CharSetToUTF16( diff --git a/ppapi/tests/test_char_set.h b/ppapi/tests/test_char_set.h index 980b29c..c6a14fe 100644 --- a/ppapi/tests/test_char_set.h +++ b/ppapi/tests/test_char_set.h @@ -24,6 +24,7 @@ class TestCharSet : public TestCase { private: std::string TestUTF16ToCharSet(); std::string TestCharSetToUTF16(); + std::string TestGetDefaultCharSet(); // Converts the given UTF-8 string to a NON-NULL TERMINATED UTF-16 string // stored in the given vector. diff --git a/ppapi/tests/test_cursor_control.cc b/ppapi/tests/test_cursor_control.cc new file mode 100644 index 0000000..80aca34 --- /dev/null +++ b/ppapi/tests/test_cursor_control.cc @@ -0,0 +1,37 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ppapi/tests/test_cursor_control.h" + +#include "ppapi/c/dev/ppb_cursor_control_dev.h" +#include "ppapi/cpp/module.h" +#include "ppapi/tests/testing_instance.h" + +REGISTER_TEST_CASE(CursorControl); + +TestCursorControl::TestCursorControl(TestingInstance* instance) + : TestCase(instance), + cursor_control_interface_(NULL) { +} + +bool TestCursorControl::Init() { + cursor_control_interface_ = static_cast<PPB_CursorControl_Dev const*>( + pp::Module::Get()->GetBrowserInterface(PPB_CURSOR_CONTROL_DEV_INTERFACE)); + return !!cursor_control_interface_; +} + +void TestCursorControl::RunTest() { + RUN_TEST(SetCursor); +} + +std::string TestCursorControl::TestSetCursor() { + // Very simplistic test to make sure we can actually call the function and + // it reports success. This is a nice integration test to make sure the + // interface is hooked up. Obviously it's not easy in a plugin to test whether + // the mouse cursor actually changed. + ASSERT_TRUE(cursor_control_interface_->SetCursor(instance_->pp_instance(), + PP_CURSORTYPE_WAIT, 0, NULL)); + + PASS(); +} diff --git a/ppapi/tests/test_cursor_control.h b/ppapi/tests/test_cursor_control.h new file mode 100644 index 0000000..65bc7a9 --- /dev/null +++ b/ppapi/tests/test_cursor_control.h @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_TESTS_TEST_CURSOR_CONTROL_H_ +#define PPAPI_TESTS_TEST_CURSOR_CONTROL_H_ + +#include <string> +#include <vector> + +#include "ppapi/tests/test_case.h" + +struct PPB_CursorControl_Dev; + +class TestCursorControl : public TestCase { + public: + TestCursorControl(TestingInstance* instance); + + // TestCase implementation. + virtual bool Init(); + virtual void RunTest(); + + private: + std::string TestSetCursor(); + + const struct PPB_CursorControl_Dev* cursor_control_interface_; +}; + +#endif // PPAPI_TESTS_TEST_CURSOR_CONTROL_H_ |