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

Side by Side Diff: content/shell/browser/layout_test/layout_test_browser_main.cc

Issue 1874903002: Convert //content from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix indent Created 4 years, 8 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/shell/browser/layout_test/layout_test_browser_main.h" 5 #include "content/shell/browser/layout_test/layout_test_browser_main.h"
6 6
7 #include <iostream> 7 #include <iostream>
8 #include <memory>
8 9
9 #include "base/command_line.h" 10 #include "base/command_line.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
13 #include "base/location.h" 14 #include "base/location.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/thread_restrictions.h" 20 #include "base/threading/thread_restrictions.h"
21 #include "build/build_config.h" 21 #include "build/build_config.h"
22 #include "content/public/browser/browser_main_runner.h" 22 #include "content/public/browser/browser_main_runner.h"
23 #include "content/public/common/url_constants.h" 23 #include "content/public/common/url_constants.h"
24 #include "content/shell/browser/layout_test/blink_test_controller.h" 24 #include "content/shell/browser/layout_test/blink_test_controller.h"
25 #include "content/shell/browser/layout_test/test_info_extractor.h" 25 #include "content/shell/browser/layout_test/test_info_extractor.h"
26 #include "content/shell/browser/shell.h" 26 #include "content/shell/browser/shell.h"
27 #include "content/shell/common/layout_test/layout_test_switches.h" 27 #include "content/shell/common/layout_test/layout_test_switches.h"
28 #include "content/shell/common/shell_switches.h" 28 #include "content/shell/common/shell_switches.h"
29 #include "content/shell/renderer/layout_test/blink_test_helpers.h" 29 #include "content/shell/renderer/layout_test/blink_test_helpers.h"
30 #include "net/base/filename_util.h" 30 #include "net/base/filename_util.h"
31 31
32 #if defined(OS_ANDROID) 32 #if defined(OS_ANDROID)
33 #include "base/run_loop.h" 33 #include "base/run_loop.h"
34 #include "content/shell/browser/layout_test/layout_test_android.h" 34 #include "content/shell/browser/layout_test/layout_test_android.h"
35 #endif 35 #endif
36 36
37 namespace { 37 namespace {
38 38
39 bool RunOneTest(const content::TestInfo& test_info, 39 bool RunOneTest(
40 bool* ran_at_least_once, 40 const content::TestInfo& test_info,
41 const scoped_ptr<content::BrowserMainRunner>& main_runner) { 41 bool* ran_at_least_once,
42 const std::unique_ptr<content::BrowserMainRunner>& main_runner) {
42 if (!content::BlinkTestController::Get()->PrepareForLayoutTest( 43 if (!content::BlinkTestController::Get()->PrepareForLayoutTest(
43 test_info.url, test_info.current_working_directory, 44 test_info.url, test_info.current_working_directory,
44 test_info.enable_pixel_dumping, test_info.expected_pixel_hash)) { 45 test_info.enable_pixel_dumping, test_info.expected_pixel_hash)) {
45 return false; 46 return false;
46 } 47 }
47 48
48 *ran_at_least_once = true; 49 *ran_at_least_once = true;
49 #if defined(OS_ANDROID) 50 #if defined(OS_ANDROID)
50 // The message loop on Android is provided by the system, and does not 51 // The message loop on Android is provided by the system, and does not
51 // offer a blocking Run() method. For layout tests, use a nested loop 52 // offer a blocking Run() method. For layout tests, use a nested loop
52 // together with a base::RunLoop so it can block until a QuitClosure. 53 // together with a base::RunLoop so it can block until a QuitClosure.
53 base::RunLoop run_loop; 54 base::RunLoop run_loop;
54 run_loop.Run(); 55 run_loop.Run();
55 #else 56 #else
56 main_runner->Run(); 57 main_runner->Run();
57 #endif 58 #endif
58 59
59 if (!content::BlinkTestController::Get()->ResetAfterLayoutTest()) 60 if (!content::BlinkTestController::Get()->ResetAfterLayoutTest())
60 return false; 61 return false;
61 62
62 #if defined(OS_ANDROID) 63 #if defined(OS_ANDROID)
63 // There will be left-over tasks in the queue for Android because the 64 // There will be left-over tasks in the queue for Android because the
64 // main window is being destroyed. Run them before starting the next test. 65 // main window is being destroyed. Run them before starting the next test.
65 base::MessageLoop::current()->RunUntilIdle(); 66 base::MessageLoop::current()->RunUntilIdle();
66 #endif 67 #endif
67 return true; 68 return true;
68 } 69 }
69 70
70 int RunTests(const scoped_ptr<content::BrowserMainRunner>& main_runner) { 71 int RunTests(const std::unique_ptr<content::BrowserMainRunner>& main_runner) {
71 content::BlinkTestController test_controller; 72 content::BlinkTestController test_controller;
72 { 73 {
73 // We're outside of the message loop here, and this is a test. 74 // We're outside of the message loop here, and this is a test.
74 base::ThreadRestrictions::ScopedAllowIO allow_io; 75 base::ThreadRestrictions::ScopedAllowIO allow_io;
75 base::FilePath temp_path; 76 base::FilePath temp_path;
76 base::GetTempDir(&temp_path); 77 base::GetTempDir(&temp_path);
77 test_controller.SetTempPath(temp_path); 78 test_controller.SetTempPath(temp_path);
78 } 79 }
79 80
80 std::cout << "#READY\n"; 81 std::cout << "#READY\n";
81 std::cout.flush(); 82 std::cout.flush();
82 83
83 base::CommandLine::StringVector args = 84 base::CommandLine::StringVector args =
84 base::CommandLine::ForCurrentProcess()->GetArgs(); 85 base::CommandLine::ForCurrentProcess()->GetArgs();
85 content::TestInfoExtractor test_extractor(args); 86 content::TestInfoExtractor test_extractor(args);
86 bool ran_at_least_once = false; 87 bool ran_at_least_once = false;
87 scoped_ptr<content::TestInfo> test_info; 88 std::unique_ptr<content::TestInfo> test_info;
88 while ((test_info = test_extractor.GetNextTest())) { 89 while ((test_info = test_extractor.GetNextTest())) {
89 if (!RunOneTest(*test_info, &ran_at_least_once, main_runner)) 90 if (!RunOneTest(*test_info, &ran_at_least_once, main_runner))
90 break; 91 break;
91 } 92 }
92 if (!ran_at_least_once) { 93 if (!ran_at_least_once) {
93 base::ThreadTaskRunnerHandle::Get()->PostTask( 94 base::ThreadTaskRunnerHandle::Get()->PostTask(
94 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); 95 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure());
95 main_runner->Run(); 96 main_runner->Run();
96 } 97 }
97 98
98 #if defined(OS_ANDROID) 99 #if defined(OS_ANDROID)
99 // We need to execute 'main_runner->Shutdown()' before the test_controller 100 // We need to execute 'main_runner->Shutdown()' before the test_controller
100 // destructs when running on Android, and after it destructs when running 101 // destructs when running on Android, and after it destructs when running
101 // anywhere else. 102 // anywhere else.
102 main_runner->Shutdown(); 103 main_runner->Shutdown();
103 #endif 104 #endif
104 105
105 return 0; 106 return 0;
106 } 107 }
107 108
108 } // namespace 109 } // namespace
109 110
110 // Main routine for running as the Browser process. 111 // Main routine for running as the Browser process.
111 int LayoutTestBrowserMain( 112 int LayoutTestBrowserMain(
112 const content::MainFunctionParams& parameters, 113 const content::MainFunctionParams& parameters,
113 const scoped_ptr<content::BrowserMainRunner>& main_runner) { 114 const std::unique_ptr<content::BrowserMainRunner>& main_runner) {
114 base::ScopedTempDir browser_context_path_for_layout_tests; 115 base::ScopedTempDir browser_context_path_for_layout_tests;
115 116
116 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir()); 117 CHECK(browser_context_path_for_layout_tests.CreateUniqueTempDir());
117 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty()); 118 CHECK(!browser_context_path_for_layout_tests.path().MaybeAsASCII().empty());
118 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 119 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
119 switches::kContentShellDataPath, 120 switches::kContentShellDataPath,
120 browser_context_path_for_layout_tests.path().MaybeAsASCII()); 121 browser_context_path_for_layout_tests.path().MaybeAsASCII());
121 122
122 #if defined(OS_ANDROID) 123 #if defined(OS_ANDROID)
123 content::EnsureInitializeForAndroidLayoutTests(); 124 content::EnsureInitializeForAndroidLayoutTests();
(...skipping 17 matching lines...) Expand all
141 } 142 }
142 143
143 exit_code = RunTests(main_runner); 144 exit_code = RunTests(main_runner);
144 145
145 #if !defined(OS_ANDROID) 146 #if !defined(OS_ANDROID)
146 main_runner->Shutdown(); 147 main_runner->Shutdown();
147 #endif 148 #endif
148 149
149 return exit_code; 150 return exit_code;
150 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698