Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 2630683003: Revert of Convert more test helpers to base::RunLoop, fix page title checks. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <tuple> 8 #include <tuple>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/process/kill.h" 17 #include "base/process/kill.h"
18 #include "base/rand_util.h" 18 #include "base/rand_util.h"
19 #include "base/stl_util.h"
20 #include "base/strings/pattern.h" 19 #include "base/strings/pattern.h"
21 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_piece.h" 21 #include "base/strings/string_piece.h"
23 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
24 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
25 #include "base/test/test_timeouts.h" 24 #include "base/test/test_timeouts.h"
26 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/values.h" 26 #include "base/values.h"
28 #include "build/build_config.h" 27 #include "build/build_config.h"
29 #include "cc/surfaces/surface.h" 28 #include "cc/surfaces/surface.h"
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 1185
1187 while (!ContainsSurfaceId(root_surface_id, child_view)) { 1186 while (!ContainsSurfaceId(root_surface_id, child_view)) {
1188 base::RunLoop run_loop; 1187 base::RunLoop run_loop;
1189 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1188 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1190 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); 1189 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
1191 run_loop.Run(); 1190 run_loop.Run();
1192 } 1191 }
1193 } 1192 }
1194 #endif 1193 #endif
1195 1194
1196 TitleWatcher::TitleWatcher(WebContents* web_contents)
1197 : WebContentsObserver(web_contents) {
1198 EXPECT_TRUE(web_contents != nullptr);
1199 }
1200
1201 TitleWatcher::TitleWatcher(WebContents* web_contents, 1195 TitleWatcher::TitleWatcher(WebContents* web_contents,
1202 const base::string16& expected_title) 1196 const base::string16& expected_title)
1203 : TitleWatcher(web_contents) { 1197 : WebContentsObserver(web_contents),
1198 message_loop_runner_(new MessageLoopRunner) {
1199 EXPECT_TRUE(web_contents != NULL);
1204 expected_titles_.push_back(expected_title); 1200 expected_titles_.push_back(expected_title);
1205 } 1201 }
1206 1202
1207 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { 1203 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) {
1208 expected_titles_.push_back(expected_title); 1204 expected_titles_.push_back(expected_title);
1209 } 1205 }
1210 1206
1211 TitleWatcher::~TitleWatcher() { 1207 TitleWatcher::~TitleWatcher() {
1212 } 1208 }
1213 1209
1214 const base::string16& TitleWatcher::WaitAndGetTitle() { 1210 const base::string16& TitleWatcher::WaitAndGetTitle() {
1215 TestTitle(); 1211 TestTitle();
1216 run_loop_.Run(); 1212 message_loop_runner_->Run();
1217 return observed_title_; 1213 return observed_title_;
1218 } 1214 }
1219 1215
1220 void TitleWatcher::DidStopLoading() { 1216 void TitleWatcher::DidStopLoading() {
1221 // When navigating through the history, the restored NavigationEntry's title 1217 // When navigating through the history, the restored NavigationEntry's title
1222 // will be used. If the entry ends up having the same title after we return 1218 // will be used. If the entry ends up having the same title after we return
1223 // to it, as will usually be the case, then WebContentsObserver::TitleSet 1219 // to it, as will usually be the case, then WebContentsObserver::TitleSet
1224 // will then be suppressed, since the NavigationEntry's title hasn't changed. 1220 // will then be suppressed, since the NavigationEntry's title hasn't changed.
1225 TestTitle(); 1221 TestTitle();
1226 } 1222 }
1227 1223
1228 void TitleWatcher::TitleWasSet(NavigationEntry* entry, bool explicit_set) { 1224 void TitleWatcher::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
1229 TestTitle(); 1225 TestTitle();
1230 } 1226 }
1231 1227
1232 void TitleWatcher::TestTitle() { 1228 void TitleWatcher::TestTitle() {
1233 const base::string16& current_title = web_contents()->GetTitle(); 1229 std::vector<base::string16>::const_iterator it =
1234 if ((!current_title.empty() && expected_titles_.empty()) || 1230 std::find(expected_titles_.begin(),
1235 base::ContainsValue(expected_titles_, current_title)) { 1231 expected_titles_.end(),
1236 observed_title_ = current_title; 1232 web_contents()->GetTitle());
1237 run_loop_.Quit(); 1233 if (it == expected_titles_.end())
1238 } 1234 return;
1235
1236 observed_title_ = *it;
1237 message_loop_runner_->Quit();
1239 } 1238 }
1240 1239
1241 RenderProcessHostWatcher::RenderProcessHostWatcher( 1240 RenderProcessHostWatcher::RenderProcessHostWatcher(
1242 RenderProcessHost* render_process_host, WatchType type) 1241 RenderProcessHost* render_process_host, WatchType type)
1243 : render_process_host_(render_process_host), 1242 : render_process_host_(render_process_host),
1244 type_(type), 1243 type_(type),
1245 did_exit_normally_(true), 1244 did_exit_normally_(true),
1246 message_loop_runner_(new MessageLoopRunner) { 1245 message_loop_runner_(new MessageLoopRunner) {
1247 render_process_host_->AddObserver(this); 1246 render_process_host_->AddObserver(this);
1248 } 1247 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 IPC::IpcSecurityTestUtil::PwnMessageReceived( 1840 IPC::IpcSecurityTestUtil::PwnMessageReceived(
1842 process->GetChannel(), 1841 process->GetChannel(),
1843 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position)); 1842 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position));
1844 1843
1845 // If this started an async operation, wait for it to complete. 1844 // If this started an async operation, wait for it to complete.
1846 if (waiter.did_start_update()) 1845 if (waiter.did_start_update())
1847 waiter.WaitForEndUpdate(); 1846 waiter.WaitForEndUpdate();
1848 } 1847 }
1849 1848
1850 } // namespace content 1849 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/public/test/test_frame_navigation_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698