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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/md5.h" | 8 #include "base/md5.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 "</body>"; | 77 "</body>"; |
78 LoadHTML(kThreeBoxesRTLHTML); | 78 LoadHTML(kThreeBoxesRTLHTML); |
79 std::vector<unsigned char> png_data; | 79 std::vector<unsigned char> png_data; |
80 std::string error_msg; | 80 std::string error_msg; |
81 ASSERT_TRUE(AutomationRendererHelper(view_).SnapshotEntirePage( | 81 ASSERT_TRUE(AutomationRendererHelper(view_).SnapshotEntirePage( |
82 view_->GetWebView(), &png_data, &error_msg)) << error_msg; | 82 view_->GetWebView(), &png_data, &error_msg)) << error_msg; |
83 CompareSnapshot(png_data, kThreeBoxesMD5); | 83 CompareSnapshot(png_data, kThreeBoxesMD5); |
84 } | 84 } |
85 | 85 |
86 TEST_F(AutomationRendererHelperTest, ScriptChain) { | 86 TEST_F(AutomationRendererHelperTest, ScriptChain) { |
87 ScriptEvaluationRequest request("({'result': 10})", ""); | 87 ScriptEvaluationRequest request("({'result': 10})", std::string()); |
88 ScriptEvaluationRequest request_plus1( | 88 ScriptEvaluationRequest request_plus1("({'result': arguments[0].result + 1})", |
89 "({'result': arguments[0].result + 1})", ""); | 89 std::string()); |
90 std::vector<ScriptEvaluationRequest> script_chain; | 90 std::vector<ScriptEvaluationRequest> script_chain; |
91 script_chain.push_back(request); | 91 script_chain.push_back(request); |
92 script_chain.push_back(request_plus1); | 92 script_chain.push_back(request_plus1); |
93 script_chain.push_back(request_plus1); | 93 script_chain.push_back(request_plus1); |
94 | 94 |
95 AutomationRendererHelper helper(view_); | 95 AutomationRendererHelper helper(view_); |
96 scoped_ptr<base::DictionaryValue> value; | 96 scoped_ptr<base::DictionaryValue> value; |
97 std::string error; | 97 std::string error; |
98 ASSERT_TRUE(helper.EvaluateScriptChain(script_chain, &value, &error)); | 98 ASSERT_TRUE(helper.EvaluateScriptChain(script_chain, &value, &error)); |
99 int result; | 99 int result; |
100 ASSERT_TRUE(value->GetInteger("result", &result)); | 100 ASSERT_TRUE(value->GetInteger("result", &result)); |
101 EXPECT_EQ(12, result); | 101 EXPECT_EQ(12, result); |
102 } | 102 } |
103 | 103 |
104 TEST_F(AutomationRendererHelperTest, ScriptChainError) { | 104 TEST_F(AutomationRendererHelperTest, ScriptChainError) { |
105 ScriptEvaluationRequest request("({'result': 10})", ""); | 105 ScriptEvaluationRequest request("({'result': 10})", std::string()); |
106 ScriptEvaluationRequest error_request( | 106 ScriptEvaluationRequest error_request( |
107 "({'result': arguments[0].result + 1, 'error': {'msg': 'some msg'}})", | 107 "({'result': arguments[0].result + 1, 'error': {'msg': 'some msg'}})", |
108 ""); | 108 std::string()); |
109 std::vector<ScriptEvaluationRequest> script_chain; | 109 std::vector<ScriptEvaluationRequest> script_chain; |
110 script_chain.push_back(request); | 110 script_chain.push_back(request); |
111 script_chain.push_back(error_request); | 111 script_chain.push_back(error_request); |
112 script_chain.push_back(request); | 112 script_chain.push_back(request); |
113 | 113 |
114 AutomationRendererHelper helper(view_); | 114 AutomationRendererHelper helper(view_); |
115 scoped_ptr<base::DictionaryValue> result; | 115 scoped_ptr<base::DictionaryValue> result; |
116 std::string error; | 116 std::string error; |
117 ASSERT_FALSE(helper.EvaluateScriptChain(script_chain, &result, &error)); | 117 ASSERT_FALSE(helper.EvaluateScriptChain(script_chain, &result, &error)); |
118 scoped_ptr<base::Value> value(base::JSONReader::Read(error)); | 118 scoped_ptr<base::Value> value(base::JSONReader::Read(error)); |
119 base::DictionaryValue* dict; | 119 base::DictionaryValue* dict; |
120 ASSERT_TRUE(value->GetAsDictionary(&dict)); | 120 ASSERT_TRUE(value->GetAsDictionary(&dict)); |
121 std::string msg; | 121 std::string msg; |
122 ASSERT_TRUE(dict->GetString("msg", &msg)); | 122 ASSERT_TRUE(dict->GetString("msg", &msg)); |
123 EXPECT_STREQ("some msg", msg.c_str()); | 123 EXPECT_STREQ("some msg", msg.c_str()); |
124 } | 124 } |
OLD | NEW |