Chromium Code Reviews| Index: ppapi/tests/test_flash.cc |
| diff --git a/ppapi/tests/test_flash.cc b/ppapi/tests/test_flash.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..36b1f814afb75f8f42216b10ad8fadc49c3e9818 |
| --- /dev/null |
| +++ b/ppapi/tests/test_flash.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright (c) 2011 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_flash.h" |
| + |
| +#include "base/compiler_specific.h" |
| +#include "ppapi/c/private/ppb_flash.h" |
| +#include "ppapi/cpp/instance.h" |
| +#include "ppapi/cpp/module.h" |
| +#include "ppapi/cpp/var.h" |
| +#include "ppapi/tests/testing_instance.h" |
| + |
| +REGISTER_TEST_CASE(Flash); |
| + |
| +using pp::Var; |
| + |
| +TestFlash::TestFlash(TestingInstance* instance) |
| + : TestCase(instance), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
| +} |
| + |
| +bool TestFlash::Init() { |
| + flash_interface_ = reinterpret_cast<PPB_Flash const*>( |
|
yzshen1
2011/11/17 01:39:45
nit: maybe it is better to keep const at the same
dmichael (off chromium)
2011/11/17 04:10:46
static_cast
viettrungluu
2011/11/17 19:13:39
Done.
viettrungluu
2011/11/17 19:13:39
Done.
|
| + pp::Module::Get()->GetBrowserInterface(PPB_FLASH_INTERFACE)); |
| + return !!flash_interface_; |
| +} |
| + |
| +void TestFlash::RunTest() { |
|
yzshen1
2011/11/17 01:39:45
I thought a filter string is needed?
viettrungluu
2011/11/17 19:13:39
Yeah, I was working off a stale tree and rebasing
|
| + RUN_TEST(SetInstanceAlwaysOnTop); |
| + RUN_TEST(GetProxyForURL); |
| + RUN_TEST(MessageLoop); |
| + RUN_TEST(GetLocalTimeZoneOffset); |
| + RUN_TEST(GetCommandLineArgs); |
| +} |
| + |
| +std::string TestFlash::TestSetInstanceAlwaysOnTop() { |
| + flash_interface_->SetInstanceAlwaysOnTop(instance_->pp_instance(), PP_TRUE); |
| + flash_interface_->SetInstanceAlwaysOnTop(instance_->pp_instance(), PP_FALSE); |
| + PASS(); |
| +} |
| + |
| +std::string TestFlash::TestGetProxyForURL() { |
| + Var result(Var::PassRef(), |
| + flash_interface_->GetProxyForURL(instance_->pp_instance(), |
| + "http://127.0.0.1/foobar/")); |
| + ASSERT_TRUE(result.is_string()); |
| + // Assume no one configures a proxy for localhost. |
| + ASSERT_EQ("DIRECT", result.AsString()); |
| + |
| + result = Var(Var::PassRef(), |
| + flash_interface_->GetProxyForURL(instance_->pp_instance(), |
| + "http://www.google.com")); |
| + // Don't know what the proxy might be, but it should be a valid result. |
| + ASSERT_TRUE(result.is_string()); |
| + |
| + result = Var(Var::PassRef(), |
| + flash_interface_->GetProxyForURL(instance_->pp_instance(), |
| + "file:///tmp")); |
| + ASSERT_TRUE(result.is_string()); |
| + // Should get "DIRECT" for file:// URLs. |
| + ASSERT_EQ("DIRECT", result.AsString()); |
| + |
| + result = Var(Var::PassRef(), |
| + flash_interface_->GetProxyForURL(instance_->pp_instance(), |
| + "this_isnt_an_url")); |
| + // Should be an error. |
| + ASSERT_TRUE(result.is_undefined()); |
| + |
| + PASS(); |
| +} |
| + |
| +std::string TestFlash::TestMessageLoop() { |
| + pp::CompletionCallback callback = |
| + callback_factory_.NewRequiredCallback(&TestFlash::QuitMessageLoopTask); |
| + pp::Module::Get()->core()->CallOnMainThread(0, callback); |
| + flash_interface_->RunMessageLoop(instance_->pp_instance()); |
| + |
| + PASS(); |
| +} |
| + |
| +std::string TestFlash::TestGetLocalTimeZoneOffset() { |
| + double result = flash_interface_->GetLocalTimeZoneOffset( |
| + instance_->pp_instance(), 1321491298.0); |
| + // The result depends on the local time zone, but +/- 14h from UTC should |
| + // cover the possibilities. |
| + ASSERT_TRUE(result >= -14 * 60 * 60); |
| + ASSERT_TRUE(result <= 14 * 60 * 60); |
| + |
| + PASS(); |
| +} |
| + |
| +std::string TestFlash::TestGetCommandLineArgs() { |
| + Var result(Var::PassRef(), |
| + flash_interface_->GetCommandLineArgs( |
| + pp::Module::Get()->pp_module())); |
| + ASSERT_TRUE(result.is_string()); |
| + |
| + PASS(); |
| +} |
| + |
| +void TestFlash::QuitMessageLoopTask(int32_t) { |
| + flash_interface_->QuitMessageLoop(instance_->pp_instance()); |
| +} |