| 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/api_bindings_system.h" | 5 #include "extensions/renderer/api_bindings_system.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // The base class to test the APIBindingsSystem. This allows subclasses to | 88 // The base class to test the APIBindingsSystem. This allows subclasses to |
| 89 // retrieve API schemas differently. | 89 // retrieve API schemas differently. |
| 90 class APIBindingsSystemTestBase : public APIBindingTest { | 90 class APIBindingsSystemTestBase : public APIBindingTest { |
| 91 public: | 91 public: |
| 92 // Returns the DictionaryValue representing the schema with the given API | 92 // Returns the DictionaryValue representing the schema with the given API |
| 93 // name. | 93 // name. |
| 94 virtual const base::DictionaryValue& GetAPISchema( | 94 virtual const base::DictionaryValue& GetAPISchema( |
| 95 const std::string& api_name) = 0; | 95 const std::string& api_name) = 0; |
| 96 | 96 |
| 97 // Stores the request in |last_request_|. | 97 // Stores the request in |last_request_|. |
| 98 void OnAPIRequest(std::unique_ptr<APIBinding::Request> request, | 98 void OnAPIRequest(std::unique_ptr<APIRequestHandler::Request> request, |
| 99 v8::Local<v8::Context> context) { | 99 v8::Local<v8::Context> context) { |
| 100 ASSERT_FALSE(last_request_); | 100 ASSERT_FALSE(last_request_); |
| 101 last_request_ = std::move(request); | 101 last_request_ = std::move(request); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void OnEventListenersChanged(const std::string& event_name, | 104 void OnEventListenersChanged(const std::string& event_name, |
| 105 binding::EventListenersChanged changed, | 105 binding::EventListenersChanged changed, |
| 106 v8::Local<v8::Context> context) {} | 106 v8::Local<v8::Context> context) {} |
| 107 | 107 |
| 108 protected: | 108 protected: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 124 void TearDown() override { | 124 void TearDown() override { |
| 125 bindings_system_.reset(); | 125 bindings_system_.reset(); |
| 126 APIBindingTest::TearDown(); | 126 APIBindingTest::TearDown(); |
| 127 } | 127 } |
| 128 | 128 |
| 129 // Checks that |last_request_| exists and was provided with the | 129 // Checks that |last_request_| exists and was provided with the |
| 130 // |expected_name| and |expected_arguments|. | 130 // |expected_name| and |expected_arguments|. |
| 131 void ValidateLastRequest(const std::string& expected_name, | 131 void ValidateLastRequest(const std::string& expected_name, |
| 132 const std::string& expected_arguments); | 132 const std::string& expected_arguments); |
| 133 | 133 |
| 134 const APIBinding::Request* last_request() const { | 134 const APIRequestHandler::Request* last_request() const { |
| 135 return last_request_.get(); | 135 return last_request_.get(); |
| 136 } | 136 } |
| 137 void reset_last_request() { last_request_.reset(); } | 137 void reset_last_request() { last_request_.reset(); } |
| 138 APIBindingsSystem* bindings_system() { return bindings_system_.get(); } | 138 APIBindingsSystem* bindings_system() { return bindings_system_.get(); } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 // The APIBindingsSystem associated with the test. Safe to use across multiple | 141 // The APIBindingsSystem associated with the test. Safe to use across multiple |
| 142 // contexts. | 142 // contexts. |
| 143 std::unique_ptr<APIBindingsSystem> bindings_system_; | 143 std::unique_ptr<APIBindingsSystem> bindings_system_; |
| 144 | 144 |
| 145 // The last request to be received from the APIBindingsSystem, or null if | 145 // The last request to be received from the APIBindingsSystem, or null if |
| 146 // there is none. | 146 // there is none. |
| 147 std::unique_ptr<APIBinding::Request> last_request_; | 147 std::unique_ptr<APIRequestHandler::Request> last_request_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystemTestBase); | 149 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystemTestBase); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 void APIBindingsSystemTestBase::ValidateLastRequest( | 152 void APIBindingsSystemTestBase::ValidateLastRequest( |
| 153 const std::string& expected_name, | 153 const std::string& expected_name, |
| 154 const std::string& expected_arguments) { | 154 const std::string& expected_arguments) { |
| 155 ASSERT_TRUE(last_request()); | 155 ASSERT_TRUE(last_request()); |
| 156 // Note that even if no arguments are provided by the API call, we should have | 156 // Note that even if no arguments are provided by the API call, we should have |
| 157 // an empty list. | 157 // an empty list. |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 context, "idleState")); | 582 context, "idleState")); |
| 583 bindings_system()->FireEventInContext("idle.onStateChanged", context, | 583 bindings_system()->FireEventInContext("idle.onStateChanged", context, |
| 584 *ListValueFromString("['active']")); | 584 *ListValueFromString("['active']")); |
| 585 | 585 |
| 586 EXPECT_EQ("\"active\"", GetStringPropertyFromObject(context->Global(), | 586 EXPECT_EQ("\"active\"", GetStringPropertyFromObject(context->Global(), |
| 587 context, "idleState")); | 587 context, "idleState")); |
| 588 } | 588 } |
| 589 } | 589 } |
| 590 | 590 |
| 591 } // namespace extensions | 591 } // namespace extensions |
| OLD | NEW |