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

Side by Side Diff: chrome/test/ui/ui_test.cc

Issue 54003: Replace chrome_process_filter with chrome_process_util. (Closed)
Patch Set: error handling Created 11 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
« no previous file with comments | « chrome/test/tab_switching/tab_switching.vcproj ('k') | chrome/test/ui/ui_tests.vcproj » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/test/ui/ui_test.h" 5 #include "chrome/test/ui/ui_test.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/base_switches.h" 10 #include "base/base_switches.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/file_path.h" 12 #include "base/file_path.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/path_service.h"
14 #include "base/platform_thread.h" 15 #include "base/platform_thread.h"
15 #include "base/process_util.h" 16 #include "base/process_util.h"
16 #include "base/scoped_ptr.h" 17 #include "base/scoped_ptr.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/test_file_util.h" 19 #include "base/test_file_util.h"
19 #include "base/time.h" 20 #include "base/time.h"
20 #include "chrome/app/chrome_dll_resource.h" 21 #include "chrome/app/chrome_dll_resource.h"
21 #include "chrome/browser/net/url_fixer_upper.h" 22 #include "chrome/browser/net/url_fixer_upper.h"
22 #include "chrome/common/chrome_constants.h" 23 #include "chrome/common/chrome_constants.h"
23 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
25 #include "chrome/common/debug_flags.h" 26 #include "chrome/common/debug_flags.h"
26 #include "chrome/common/logging_chrome.h" 27 #include "chrome/common/logging_chrome.h"
27 #include "chrome/common/json_value_serializer.h" 28 #include "chrome/common/json_value_serializer.h"
28 #include "chrome/test/automation/automation_proxy.h" 29 #include "chrome/test/automation/automation_proxy.h"
29 #include "chrome/test/automation/browser_proxy.h" 30 #include "chrome/test/automation/browser_proxy.h"
30 #include "chrome/test/automation/tab_proxy.h" 31 #include "chrome/test/automation/tab_proxy.h"
32 #include "chrome/test/chrome_process_util.h"
31 #include "googleurl/src/gurl.h" 33 #include "googleurl/src/gurl.h"
32 #include "net/base/net_util.h" 34 #include "net/base/net_util.h"
33 35
34 #if defined(OS_WIN) 36 #if defined(OS_WIN)
35 // TODO(port): these just need to be ported. 37 // TODO(port): this just needs to be ported.
36 #include "chrome/common/chrome_process_filter.h"
37 #include "chrome/test/automation/window_proxy.h" 38 #include "chrome/test/automation/window_proxy.h"
38 #endif 39 #endif
39 40
40 using base::TimeTicks; 41 using base::TimeTicks;
41 42
42 // Delay to let browser complete a requested action. 43 // Delay to let browser complete a requested action.
43 static const int kWaitForActionMsec = 2000; 44 static const int kWaitForActionMsec = 2000;
44 static const int kWaitForActionMaxMsec = 10000; 45 static const int kWaitForActionMaxMsec = 10000;
45 // Delay to let the browser complete the test. 46 // Delay to let the browser complete the test.
46 static const int kMaxTestExecutionTime = 30000; 47 static const int kMaxTestExecutionTime = 30000;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 439
439 // Don't forget to close the handle 440 // Don't forget to close the handle
440 base::CloseProcessHandle(process_); 441 base::CloseProcessHandle(process_);
441 process_ = NULL; 442 process_ = NULL;
442 } 443 }
443 444
444 void UITest::AssertAppNotRunning(const std::wstring& error_message) { 445 void UITest::AssertAppNotRunning(const std::wstring& error_message) {
445 #if defined(OS_WIN) 446 #if defined(OS_WIN)
446 ASSERT_EQ(0, GetBrowserProcessCount()) << error_message; 447 ASSERT_EQ(0, GetBrowserProcessCount()) << error_message;
447 #else 448 #else
448 // TODO(port): Enable when chrome_process_filter is ported. 449 // TODO(port): Enable when chrome_process_util is ported.
449 NOTIMPLEMENTED(); 450 NOTIMPLEMENTED();
450 #endif 451 #endif
451 } 452 }
452 453
453 void UITest::CleanupAppProcesses() { 454 void UITest::CleanupAppProcesses() {
454 #if defined(OS_WIN) 455 #if defined(OS_WIN)
455 BrowserProcessFilter filter(L""); 456 TerminateAllChromeProcesses(FilePath::FromWStringHack(user_data_dir()));
456
457 // Make sure that no instances of the browser remain.
458 const int kExitTimeoutMs = 5000;
459 const int kExitCode = 1;
460 base::CleanupProcesses(
461 chrome::kBrowserProcessExecutableName, kExitTimeoutMs, kExitCode,
462 &filter);
463 457
464 // Suppress spammy failures that seem to be occurring when running 458 // Suppress spammy failures that seem to be occurring when running
465 // the UI tests in single-process mode. 459 // the UI tests in single-process mode.
466 // TODO(jhughes): figure out why this is necessary at all, and fix it 460 // TODO(jhughes): figure out why this is necessary at all, and fix it
467 if (!in_process_renderer_) { 461 if (!in_process_renderer_)
468 AssertAppNotRunning(L"Unable to quit all browser processes."); 462 AssertAppNotRunning(L"Unable to quit all browser processes.");
469 }
470 #else 463 #else
471 // TODO(port): depends on BrowserProcessFilter. 464 // TODO(port): depends on chrome_process_util.
472 NOTIMPLEMENTED(); 465 NOTIMPLEMENTED();
473 #endif 466 #endif
474 } 467 }
475 468
476 TabProxy* UITest::GetActiveTab() { 469 TabProxy* UITest::GetActiveTab() {
477 scoped_ptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); 470 scoped_ptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
478 if (!window_proxy.get()) 471 if (!window_proxy.get())
479 return NULL; 472 return NULL;
480 473
481 int active_tab_index = -1; 474 int active_tab_index = -1;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 576
584 bool UITest::IsBrowserRunning() { 577 bool UITest::IsBrowserRunning() {
585 return CrashAwareSleep(0); 578 return CrashAwareSleep(0);
586 } 579 }
587 580
588 bool UITest::CrashAwareSleep(int time_out_ms) { 581 bool UITest::CrashAwareSleep(int time_out_ms) {
589 return base::CrashAwareSleep(process_, time_out_ms); 582 return base::CrashAwareSleep(process_, time_out_ms);
590 } 583 }
591 584
592 #if defined(OS_WIN) 585 #if defined(OS_WIN)
593 // TODO(port): Port BrowserProcessFilter and sort out one wstring/string issue. 586 // TODO(port): Port GetRunningChromeProcesses and sort out one w/string issue.
594 587
595 /*static*/ 588 /*static*/
596 int UITest::GetBrowserProcessCount() { 589 int UITest::GetBrowserProcessCount() {
597 BrowserProcessFilter filter(L""); 590 FilePath data_dir;
598 return base::GetProcessCount(chrome::kBrowserProcessExecutableName, 591 PathService::Get(chrome::DIR_USER_DATA, &data_dir);
599 &filter); 592 return GetRunningChromeProcesses(data_dir).size();
600 } 593 }
601 594
602 static DictionaryValue* LoadDictionaryValueFromPath(const FilePath& path) { 595 static DictionaryValue* LoadDictionaryValueFromPath(const FilePath& path) {
603 if (path.empty()) 596 if (path.empty())
604 return NULL; 597 return NULL;
605 598
606 JSONFileValueSerializer serializer(path); 599 JSONFileValueSerializer serializer(path);
607 scoped_ptr<Value> root_value(serializer.Deserialize(NULL)); 600 scoped_ptr<Value> root_value(serializer.Deserialize(NULL));
608 if (!root_value.get() || root_value->GetType() != Value::TYPE_DICTIONARY) 601 if (!root_value.get() || root_value->GetType() != Value::TYPE_DICTIONARY)
609 return NULL; 602 return NULL;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 } 855 }
863 856
864 bool UITest::EvictFileFromSystemCacheWrapper(const FilePath& path) { 857 bool UITest::EvictFileFromSystemCacheWrapper(const FilePath& path) {
865 for (int i = 0; i < 10; i++) { 858 for (int i = 0; i < 10; i++) {
866 if (file_util::EvictFileFromSystemCache(path)) 859 if (file_util::EvictFileFromSystemCache(path))
867 return true; 860 return true;
868 PlatformThread::Sleep(1000); 861 PlatformThread::Sleep(1000);
869 } 862 }
870 return false; 863 return false;
871 } 864 }
OLDNEW
« no previous file with comments | « chrome/test/tab_switching/tab_switching.vcproj ('k') | chrome/test/ui/ui_tests.vcproj » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698