| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_var_deprecated.h" | 5 #include "ppapi/tests/test_var_deprecated.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 return "Expected 0 on string conversion from Double var."; | 287 return "Expected 0 on string conversion from Double var."; |
| 288 } | 288 } |
| 289 if (result != NULL) { | 289 if (result != NULL) { |
| 290 return "Expected NULL on string conversion from Double var."; | 290 return "Expected NULL on string conversion from Double var."; |
| 291 } | 291 } |
| 292 | 292 |
| 293 PASS(); | 293 PASS(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 std::string TestVarDeprecated::TestHasPropertyAndMethod() { | 296 std::string TestVarDeprecated::TestHasPropertyAndMethod() { |
| 297 uint32_t before_objects = testing_interface_->GetLiveObjectsForInstance( | 297 pp::VarPrivate window = instance_->GetWindowObject(); |
| 298 instance_->pp_instance()); | 298 ASSERT_TRUE(window.is_object()); |
| 299 { | |
| 300 pp::VarPrivate window = instance_->GetWindowObject(); | |
| 301 ASSERT_TRUE(window.is_object()); | |
| 302 | 299 |
| 303 // Regular property. | 300 // Regular property. |
| 304 pp::Var exception; | 301 pp::Var exception; |
| 305 ASSERT_TRUE(window.HasProperty("scrollX", &exception)); | 302 ASSERT_TRUE(window.HasProperty("scrollX", &exception)); |
| 306 ASSERT_TRUE(exception.is_undefined()); | 303 ASSERT_TRUE(exception.is_undefined()); |
| 307 ASSERT_FALSE(window.HasMethod("scrollX", &exception)); | 304 ASSERT_FALSE(window.HasMethod("scrollX", &exception)); |
| 308 ASSERT_TRUE(exception.is_undefined()); | 305 ASSERT_TRUE(exception.is_undefined()); |
| 309 | 306 |
| 310 // Regular method (also counts as HasProperty). | 307 // Regular method (also counts as HasProperty). |
| 311 ASSERT_TRUE(window.HasProperty("find", &exception)); | 308 ASSERT_TRUE(window.HasProperty("find", &exception)); |
| 312 ASSERT_TRUE(exception.is_undefined()); | 309 ASSERT_TRUE(exception.is_undefined()); |
| 313 ASSERT_TRUE(window.HasMethod("find", &exception)); | 310 ASSERT_TRUE(window.HasMethod("find", &exception)); |
| 314 ASSERT_TRUE(exception.is_undefined()); | 311 ASSERT_TRUE(exception.is_undefined()); |
| 315 | 312 |
| 316 // Nonexistant ones should return false and not set the exception. | 313 // Nonexistant ones should return false and not set the exception. |
| 317 ASSERT_FALSE(window.HasProperty("superEvilBit", &exception)); | 314 ASSERT_FALSE(window.HasProperty("superEvilBit", &exception)); |
| 318 ASSERT_TRUE(exception.is_undefined()); | 315 ASSERT_TRUE(exception.is_undefined()); |
| 319 ASSERT_FALSE(window.HasMethod("superEvilBit", &exception)); | 316 ASSERT_FALSE(window.HasMethod("superEvilBit", &exception)); |
| 320 ASSERT_TRUE(exception.is_undefined()); | 317 ASSERT_TRUE(exception.is_undefined()); |
| 321 | 318 |
| 322 // Check exception and return false on invalid property name. | 319 // Check exception and return false on invalid property name. |
| 323 ASSERT_FALSE(window.HasProperty(3.14159, &exception)); | 320 ASSERT_FALSE(window.HasProperty(3.14159, &exception)); |
| 324 ASSERT_FALSE(exception.is_undefined()); | 321 ASSERT_FALSE(exception.is_undefined()); |
| 325 exception = pp::Var(); | 322 exception = pp::Var(); |
| 326 | 323 |
| 327 exception = pp::Var(); | 324 exception = pp::Var(); |
| 328 ASSERT_FALSE(window.HasMethod(3.14159, &exception)); | 325 ASSERT_FALSE(window.HasMethod(3.14159, &exception)); |
| 329 ASSERT_FALSE(exception.is_undefined()); | 326 ASSERT_FALSE(exception.is_undefined()); |
| 330 | 327 |
| 331 // Try to use something not an object. | 328 // Try to use something not an object. |
| 332 exception = pp::Var(); | 329 exception = pp::Var(); |
| 333 pp::VarPrivate string_object("asdf"); | 330 pp::VarPrivate string_object("asdf"); |
| 334 ASSERT_FALSE(string_object.HasProperty("find", &exception)); | 331 ASSERT_FALSE(string_object.HasProperty("find", &exception)); |
| 335 ASSERT_FALSE(exception.is_undefined()); | 332 ASSERT_FALSE(exception.is_undefined()); |
| 336 exception = pp::Var(); | 333 exception = pp::Var(); |
| 337 ASSERT_FALSE(string_object.HasMethod("find", &exception)); | 334 ASSERT_FALSE(string_object.HasMethod("find", &exception)); |
| 338 ASSERT_FALSE(exception.is_undefined()); | 335 ASSERT_FALSE(exception.is_undefined()); |
| 339 | 336 |
| 340 // Try to use an invalid object (need to use the C API). | 337 // Try to use an invalid object (need to use the C API). |
| 341 PP_Var invalid_object; | 338 PP_Var invalid_object; |
| 342 invalid_object.type = PP_VARTYPE_OBJECT; | 339 invalid_object.type = PP_VARTYPE_OBJECT; |
| 343 invalid_object.value.as_id = static_cast<int64_t>(-1234567); | 340 invalid_object.value.as_id = static_cast<int64_t>(-1234567); |
| 344 PP_Var exception2 = PP_MakeUndefined(); | 341 PP_Var exception2 = PP_MakeUndefined(); |
| 345 ASSERT_FALSE(var_interface_->HasProperty(invalid_object, | 342 ASSERT_FALSE(var_interface_->HasProperty(invalid_object, |
| 346 pp::Var("find").pp_var(), | |
| 347 &exception2)); | |
| 348 ASSERT_NE(PP_VARTYPE_UNDEFINED, exception2.type); | |
| 349 var_interface_->Release(exception2); | |
| 350 | |
| 351 exception2 = PP_MakeUndefined(); | |
| 352 ASSERT_FALSE(var_interface_->HasMethod(invalid_object, | |
| 353 pp::Var("find").pp_var(), | 343 pp::Var("find").pp_var(), |
| 354 &exception2)); | 344 &exception2)); |
| 355 ASSERT_NE(PP_VARTYPE_UNDEFINED, exception2.type); | 345 ASSERT_NE(PP_VARTYPE_UNDEFINED, exception2.type); |
| 356 var_interface_->Release(exception2); | 346 var_interface_->Release(exception2); |
| 357 | 347 |
| 358 // Get a valid property/method when the exception is set returns false. | 348 exception2 = PP_MakeUndefined(); |
| 359 exception = pp::Var("Bad something-or-other exception"); | 349 ASSERT_FALSE(var_interface_->HasMethod(invalid_object, |
| 360 ASSERT_FALSE(window.HasProperty("find", &exception)); | 350 pp::Var("find").pp_var(), |
| 361 ASSERT_FALSE(exception.is_undefined()); | 351 &exception2)); |
| 362 ASSERT_FALSE(window.HasMethod("find", &exception)); | 352 ASSERT_NE(PP_VARTYPE_UNDEFINED, exception2.type); |
| 363 ASSERT_FALSE(exception.is_undefined()); | 353 var_interface_->Release(exception2); |
| 364 } | |
| 365 | 354 |
| 366 // Make sure nothing leaked. | 355 // Getting a valid property/method when the exception is set returns false. |
| 367 ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance( | 356 exception = pp::Var("Bad something-or-other exception"); |
| 368 instance_->pp_instance()) == before_objects); | 357 ASSERT_FALSE(window.HasProperty("find", &exception)); |
| 358 ASSERT_FALSE(exception.is_undefined()); |
| 359 ASSERT_FALSE(window.HasMethod("find", &exception)); |
| 360 ASSERT_FALSE(exception.is_undefined()); |
| 369 | 361 |
| 370 PASS(); | 362 PASS(); |
| 371 } | 363 } |
| 372 | 364 |
| 373 // Tests that when the page sends an object to the plugin via a function call, | 365 // Tests that when the page sends an object to the plugin via a function call, |
| 374 // that the refcounting works properly (bug 79813). | 366 // that the refcounting works properly (bug 79813). |
| 375 std::string TestVarDeprecated::TestPassReference() { | 367 std::string TestVarDeprecated::TestPassReference() { |
| 376 var_from_page_ = pp::Var(); | 368 var_from_page_ = pp::Var(); |
| 377 | 369 |
| 378 // Send a JS object from the page to the plugin. | 370 // Send a JS object from the page to the plugin. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 391 // this by executing it (it was a function we defined above) and it should | 383 // this by executing it (it was a function we defined above) and it should |
| 392 // return "works" concatenated with the argument. | 384 // return "works" concatenated with the argument. |
| 393 pp::VarPrivate function(var_from_page_); | 385 pp::VarPrivate function(var_from_page_); |
| 394 pp::Var result = var_from_page_.Call(pp::Var(), "nice"); | 386 pp::Var result = var_from_page_.Call(pp::Var(), "nice"); |
| 395 ASSERT_TRUE(result.is_string()); | 387 ASSERT_TRUE(result.is_string()); |
| 396 ASSERT_TRUE(result.AsString() == "worksnice"); | 388 ASSERT_TRUE(result.AsString() == "worksnice"); |
| 397 | 389 |
| 398 PASS(); | 390 PASS(); |
| 399 } | 391 } |
| 400 | 392 |
| OLD | NEW |