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

Side by Side Diff: components/printing/test/print_web_view_helper_browsertest.cc

Issue 2870633002: Use ScopedTaskEnvironment instead of MessageLoop in RenderViewTest. (Closed)
Patch Set: fix-build-error Created 3 years, 7 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 "components/printing/renderer/print_web_view_helper.h" 5 #include "components/printing/renderer/print_web_view_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <tuple> 10 #include <tuple>
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Do this before shutting down V8 in RenderViewTest::TearDown(). 165 // Do this before shutting down V8 in RenderViewTest::TearDown().
166 // http://crbug.com/328552 166 // http://crbug.com/328552
167 __lsan_do_leak_check(); 167 __lsan_do_leak_check();
168 #endif 168 #endif
169 169
170 content::RenderViewTest::TearDown(); 170 content::RenderViewTest::TearDown();
171 } 171 }
172 172
173 void PrintWithJavaScript() { 173 void PrintWithJavaScript() {
174 ExecuteJavaScriptForTests("window.print();"); 174 ExecuteJavaScriptForTests("window.print();");
175 ProcessPendingMessages(); 175 base::RunLoop().RunUntilIdle();
176 } 176 }
177 177
178 // The renderer should be done calculating the number of rendered pages 178 // The renderer should be done calculating the number of rendered pages
179 // according to the specified settings defined in the mock render thread. 179 // according to the specified settings defined in the mock render thread.
180 // Verify the page count is correct. 180 // Verify the page count is correct.
181 void VerifyPageCount(int expected_count) { 181 void VerifyPageCount(int expected_count) {
182 #if defined(OS_CHROMEOS) 182 #if defined(OS_CHROMEOS)
183 // The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we 183 // The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we
184 // always print all pages, and there are checks to that effect built into 184 // always print all pages, and there are checks to that effect built into
185 // the print code. 185 // the print code.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (did_print) { 235 if (did_print) {
236 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 236 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
237 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 237 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
238 EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number); 238 EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number);
239 } 239 }
240 } 240 }
241 241
242 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 242 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
243 void OnPrintPages() { 243 void OnPrintPages() {
244 GetPrintWebViewHelper()->OnPrintPages(); 244 GetPrintWebViewHelper()->OnPrintPages();
245 ProcessPendingMessages(); 245 base::RunLoop().RunUntilIdle();
246 } 246 }
247 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 247 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
248 248
249 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 249 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
250 void VerifyPreviewRequest(bool expect_request) { 250 void VerifyPreviewRequest(bool expect_request) {
251 const IPC::Message* print_msg = 251 const IPC::Message* print_msg =
252 render_thread_->sink().GetUniqueMessageMatching( 252 render_thread_->sink().GetUniqueMessageMatching(
253 PrintHostMsg_SetupScriptedPrintPreview::ID); 253 PrintHostMsg_SetupScriptedPrintPreview::ID);
254 bool got_preview_request = !!print_msg; 254 bool got_preview_request = !!print_msg;
255 EXPECT_EQ(expect_request, got_preview_request); 255 EXPECT_EQ(expect_request, got_preview_request);
256 } 256 }
257 257
258 void OnPrintPreview(const base::DictionaryValue& dict) { 258 void OnPrintPreview(const base::DictionaryValue& dict) {
259 PrintWebViewHelper* print_web_view_helper = GetPrintWebViewHelper(); 259 PrintWebViewHelper* print_web_view_helper = GetPrintWebViewHelper();
260 print_web_view_helper->OnInitiatePrintPreview(false); 260 print_web_view_helper->OnInitiatePrintPreview(false);
261 base::RunLoop run_loop; 261 base::RunLoop run_loop;
262 DidPreviewPageListener filter(&run_loop); 262 DidPreviewPageListener filter(&run_loop);
263 render_thread_->sink().AddFilter(&filter); 263 render_thread_->sink().AddFilter(&filter);
264 print_web_view_helper->OnPrintPreview(dict); 264 print_web_view_helper->OnPrintPreview(dict);
265 run_loop.Run(); 265 run_loop.Run();
266 render_thread_->sink().RemoveFilter(&filter); 266 render_thread_->sink().RemoveFilter(&filter);
267 } 267 }
268 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 268 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
269 269
270 #if BUILDFLAG(ENABLE_BASIC_PRINTING) 270 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
271 void OnPrintForPrintPreview(const base::DictionaryValue& dict) { 271 void OnPrintForPrintPreview(const base::DictionaryValue& dict) {
272 GetPrintWebViewHelper()->OnPrintForPrintPreview(dict); 272 GetPrintWebViewHelper()->OnPrintForPrintPreview(dict);
273 ProcessPendingMessages(); 273 base::RunLoop().RunUntilIdle();
274 } 274 }
275 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 275 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
276 276
277 PrintWebViewHelper* GetPrintWebViewHelper() { 277 PrintWebViewHelper* GetPrintWebViewHelper() {
278 return PrintWebViewHelper::Get( 278 return PrintWebViewHelper::Get(
279 content::RenderFrame::FromWebFrame(GetMainFrame())); 279 content::RenderFrame::FromWebFrame(GetMainFrame()));
280 } 280 }
281 281
282 // Naked pointer as ownership is with content::RenderViewTest::render_thread_. 282 // Naked pointer as ownership is with content::RenderViewTest::render_thread_.
283 PrintMockRenderThread* print_render_thread_; 283 PrintMockRenderThread* print_render_thread_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 blink::WebMouseEvent mouse_event(blink::WebInputEvent::kMouseDown, 358 blink::WebMouseEvent mouse_event(blink::WebInputEvent::kMouseDown,
359 blink::WebInputEvent::kNoModifiers, 359 blink::WebInputEvent::kNoModifiers,
360 blink::WebInputEvent::kTimeStampForTesting); 360 blink::WebInputEvent::kTimeStampForTesting);
361 mouse_event.button = blink::WebMouseEvent::Button::kLeft; 361 mouse_event.button = blink::WebMouseEvent::Button::kLeft;
362 mouse_event.SetPositionInWidget(bounds.CenterPoint().x(), 362 mouse_event.SetPositionInWidget(bounds.CenterPoint().x(),
363 bounds.CenterPoint().y()); 363 bounds.CenterPoint().y());
364 mouse_event.click_count = 1; 364 mouse_event.click_count = 1;
365 SendWebMouseEvent(mouse_event); 365 SendWebMouseEvent(mouse_event);
366 mouse_event.SetType(blink::WebInputEvent::kMouseUp); 366 mouse_event.SetType(blink::WebInputEvent::kMouseUp);
367 SendWebMouseEvent(mouse_event); 367 SendWebMouseEvent(mouse_event);
368 ProcessPendingMessages(); 368 base::RunLoop().RunUntilIdle();
369 369
370 VerifyPageCount(1); 370 VerifyPageCount(1);
371 VerifyPagesPrinted(true); 371 VerifyPagesPrinted(true);
372 } 372 }
373 373
374 // Duplicate of OnPrintPagesTest only using javascript to print. 374 // Duplicate of OnPrintPagesTest only using javascript to print.
375 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) { 375 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) {
376 PrintWithJavaScript(); 376 PrintWithJavaScript();
377 377
378 VerifyPageCount(1); 378 VerifyPageCount(1);
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 1154
1155 VerifyPrintFailed(true); 1155 VerifyPrintFailed(true);
1156 VerifyPagesPrinted(false); 1156 VerifyPagesPrinted(false);
1157 } 1157 }
1158 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1158 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1159 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1159 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1160 1160
1161 #endif // !defined(OS_CHROMEOS) 1161 #endif // !defined(OS_CHROMEOS)
1162 1162
1163 } // namespace printing 1163 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/renderer/content_settings_observer_browsertest.cc ('k') | content/public/test/render_view_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698