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 "content/public/test/test_utils.h" | 5 #include "content/public/test/test_utils.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 BrowserThread::PostTask(thread_id, FROM_HERE, quit_task); | 63 BrowserThread::PostTask(thread_id, FROM_HERE, quit_task); |
64 } | 64 } |
65 | 65 |
66 // Class used to handle result callbacks for ExecuteScriptAndGetValue. | 66 // Class used to handle result callbacks for ExecuteScriptAndGetValue. |
67 class ScriptCallback { | 67 class ScriptCallback { |
68 public: | 68 public: |
69 ScriptCallback() { } | 69 ScriptCallback() { } |
70 virtual ~ScriptCallback() { } | 70 virtual ~ScriptCallback() { } |
71 void ResultCallback(const base::Value* result); | 71 void ResultCallback(const base::Value* result); |
72 | 72 |
73 scoped_ptr<base::Value> result() { return std::move(result_); } | 73 std::unique_ptr<base::Value> result() { return std::move(result_); } |
74 | 74 |
75 private: | 75 private: |
76 scoped_ptr<base::Value> result_; | 76 std::unique_ptr<base::Value> result_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(ScriptCallback); | 78 DISALLOW_COPY_AND_ASSIGN(ScriptCallback); |
79 }; | 79 }; |
80 | 80 |
81 void ScriptCallback::ResultCallback(const base::Value* result) { | 81 void ScriptCallback::ResultCallback(const base::Value* result) { |
82 if (result) | 82 if (result) |
83 result_.reset(result->DeepCopy()); | 83 result_.reset(result->DeepCopy()); |
84 base::MessageLoop::current()->QuitWhenIdle(); | 84 base::MessageLoop::current()->QuitWhenIdle(); |
85 } | 85 } |
86 | 86 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 if (!task_observer.processed()) | 174 if (!task_observer.processed()) |
175 break; | 175 break; |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) { | 179 base::Closure GetQuitTaskForRunLoop(base::RunLoop* run_loop) { |
180 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), | 180 return base::Bind(&DeferredQuitRunLoop, run_loop->QuitClosure(), |
181 kNumQuitDeferrals); | 181 kNumQuitDeferrals); |
182 } | 182 } |
183 | 183 |
184 scoped_ptr<base::Value> ExecuteScriptAndGetValue( | 184 std::unique_ptr<base::Value> ExecuteScriptAndGetValue( |
185 RenderFrameHost* render_frame_host, const std::string& script) { | 185 RenderFrameHost* render_frame_host, |
| 186 const std::string& script) { |
186 ScriptCallback observer; | 187 ScriptCallback observer; |
187 | 188 |
188 render_frame_host->ExecuteJavaScriptForTests( | 189 render_frame_host->ExecuteJavaScriptForTests( |
189 base::UTF8ToUTF16(script), | 190 base::UTF8ToUTF16(script), |
190 base::Bind(&ScriptCallback::ResultCallback, base::Unretained(&observer))); | 191 base::Bind(&ScriptCallback::ResultCallback, base::Unretained(&observer))); |
191 base::MessageLoop* loop = base::MessageLoop::current(); | 192 base::MessageLoop* loop = base::MessageLoop::current(); |
192 loop->Run(); | 193 loop->Run(); |
193 return observer.result(); | 194 return observer.result(); |
194 } | 195 } |
195 | 196 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 381 |
381 void WebContentsDestroyedWatcher::Wait() { | 382 void WebContentsDestroyedWatcher::Wait() { |
382 message_loop_runner_->Run(); | 383 message_loop_runner_->Run(); |
383 } | 384 } |
384 | 385 |
385 void WebContentsDestroyedWatcher::WebContentsDestroyed() { | 386 void WebContentsDestroyedWatcher::WebContentsDestroyed() { |
386 message_loop_runner_->Quit(); | 387 message_loop_runner_->Quit(); |
387 } | 388 } |
388 | 389 |
389 } // namespace content | 390 } // namespace content |
OLD | NEW |