| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/base/extension_js_browser_test.h" |
| 6 |
| 7 #include "base/json/json_reader.h" |
| 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/browser/extensions/browsertest_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "content/public/test/browser_test_utils.h" |
| 15 |
| 16 void ExtensionJSBrowserTest::WaitFor(const char* extension_id) { |
| 17 load_waiter_.WaitFor(extension_id); |
| 18 } |
| 19 |
| 20 bool ExtensionJSBrowserTest::RunJavascriptTestF(bool is_async, |
| 21 const std::string& test_fixture, |
| 22 const std::string& test_name) { |
| 23 CHECK(load_waiter_.browser_context()); |
| 24 ConstValueVector args; |
| 25 args.push_back(new base::StringValue(test_fixture)); |
| 26 args.push_back(new base::StringValue(test_name)); |
| 27 std::vector<base::string16> scripts; |
| 28 if (!libs_loaded_) { |
| 29 BuildJavascriptLibraries(&scripts); |
| 30 libs_loaded_ = true; |
| 31 } |
| 32 scripts.push_back(BuildRunTestJSCall(is_async, "RUN_TEST_F", args)); |
| 33 |
| 34 base::string16 script_16 = JoinString(scripts, '\n'); |
| 35 std::string script = base::UTF16ToUTF8(script_16); |
| 36 |
| 37 std::string result = |
| 38 extensions::browsertest_util::ExecuteScriptInBackgroundPage( |
| 39 Profile::FromBrowserContext(load_waiter_.browser_context()), |
| 40 load_waiter_.extension_id(), |
| 41 script); |
| 42 |
| 43 base::JSONReader reader; |
| 44 scoped_ptr<base::Value> value_result; |
| 45 value_result.reset(reader.Read(result)); |
| 46 CHECK_EQ(base::Value::TYPE_DICTIONARY, value_result->GetType()); |
| 47 base::DictionaryValue* dict_value = |
| 48 static_cast<base::DictionaryValue*>(value_result.get()); |
| 49 bool test_result; |
| 50 std::string test_result_message; |
| 51 CHECK(dict_value->GetBoolean("result", &test_result)); |
| 52 CHECK(dict_value->GetString("message", &test_result_message)); |
| 53 return test_result; |
| 54 } |
| OLD | NEW |