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 = | 45 base::string16 script_16 = JoinString(scripts, '\n'); |
46 base::JoinString(scripts, base::ASCIIToUTF16("\n")); | |
47 std::string script = base::UTF16ToUTF8(script_16); | 46 std::string script = base::UTF16ToUTF8(script_16); |
48 | 47 |
49 std::string result = | 48 std::string result = |
50 extensions::browsertest_util::ExecuteScriptInBackgroundPage( | 49 extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
51 Profile::FromBrowserContext(load_waiter_->browser_context()), | 50 Profile::FromBrowserContext(load_waiter_->browser_context()), |
52 load_waiter_->extension_id(), | 51 load_waiter_->extension_id(), |
53 script); | 52 script); |
54 | 53 |
55 scoped_ptr<base::Value> value_result = base::JSONReader::Read(result); | 54 scoped_ptr<base::Value> value_result = base::JSONReader::Read(result); |
56 CHECK_EQ(base::Value::TYPE_DICTIONARY, value_result->GetType()); | 55 CHECK_EQ(base::Value::TYPE_DICTIONARY, value_result->GetType()); |
57 base::DictionaryValue* dict_value = | 56 base::DictionaryValue* dict_value = |
58 static_cast<base::DictionaryValue*>(value_result.get()); | 57 static_cast<base::DictionaryValue*>(value_result.get()); |
59 bool test_result; | 58 bool test_result; |
60 std::string test_result_message; | 59 std::string test_result_message; |
61 CHECK(dict_value->GetBoolean("result", &test_result)); | 60 CHECK(dict_value->GetBoolean("result", &test_result)); |
62 CHECK(dict_value->GetString("message", &test_result_message)); | 61 CHECK(dict_value->GetString("message", &test_result_message)); |
63 if (!test_result_message.empty()) | 62 if (!test_result_message.empty()) |
64 ADD_FAILURE() << test_result_message; | 63 ADD_FAILURE() << test_result_message; |
65 return test_result; | 64 return test_result; |
66 } | 65 } |
OLD | NEW |