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

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

Issue 2601143002: [Extensions Bindings] Add a GetStringPropertyFromObject test method (Closed)
Patch Set: Created 3 years, 11 months 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/guid.h" 6 #include "base/guid.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 EXPECT_THAT(request_handler.GetPendingRequestIdsForTesting(), 71 EXPECT_THAT(request_handler.GetPendingRequestIdsForTesting(),
72 testing::UnorderedElementsAre(request_id)); 72 testing::UnorderedElementsAre(request_id));
73 73
74 const char kArguments[] = "['foo',1,{'prop1':'bar'}]"; 74 const char kArguments[] = "['foo',1,{'prop1':'bar'}]";
75 std::unique_ptr<base::ListValue> response_arguments = 75 std::unique_ptr<base::ListValue> response_arguments =
76 ListValueFromString(kArguments); 76 ListValueFromString(kArguments);
77 ASSERT_TRUE(response_arguments); 77 ASSERT_TRUE(response_arguments);
78 request_handler.CompleteRequest(request_id, *response_arguments); 78 request_handler.CompleteRequest(request_id, *response_arguments);
79 79
80 EXPECT_TRUE(did_run_js()); 80 EXPECT_TRUE(did_run_js());
81 std::unique_ptr<base::Value> result_value = 81 EXPECT_EQ(ReplaceSingleQuotes(kArguments),
82 GetBaseValuePropertyFromObject(context->Global(), context, "result"); 82 GetStringPropertyFromObject(context->Global(), context, "result"));
83 ASSERT_TRUE(result_value);
84 EXPECT_EQ(ReplaceSingleQuotes(kArguments), ValueToString(*result_value));
85 83
86 EXPECT_TRUE(request_handler.GetPendingRequestIdsForTesting().empty()); 84 EXPECT_TRUE(request_handler.GetPendingRequestIdsForTesting().empty());
87 } 85 }
88 86
89 // Tests that trying to run non-existent or invalided requests is a no-op. 87 // Tests that trying to run non-existent or invalided requests is a no-op.
90 TEST_F(APIRequestHandlerTest, InvalidRequestsTest) { 88 TEST_F(APIRequestHandlerTest, InvalidRequestsTest) {
91 v8::Isolate* isolate = instance_->isolate(); 89 v8::Isolate* isolate = instance_->isolate();
92 v8::HandleScope handle_scope(instance_->isolate()); 90 v8::HandleScope handle_scope(instance_->isolate());
93 v8::Local<v8::Context> context = 91 v8::Local<v8::Context> context =
94 v8::Local<v8::Context>::New(instance_->isolate(), context_); 92 v8::Local<v8::Context>::New(instance_->isolate(), context_);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 145
148 std::unique_ptr<base::ListValue> response_a = 146 std::unique_ptr<base::ListValue> response_a =
149 ListValueFromString("['response_a:']"); 147 ListValueFromString("['response_a:']");
150 ASSERT_TRUE(response_a); 148 ASSERT_TRUE(response_a);
151 149
152 request_handler.CompleteRequest(request_a, *response_a); 150 request_handler.CompleteRequest(request_a, *response_a);
153 EXPECT_TRUE(did_run_js()); 151 EXPECT_TRUE(did_run_js());
154 EXPECT_THAT(request_handler.GetPendingRequestIdsForTesting(), 152 EXPECT_THAT(request_handler.GetPendingRequestIdsForTesting(),
155 testing::UnorderedElementsAre(request_b)); 153 testing::UnorderedElementsAre(request_b));
156 154
157 std::unique_ptr<base::Value> result_a = 155 EXPECT_EQ(
158 GetBaseValuePropertyFromObject(context_a->Global(), context_a, "result"); 156 ReplaceSingleQuotes("'response_a:alpha'"),
159 ASSERT_TRUE(result_a); 157 GetStringPropertyFromObject(context_a->Global(), context_a, "result"));
160 EXPECT_EQ(ReplaceSingleQuotes("'response_a:alpha'"),
161 ValueToString(*result_a));
162 158
163 std::unique_ptr<base::ListValue> response_b = 159 std::unique_ptr<base::ListValue> response_b =
164 ListValueFromString("['response_b:']"); 160 ListValueFromString("['response_b:']");
165 ASSERT_TRUE(response_b); 161 ASSERT_TRUE(response_b);
166 162
167 request_handler.CompleteRequest(request_b, *response_b); 163 request_handler.CompleteRequest(request_b, *response_b);
168 EXPECT_TRUE(request_handler.GetPendingRequestIdsForTesting().empty()); 164 EXPECT_TRUE(request_handler.GetPendingRequestIdsForTesting().empty());
169 165
170 std::unique_ptr<base::Value> result_b = 166 EXPECT_EQ(
171 GetBaseValuePropertyFromObject(context_b->Global(), context_b, "result"); 167 ReplaceSingleQuotes("'response_b:beta'"),
172 ASSERT_TRUE(result_b); 168 GetStringPropertyFromObject(context_b->Global(), context_b, "result"));
173 EXPECT_EQ(ReplaceSingleQuotes("'response_b:beta'"), ValueToString(*result_b));
174 } 169 }
175 170
176 } // namespace extensions 171 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_event_handler_unittest.cc ('k') | extensions/renderer/native_extension_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698