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
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_flash.h"
7 #include "ppapi/c/pp_macros.h"
8 #include "ppapi/c/private/ppb_flash.h"
9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h"
11 #include "ppapi/cpp/private/flash.h"
12 #include "ppapi/cpp/var.h"
13 #include "ppapi/tests/testing_instance.h"
15 REGISTER_TEST_CASE(Flash
);
17 using pp::flash::Flash
;
20 TestFlash::TestFlash(TestingInstance
* instance
)
22 PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
25 void TestFlash::RunTests(const std::string
& filter
) {
26 RUN_TEST(SetInstanceAlwaysOnTop
, filter
);
27 RUN_TEST(GetProxyForURL
, filter
);
28 RUN_TEST(GetLocalTimeZoneOffset
, filter
);
29 RUN_TEST(GetCommandLineArgs
, filter
);
30 RUN_TEST(GetSetting
, filter
);
31 RUN_TEST(SetCrashData
, filter
);
34 std::string
TestFlash::TestSetInstanceAlwaysOnTop() {
35 Flash::SetInstanceAlwaysOnTop(instance_
, PP_TRUE
);
36 Flash::SetInstanceAlwaysOnTop(instance_
, PP_FALSE
);
40 std::string
TestFlash::TestGetProxyForURL() {
41 Var result
= Flash::GetProxyForURL(instance_
, "http://127.0.0.1/foobar/");
42 ASSERT_TRUE(result
.is_string());
43 // Assume no one configures a proxy for localhost.
44 ASSERT_EQ("DIRECT", result
.AsString());
46 result
= Flash::GetProxyForURL(instance_
, "http://www.google.com");
47 // Don't know what the proxy might be, but it should be a valid result.
48 ASSERT_TRUE(result
.is_string());
50 result
= Flash::GetProxyForURL(instance_
, "file:///tmp");
51 ASSERT_TRUE(result
.is_string());
52 // Should get "DIRECT" for file:// URLs.
53 ASSERT_EQ("DIRECT", result
.AsString());
55 result
= Flash::GetProxyForURL(instance_
, "this_isnt_an_url");
56 // Should be an error.
57 ASSERT_TRUE(result
.is_undefined());
62 std::string
TestFlash::TestGetLocalTimeZoneOffset() {
63 double result
= Flash::GetLocalTimeZoneOffset(instance_
, 1321491298.0);
64 // The result depends on the local time zone, but +/- 14h from UTC should
65 // cover the possibilities.
66 ASSERT_TRUE(result
>= -14 * 60 * 60);
67 ASSERT_TRUE(result
<= 14 * 60 * 60);
72 std::string
TestFlash::TestGetCommandLineArgs() {
73 Var result
= Flash::GetCommandLineArgs(pp::Module::Get());
74 ASSERT_TRUE(result
.is_string());
79 std::string
TestFlash::TestGetSetting() {
80 Var is_3denabled
= Flash::GetSetting(instance_
, PP_FLASHSETTING_3DENABLED
);
81 ASSERT_TRUE(is_3denabled
.is_bool());
83 Var is_incognito
= Flash::GetSetting(instance_
, PP_FLASHSETTING_INCOGNITO
);
84 ASSERT_TRUE(is_incognito
.is_bool());
86 Var is_stage3denabled
= Flash::GetSetting(instance_
,
87 PP_FLASHSETTING_STAGE3DENABLED
);
88 // This may "fail" if 3d isn't enabled.
89 ASSERT_TRUE(is_stage3denabled
.is_bool() ||
90 (is_stage3denabled
.is_undefined() && !is_3denabled
.AsBool()));
92 Var num_cores
= Flash::GetSetting(instance_
, PP_FLASHSETTING_NUMCORES
);
93 ASSERT_TRUE(num_cores
.is_int() && num_cores
.AsInt() > 0);
95 Var lso_restrictions
= Flash::GetSetting(instance_
,
96 PP_FLASHSETTING_LSORESTRICTIONS
);
97 ASSERT_TRUE(lso_restrictions
.is_int());
98 int32_t lso_restrictions_int
= lso_restrictions
.AsInt();
99 ASSERT_TRUE(lso_restrictions_int
== PP_FLASHLSORESTRICTIONS_NONE
||
100 lso_restrictions_int
== PP_FLASHLSORESTRICTIONS_BLOCK
||
101 lso_restrictions_int
== PP_FLASHLSORESTRICTIONS_IN_MEMORY
);
103 // Invalid instance cases.
104 Var result
= Flash::GetSetting(
105 pp::InstanceHandle(static_cast<PP_Instance
>(0)),
106 PP_FLASHSETTING_3DENABLED
);
107 ASSERT_TRUE(result
.is_undefined());
108 result
= Flash::GetSetting(pp::InstanceHandle(static_cast<PP_Instance
>(0)),
109 PP_FLASHSETTING_INCOGNITO
);
110 ASSERT_TRUE(result
.is_undefined());
111 result
= Flash::GetSetting(pp::InstanceHandle(static_cast<PP_Instance
>(0)),
112 PP_FLASHSETTING_STAGE3DENABLED
);
113 ASSERT_TRUE(result
.is_undefined());
118 std::string
TestFlash::TestSetCrashData() {
119 pp::Var
url("http://...");
120 ASSERT_TRUE(Flash::SetCrashData(instance_
, PP_FLASHCRASHKEY_URL
, url
));