OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include "native_client/tests/fake_browser_ppapi/test_scriptable.h" | 7 #include "native_client/tests/fake_browser_ppapi/test_scriptable.h" |
8 | 8 |
9 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 // Some canonical constants used to initialize properties of various types. | 28 // Some canonical constants used to initialize properties of various types. |
29 const bool kBoolValue = true; | 29 const bool kBoolValue = true; |
30 const int32_t kInt32Value = 144000; | 30 const int32_t kInt32Value = 144000; |
31 const double kDoubleValue = 3.1415; | 31 const double kDoubleValue = 3.1415; |
32 const char kStringValue[] = "hello, world"; | 32 const char kStringValue[] = "hello, world"; |
33 | 33 |
34 // Some global state. | 34 // Some global state. |
35 const PPB_Var* g_var_interface; | 35 const PPB_Var* g_var_interface; |
36 const PPB_Instance* g_instance_interface; | 36 const PPB_Instance* g_instance_interface; |
37 PP_Instance g_instance_id; | 37 PP_Instance g_instance_id; |
| 38 PP_Instance g_browser_module_id; |
38 int64_t g_object_as_id; | 39 int64_t g_object_as_id; |
39 | 40 |
40 // TODO(sehr,polina): add this to the ppapi/c/ppb_var.h? | 41 // TODO(sehr,polina): add this to the ppapi/c/ppb_var.h? |
41 PP_Var MakeString(const char* str) { | 42 PP_Var MakeString(const char* str) { |
42 return g_var_interface->VarFromUtf8(str, static_cast<uint32_t>(strlen(str))); | 43 return g_var_interface->VarFromUtf8(g_browser_module_id, |
| 44 str, |
| 45 static_cast<uint32_t>(strlen(str))); |
43 } | 46 } |
44 | 47 |
45 // PP_Var of string type that names a property of the specified type. | 48 // PP_Var of string type that names a property of the specified type. |
46 PP_Var PropertyName(PP_VarType type) { | 49 PP_Var PropertyName(PP_VarType type) { |
47 switch (type) { | 50 switch (type) { |
48 case PP_VARTYPE_VOID: | 51 case PP_VARTYPE_VOID: |
49 return MakeString("identVoid"); | 52 return MakeString("identVoid"); |
50 case PP_VARTYPE_NULL: | 53 case PP_VARTYPE_NULL: |
51 return MakeString("identNull"); | 54 return MakeString("identNull"); |
52 case PP_VARTYPE_BOOL: | 55 case PP_VARTYPE_BOOL: |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 // attributes. For each PP_VARTYPE variant, | 344 // attributes. For each PP_VARTYPE variant, |
342 // 1) There is a property, of PP_VARTYPE_<TYPE>, named "ident<Type>". | 345 // 1) There is a property, of PP_VARTYPE_<TYPE>, named "ident<Type>". |
343 // 2) SetProperty("ident<Type>", value) only succeeds when value.type == type. | 346 // 2) SetProperty("ident<Type>", value) only succeeds when value.type == type. |
344 // 3) GetProperty("ident<Type>") only succeeds when value.type == type, | 347 // 3) GetProperty("ident<Type>") only succeeds when value.type == type, |
345 // and returns the value set by the corresponding call to SetProperty. | 348 // and returns the value set by the corresponding call to SetProperty. |
346 // 4) Call("ident<Type>", { arg1, arg2 }) only succeeds when arg1.type == type, | 349 // 4) Call("ident<Type>", { arg1, arg2 }) only succeeds when arg1.type == type, |
347 // arg2.type == type. It returns arg1.type. | 350 // arg2.type == type. It returns arg1.type. |
348 void TestScriptableObject(PP_Var object, | 351 void TestScriptableObject(PP_Var object, |
349 const PPB_Instance* browser_instance_interface, | 352 const PPB_Instance* browser_instance_interface, |
350 const PPB_Var* var_interface, | 353 const PPB_Var* var_interface, |
351 PP_Instance instance_id) { | 354 PP_Instance instance_id, |
| 355 PP_Module browser_module_id) { |
352 // Receiver needs to be a valid scriptable object. We cannot use | 356 // Receiver needs to be a valid scriptable object. We cannot use |
353 // is_valid_value here because we haven't set g_object_as_id yet. | 357 // is_valid_value here because we haven't set g_object_as_id yet. |
354 CHECK(object.type == PP_VARTYPE_OBJECT); | 358 CHECK(object.type == PP_VARTYPE_OBJECT); |
355 // Save g_object_as_id for future object value validity checks. | 359 // Save g_object_as_id for future object value validity checks. |
356 g_object_as_id = object.value.as_id; | 360 g_object_as_id = object.value.as_id; |
357 // Initialize the global state. | 361 // Initialize the global state. |
358 g_var_interface = var_interface; | 362 g_var_interface = var_interface; |
359 g_instance_interface = browser_instance_interface; | 363 g_instance_interface = browser_instance_interface; |
360 g_instance_id = instance_id; | 364 g_instance_id = instance_id; |
| 365 g_browser_module_id = browser_module_id; |
361 // And test the scriptable object interfaces one-by-one. | 366 // And test the scriptable object interfaces one-by-one. |
362 TestHasProperty(object); | 367 TestHasProperty(object); |
363 TestSetProperty(object); | 368 TestSetProperty(object); |
364 TestGetProperty(object); | 369 TestGetProperty(object); |
365 TestCall(object); | 370 TestCall(object); |
366 TestWindowScripting(object); | 371 TestWindowScripting(object); |
367 // TODO(sehr,polina): add other methods such as RemoveProperty. | 372 // TODO(sehr,polina): add other methods such as RemoveProperty. |
368 } | 373 } |
OLD | NEW |