OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/test/base/extension_js_browser_test.h" | 5 #include "chrome/test/base/extension_js_browser_test.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 ConstValueVector args; | 35 ConstValueVector args; |
36 args.push_back(new base::StringValue(test_fixture)); | 36 args.push_back(new base::StringValue(test_fixture)); |
37 args.push_back(new base::StringValue(test_name)); | 37 args.push_back(new base::StringValue(test_name)); |
38 std::vector<base::string16> scripts; | 38 std::vector<base::string16> scripts; |
39 if (!libs_loaded_) { | 39 if (!libs_loaded_) { |
40 BuildJavascriptLibraries(&scripts); | 40 BuildJavascriptLibraries(&scripts); |
41 libs_loaded_ = true; | 41 libs_loaded_ = true; |
42 } | 42 } |
43 scripts.push_back(BuildRunTestJSCall(is_async, "RUN_TEST_F", args)); | 43 scripts.push_back(BuildRunTestJSCall(is_async, "RUN_TEST_F", args)); |
44 | 44 |
45 base::string16 script_16 = JoinString(scripts, '\n'); | 45 base::string16 script_16 = |
| 46 base::JoinString(scripts, base::ASCIIToUTF16("\n")); |
46 std::string script = base::UTF16ToUTF8(script_16); | 47 std::string script = base::UTF16ToUTF8(script_16); |
47 | 48 |
48 std::string result = | 49 std::string result = |
49 extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 50 extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
50 Profile::FromBrowserContext(load_waiter_->browser_context()), | 51 Profile::FromBrowserContext(load_waiter_->browser_context()), |
51 load_waiter_->extension_id(), | 52 load_waiter_->extension_id(), |
52 script); | 53 script); |
53 | 54 |
54 scoped_ptr<base::Value> value_result = base::JSONReader::Read(result); | 55 scoped_ptr<base::Value> value_result = base::JSONReader::Read(result); |
55 CHECK_EQ(base::Value::TYPE_DICTIONARY, value_result->GetType()); | 56 CHECK_EQ(base::Value::TYPE_DICTIONARY, value_result->GetType()); |
56 base::DictionaryValue* dict_value = | 57 base::DictionaryValue* dict_value = |
57 static_cast<base::DictionaryValue*>(value_result.get()); | 58 static_cast<base::DictionaryValue*>(value_result.get()); |
58 bool test_result; | 59 bool test_result; |
59 std::string test_result_message; | 60 std::string test_result_message; |
60 CHECK(dict_value->GetBoolean("result", &test_result)); | 61 CHECK(dict_value->GetBoolean("result", &test_result)); |
61 CHECK(dict_value->GetString("message", &test_result_message)); | 62 CHECK(dict_value->GetString("message", &test_result_message)); |
62 if (!test_result_message.empty()) | 63 if (!test_result_message.empty()) |
63 ADD_FAILURE() << test_result_message; | 64 ADD_FAILURE() << test_result_message; |
64 return test_result; | 65 return test_result; |
65 } | 66 } |
OLD | NEW |