Skip to content

Commit 6b8ab60

Browse files
committed
added silence and verbose mode
1 parent 2fbcef8 commit 6b8ab60

File tree

1 file changed

+68
-12
lines changed

1 file changed

+68
-12
lines changed

src/chrome/test/webdriver/webdriver_server.cc

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,48 @@ namespace webdriver {
8686

8787
namespace {
8888

89+
void silentMessageOutput(QtMsgType type, const char *msg)
90+
{
91+
// keep silence
92+
return;
93+
}
94+
95+
void normalMessageOutput(QtMsgType type, const char *msg)
96+
{
97+
switch (type) {
98+
case QtDebugMsg:
99+
// keep silence
100+
break;
101+
case QtWarningMsg:
102+
fprintf(stderr, "Warning: %s\n", msg);
103+
break;
104+
case QtCriticalMsg:
105+
fprintf(stderr, "Critical: %s\n", msg);
106+
break;
107+
case QtFatalMsg:
108+
fprintf(stderr, "Fatal: %s\n", msg);
109+
abort();
110+
}
111+
}
112+
113+
void verboseMessageOutput(QtMsgType type, const char *msg)
114+
{
115+
switch (type) {
116+
case QtDebugMsg:
117+
fprintf(stderr, "Debug: %s\n", msg);
118+
break;
119+
case QtWarningMsg:
120+
fprintf(stderr, "Warning: %s\n", msg);
121+
break;
122+
case QtCriticalMsg:
123+
fprintf(stderr, "Critical: %s\n", msg);
124+
break;
125+
case QtFatalMsg:
126+
fprintf(stderr, "Fatal: %s\n", msg);
127+
abort();
128+
}
129+
}
130+
89131
void InitCallbacks(Dispatcher* dispatcher,
90132
base::WaitableEvent* shutdown_event,
91133
bool forbid_other_requests) {
@@ -241,6 +283,22 @@ int RunChromeDriver() {
241283
base::WaitableEvent shutdown_event(false, false);
242284
CommandLine* cmd_line = CommandLine::ForCurrentProcess();
243285

286+
// set default output mode
287+
qInstallMsgHandler(normalMessageOutput);
288+
289+
// check if verbose mode
290+
if (cmd_line->HasSwitch("verbose")) {
291+
qInstallMsgHandler(verboseMessageOutput);
292+
}
293+
294+
// check if silence mode
295+
if (cmd_line->HasSwitch("silence")) {
296+
std::ostream null_stream(0);
297+
std::cerr.rdbuf(null_stream.rdbuf());
298+
std::cout.rdbuf(null_stream.rdbuf());
299+
qInstallMsgHandler(silentMessageOutput);
300+
}
301+
244302
//#if defined(OS_POSIX)
245303
// signal(SIGPIPE, SIG_IGN);
246304
//#endif
@@ -322,20 +380,18 @@ int RunChromeDriver() {
322380

323381
// The tests depend on parsing the first line ChromeDriver outputs,
324382
// so all other logging should happen after this.
325-
if (!cmd_line->HasSwitch("silent")) {
326-
std::cout << "************************"<< std::endl
327-
<< "Started WebDriver" << std::endl
328-
<< "port=" << port << std::endl
329-
<< "root=" << root << std::endl
330-
<< "url-base=" << url_base << std::endl
331-
<< "http-threads=" << http_threads << std::endl
332-
/*<< "version=" << chrome::kChromeVersion << std::endl*/;
333-
if (logging_success)
383+
std::cout << "************************"<< std::endl
384+
<< "Started WebDriver" << std::endl
385+
<< "port=" << port << std::endl
386+
<< "root=" << root << std::endl
387+
<< "url-base=" << url_base << std::endl
388+
<< "http-threads=" << http_threads << std::endl
389+
/*<< "version=" << chrome::kChromeVersion << std::endl*/;
390+
if (logging_success)
334391
std::cout << "log=" << FileLog::Get()->path().value() << std::endl;
335-
else
392+
else
336393
std::cout << "Log file could not be created. log = " << FileLog::Get()->path().value() << std::endl;
337-
std::cout << "************************"<< std::endl;
338-
}
394+
std::cout << "************************"<< std::endl;
339395

340396
// Run until we receive command to shutdown.
341397
// Don't call mg_stop because mongoose will hang if clients are still

0 commit comments

Comments
 (0)