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 "content/shell/browser/layout_test/layout_test_devtools_frontend.h" | 5 #include "content/shell/browser/layout_test/layout_test_devtools_frontend.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" |
8 #include "base/path_service.h" | 10 #include "base/path_service.h" |
9 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" |
10 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/public/browser/render_frame_host.h" |
11 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
12 #include "content/shell/browser/layout_test/blink_test_controller.h" | 16 #include "content/shell/browser/layout_test/blink_test_controller.h" |
13 #include "content/shell/browser/shell.h" | 17 #include "content/shell/browser/shell.h" |
14 #include "net/base/filename_util.h" | 18 #include "net/base/filename_util.h" |
15 | 19 |
16 namespace content { | 20 namespace content { |
17 | 21 |
18 // static | 22 // static |
19 LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show( | 23 LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show( |
20 WebContents* inspected_contents, | 24 WebContents* inspected_contents, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #endif // defined(DEBUG_DEVTOOLS) | 64 #endif // defined(DEBUG_DEVTOOLS) |
61 if (!settings.empty()) | 65 if (!settings.empty()) |
62 url_string += "&settings=" + settings; | 66 url_string += "&settings=" + settings; |
63 return GURL(url_string); | 67 return GURL(url_string); |
64 } | 68 } |
65 | 69 |
66 void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings, | 70 void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings, |
67 const std::string frontend_url) { | 71 const std::string frontend_url) { |
68 DisconnectFromTarget(); | 72 DisconnectFromTarget(); |
69 preferences()->Clear(); | 73 preferences()->Clear(); |
| 74 ready_for_test_ = false; |
| 75 pending_evaluations_.clear(); |
70 frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); | 76 frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); |
71 } | 77 } |
72 | 78 |
| 79 void LayoutTestDevToolsFrontend::EvaluateInFrontend( |
| 80 int call_id, |
| 81 const std::string& script) { |
| 82 if (!ready_for_test_) { |
| 83 pending_evaluations_.push_back(std::make_pair(call_id, script)); |
| 84 return; |
| 85 } |
| 86 |
| 87 std::string encoded_script; |
| 88 base::JSONWriter::Write(base::StringValue(script), &encoded_script); |
| 89 std::string source = |
| 90 base::StringPrintf("DevToolsAPI.evaluateForTestInFrontend(%d, %s);", |
| 91 call_id, |
| 92 encoded_script.c_str()); |
| 93 web_contents()->GetMainFrame()->ExecuteJavaScriptForTests( |
| 94 base::UTF8ToUTF16(source)); |
| 95 } |
| 96 |
73 LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend( | 97 LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend( |
74 Shell* frontend_shell, | 98 Shell* frontend_shell, |
75 WebContents* inspected_contents) | 99 WebContents* inspected_contents) |
76 : ShellDevToolsFrontend(frontend_shell, inspected_contents) { | 100 : ShellDevToolsFrontend(frontend_shell, inspected_contents), |
| 101 ready_for_test_(false) { |
77 } | 102 } |
78 | 103 |
79 LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() { | 104 LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() { |
80 } | 105 } |
81 | 106 |
82 void LayoutTestDevToolsFrontend::AgentHostClosed( | 107 void LayoutTestDevToolsFrontend::AgentHostClosed( |
83 DevToolsAgentHost* agent_host, bool replaced) { | 108 DevToolsAgentHost* agent_host, bool replaced) { |
84 // Do not close the front-end shell. | 109 // Do not close the front-end shell. |
85 } | 110 } |
86 | 111 |
| 112 void LayoutTestDevToolsFrontend::HandleMessageFromDevToolsFrontend( |
| 113 const std::string& message) { |
| 114 std::string method; |
| 115 base::DictionaryValue* dict = nullptr; |
| 116 scoped_ptr<base::Value> parsed_message = base::JSONReader::Read(message); |
| 117 if (parsed_message && |
| 118 parsed_message->GetAsDictionary(&dict) && |
| 119 dict->GetString("method", &method) && |
| 120 method == "readyForTest") { |
| 121 ready_for_test_ = true; |
| 122 for (const auto& pair : pending_evaluations_) |
| 123 EvaluateInFrontend(pair.first, pair.second); |
| 124 pending_evaluations_.clear(); |
| 125 return; |
| 126 } |
| 127 |
| 128 ShellDevToolsFrontend::HandleMessageFromDevToolsFrontend(message); |
| 129 } |
| 130 |
87 void LayoutTestDevToolsFrontend::RenderProcessGone( | 131 void LayoutTestDevToolsFrontend::RenderProcessGone( |
88 base::TerminationStatus status) { | 132 base::TerminationStatus status) { |
89 BlinkTestController::Get()->DevToolsProcessCrashed(); | 133 BlinkTestController::Get()->DevToolsProcessCrashed(); |
90 } | 134 } |
91 | 135 |
92 } // namespace content | 136 } // namespace content |
OLD | NEW |