| OLD | NEW | 
|    1 // Copyright 2017 The Chromium Authors. All rights reserved. |    1 // Copyright 2017 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/declarative_event.h" |    5 #include "extensions/renderer/declarative_event.h" | 
|    6  |    6  | 
|    7 #include <memory> |    7 #include <memory> | 
|    8  |    8  | 
|    9 #include "base/bind.h" |    9 #include "base/bind.h" | 
|   10 #include "base/memory/ptr_util.h" |   10 #include "base/memory/ptr_util.h" | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   44     "    'name': 'declarativeEvent'," |   44     "    'name': 'declarativeEvent'," | 
|   45     "    'options': {" |   45     "    'options': {" | 
|   46     "      'supportsRules': true," |   46     "      'supportsRules': true," | 
|   47     "      'supportsListeners': false," |   47     "      'supportsListeners': false," | 
|   48     "      'actions': ['alpha.enumRef']," |   48     "      'actions': ['alpha.enumRef']," | 
|   49     "      'conditions': ['alpha.objRef']" |   49     "      'conditions': ['alpha.objRef']" | 
|   50     "    }" |   50     "    }" | 
|   51     "  }]" |   51     "  }]" | 
|   52     "}"; |   52     "}"; | 
|   53  |   53  | 
|   54 bool AllowAllAPIs(const std::string& name) { |  | 
|   55   return true; |  | 
|   56 } |  | 
|   57  |  | 
|   58 }  // namespace |   54 }  // namespace | 
|   59  |   55  | 
|   60 class DeclarativeEventTest : public APIBindingTest { |   56 class DeclarativeEventTest : public APIBindingTest { | 
|   61  public: |   57  public: | 
|   62   DeclarativeEventTest() |   58   DeclarativeEventTest() | 
|   63       : type_refs_(APITypeReferenceMap::InitializeTypeCallback()) {} |   59       : type_refs_(APITypeReferenceMap::InitializeTypeCallback()) {} | 
|   64   ~DeclarativeEventTest() override {} |   60   ~DeclarativeEventTest() override {} | 
|   65  |   61  | 
|   66   void OnRequest(std::unique_ptr<APIRequestHandler::Request> request, |   62   void OnRequest(std::unique_ptr<APIRequestHandler::Request> request, | 
|   67                  v8::Local<v8::Context> context) { |   63                  v8::Local<v8::Context> context) { | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  192             {"events", events_schema.data()}}; |  188             {"events", events_schema.data()}}; | 
|  193   } |  189   } | 
|  194 }; |  190 }; | 
|  195  |  191  | 
|  196 // Test all methods of declarative events. |  192 // Test all methods of declarative events. | 
|  197 TEST_F(DeclarativeEventWithSchemaTest, TestAllMethods) { |  193 TEST_F(DeclarativeEventWithSchemaTest, TestAllMethods) { | 
|  198   v8::HandleScope handle_scope(isolate()); |  194   v8::HandleScope handle_scope(isolate()); | 
|  199   v8::Local<v8::Context> context = MainContext(); |  195   v8::Local<v8::Context> context = MainContext(); | 
|  200  |  196  | 
|  201   v8::Local<v8::Object> api = bindings_system()->CreateAPIInstance( |  197   v8::Local<v8::Object> api = bindings_system()->CreateAPIInstance( | 
|  202       kDeclarativeAPIName, context, base::Bind(&AllowAllAPIs), nullptr); |  198       kDeclarativeAPIName, context, nullptr); | 
|  203   ASSERT_FALSE(api.IsEmpty()); |  199   ASSERT_FALSE(api.IsEmpty()); | 
|  204  |  200  | 
|  205   v8::Local<v8::Value> declarative_event = |  201   v8::Local<v8::Value> declarative_event = | 
|  206       GetPropertyFromObject(api, context, "declarativeEvent"); |  202       GetPropertyFromObject(api, context, "declarativeEvent"); | 
|  207   ASSERT_FALSE(declarative_event.IsEmpty()); |  203   ASSERT_FALSE(declarative_event.IsEmpty()); | 
|  208   ASSERT_TRUE(declarative_event->IsObject()); |  204   ASSERT_TRUE(declarative_event->IsObject()); | 
|  209   v8::Local<v8::Value> add_rules = GetPropertyFromObject( |  205   v8::Local<v8::Value> add_rules = GetPropertyFromObject( | 
|  210       declarative_event.As<v8::Object>(), context, "addRules"); |  206       declarative_event.As<v8::Object>(), context, "addRules"); | 
|  211   ASSERT_FALSE(add_rules.IsEmpty()); |  207   ASSERT_FALSE(add_rules.IsEmpty()); | 
|  212   ASSERT_TRUE(add_rules->IsFunction()); |  208   ASSERT_TRUE(add_rules->IsFunction()); | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  253         "})"; |  249         "})"; | 
|  254     v8::Local<v8::Function> remove_rules = |  250     v8::Local<v8::Function> remove_rules = | 
|  255         FunctionFromString(context, kGetRules); |  251         FunctionFromString(context, kGetRules); | 
|  256     RunFunctionOnGlobal(remove_rules, context, arraysize(args), args); |  252     RunFunctionOnGlobal(remove_rules, context, arraysize(args), args); | 
|  257     ValidateLastRequest("events.getRules", "['alpha.declarativeEvent',0,null]"); |  253     ValidateLastRequest("events.getRules", "['alpha.declarativeEvent',0,null]"); | 
|  258     reset_last_request(); |  254     reset_last_request(); | 
|  259   } |  255   } | 
|  260 } |  256 } | 
|  261  |  257  | 
|  262 }  // namespace extensions |  258 }  // namespace extensions | 
| OLD | NEW |