OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "ppapi/tests/test_flash.h" | 5 #include "ppapi/tests/test_flash.h" |
6 | 6 |
7 #include "ppapi/c/pp_macros.h" | 7 #include "ppapi/c/pp_macros.h" |
8 #include "ppapi/c/private/ppb_flash.h" | 8 #include "ppapi/c/private/ppb_flash.h" |
9 #include "ppapi/cpp/instance.h" | 9 #include "ppapi/cpp/instance.h" |
10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
| 11 #include "ppapi/cpp/private/flash.h" |
11 #include "ppapi/cpp/var.h" | 12 #include "ppapi/cpp/var.h" |
12 #include "ppapi/tests/testing_instance.h" | 13 #include "ppapi/tests/testing_instance.h" |
13 | 14 |
14 REGISTER_TEST_CASE(Flash); | 15 REGISTER_TEST_CASE(Flash); |
15 | 16 |
| 17 using pp::flash::Flash; |
16 using pp::Var; | 18 using pp::Var; |
17 | 19 |
18 TestFlash::TestFlash(TestingInstance* instance) | 20 TestFlash::TestFlash(TestingInstance* instance) |
19 : TestCase(instance), | 21 : TestCase(instance), |
20 PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { | 22 PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { |
21 } | 23 } |
22 | 24 |
23 bool TestFlash::Init() { | |
24 flash_interface_ = static_cast<const PPB_Flash*>( | |
25 pp::Module::Get()->GetBrowserInterface(PPB_FLASH_INTERFACE)); | |
26 return !!flash_interface_; | |
27 } | |
28 | |
29 void TestFlash::RunTests(const std::string& filter) { | 25 void TestFlash::RunTests(const std::string& filter) { |
30 RUN_TEST(SetInstanceAlwaysOnTop, filter); | 26 RUN_TEST(SetInstanceAlwaysOnTop, filter); |
31 RUN_TEST(GetProxyForURL, filter); | 27 RUN_TEST(GetProxyForURL, filter); |
32 RUN_TEST(MessageLoop, filter); | |
33 RUN_TEST(GetLocalTimeZoneOffset, filter); | 28 RUN_TEST(GetLocalTimeZoneOffset, filter); |
34 RUN_TEST(GetCommandLineArgs, filter); | 29 RUN_TEST(GetCommandLineArgs, filter); |
35 RUN_TEST(GetDeviceID, filter); | |
36 RUN_TEST(GetSettingInt, filter); | |
37 RUN_TEST(GetSetting, filter); | 30 RUN_TEST(GetSetting, filter); |
38 RUN_TEST(SetCrashData, filter); | 31 RUN_TEST(SetCrashData, filter); |
39 } | 32 } |
40 | 33 |
41 std::string TestFlash::TestSetInstanceAlwaysOnTop() { | 34 std::string TestFlash::TestSetInstanceAlwaysOnTop() { |
42 flash_interface_->SetInstanceAlwaysOnTop(instance_->pp_instance(), PP_TRUE); | 35 Flash::SetInstanceAlwaysOnTop(instance_, PP_TRUE); |
43 flash_interface_->SetInstanceAlwaysOnTop(instance_->pp_instance(), PP_FALSE); | 36 Flash::SetInstanceAlwaysOnTop(instance_, PP_FALSE); |
44 PASS(); | 37 PASS(); |
45 } | 38 } |
46 | 39 |
47 std::string TestFlash::TestGetProxyForURL() { | 40 std::string TestFlash::TestGetProxyForURL() { |
48 Var result(pp::PASS_REF, | 41 Var result = Flash::GetProxyForURL(instance_, "http://127.0.0.1/foobar/"); |
49 flash_interface_->GetProxyForURL(instance_->pp_instance(), | |
50 "http://127.0.0.1/foobar/")); | |
51 ASSERT_TRUE(result.is_string()); | 42 ASSERT_TRUE(result.is_string()); |
52 // Assume no one configures a proxy for localhost. | 43 // Assume no one configures a proxy for localhost. |
53 ASSERT_EQ("DIRECT", result.AsString()); | 44 ASSERT_EQ("DIRECT", result.AsString()); |
54 | 45 |
55 result = Var(pp::PASS_REF, | 46 result = Flash::GetProxyForURL(instance_, "http://www.google.com"); |
56 flash_interface_->GetProxyForURL(instance_->pp_instance(), | |
57 "http://www.google.com")); | |
58 // Don't know what the proxy might be, but it should be a valid result. | 47 // Don't know what the proxy might be, but it should be a valid result. |
59 ASSERT_TRUE(result.is_string()); | 48 ASSERT_TRUE(result.is_string()); |
60 | 49 |
61 result = Var(pp::PASS_REF, | 50 result = Flash::GetProxyForURL(instance_, "file:///tmp"); |
62 flash_interface_->GetProxyForURL(instance_->pp_instance(), | |
63 "file:///tmp")); | |
64 ASSERT_TRUE(result.is_string()); | 51 ASSERT_TRUE(result.is_string()); |
65 // Should get "DIRECT" for file:// URLs. | 52 // Should get "DIRECT" for file:// URLs. |
66 ASSERT_EQ("DIRECT", result.AsString()); | 53 ASSERT_EQ("DIRECT", result.AsString()); |
67 | 54 |
68 result = Var(pp::PASS_REF, | 55 result = Flash::GetProxyForURL(instance_, "this_isnt_an_url"); |
69 flash_interface_->GetProxyForURL(instance_->pp_instance(), | |
70 "this_isnt_an_url")); | |
71 // Should be an error. | 56 // Should be an error. |
72 ASSERT_TRUE(result.is_undefined()); | 57 ASSERT_TRUE(result.is_undefined()); |
73 | 58 |
74 PASS(); | 59 PASS(); |
75 } | 60 } |
76 | 61 |
77 std::string TestFlash::TestMessageLoop() { | |
78 pp::CompletionCallback callback = | |
79 callback_factory_.NewCallback(&TestFlash::QuitMessageLoopTask); | |
80 pp::Module::Get()->core()->CallOnMainThread(0, callback); | |
81 flash_interface_->RunMessageLoop(instance_->pp_instance()); | |
82 | |
83 PASS(); | |
84 } | |
85 | |
86 std::string TestFlash::TestGetLocalTimeZoneOffset() { | 62 std::string TestFlash::TestGetLocalTimeZoneOffset() { |
87 double result = flash_interface_->GetLocalTimeZoneOffset( | 63 double result = Flash::GetLocalTimeZoneOffset(instance_, 1321491298.0); |
88 instance_->pp_instance(), 1321491298.0); | |
89 // The result depends on the local time zone, but +/- 14h from UTC should | 64 // The result depends on the local time zone, but +/- 14h from UTC should |
90 // cover the possibilities. | 65 // cover the possibilities. |
91 ASSERT_TRUE(result >= -14 * 60 * 60); | 66 ASSERT_TRUE(result >= -14 * 60 * 60); |
92 ASSERT_TRUE(result <= 14 * 60 * 60); | 67 ASSERT_TRUE(result <= 14 * 60 * 60); |
93 | 68 |
94 PASS(); | 69 PASS(); |
95 } | 70 } |
96 | 71 |
97 std::string TestFlash::TestGetCommandLineArgs() { | 72 std::string TestFlash::TestGetCommandLineArgs() { |
98 Var result(pp::PASS_REF, | 73 Var result = Flash::GetCommandLineArgs(pp::Module::Get()); |
99 flash_interface_->GetCommandLineArgs( | |
100 pp::Module::Get()->pp_module())); | |
101 ASSERT_TRUE(result.is_string()); | 74 ASSERT_TRUE(result.is_string()); |
102 | 75 |
103 PASS(); | 76 PASS(); |
104 } | 77 } |
105 | 78 |
106 std::string TestFlash::TestGetDeviceID() { | |
107 Var result(pp::PASS_REF, | |
108 flash_interface_->GetDeviceID(instance_->pp_instance())); | |
109 // TODO(wad) figure out how to mock the input and test the full flow. | |
110 ASSERT_TRUE(result.is_string()); | |
111 PASS(); | |
112 } | |
113 | |
114 std::string TestFlash::TestGetSettingInt() { | |
115 // This only works out of process. | |
116 if (testing_interface_->IsOutOfProcess()) { | |
117 int32_t is_3denabled = flash_interface_->GetSettingInt( | |
118 instance_->pp_instance(), PP_FLASHSETTING_3DENABLED); | |
119 ASSERT_TRUE(is_3denabled == 0 || is_3denabled == 1); | |
120 | |
121 int32_t is_incognito = flash_interface_->GetSettingInt( | |
122 instance_->pp_instance(), PP_FLASHSETTING_INCOGNITO); | |
123 ASSERT_TRUE(is_incognito == 0 || is_incognito == 1); | |
124 | |
125 int32_t is_stage3denabled = flash_interface_->GetSettingInt( | |
126 instance_->pp_instance(), PP_FLASHSETTING_STAGE3DENABLED); | |
127 // This may "fail" if 3d isn't enabled. | |
128 ASSERT_TRUE((is_stage3denabled == 0 || is_stage3denabled == 1) || | |
129 (is_stage3denabled == -1 && is_3denabled == 0)); | |
130 } | |
131 | |
132 // Invalid instance cases. | |
133 int32_t result = flash_interface_->GetSettingInt( | |
134 0, PP_FLASHSETTING_3DENABLED); | |
135 ASSERT_EQ(-1, result); | |
136 result = flash_interface_->GetSettingInt(0, PP_FLASHSETTING_INCOGNITO); | |
137 ASSERT_EQ(-1, result); | |
138 result = flash_interface_->GetSettingInt(0, PP_FLASHSETTING_STAGE3DENABLED); | |
139 ASSERT_EQ(-1, result); | |
140 | |
141 PASS(); | |
142 } | |
143 | |
144 std::string TestFlash::TestGetSetting() { | 79 std::string TestFlash::TestGetSetting() { |
145 // This only works out of process. | 80 // This only works out of process. |
146 if (testing_interface_->IsOutOfProcess()) { | 81 if (testing_interface_->IsOutOfProcess()) { |
147 Var is_3denabled(pp::PASS_REF, flash_interface_->GetSetting( | 82 Var is_3denabled = Flash::GetSetting(instance_, PP_FLASHSETTING_3DENABLED); |
148 instance_->pp_instance(), PP_FLASHSETTING_3DENABLED)); | |
149 ASSERT_TRUE(is_3denabled.is_bool()); | 83 ASSERT_TRUE(is_3denabled.is_bool()); |
150 | 84 |
151 Var is_incognito(pp::PASS_REF, flash_interface_->GetSetting( | 85 Var is_incognito = Flash::GetSetting(instance_, PP_FLASHSETTING_INCOGNITO); |
152 instance_->pp_instance(), PP_FLASHSETTING_INCOGNITO)); | |
153 ASSERT_TRUE(is_incognito.is_bool()); | 86 ASSERT_TRUE(is_incognito.is_bool()); |
154 | 87 |
155 Var is_stage3denabled(pp::PASS_REF, flash_interface_->GetSetting( | 88 Var is_stage3denabled = Flash::GetSetting(instance_, |
156 instance_->pp_instance(), PP_FLASHSETTING_STAGE3DENABLED)); | 89 PP_FLASHSETTING_STAGE3DENABLED); |
157 // This may "fail" if 3d isn't enabled. | 90 // This may "fail" if 3d isn't enabled. |
158 ASSERT_TRUE(is_stage3denabled.is_bool() || | 91 ASSERT_TRUE(is_stage3denabled.is_bool() || |
159 (is_stage3denabled.is_undefined() && !is_3denabled.AsBool())); | 92 (is_stage3denabled.is_undefined() && !is_3denabled.AsBool())); |
160 | 93 |
161 Var num_cores(pp::PASS_REF, flash_interface_->GetSetting( | 94 Var num_cores = Flash::GetSetting(instance_, PP_FLASHSETTING_NUMCORES); |
162 instance_->pp_instance(), PP_FLASHSETTING_NUMCORES)); | |
163 ASSERT_TRUE(num_cores.is_int() && num_cores.AsInt() > 0); | 95 ASSERT_TRUE(num_cores.is_int() && num_cores.AsInt() > 0); |
164 } | 96 } |
165 | 97 |
166 // Invalid instance cases. | 98 // Invalid instance cases. |
167 Var result(pp::PASS_REF, | 99 Var result = Flash::GetSetting( |
168 flash_interface_->GetSetting(0, PP_FLASHSETTING_3DENABLED)); | 100 pp::InstanceHandle(static_cast<PP_Instance>(0)), |
| 101 PP_FLASHSETTING_3DENABLED); |
169 ASSERT_TRUE(result.is_undefined()); | 102 ASSERT_TRUE(result.is_undefined()); |
170 result = Var(pp::PASS_REF, | 103 result = Flash::GetSetting(pp::InstanceHandle(static_cast<PP_Instance>(0)), |
171 flash_interface_->GetSetting(0, PP_FLASHSETTING_INCOGNITO)); | 104 PP_FLASHSETTING_INCOGNITO); |
172 ASSERT_TRUE(result.is_undefined()); | 105 ASSERT_TRUE(result.is_undefined()); |
173 result = Var(pp::PASS_REF, | 106 result = Flash::GetSetting(pp::InstanceHandle(static_cast<PP_Instance>(0)), |
174 flash_interface_->GetSetting(0, PP_FLASHSETTING_STAGE3DENABLED)); | 107 PP_FLASHSETTING_STAGE3DENABLED); |
175 ASSERT_TRUE(result.is_undefined()); | 108 ASSERT_TRUE(result.is_undefined()); |
176 | 109 |
177 PASS(); | 110 PASS(); |
178 } | 111 } |
179 | 112 |
180 std::string TestFlash::TestSetCrashData() { | 113 std::string TestFlash::TestSetCrashData() { |
181 pp::Var url("http://..."); | 114 pp::Var url("http://..."); |
182 ASSERT_TRUE(flash_interface_->SetCrashData(instance_->pp_instance(), | 115 ASSERT_TRUE(Flash::SetCrashData(instance_, PP_FLASHCRASHKEY_URL, url)); |
183 PP_FLASHCRASHKEY_URL, | |
184 url.pp_var())); | |
185 | 116 |
186 PASS(); | 117 PASS(); |
187 } | 118 } |
188 | |
189 void TestFlash::QuitMessageLoopTask(int32_t) { | |
190 flash_interface_->QuitMessageLoop(instance_->pp_instance()); | |
191 } | |
OLD | NEW |