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