OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/md5.h" | 8 #include "base/md5.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/common/automation_constants.h" |
| 11 #include "chrome/common/automation_events.h" |
8 #include "chrome/test/base/chrome_render_view_test.h" | 12 #include "chrome/test/base/chrome_render_view_test.h" |
9 #include "chrome/renderer/automation/automation_renderer_helper.h" | 13 #include "chrome/renderer/automation/automation_renderer_helper.h" |
10 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWidget.h" |
14 | 18 |
15 namespace { | 19 namespace { |
16 | 20 |
17 const char kThreeBoxesHTML[] = | 21 const char kThreeBoxesHTML[] = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 " <div style='background:green;width:100;height:100'></div>" | 73 " <div style='background:green;width:100;height:100'></div>" |
70 " <div style='background:blue;width:100;height:100'></div>" | 74 " <div style='background:blue;width:100;height:100'></div>" |
71 "</body>"; | 75 "</body>"; |
72 LoadHTML(kThreeBoxesRTLHTML); | 76 LoadHTML(kThreeBoxesRTLHTML); |
73 std::vector<unsigned char> png_data; | 77 std::vector<unsigned char> png_data; |
74 std::string error_msg; | 78 std::string error_msg; |
75 ASSERT_TRUE(AutomationRendererHelper(view_).SnapshotEntirePage( | 79 ASSERT_TRUE(AutomationRendererHelper(view_).SnapshotEntirePage( |
76 view_->GetWebView(), &png_data, &error_msg)) << error_msg; | 80 view_->GetWebView(), &png_data, &error_msg)) << error_msg; |
77 CompareSnapshot(png_data, kThreeBoxesMD5); | 81 CompareSnapshot(png_data, kThreeBoxesMD5); |
78 } | 82 } |
| 83 |
| 84 TEST_F(AutomationRendererHelperTest, ScriptChain) { |
| 85 ScriptEvaluationRequest request("({'result': 10})", ""); |
| 86 ScriptEvaluationRequest request_plus1( |
| 87 "({'result': arguments[0].result + 1})", ""); |
| 88 std::vector<ScriptEvaluationRequest> script_chain; |
| 89 script_chain.push_back(request); |
| 90 script_chain.push_back(request_plus1); |
| 91 script_chain.push_back(request_plus1); |
| 92 |
| 93 AutomationRendererHelper helper(view_); |
| 94 scoped_ptr<base::DictionaryValue> value; |
| 95 std::string error; |
| 96 ASSERT_TRUE(helper.EvaluateScriptChain(script_chain, &value, &error)); |
| 97 int result; |
| 98 ASSERT_TRUE(value->GetInteger("result", &result)); |
| 99 EXPECT_EQ(12, result); |
| 100 } |
| 101 |
| 102 TEST_F(AutomationRendererHelperTest, ScriptChainError) { |
| 103 ScriptEvaluationRequest request("({'result': 10})", ""); |
| 104 ScriptEvaluationRequest error_request( |
| 105 "({'result': arguments[0].result + 1, 'error': {'msg': 'some msg'}})", |
| 106 ""); |
| 107 std::vector<ScriptEvaluationRequest> script_chain; |
| 108 script_chain.push_back(request); |
| 109 script_chain.push_back(error_request); |
| 110 script_chain.push_back(request); |
| 111 |
| 112 AutomationRendererHelper helper(view_); |
| 113 scoped_ptr<base::DictionaryValue> result; |
| 114 std::string error; |
| 115 ASSERT_FALSE(helper.EvaluateScriptChain(script_chain, &result, &error)); |
| 116 scoped_ptr<base::Value> value(base::JSONReader::Read(error)); |
| 117 base::DictionaryValue* dict; |
| 118 ASSERT_TRUE(value->GetAsDictionary(&dict)); |
| 119 std::string msg; |
| 120 ASSERT_TRUE(dict->GetString("msg", &msg)); |
| 121 EXPECT_STREQ("some msg", msg.c_str()); |
| 122 } |
OLD | NEW |