Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: extensions/renderer/native_extension_bindings_system_unittest.cc

Issue 2512233002: [Extensions Bindings] Add ExtensionBindingsSystem interface; hook it up (Closed)
Patch Set: lazyboys Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/crx_file/id_util.h" 9 #include "components/crx_file/id_util.h"
10 #include "extensions/common/extension.h" 10 #include "extensions/common/extension.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 scoped_refptr<Extension> extension = CreateExtension("foo", {"idle"}); 113 scoped_refptr<Extension> extension = CreateExtension("foo", {"idle"});
114 RegisterExtension(extension->id()); 114 RegisterExtension(extension->id());
115 115
116 v8::HandleScope handle_scope(isolate()); 116 v8::HandleScope handle_scope(isolate());
117 v8::Local<v8::Context> context = ContextLocal(); 117 v8::Local<v8::Context> context = ContextLocal();
118 118
119 ScriptContext* script_context = CreateScriptContext( 119 ScriptContext* script_context = CreateScriptContext(
120 context, extension.get(), Feature::BLESSED_EXTENSION_CONTEXT); 120 context, extension.get(), Feature::BLESSED_EXTENSION_CONTEXT);
121 script_context->set_url(extension->url()); 121 script_context->set_url(extension->url());
122 122
123 bindings_system()->CreateAPIsInContext(script_context); 123 bindings_system()->UpdateBindingsForContext(script_context);
124 124
125 // chrome.idle.queryState should exist. 125 // chrome.idle.queryState should exist.
126 v8::Local<v8::Value> chrome = 126 v8::Local<v8::Value> chrome =
127 GetPropertyFromObject(context->Global(), context, "chrome"); 127 GetPropertyFromObject(context->Global(), context, "chrome");
128 ASSERT_FALSE(chrome.IsEmpty()); 128 ASSERT_FALSE(chrome.IsEmpty());
129 ASSERT_TRUE(chrome->IsObject()); 129 ASSERT_TRUE(chrome->IsObject());
130 130
131 v8::Local<v8::Value> idle = GetPropertyFromObject( 131 v8::Local<v8::Value> idle = GetPropertyFromObject(
132 v8::Local<v8::Object>::Cast(chrome), context, "idle"); 132 v8::Local<v8::Object>::Cast(chrome), context, "idle");
133 ASSERT_FALSE(idle.IsEmpty()); 133 ASSERT_FALSE(idle.IsEmpty());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // Validate the params that would be sent to the browser. 170 // Validate the params that would be sent to the browser.
171 EXPECT_EQ(extension->id(), last_params().extension_id); 171 EXPECT_EQ(extension->id(), last_params().extension_id);
172 EXPECT_EQ("idle.queryState", last_params().name); 172 EXPECT_EQ("idle.queryState", last_params().name);
173 EXPECT_EQ(extension->url(), last_params().source_url); 173 EXPECT_EQ(extension->url(), last_params().source_url);
174 EXPECT_EQ(-1, last_params().source_tab_id); 174 EXPECT_EQ(-1, last_params().source_tab_id);
175 EXPECT_TRUE(last_params().has_callback); 175 EXPECT_TRUE(last_params().has_callback);
176 EXPECT_TRUE( 176 EXPECT_TRUE(
177 last_params().arguments.Equals(ListValueFromString("[30]").get())); 177 last_params().arguments.Equals(ListValueFromString("[30]").get()));
178 178
179 // Respond and validate. 179 // Respond and validate.
180 bindings_system()->OnResponse(last_params().request_id, true, 180 bindings_system()->HandleResponse(last_params().request_id, true,
181 *ListValueFromString("['active']"), 181 *ListValueFromString("['active']"),
182 std::string()); 182 std::string());
183 183
184 std::unique_ptr<base::Value> result_value = GetBaseValuePropertyFromObject( 184 std::unique_ptr<base::Value> result_value = GetBaseValuePropertyFromObject(
185 context->Global(), context, "responseState"); 185 context->Global(), context, "responseState");
186 ASSERT_TRUE(result_value); 186 ASSERT_TRUE(result_value);
187 EXPECT_EQ("\"active\"", ValueToString(*result_value)); 187 EXPECT_EQ("\"active\"", ValueToString(*result_value));
188 } 188 }
189 189
190 } // namespace extensions 190 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/native_extension_bindings_system.cc ('k') | extensions/renderer/service_worker_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698