| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 Status status_; | 55 Status status_; |
| 56 base::DictionaryValue result_; | 56 base::DictionaryValue result_; |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 void AssertEvalFails(const base::DictionaryValue& command_result) { | 59 void AssertEvalFails(const base::DictionaryValue& command_result) { |
| 60 scoped_ptr<base::DictionaryValue> result; | 60 scoped_ptr<base::DictionaryValue> result; |
| 61 FakeDevToolsClient client; | 61 FakeDevToolsClient client; |
| 62 client.set_result(command_result); | 62 client.set_result(command_result); |
| 63 Status status = internal::EvaluateScript(&client, 0, "", | 63 Status status = internal::EvaluateScript( |
| 64 internal::ReturnByValue, &result); | 64 &client, 0, std::string(), internal::ReturnByValue, &result); |
| 65 ASSERT_EQ(kUnknownError, status.code()); | 65 ASSERT_EQ(kUnknownError, status.code()); |
| 66 ASSERT_FALSE(result); | 66 ASSERT_FALSE(result); |
| 67 } | 67 } |
| 68 | 68 |
| 69 } // namespace | 69 } // namespace |
| 70 | 70 |
| 71 TEST(EvaluateScript, CommandError) { | 71 TEST(EvaluateScript, CommandError) { |
| 72 scoped_ptr<base::DictionaryValue> result; | 72 scoped_ptr<base::DictionaryValue> result; |
| 73 FakeDevToolsClient client; | 73 FakeDevToolsClient client; |
| 74 client.set_status(Status(kUnknownError)); | 74 client.set_status(Status(kUnknownError)); |
| 75 Status status = internal::EvaluateScript(&client, 0, "", | 75 Status status = internal::EvaluateScript( |
| 76 internal::ReturnByValue, &result); | 76 &client, 0, std::string(), internal::ReturnByValue, &result); |
| 77 ASSERT_EQ(kUnknownError, status.code()); | 77 ASSERT_EQ(kUnknownError, status.code()); |
| 78 ASSERT_FALSE(result); | 78 ASSERT_FALSE(result); |
| 79 } | 79 } |
| 80 | 80 |
| 81 TEST(EvaluateScript, MissingWasThrown) { | 81 TEST(EvaluateScript, MissingWasThrown) { |
| 82 base::DictionaryValue dict; | 82 base::DictionaryValue dict; |
| 83 ASSERT_NO_FATAL_FAILURE(AssertEvalFails(dict)); | 83 ASSERT_NO_FATAL_FAILURE(AssertEvalFails(dict)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 TEST(EvaluateScript, MissingResult) { | 86 TEST(EvaluateScript, MissingResult) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST(EvaluateScript, Ok) { | 99 TEST(EvaluateScript, Ok) { |
| 100 scoped_ptr<base::DictionaryValue> result; | 100 scoped_ptr<base::DictionaryValue> result; |
| 101 base::DictionaryValue dict; | 101 base::DictionaryValue dict; |
| 102 dict.SetBoolean("wasThrown", false); | 102 dict.SetBoolean("wasThrown", false); |
| 103 dict.SetInteger("result.key", 100); | 103 dict.SetInteger("result.key", 100); |
| 104 FakeDevToolsClient client; | 104 FakeDevToolsClient client; |
| 105 client.set_result(dict); | 105 client.set_result(dict); |
| 106 ASSERT_TRUE(internal::EvaluateScript( | 106 ASSERT_TRUE(internal::EvaluateScript( |
| 107 &client, 0, "", internal::ReturnByValue, &result).IsOk()); | 107 &client, 0, std::string(), internal::ReturnByValue, &result).IsOk()); |
| 108 ASSERT_TRUE(result); | 108 ASSERT_TRUE(result); |
| 109 ASSERT_TRUE(result->HasKey("key")); | 109 ASSERT_TRUE(result->HasKey("key")); |
| 110 } | 110 } |
| 111 | 111 |
| 112 TEST(EvaluateScriptAndGetValue, MissingType) { | 112 TEST(EvaluateScriptAndGetValue, MissingType) { |
| 113 scoped_ptr<base::Value> result; | 113 scoped_ptr<base::Value> result; |
| 114 FakeDevToolsClient client; | 114 FakeDevToolsClient client; |
| 115 base::DictionaryValue dict; | 115 base::DictionaryValue dict; |
| 116 dict.SetBoolean("wasThrown", false); | 116 dict.SetBoolean("wasThrown", false); |
| 117 dict.SetInteger("result.value", 1); | 117 dict.SetInteger("result.value", 1); |
| 118 client.set_result(dict); | 118 client.set_result(dict); |
| 119 ASSERT_TRUE(internal::EvaluateScriptAndGetValue( | 119 ASSERT_TRUE(internal::EvaluateScriptAndGetValue( |
| 120 &client, 0, "", &result).IsError()); | 120 &client, 0, std::string(), &result).IsError()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 TEST(EvaluateScriptAndGetValue, Undefined) { | 123 TEST(EvaluateScriptAndGetValue, Undefined) { |
| 124 scoped_ptr<base::Value> result; | 124 scoped_ptr<base::Value> result; |
| 125 FakeDevToolsClient client; | 125 FakeDevToolsClient client; |
| 126 base::DictionaryValue dict; | 126 base::DictionaryValue dict; |
| 127 dict.SetBoolean("wasThrown", false); | 127 dict.SetBoolean("wasThrown", false); |
| 128 dict.SetString("result.type", "undefined"); | 128 dict.SetString("result.type", "undefined"); |
| 129 client.set_result(dict); | 129 client.set_result(dict); |
| 130 Status status = internal::EvaluateScriptAndGetValue( | 130 Status status = |
| 131 &client, 0, "", &result); | 131 internal::EvaluateScriptAndGetValue(&client, 0, std::string(), &result); |
| 132 ASSERT_EQ(kOk, status.code()); | 132 ASSERT_EQ(kOk, status.code()); |
| 133 ASSERT_TRUE(result && result->IsType(base::Value::TYPE_NULL)); | 133 ASSERT_TRUE(result && result->IsType(base::Value::TYPE_NULL)); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST(EvaluateScriptAndGetValue, Ok) { | 136 TEST(EvaluateScriptAndGetValue, Ok) { |
| 137 scoped_ptr<base::Value> result; | 137 scoped_ptr<base::Value> result; |
| 138 FakeDevToolsClient client; | 138 FakeDevToolsClient client; |
| 139 base::DictionaryValue dict; | 139 base::DictionaryValue dict; |
| 140 dict.SetBoolean("wasThrown", false); | 140 dict.SetBoolean("wasThrown", false); |
| 141 dict.SetString("result.type", "integer"); | 141 dict.SetString("result.type", "integer"); |
| 142 dict.SetInteger("result.value", 1); | 142 dict.SetInteger("result.value", 1); |
| 143 client.set_result(dict); | 143 client.set_result(dict); |
| 144 Status status = internal::EvaluateScriptAndGetValue( | 144 Status status = |
| 145 &client, 0, "", &result); | 145 internal::EvaluateScriptAndGetValue(&client, 0, std::string(), &result); |
| 146 ASSERT_EQ(kOk, status.code()); | 146 ASSERT_EQ(kOk, status.code()); |
| 147 int value; | 147 int value; |
| 148 ASSERT_TRUE(result && result->GetAsInteger(&value)); | 148 ASSERT_TRUE(result && result->GetAsInteger(&value)); |
| 149 ASSERT_EQ(1, value); | 149 ASSERT_EQ(1, value); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST(EvaluateScriptAndGetObject, NoObject) { | 152 TEST(EvaluateScriptAndGetObject, NoObject) { |
| 153 FakeDevToolsClient client; | 153 FakeDevToolsClient client; |
| 154 base::DictionaryValue dict; | 154 base::DictionaryValue dict; |
| 155 dict.SetBoolean("wasThrown", false); | 155 dict.SetBoolean("wasThrown", false); |
| 156 dict.SetString("result.type", "integer"); | 156 dict.SetString("result.type", "integer"); |
| 157 client.set_result(dict); | 157 client.set_result(dict); |
| 158 bool got_object; | 158 bool got_object; |
| 159 std::string object_id; | 159 std::string object_id; |
| 160 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( | 160 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( |
| 161 &client, 0, "", &got_object, &object_id).IsOk()); | 161 &client, 0, std::string(), &got_object, &object_id).IsOk()); |
| 162 ASSERT_FALSE(got_object); | 162 ASSERT_FALSE(got_object); |
| 163 ASSERT_TRUE(object_id.empty()); | 163 ASSERT_TRUE(object_id.empty()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 TEST(EvaluateScriptAndGetObject, Ok) { | 166 TEST(EvaluateScriptAndGetObject, Ok) { |
| 167 FakeDevToolsClient client; | 167 FakeDevToolsClient client; |
| 168 base::DictionaryValue dict; | 168 base::DictionaryValue dict; |
| 169 dict.SetBoolean("wasThrown", false); | 169 dict.SetBoolean("wasThrown", false); |
| 170 dict.SetString("result.objectId", "id"); | 170 dict.SetString("result.objectId", "id"); |
| 171 client.set_result(dict); | 171 client.set_result(dict); |
| 172 bool got_object; | 172 bool got_object; |
| 173 std::string object_id; | 173 std::string object_id; |
| 174 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( | 174 ASSERT_TRUE(internal::EvaluateScriptAndGetObject( |
| 175 &client, 0, "", &got_object, &object_id).IsOk()); | 175 &client, 0, std::string(), &got_object, &object_id).IsOk()); |
| 176 ASSERT_TRUE(got_object); | 176 ASSERT_TRUE(got_object); |
| 177 ASSERT_STREQ("id", object_id.c_str()); | 177 ASSERT_STREQ("id", object_id.c_str()); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST(ParseCallFunctionResult, NotDict) { | 180 TEST(ParseCallFunctionResult, NotDict) { |
| 181 scoped_ptr<base::Value> result; | 181 scoped_ptr<base::Value> result; |
| 182 base::FundamentalValue value(1); | 182 base::FundamentalValue value(1); |
| 183 ASSERT_NE(kOk, internal::ParseCallFunctionResult(value, &result).code()); | 183 ASSERT_NE(kOk, internal::ParseCallFunctionResult(value, &result).code()); |
| 184 } | 184 } |
| 185 | 185 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 197 | 197 |
| 198 TEST(ParseCallFunctionResult, ScriptError) { | 198 TEST(ParseCallFunctionResult, ScriptError) { |
| 199 scoped_ptr<base::Value> result; | 199 scoped_ptr<base::Value> result; |
| 200 base::DictionaryValue dict; | 200 base::DictionaryValue dict; |
| 201 dict.SetInteger("status", 1); | 201 dict.SetInteger("status", 1); |
| 202 dict.SetInteger("value", 1); | 202 dict.SetInteger("value", 1); |
| 203 Status status = internal::ParseCallFunctionResult(dict, &result); | 203 Status status = internal::ParseCallFunctionResult(dict, &result); |
| 204 ASSERT_EQ(1, status.code()); | 204 ASSERT_EQ(1, status.code()); |
| 205 ASSERT_FALSE(result); | 205 ASSERT_FALSE(result); |
| 206 } | 206 } |
| OLD | NEW |