OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "extensions/renderer/native_extension_bindings_system.h" | 5 #include "extensions/renderer/native_extension_bindings_system.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "components/crx_file/id_util.h" | 10 #include "components/crx_file/id_util.h" |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 | 646 |
647 // Respond and validate. | 647 // Respond and validate. |
648 bindings_system()->HandleResponse(last_params().request_id, true, | 648 bindings_system()->HandleResponse(last_params().request_id, true, |
649 base::ListValue(), "Some API Error"); | 649 base::ListValue(), "Some API Error"); |
650 | 650 |
651 EXPECT_EQ("\"Some API Error\"", | 651 EXPECT_EQ("\"Some API Error\"", |
652 GetStringPropertyFromObject(context->Global(), context, | 652 GetStringPropertyFromObject(context->Global(), context, |
653 "lastErrorMessage")); | 653 "lastErrorMessage")); |
654 } | 654 } |
655 | 655 |
| 656 TEST_F(NativeExtensionBindingsSystemUnittest, TestCustomProperties) { |
| 657 scoped_refptr<Extension> extension = |
| 658 CreateExtension("storage extension", ItemType::EXTENSION, {"storage"}); |
| 659 RegisterExtension(extension->id()); |
| 660 |
| 661 v8::HandleScope handle_scope(isolate()); |
| 662 v8::Local<v8::Context> context = ContextLocal(); |
| 663 |
| 664 ScriptContext* script_context = CreateScriptContext( |
| 665 context, extension.get(), Feature::BLESSED_EXTENSION_CONTEXT); |
| 666 script_context->set_url(extension->url()); |
| 667 |
| 668 bindings_system()->UpdateBindingsForContext(script_context); |
| 669 |
| 670 v8::Local<v8::Value> storage = |
| 671 V8ValueFromScriptSource(context, "chrome.storage"); |
| 672 ASSERT_FALSE(storage.IsEmpty()); |
| 673 ASSERT_TRUE(storage->IsObject()); |
| 674 |
| 675 v8::Local<v8::Value> local = |
| 676 GetPropertyFromObject(storage.As<v8::Object>(), context, "local"); |
| 677 ASSERT_FALSE(local.IsEmpty()); |
| 678 ASSERT_TRUE(local->IsObject()); |
| 679 |
| 680 v8::Local<v8::Object> local_object = local.As<v8::Object>(); |
| 681 const std::vector<std::string> kKeys = {"get", "set", "remove", "clear", |
| 682 "getBytesInUse"}; |
| 683 for (const auto& key : kKeys) { |
| 684 v8::Local<v8::String> v8_key = gin::StringToV8(isolate(), key); |
| 685 EXPECT_TRUE(local_object->HasOwnProperty(context, v8_key).FromJust()) |
| 686 << key; |
| 687 } |
| 688 } |
| 689 |
656 } // namespace extensions | 690 } // namespace extensions |
OLD | NEW |