OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <list> | 5 #include <list> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 ASSERT_EQ(kOk, status.code()); | 178 ASSERT_EQ(kOk, status.code()); |
179 ASSERT_TRUE(result && result->IsType(base::Value::TYPE_NULL)); | 179 ASSERT_TRUE(result && result->IsType(base::Value::TYPE_NULL)); |
180 } | 180 } |
181 | 181 |
182 TEST(EvaluateScriptAndGetValue, Ok) { | 182 TEST(EvaluateScriptAndGetValue, Ok) { |
183 scoped_ptr<base::Value> result; | 183 scoped_ptr<base::Value> result; |
184 FakeDevToolsClient client; | 184 FakeDevToolsClient client; |
185 base::DictionaryValue dict; | 185 base::DictionaryValue dict; |
186 dict.SetBoolean("wasThrown", false); | 186 dict.SetBoolean("wasThrown", false); |
187 dict.SetString("result.type", "integer"); | 187 dict.SetString("result.type", "integer"); |
188 dict.SetInteger("result.value.status", 0); | 188 dict.SetInteger("result.value", 1); |
189 dict.SetInteger("result.value.value", 1); | |
190 client.set_result(dict); | 189 client.set_result(dict); |
191 Status status = internal::EvaluateScriptAndGetValue( | 190 Status status = internal::EvaluateScriptAndGetValue( |
192 &client, 0, "", &result); | 191 &client, 0, "", &result); |
193 ASSERT_EQ(kOk, status.code()); | 192 ASSERT_EQ(kOk, status.code()); |
194 int value; | 193 int value; |
195 ASSERT_TRUE(result && result->GetAsInteger(&value)); | 194 ASSERT_TRUE(result && result->GetAsInteger(&value)); |
196 ASSERT_EQ(1, value); | 195 ASSERT_EQ(1, value); |
197 } | 196 } |
198 | 197 |
199 TEST(EvaluateScriptAndGetValue, ScriptError) { | |
200 scoped_ptr<base::Value> result; | |
201 FakeDevToolsClient client; | |
202 base::DictionaryValue dict; | |
203 dict.SetBoolean("wasThrown", false); | |
204 dict.SetString("result.type", "integer"); | |
205 dict.SetInteger("result.value.status", 1); | |
206 dict.SetInteger("result.value.value", 1); | |
207 client.set_result(dict); | |
208 Status status = internal::EvaluateScriptAndGetValue( | |
209 &client, 0, "", &result); | |
210 ASSERT_EQ(1, status.code()); | |
211 ASSERT_FALSE(result); | |
212 } | |
213 | |
214 TEST(EvaluateScriptAndGetObject, NoObject) { | 198 TEST(EvaluateScriptAndGetObject, NoObject) { |
215 FakeDevToolsClient client; | 199 FakeDevToolsClient client; |
216 base::DictionaryValue dict; | 200 base::DictionaryValue dict; |
217 dict.SetBoolean("wasThrown", false); | 201 dict.SetBoolean("wasThrown", false); |
218 dict.SetString("result.type", "integer"); | 202 dict.SetString("result.type", "integer"); |
219 client.set_result(dict); | 203 client.set_result(dict); |
220 std::string object_id; | 204 std::string object_id; |
221 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( | 205 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( |
222 &client, 0, "", &object_id).IsError()); | 206 &client, 0, "", &object_id).IsError()); |
223 ASSERT_TRUE(object_id.empty()); | 207 ASSERT_TRUE(object_id.empty()); |
224 } | 208 } |
225 | 209 |
226 TEST(EvaluateScriptAndGetObject, Ok) { | 210 TEST(EvaluateScriptAndGetObject, Ok) { |
227 FakeDevToolsClient client; | 211 FakeDevToolsClient client; |
228 base::DictionaryValue dict; | 212 base::DictionaryValue dict; |
229 dict.SetBoolean("wasThrown", false); | 213 dict.SetBoolean("wasThrown", false); |
230 dict.SetString("result.objectId", "id"); | 214 dict.SetString("result.objectId", "id"); |
231 client.set_result(dict); | 215 client.set_result(dict); |
232 std::string object_id; | 216 std::string object_id; |
233 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( | 217 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( |
234 &client, 0, "", &object_id).IsOk()); | 218 &client, 0, "", &object_id).IsOk()); |
235 ASSERT_STREQ("id", object_id.c_str()); | 219 ASSERT_STREQ("id", object_id.c_str()); |
236 } | 220 } |
| 221 |
| 222 TEST(ParseCallFunctionResult, NotDict) { |
| 223 scoped_ptr<base::Value> result; |
| 224 base::FundamentalValue value(1); |
| 225 ASSERT_NE(kOk, internal::ParseCallFunctionResult(value, &result).code()); |
| 226 } |
| 227 |
| 228 TEST(ParseCallFunctionResult, Ok) { |
| 229 scoped_ptr<base::Value> result; |
| 230 base::DictionaryValue dict; |
| 231 dict.SetInteger("status", 0); |
| 232 dict.SetInteger("value", 1); |
| 233 Status status = internal::ParseCallFunctionResult(dict, &result); |
| 234 ASSERT_EQ(kOk, status.code()); |
| 235 int value; |
| 236 ASSERT_TRUE(result && result->GetAsInteger(&value)); |
| 237 ASSERT_EQ(1, value); |
| 238 } |
| 239 |
| 240 TEST(ParseCallFunctionResult, ScriptError) { |
| 241 scoped_ptr<base::Value> result; |
| 242 base::DictionaryValue dict; |
| 243 dict.SetInteger("status", 1); |
| 244 dict.SetInteger("value", 1); |
| 245 Status status = internal::ParseCallFunctionResult(dict, &result); |
| 246 ASSERT_EQ(1, status.code()); |
| 247 ASSERT_FALSE(result); |
| 248 } |
OLD | NEW |