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

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

Issue 2635933003: Convert more test helpers to base::RunLoop, fix page title checks. (Reland) (Closed)
Patch Set: Fix ClickModifierTests. 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"
19 #include "base/strings/pattern.h" 20 #include "base/strings/pattern.h"
20 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_piece.h" 22 #include "base/strings/string_piece.h"
22 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
23 #include "base/synchronization/waitable_event.h" 24 #include "base/synchronization/waitable_event.h"
24 #include "base/test/test_timeouts.h" 25 #include "base/test/test_timeouts.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
26 #include "base/values.h" 27 #include "base/values.h"
27 #include "build/build_config.h" 28 #include "build/build_config.h"
28 #include "cc/surfaces/surface.h" 29 #include "cc/surfaces/surface.h"
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 base::RunLoop run_loop; 1199 base::RunLoop run_loop;
1199 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1200 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1200 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); 1201 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
1201 run_loop.Run(); 1202 run_loop.Run();
1202 } 1203 }
1203 } 1204 }
1204 #endif 1205 #endif
1205 1206
1206 TitleWatcher::TitleWatcher(WebContents* web_contents, 1207 TitleWatcher::TitleWatcher(WebContents* web_contents,
1207 const base::string16& expected_title) 1208 const base::string16& expected_title)
1208 : WebContentsObserver(web_contents), 1209 : WebContentsObserver(web_contents) {
1209 message_loop_runner_(new MessageLoopRunner) {
1210 EXPECT_TRUE(web_contents != NULL);
1211 expected_titles_.push_back(expected_title); 1210 expected_titles_.push_back(expected_title);
1212 } 1211 }
1213 1212
1214 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { 1213 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) {
1215 expected_titles_.push_back(expected_title); 1214 expected_titles_.push_back(expected_title);
1216 } 1215 }
1217 1216
1218 TitleWatcher::~TitleWatcher() { 1217 TitleWatcher::~TitleWatcher() {
1219 } 1218 }
1220 1219
1221 const base::string16& TitleWatcher::WaitAndGetTitle() { 1220 const base::string16& TitleWatcher::WaitAndGetTitle() {
1222 TestTitle(); 1221 TestTitle();
1223 message_loop_runner_->Run(); 1222 run_loop_.Run();
1224 return observed_title_; 1223 return observed_title_;
1225 } 1224 }
1226 1225
1227 void TitleWatcher::DidStopLoading() { 1226 void TitleWatcher::DidStopLoading() {
1228 // When navigating through the history, the restored NavigationEntry's title 1227 // When navigating through the history, the restored NavigationEntry's title
1229 // will be used. If the entry ends up having the same title after we return 1228 // will be used. If the entry ends up having the same title after we return
1230 // to it, as will usually be the case, then WebContentsObserver::TitleSet 1229 // to it, as will usually be the case, then WebContentsObserver::TitleSet
1231 // will then be suppressed, since the NavigationEntry's title hasn't changed. 1230 // will then be suppressed, since the NavigationEntry's title hasn't changed.
1232 TestTitle(); 1231 TestTitle();
1233 } 1232 }
1234 1233
1235 void TitleWatcher::TitleWasSet(NavigationEntry* entry, bool explicit_set) { 1234 void TitleWatcher::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
1236 TestTitle(); 1235 TestTitle();
1237 } 1236 }
1238 1237
1239 void TitleWatcher::TestTitle() { 1238 void TitleWatcher::TestTitle() {
1240 std::vector<base::string16>::const_iterator it = 1239 const base::string16& current_title = web_contents()->GetTitle();
1241 std::find(expected_titles_.begin(), 1240 if (base::ContainsValue(expected_titles_, current_title)) {
1242 expected_titles_.end(), 1241 observed_title_ = current_title;
1243 web_contents()->GetTitle()); 1242 run_loop_.Quit();
1244 if (it == expected_titles_.end()) 1243 }
1245 return;
1246
1247 observed_title_ = *it;
1248 message_loop_runner_->Quit();
1249 } 1244 }
1250 1245
1251 RenderProcessHostWatcher::RenderProcessHostWatcher( 1246 RenderProcessHostWatcher::RenderProcessHostWatcher(
1252 RenderProcessHost* render_process_host, WatchType type) 1247 RenderProcessHost* render_process_host, WatchType type)
1253 : render_process_host_(render_process_host), 1248 : render_process_host_(render_process_host),
1254 type_(type), 1249 type_(type),
1255 did_exit_normally_(true), 1250 did_exit_normally_(true),
1256 message_loop_runner_(new MessageLoopRunner) { 1251 message_loop_runner_(new MessageLoopRunner) {
1257 render_process_host_->AddObserver(this); 1252 render_process_host_->AddObserver(this);
1258 } 1253 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1851 IPC::IpcSecurityTestUtil::PwnMessageReceived( 1846 IPC::IpcSecurityTestUtil::PwnMessageReceived(
1852 process->GetChannel(), 1847 process->GetChannel(),
1853 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position)); 1848 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position));
1854 1849
1855 // If this started an async operation, wait for it to complete. 1850 // If this started an async operation, wait for it to complete.
1856 if (waiter.did_start_update()) 1851 if (waiter.did_start_update())
1857 waiter.WaitForEndUpdate(); 1852 waiter.WaitForEndUpdate();
1858 } 1853 }
1859 1854
1860 } // namespace content 1855 } // 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