| 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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 v8::Local<v8::Function> add_listeners = | 1047 v8::Local<v8::Function> add_listeners = |
| 1044 FunctionFromString(context, kAddListeners); | 1048 FunctionFromString(context, kAddListeners); |
| 1045 RunFunctionOnGlobal(add_listeners, context, 0, nullptr); | 1049 RunFunctionOnGlobal(add_listeners, context, 0, nullptr); |
| 1046 | 1050 |
| 1047 // We should have no notifications for event listeners added (since the | 1051 // We should have no notifications for event listeners added (since the |
| 1048 // mock is a strict mock, this will fail if anything was called). | 1052 // mock is a strict mock, this will fail if anything was called). |
| 1049 ::testing::Mock::VerifyAndClearExpectations(event_change_handler()); | 1053 ::testing::Mock::VerifyAndClearExpectations(event_change_handler()); |
| 1050 } | 1054 } |
| 1051 | 1055 |
| 1052 } // namespace extensions | 1056 } // namespace extensions |
| OLD | NEW |