Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: tests/ppapi_test_lib/test_interface.cc

Issue 7292002: Remove plugin connection to PPAPI scriptable objects (var deprecated). Also (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/ppapi_test_lib/test_interface.h ('k') | tests/pyauto_nacl/multiple_nexes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. 1 // Copyright (c) 2011 The Native Client 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 "native_client/tests/ppapi_test_lib/test_interface.h" 5 #include "native_client/tests/ppapi_test_lib/test_interface.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <map> 8 #include <map>
9 #include <new> 9 #include <new>
10 10
11 #include "native_client/src/include/nacl_macros.h" 11 #include "native_client/src/include/nacl_macros.h"
12 #include "native_client/src/shared/platform/nacl_check.h" 12 #include "native_client/src/shared/platform/nacl_check.h"
13 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h" 13 #include "native_client/tests/ppapi_test_lib/get_browser_interface.h"
14 #include "native_client/tests/ppapi_test_lib/internal_utils.h" 14 #include "native_client/tests/ppapi_test_lib/internal_utils.h"
15 15
16 #include "ppapi/c/dev/ppb_var_deprecated.h"
17
18 #include "ppapi/c/pp_instance.h" 16 #include "ppapi/c/pp_instance.h"
19 #include "ppapi/c/pp_module.h" 17 #include "ppapi/c/pp_module.h"
20 #include "ppapi/c/pp_var.h" 18 #include "ppapi/c/pp_var.h"
21 #include "ppapi/c/ppb_instance.h" 19 #include "ppapi/c/ppb_instance.h"
22 #include "ppapi/c/ppb_messaging.h" 20 #include "ppapi/c/ppb_messaging.h"
23 #include "ppapi/c/ppb_var.h" 21 #include "ppapi/c/ppb_var.h"
24 22
25 void PostTestMessage(nacl::string test_name, nacl::string message) { 23 void PostTestMessage(nacl::string test_name, nacl::string message) {
26 nacl::string test_message = test_name; 24 nacl::string test_message = test_name;
27 test_message += ":"; 25 test_message += ":";
(...skipping 12 matching lines...) Expand all
40 namespace { 38 namespace {
41 39
42 class TestTable { 40 class TestTable {
43 public: 41 public:
44 // Return singleton intsance. 42 // Return singleton intsance.
45 static TestTable* Get() { 43 static TestTable* Get() {
46 static TestTable table; 44 static TestTable table;
47 return &table; 45 return &table;
48 } 46 }
49 47
50 void AddScriptableTest(nacl::string test_name,
51 ScriptableTestFunction test_function) {
52 scriptable_test_map_[test_name] = test_function;
53 }
54 bool HasScriptableTest(nacl::string test_name);
55 PP_Var RunScriptableTest(nacl::string test_name);
56
57 void AddTest(nacl::string test_name, TestFunction test_function) { 48 void AddTest(nacl::string test_name, TestFunction test_function) {
58 test_map_[test_name] = test_function; 49 test_map_[test_name] = test_function;
59 } 50 }
60 void RunTest(nacl::string test_name); 51 void RunTest(nacl::string test_name);
61 52
62 private: 53 private:
63 NACL_DISALLOW_COPY_AND_ASSIGN(TestTable); 54 NACL_DISALLOW_COPY_AND_ASSIGN(TestTable);
64 55
65 TestTable() {} 56 TestTable() {}
66 57
67 typedef std::map<nacl::string, ScriptableTestFunction> ScriptableTestMap;
68 ScriptableTestMap scriptable_test_map_; // DEPRECATED.
69 typedef std::map<nacl::string, TestFunction> TestMap; 58 typedef std::map<nacl::string, TestFunction> TestMap;
70 TestMap test_map_; 59 TestMap test_map_;
71 }; 60 };
72 61
73 bool TestTable::HasScriptableTest(nacl::string test_name) {
74 ScriptableTestMap::iterator it = scriptable_test_map_.find(test_name);
75 return it != scriptable_test_map_.end();
76 }
77
78 PP_Var TestTable::RunScriptableTest(nacl::string test_name) {
79 ScriptableTestMap::iterator it = scriptable_test_map_.find(test_name);
80 if (it == scriptable_test_map_.end())
81 return PP_MakeUndefined();
82 CHECK(it->second != NULL);
83 ScriptableTestFunction test_function = it->second;
84 return test_function();
85 }
86
87 void TestTable::RunTest(nacl::string test_name) { 62 void TestTable::RunTest(nacl::string test_name) {
88 TestMap::iterator it = test_map_.find(test_name); 63 TestMap::iterator it = test_map_.find(test_name);
89 if (it == test_map_.end()) { 64 if (it == test_map_.end()) {
90 PostTestMessage(test_name, "NOTFOUND"); 65 PostTestMessage(test_name, "NOTFOUND");
91 return; 66 return;
92 } 67 }
93 CHECK(it->second != NULL); 68 CHECK(it->second != NULL);
94 TestFunction test_function = it->second; 69 TestFunction test_function = it->second;
95 return test_function(); 70 return test_function();
96 } 71 }
97 72
98 } // namespace 73 } // namespace
99 74
100 void RegisterScriptableTest(nacl::string test_name,
101 ScriptableTestFunction test_func) {
102 TestTable::Get()->AddScriptableTest(test_name, test_func);
103 }
104
105 bool HasScriptableTest(nacl::string test_name) {
106 return TestTable::Get()->HasScriptableTest(test_name);
107 }
108
109 PP_Var RunScriptableTest(nacl::string test_name) {
110 return TestTable::Get()->RunScriptableTest(test_name);
111 }
112
113 void RegisterTest(nacl::string test_name, TestFunction test_func) { 75 void RegisterTest(nacl::string test_name, TestFunction test_func) {
114 TestTable::Get()->AddTest(test_name, test_func); 76 TestTable::Get()->AddTest(test_name, test_func);
115 } 77 }
116 78
117 void RunTest(nacl::string test_name) { 79 void RunTest(nacl::string test_name) {
118 TestTable::Get()->RunTest(test_name); 80 TestTable::Get()->RunTest(test_name);
119 } 81 }
120 82
121 //////////////////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////////////////
122 // Testable callback support 84 // Testable callback support
123 //////////////////////////////////////////////////////////////////////////////// 85 ////////////////////////////////////////////////////////////////////////////////
124 86
125 namespace { 87 namespace {
126 88
127 struct CallbackInfo { 89 struct CallbackInfo {
128 nacl::string callback_name; 90 nacl::string callback_name;
129 PP_CompletionCallback user_callback; 91 PP_CompletionCallback user_callback;
130 }; 92 };
131 93
132 void ReportCallbackInvocationToJS(const char* callback_name) { 94 void ReportCallbackInvocationToJS(const char* callback_name) {
133 PP_Var callback_var = PPBVar()->VarFromUtf8(pp_module(), 95 PP_Var callback_var = PPBVar()->VarFromUtf8(pp_module(),
134 callback_name, 96 callback_name,
135 strlen(callback_name)); 97 strlen(callback_name));
136 // Report using synchronous scripting for sync tests.
137 // This is deprecated and will be removed shortly.
138 #ifndef PPAPI_INSTANCE_REMOVE_SCRIPTING
139 PP_Var window = PPBInstance()->GetWindowObject(pp_instance());
140 CHECK(window.type == PP_VARTYPE_OBJECT);
141
142 PP_Var exception = PP_MakeUndefined();
143 PPBVarDeprecated()->Call(window, callback_var, 0, NULL, &exception);
144 PPBVarDeprecated()->Release(window);
145 #endif
146
147 // Report using postmessage for async tests. 98 // Report using postmessage for async tests.
148 PPBMessaging()->PostMessage(pp_instance(), callback_var); 99 PPBMessaging()->PostMessage(pp_instance(), callback_var);
149 PPBVar()->Release(callback_var); 100 PPBVar()->Release(callback_var);
150 } 101 }
151 102
152 void CallbackWrapper(void* user_data, int32_t result) { 103 void CallbackWrapper(void* user_data, int32_t result) {
153 CallbackInfo* callback_info = reinterpret_cast<CallbackInfo*>(user_data); 104 CallbackInfo* callback_info = reinterpret_cast<CallbackInfo*>(user_data);
154 PP_RunCompletionCallback(&callback_info->user_callback, result); 105 PP_RunCompletionCallback(&callback_info->user_callback, result);
155 ReportCallbackInvocationToJS(callback_info->callback_name.c_str()); 106 ReportCallbackInvocationToJS(callback_info->callback_name.c_str());
156 delete callback_info; 107 delete callback_info;
157 } 108 }
158 109
159 } // namespace 110 } // namespace
160 111
161 PP_CompletionCallback MakeTestableCompletionCallback( 112 PP_CompletionCallback MakeTestableCompletionCallback(
162 const char* callback_name, // Tested for by JS harness. 113 const char* callback_name, // Tested for by JS harness.
163 PP_CompletionCallback_Func func, 114 PP_CompletionCallback_Func func,
164 void* user_data) { 115 void* user_data) {
165 CHECK(callback_name != NULL && strlen(callback_name) > 0); 116 CHECK(callback_name != NULL && strlen(callback_name) > 0);
166 CHECK(func != NULL); 117 CHECK(func != NULL);
167 118
168 CallbackInfo* callback_info = new(std::nothrow) CallbackInfo; 119 CallbackInfo* callback_info = new(std::nothrow) CallbackInfo;
169 CHECK(callback_info != NULL); 120 CHECK(callback_info != NULL);
170 callback_info->callback_name = callback_name; 121 callback_info->callback_name = callback_name;
171 callback_info->user_callback = PP_MakeCompletionCallback(func, user_data); 122 callback_info->user_callback = PP_MakeCompletionCallback(func, user_data);
172 123
173 return PP_MakeCompletionCallback(CallbackWrapper, callback_info); 124 return PP_MakeCompletionCallback(CallbackWrapper, callback_info);
174 } 125 }
OLDNEW
« no previous file with comments | « tests/ppapi_test_lib/test_interface.h ('k') | tests/pyauto_nacl/multiple_nexes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698