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

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

Issue 2601843002: Convert more test helpers to base::RunLoop, fix page title checks. (Closed)
Patch Set: Remove unneeded call. 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 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 1186
1186 while (!ContainsSurfaceId(root_surface_id, child_view)) { 1187 while (!ContainsSurfaceId(root_surface_id, child_view)) {
1187 base::RunLoop run_loop; 1188 base::RunLoop run_loop;
1188 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 1189 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
1189 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); 1190 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout());
1190 run_loop.Run(); 1191 run_loop.Run();
1191 } 1192 }
1192 } 1193 }
1193 #endif 1194 #endif
1194 1195
1196 TitleWatcher::TitleWatcher(WebContents* web_contents)
1197 : WebContentsObserver(web_contents) {
1198 EXPECT_TRUE(web_contents != nullptr);
1199 }
1200
1195 TitleWatcher::TitleWatcher(WebContents* web_contents, 1201 TitleWatcher::TitleWatcher(WebContents* web_contents,
1196 const base::string16& expected_title) 1202 const base::string16& expected_title)
1197 : WebContentsObserver(web_contents), 1203 : TitleWatcher(web_contents) {
1198 message_loop_runner_(new MessageLoopRunner) {
1199 EXPECT_TRUE(web_contents != NULL);
1200 expected_titles_.push_back(expected_title); 1204 expected_titles_.push_back(expected_title);
1201 } 1205 }
1202 1206
1203 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { 1207 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) {
1204 expected_titles_.push_back(expected_title); 1208 expected_titles_.push_back(expected_title);
1205 } 1209 }
1206 1210
1207 TitleWatcher::~TitleWatcher() { 1211 TitleWatcher::~TitleWatcher() {
1208 } 1212 }
1209 1213
1210 const base::string16& TitleWatcher::WaitAndGetTitle() { 1214 const base::string16& TitleWatcher::WaitAndGetTitle() {
1211 TestTitle(); 1215 TestTitle();
1212 message_loop_runner_->Run(); 1216 run_loop_.Run();
1213 return observed_title_; 1217 return observed_title_;
1214 } 1218 }
1215 1219
1216 void TitleWatcher::DidStopLoading() { 1220 void TitleWatcher::DidStopLoading() {
1217 // When navigating through the history, the restored NavigationEntry's title 1221 // When navigating through the history, the restored NavigationEntry's title
1218 // will be used. If the entry ends up having the same title after we return 1222 // will be used. If the entry ends up having the same title after we return
1219 // to it, as will usually be the case, then WebContentsObserver::TitleSet 1223 // to it, as will usually be the case, then WebContentsObserver::TitleSet
1220 // will then be suppressed, since the NavigationEntry's title hasn't changed. 1224 // will then be suppressed, since the NavigationEntry's title hasn't changed.
1221 TestTitle(); 1225 TestTitle();
1222 } 1226 }
1223 1227
1224 void TitleWatcher::TitleWasSet(NavigationEntry* entry, bool explicit_set) { 1228 void TitleWatcher::TitleWasSet(NavigationEntry* entry, bool explicit_set) {
1225 TestTitle(); 1229 TestTitle();
1226 } 1230 }
1227 1231
1228 void TitleWatcher::TestTitle() { 1232 void TitleWatcher::TestTitle() {
1229 std::vector<base::string16>::const_iterator it = 1233 const base::string16& current_title = web_contents()->GetTitle();
1230 std::find(expected_titles_.begin(), 1234 if ((!current_title.empty() && expected_titles_.empty()) ||
1231 expected_titles_.end(), 1235 base::ContainsValue(expected_titles_, current_title)) {
1232 web_contents()->GetTitle()); 1236 observed_title_ = current_title;
1233 if (it == expected_titles_.end()) 1237 run_loop_.Quit();
1234 return; 1238 }
1235
1236 observed_title_ = *it;
1237 message_loop_runner_->Quit();
1238 } 1239 }
1239 1240
1240 RenderProcessHostWatcher::RenderProcessHostWatcher( 1241 RenderProcessHostWatcher::RenderProcessHostWatcher(
1241 RenderProcessHost* render_process_host, WatchType type) 1242 RenderProcessHost* render_process_host, WatchType type)
1242 : render_process_host_(render_process_host), 1243 : render_process_host_(render_process_host),
1243 type_(type), 1244 type_(type),
1244 did_exit_normally_(true), 1245 did_exit_normally_(true),
1245 message_loop_runner_(new MessageLoopRunner) { 1246 message_loop_runner_(new MessageLoopRunner) {
1246 render_process_host_->AddObserver(this); 1247 render_process_host_->AddObserver(this);
1247 } 1248 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 IPC::IpcSecurityTestUtil::PwnMessageReceived( 1841 IPC::IpcSecurityTestUtil::PwnMessageReceived(
1841 process->GetChannel(), 1842 process->GetChannel(),
1842 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position)); 1843 FileSystemHostMsg_Write(request_id, file_path, blob_uuid, position));
1843 1844
1844 // If this started an async operation, wait for it to complete. 1845 // If this started an async operation, wait for it to complete.
1845 if (waiter.did_start_update()) 1846 if (waiter.did_start_update())
1846 waiter.WaitForEndUpdate(); 1847 waiter.WaitForEndUpdate();
1847 } 1848 }
1848 1849
1849 } // namespace content 1850 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698