| 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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 "});"; | 593 "});"; |
| 594 v8::Local<v8::Function> add_listener = | 594 v8::Local<v8::Function> add_listener = |
| 595 FunctionFromString(context, kAddListener); | 595 FunctionFromString(context, kAddListener); |
| 596 EXPECT_CALL(*event_change_handler(), | 596 EXPECT_CALL(*event_change_handler(), |
| 597 OnChange(binding::EventListenersChanged::HAS_LISTENERS, | 597 OnChange(binding::EventListenersChanged::HAS_LISTENERS, |
| 598 script_context, kEventName, nullptr, true)) | 598 script_context, kEventName, nullptr, true)) |
| 599 .Times(1); | 599 .Times(1); |
| 600 v8::Local<v8::Value> argv[] = {listener}; | 600 v8::Local<v8::Value> argv[] = {listener}; |
| 601 RunFunction(add_listener, context, arraysize(argv), argv); | 601 RunFunction(add_listener, context, arraysize(argv), argv); |
| 602 ::testing::Mock::VerifyAndClearExpectations(event_change_handler()); | 602 ::testing::Mock::VerifyAndClearExpectations(event_change_handler()); |
| 603 EXPECT_TRUE(bindings_system()->HasEventListenerInContext( |
| 604 "idle.onStateChanged", script_context)); |
| 603 | 605 |
| 604 // Remove the event listener. We should be notified again. | 606 // Remove the event listener. We should be notified again. |
| 605 const char kRemoveListener[] = | 607 const char kRemoveListener[] = |
| 606 "(function(listener) {\n" | 608 "(function(listener) {\n" |
| 607 " chrome.idle.onStateChanged.removeListener(listener);\n" | 609 " chrome.idle.onStateChanged.removeListener(listener);\n" |
| 608 "});"; | 610 "});"; |
| 609 EXPECT_CALL(*event_change_handler(), | 611 EXPECT_CALL(*event_change_handler(), |
| 610 OnChange(binding::EventListenersChanged::NO_LISTENERS, | 612 OnChange(binding::EventListenersChanged::NO_LISTENERS, |
| 611 script_context, kEventName, nullptr, true)) | 613 script_context, kEventName, nullptr, true)) |
| 612 .Times(1); | 614 .Times(1); |
| 613 v8::Local<v8::Function> remove_listener = | 615 v8::Local<v8::Function> remove_listener = |
| 614 FunctionFromString(context, kRemoveListener); | 616 FunctionFromString(context, kRemoveListener); |
| 615 RunFunction(remove_listener, context, arraysize(argv), argv); | 617 RunFunction(remove_listener, context, arraysize(argv), argv); |
| 616 ::testing::Mock::VerifyAndClearExpectations(event_change_handler()); | 618 ::testing::Mock::VerifyAndClearExpectations(event_change_handler()); |
| 619 EXPECT_FALSE(bindings_system()->HasEventListenerInContext( |
| 620 "idle.onStateChanged", script_context)); |
| 617 } | 621 } |
| 618 | 622 |
| 619 TEST_F(NativeExtensionBindingsSystemUnittest, | 623 TEST_F(NativeExtensionBindingsSystemUnittest, |
| 620 TestPrefixedApiEventsAndAppBinding) { | 624 TestPrefixedApiEventsAndAppBinding) { |
| 621 InitEventChangeHandler(); | 625 InitEventChangeHandler(); |
| 622 scoped_refptr<Extension> app = CreateExtension("foo", ItemType::PLATFORM_APP, | 626 scoped_refptr<Extension> app = CreateExtension("foo", ItemType::PLATFORM_APP, |
| 623 std::vector<std::string>()); | 627 std::vector<std::string>()); |
| 624 EXPECT_TRUE(app->is_platform_app()); | 628 EXPECT_TRUE(app->is_platform_app()); |
| 625 RegisterExtension(app->id()); | 629 RegisterExtension(app->id()); |
| 626 | 630 |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 v8::Local<v8::Boolean> fake_chrome = v8::Boolean::New(isolate(), true); | 923 v8::Local<v8::Boolean> fake_chrome = v8::Boolean::New(isolate(), true); |
| 920 context_b->Global() | 924 context_b->Global() |
| 921 ->Set(context_b, gin::StringToSymbol(isolate(), "chrome"), fake_chrome) | 925 ->Set(context_b, gin::StringToSymbol(isolate(), "chrome"), fake_chrome) |
| 922 .ToChecked(); | 926 .ToChecked(); |
| 923 } | 927 } |
| 924 // A non-object chrome shouldn't be used. | 928 // A non-object chrome shouldn't be used. |
| 925 check_runtime(false); | 929 check_runtime(false); |
| 926 } | 930 } |
| 927 | 931 |
| 928 } // namespace extensions | 932 } // namespace extensions |
| OLD | NEW |