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" | |
10 #include "base/path_service.h" | 8 #include "base/path_service.h" |
11 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
12 #include "base/strings/utf_string_conversions.h" | |
13 #include "build/build_config.h" | 10 #include "build/build_config.h" |
14 #include "content/public/browser/render_frame_host.h" | |
15 #include "content/public/browser/web_contents.h" | 11 #include "content/public/browser/web_contents.h" |
16 #include "content/shell/browser/layout_test/blink_test_controller.h" | 12 #include "content/shell/browser/layout_test/blink_test_controller.h" |
17 #include "content/shell/browser/shell.h" | 13 #include "content/shell/browser/shell.h" |
18 #include "net/base/filename_util.h" | 14 #include "net/base/filename_util.h" |
19 | 15 |
20 namespace content { | 16 namespace content { |
21 | 17 |
22 // static | 18 // static |
23 LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show( | 19 LayoutTestDevToolsFrontend* LayoutTestDevToolsFrontend::Show( |
24 WebContents* inspected_contents, | 20 WebContents* inspected_contents, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 #endif // defined(DEBUG_DEVTOOLS) | 60 #endif // defined(DEBUG_DEVTOOLS) |
65 if (!settings.empty()) | 61 if (!settings.empty()) |
66 url_string += "&settings=" + settings; | 62 url_string += "&settings=" + settings; |
67 return GURL(url_string); | 63 return GURL(url_string); |
68 } | 64 } |
69 | 65 |
70 void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings, | 66 void LayoutTestDevToolsFrontend::ReuseFrontend(const std::string& settings, |
71 const std::string frontend_url) { | 67 const std::string frontend_url) { |
72 DisconnectFromTarget(); | 68 DisconnectFromTarget(); |
73 preferences()->Clear(); | 69 preferences()->Clear(); |
74 ready_for_test_ = false; | |
75 pending_evaluations_.clear(); | |
76 frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); | 70 frontend_shell()->LoadURL(GetDevToolsPathAsURL(settings, frontend_url)); |
77 } | 71 } |
78 | 72 |
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 | |
97 LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend( | 73 LayoutTestDevToolsFrontend::LayoutTestDevToolsFrontend( |
98 Shell* frontend_shell, | 74 Shell* frontend_shell, |
99 WebContents* inspected_contents) | 75 WebContents* inspected_contents) |
100 : ShellDevToolsFrontend(frontend_shell, inspected_contents), | 76 : ShellDevToolsFrontend(frontend_shell, inspected_contents) { |
101 ready_for_test_(false) { | |
102 } | 77 } |
103 | 78 |
104 LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() { | 79 LayoutTestDevToolsFrontend::~LayoutTestDevToolsFrontend() { |
105 } | 80 } |
106 | 81 |
107 void LayoutTestDevToolsFrontend::AgentHostClosed( | 82 void LayoutTestDevToolsFrontend::AgentHostClosed( |
108 DevToolsAgentHost* agent_host, bool replaced) { | 83 DevToolsAgentHost* agent_host, bool replaced) { |
109 // Do not close the front-end shell. | 84 // Do not close the front-end shell. |
110 } | 85 } |
111 | 86 |
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 | |
131 void LayoutTestDevToolsFrontend::RenderProcessGone( | 87 void LayoutTestDevToolsFrontend::RenderProcessGone( |
132 base::TerminationStatus status) { | 88 base::TerminationStatus status) { |
133 BlinkTestController::Get()->DevToolsProcessCrashed(); | 89 BlinkTestController::Get()->DevToolsProcessCrashed(); |
134 } | 90 } |
135 | 91 |
136 } // namespace content | 92 } // namespace content |
OLD | NEW |