| OLD | NEW |
| 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 // This file provides reliablity tests which run for ChromeFrame. | 5 // This file provides reliablity tests which run for ChromeFrame. |
| 6 // | 6 // |
| 7 // Usage: | 7 // Usage: |
| 8 // <reliability test exe> --list=file --startline=start --endline=end [...] | 8 // <reliability test exe> --list=file --startline=start --endline=end [...] |
| 9 // Upon invocation, it visits each of the URLs on line numbers between start | 9 // Upon invocation, it visits each of the URLs on line numbers between start |
| 10 // and end, inclusive, stored in the input file. The line number starts from 1. | 10 // and end, inclusive, stored in the input file. The line number starts from 1. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 const char kNoClearProfileSwitch[] = "noclearprofile"; | 79 const char kNoClearProfileSwitch[] = "noclearprofile"; |
| 80 const char kSaveDebugLogSwitch[] = "savedebuglog"; | 80 const char kSaveDebugLogSwitch[] = "savedebuglog"; |
| 81 | 81 |
| 82 // These are copied from v8 definitions as we cannot include them. | 82 // These are copied from v8 definitions as we cannot include them. |
| 83 const char kV8LogFileSwitch[] = "logfile"; | 83 const char kV8LogFileSwitch[] = "logfile"; |
| 84 const char kV8LogFileDefaultName[] = "v8.log"; | 84 const char kV8LogFileDefaultName[] = "v8.log"; |
| 85 | 85 |
| 86 // String name of local chrome dll for looking up file information. | 86 // String name of local chrome dll for looking up file information. |
| 87 const wchar_t kChromeDll[] = L"chrome.dll"; | 87 const wchar_t kChromeDll[] = L"chrome.dll"; |
| 88 | 88 |
| 89 FilePath g_url_file_path; | 89 base::FilePath g_url_file_path; |
| 90 int32 g_start_index = 1; | 90 int32 g_start_index = 1; |
| 91 int32 g_end_index = kint32max; | 91 int32 g_end_index = kint32max; |
| 92 int32 g_iterations = 1; | 92 int32 g_iterations = 1; |
| 93 bool g_memory_usage = false; | 93 bool g_memory_usage = false; |
| 94 bool g_page_down = true; | 94 bool g_page_down = true; |
| 95 bool g_clear_profile = true; | 95 bool g_clear_profile = true; |
| 96 std::string g_end_url; | 96 std::string g_end_url; |
| 97 FilePath g_log_file_path; | 97 base::FilePath g_log_file_path; |
| 98 bool g_save_debug_log = false; | 98 bool g_save_debug_log = false; |
| 99 FilePath g_chrome_log_path; | 99 base::FilePath g_chrome_log_path; |
| 100 FilePath g_v8_log_path; | 100 base::FilePath g_v8_log_path; |
| 101 FilePath g_test_log_path; | 101 base::FilePath g_test_log_path; |
| 102 bool g_stand_alone = false; | 102 bool g_stand_alone = false; |
| 103 | 103 |
| 104 const int kUrlNavigationTimeoutSeconds = 20; | 104 const int kUrlNavigationTimeoutSeconds = 20; |
| 105 int g_timeout_seconds = kUrlNavigationTimeoutSeconds; | 105 int g_timeout_seconds = kUrlNavigationTimeoutSeconds; |
| 106 | 106 |
| 107 // Mocks document complete and load events. | 107 // Mocks document complete and load events. |
| 108 class MockLoadListener : public chrome_frame_test::IEEventListener { | 108 class MockLoadListener : public chrome_frame_test::IEEventListener { |
| 109 public: | 109 public: |
| 110 MOCK_METHOD1(OnDocumentComplete, void (const wchar_t* url)); // NOLINT | 110 MOCK_METHOD1(OnDocumentComplete, void (const wchar_t* url)); // NOLINT |
| 111 MOCK_METHOD1(OnLoad, void (const wchar_t* url)); // NOLINT | 111 MOCK_METHOD1(OnLoad, void (const wchar_t* url)); // NOLINT |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // Accept URL as std::string here because the url may also act as a test id | 147 // Accept URL as std::string here because the url may also act as a test id |
| 148 // and needs to be logged in its original format even if invalid. | 148 // and needs to be logged in its original format even if invalid. |
| 149 void NavigateToURLLogResult(const std::string& url_string, | 149 void NavigateToURLLogResult(const std::string& url_string, |
| 150 std::ofstream& log_file, | 150 std::ofstream& log_file, |
| 151 NavigationMetrics* metrics_output) { | 151 NavigationMetrics* metrics_output) { |
| 152 GURL url(url_string); | 152 GURL url(url_string); |
| 153 NavigationMetrics metrics = {NAVIGATION_ERROR}; | 153 NavigationMetrics metrics = {NAVIGATION_ERROR}; |
| 154 std::ofstream test_log; | 154 std::ofstream test_log; |
| 155 | 155 |
| 156 // Create a test log. | 156 // Create a test log. |
| 157 g_test_log_path = FilePath(FILE_PATH_LITERAL("test_log.log")); | 157 g_test_log_path = base::FilePath(FILE_PATH_LITERAL("test_log.log")); |
| 158 test_log.open(g_test_log_path.value().c_str()); | 158 test_log.open(g_test_log_path.value().c_str()); |
| 159 | 159 |
| 160 // Check file version info for chrome dll. | 160 // Check file version info for chrome dll. |
| 161 scoped_ptr<FileVersionInfo> file_info; | 161 scoped_ptr<FileVersionInfo> file_info; |
| 162 #if defined(OS_WIN) | 162 #if defined(OS_WIN) |
| 163 file_info.reset( | 163 file_info.reset( |
| 164 FileVersionInfo::CreateFileVersionInfo(FilePath(kChromeDll))); | 164 FileVersionInfo::CreateFileVersionInfo(base::FilePath(kChromeDll))); |
| 165 #elif defined(OS_LINUX) || defined(OS_MACOSX) | 165 #elif defined(OS_LINUX) || defined(OS_MACOSX) |
| 166 // TODO(fmeawad): the version retrieved here belongs to the test module and | 166 // TODO(fmeawad): the version retrieved here belongs to the test module and |
| 167 // not the chrome binary, need to be changed to chrome binary instead. | 167 // not the chrome binary, need to be changed to chrome binary instead. |
| 168 file_info.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule()); | 168 file_info.reset(FileVersionInfo::CreateFileVersionInfoForCurrentModule()); |
| 169 #endif // !defined(OS_WIN) | 169 #endif // !defined(OS_WIN) |
| 170 std::wstring last_change = file_info->last_change(); | 170 std::wstring last_change = file_info->last_change(); |
| 171 test_log << "Last Change: "; | 171 test_log << "Last Change: "; |
| 172 test_log << last_change << std::endl; | 172 test_log << last_change << std::endl; |
| 173 | 173 |
| 174 | 174 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 file.close(); | 328 file.close(); |
| 329 } | 329 } |
| 330 | 330 |
| 331 protected: | 331 protected: |
| 332 virtual void SetUp() { | 332 virtual void SetUp() { |
| 333 // Initialize crash_dumps_dir_path_. | 333 // Initialize crash_dumps_dir_path_. |
| 334 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dumps_dir_path_); | 334 PathService::Get(chrome::DIR_CRASH_DUMPS, &crash_dumps_dir_path_); |
| 335 file_util::FileEnumerator enumerator(crash_dumps_dir_path_, | 335 file_util::FileEnumerator enumerator(crash_dumps_dir_path_, |
| 336 false, // not recursive | 336 false, // not recursive |
| 337 file_util::FileEnumerator::FILES); | 337 file_util::FileEnumerator::FILES); |
| 338 for (FilePath path = enumerator.Next(); !path.value().empty(); | 338 for (base::FilePath path = enumerator.Next(); !path.value().empty(); |
| 339 path = enumerator.Next()) { | 339 path = enumerator.Next()) { |
| 340 if (path.MatchesExtension(FILE_PATH_LITERAL(".dmp"))) | 340 if (path.MatchesExtension(FILE_PATH_LITERAL(".dmp"))) |
| 341 crash_dumps_[path.BaseName()] = true; | 341 crash_dumps_[path.BaseName()] = true; |
| 342 } | 342 } |
| 343 | 343 |
| 344 if (g_clear_profile) { | 344 if (g_clear_profile) { |
| 345 FilePath user_data_dir; | 345 base::FilePath user_data_dir; |
| 346 chrome::GetChromeFrameUserDataDirectory(&user_data_dir); | 346 chrome::GetChromeFrameUserDataDirectory(&user_data_dir); |
| 347 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true)); | 347 ASSERT_TRUE(file_util::DieFileDie(user_data_dir, true)); |
| 348 } | 348 } |
| 349 | 349 |
| 350 SetConfigBool(kChromeFrameHeadlessMode, true); | 350 SetConfigBool(kChromeFrameHeadlessMode, true); |
| 351 SetConfigBool(kAllowUnsafeURLs, true); | 351 SetConfigBool(kAllowUnsafeURLs, true); |
| 352 } | 352 } |
| 353 | 353 |
| 354 virtual void TearDown() { | 354 virtual void TearDown() { |
| 355 DeleteConfigValue(kChromeFrameHeadlessMode); | 355 DeleteConfigValue(kChromeFrameHeadlessMode); |
| 356 DeleteConfigValue(kAllowUnsafeURLs); | 356 DeleteConfigValue(kAllowUnsafeURLs); |
| 357 } | 357 } |
| 358 | 358 |
| 359 FilePath ConstructSavedDebugLogPath(const FilePath& debug_log_path, | 359 base::FilePath ConstructSavedDebugLogPath(const base::FilePath& debug_log_path
, |
| 360 int index) { | 360 int index) { |
| 361 std::string suffix("_"); | 361 std::string suffix("_"); |
| 362 suffix.append(base::IntToString(index)); | 362 suffix.append(base::IntToString(index)); |
| 363 return debug_log_path.InsertBeforeExtensionASCII(suffix); | 363 return debug_log_path.InsertBeforeExtensionASCII(suffix); |
| 364 } | 364 } |
| 365 | 365 |
| 366 void SaveDebugLog(const FilePath& log_path, const std::wstring& log_id, | 366 void SaveDebugLog(const base::FilePath& log_path, const std::wstring& log_id, |
| 367 std::ofstream& log_file, int index) { | 367 std::ofstream& log_file, int index) { |
| 368 if (!log_path.empty()) { | 368 if (!log_path.empty()) { |
| 369 FilePath saved_log_file_path = | 369 base::FilePath saved_log_file_path = |
| 370 ConstructSavedDebugLogPath(log_path, index); | 370 ConstructSavedDebugLogPath(log_path, index); |
| 371 if (file_util::Move(log_path, saved_log_file_path)) { | 371 if (file_util::Move(log_path, saved_log_file_path)) { |
| 372 log_file << " " << log_id << "=" << saved_log_file_path.value(); | 372 log_file << " " << log_id << "=" << saved_log_file_path.value(); |
| 373 } | 373 } |
| 374 } | 374 } |
| 375 } | 375 } |
| 376 | 376 |
| 377 // Rename the chrome and v8 debug log files if existing, and save the file | 377 // Rename the chrome and v8 debug log files if existing, and save the file |
| 378 // paths in the log_file provided. | 378 // paths in the log_file provided. |
| 379 void SaveDebugLogs(std::ofstream& log_file) { | 379 void SaveDebugLogs(std::ofstream& log_file) { |
| 380 static int url_count = 1; | 380 static int url_count = 1; |
| 381 SaveDebugLog(g_chrome_log_path, L"chrome_log", log_file, url_count); | 381 SaveDebugLog(g_chrome_log_path, L"chrome_log", log_file, url_count); |
| 382 SaveDebugLog(g_v8_log_path, L"v8_log", log_file, url_count); | 382 SaveDebugLog(g_v8_log_path, L"v8_log", log_file, url_count); |
| 383 SaveDebugLog(g_test_log_path, L"test_log", log_file, url_count); | 383 SaveDebugLog(g_test_log_path, L"test_log", log_file, url_count); |
| 384 url_count++; | 384 url_count++; |
| 385 } | 385 } |
| 386 | 386 |
| 387 // If a log_file is provided, log the crash dump with the given path; | 387 // If a log_file is provided, log the crash dump with the given path; |
| 388 // otherwise, delete the crash dump file. | 388 // otherwise, delete the crash dump file. |
| 389 void LogOrDeleteCrashDump(std::ofstream& log_file, | 389 void LogOrDeleteCrashDump(std::ofstream& log_file, |
| 390 FilePath crash_dump_file_name) { | 390 base::FilePath crash_dump_file_name) { |
| 391 FilePath crash_dump_file_path(crash_dumps_dir_path_); | 391 base::FilePath crash_dump_file_path(crash_dumps_dir_path_); |
| 392 crash_dump_file_path = crash_dump_file_path.Append(crash_dump_file_name); | 392 crash_dump_file_path = crash_dump_file_path.Append(crash_dump_file_name); |
| 393 FilePath crash_text_file_path = | 393 base::FilePath crash_text_file_path = |
| 394 crash_dump_file_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); | 394 crash_dump_file_path.ReplaceExtension(FILE_PATH_LITERAL("txt")); |
| 395 | 395 |
| 396 if (log_file.is_open()) { | 396 if (log_file.is_open()) { |
| 397 crash_dumps_[crash_dump_file_name] = true; | 397 crash_dumps_[crash_dump_file_name] = true; |
| 398 log_file << " crash_dump=" << crash_dump_file_path.value().c_str(); | 398 log_file << " crash_dump=" << crash_dump_file_path.value().c_str(); |
| 399 } else { | 399 } else { |
| 400 ASSERT_TRUE(file_util::DieFileDie( | 400 ASSERT_TRUE(file_util::DieFileDie( |
| 401 crash_dump_file_path, false)); | 401 crash_dump_file_path, false)); |
| 402 ASSERT_TRUE(file_util::DieFileDie( | 402 ASSERT_TRUE(file_util::DieFileDie( |
| 403 crash_text_file_path, false)); | 403 crash_text_file_path, false)); |
| 404 } | 404 } |
| 405 } | 405 } |
| 406 | 406 |
| 407 // Check whether there are new .dmp files. Additionally, write | 407 // Check whether there are new .dmp files. Additionally, write |
| 408 // " crash_dump=<full path name of the .dmp file>" | 408 // " crash_dump=<full path name of the .dmp file>" |
| 409 // to log_file. | 409 // to log_file. |
| 410 void LogOrDeleteNewCrashDumps(std::ofstream& log_file, | 410 void LogOrDeleteNewCrashDumps(std::ofstream& log_file, |
| 411 NavigationMetrics* metrics) { | 411 NavigationMetrics* metrics) { |
| 412 int num_dumps = 0; | 412 int num_dumps = 0; |
| 413 | 413 |
| 414 file_util::FileEnumerator enumerator(crash_dumps_dir_path_, | 414 file_util::FileEnumerator enumerator(crash_dumps_dir_path_, |
| 415 false, // not recursive | 415 false, // not recursive |
| 416 file_util::FileEnumerator::FILES); | 416 file_util::FileEnumerator::FILES); |
| 417 for (FilePath path = enumerator.Next(); !path.value().empty(); | 417 for (base::FilePath path = enumerator.Next(); !path.value().empty(); |
| 418 path = enumerator.Next()) { | 418 path = enumerator.Next()) { |
| 419 if (path.MatchesExtension(FILE_PATH_LITERAL(".dmp")) && | 419 if (path.MatchesExtension(FILE_PATH_LITERAL(".dmp")) && |
| 420 !crash_dumps_[path.BaseName()]) { | 420 !crash_dumps_[path.BaseName()]) { |
| 421 LogOrDeleteCrashDump(log_file, path.BaseName()); | 421 LogOrDeleteCrashDump(log_file, path.BaseName()); |
| 422 num_dumps++; | 422 num_dumps++; |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 if (metrics) | 425 if (metrics) |
| 426 metrics->crash_dump_count = num_dumps; | 426 metrics->crash_dump_count = num_dumps; |
| 427 } | 427 } |
| 428 | 428 |
| 429 // Get a PrefService whose contents correspond to the Local State file | 429 // Get a PrefService whose contents correspond to the Local State file |
| 430 // that was saved by the app as it closed. The caller takes ownership of the | 430 // that was saved by the app as it closed. The caller takes ownership of the |
| 431 // returned PrefService object. | 431 // returned PrefService object. |
| 432 PrefService* GetLocalState(PrefRegistry* registry) { | 432 PrefService* GetLocalState(PrefRegistry* registry) { |
| 433 FilePath path; | 433 base::FilePath path; |
| 434 chrome::GetChromeFrameUserDataDirectory(&path); | 434 chrome::GetChromeFrameUserDataDirectory(&path); |
| 435 PrefServiceMockBuilder builder; | 435 PrefServiceMockBuilder builder; |
| 436 builder.WithUserFilePrefs( | 436 builder.WithUserFilePrefs( |
| 437 path, | 437 path, |
| 438 JsonPrefStore::GetTaskRunnerForFile( | 438 JsonPrefStore::GetTaskRunnerForFile( |
| 439 path, content::BrowserThread::GetBlockingPool())); | 439 path, content::BrowserThread::GetBlockingPool())); |
| 440 return builder.Create(registry); | 440 return builder.Create(registry); |
| 441 } | 441 } |
| 442 | 442 |
| 443 void GetStabilityMetrics(NavigationMetrics* metrics) { | 443 void GetStabilityMetrics(NavigationMetrics* metrics) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 464 local_state->GetInteger(prefs::kStabilityCrashCount); | 464 local_state->GetInteger(prefs::kStabilityCrashCount); |
| 465 metrics->renderer_crash_count = | 465 metrics->renderer_crash_count = |
| 466 local_state->GetInteger(prefs::kStabilityRendererCrashCount); | 466 local_state->GetInteger(prefs::kStabilityRendererCrashCount); |
| 467 // TODO(huanr) | 467 // TODO(huanr) |
| 468 metrics->plugin_crash_count = 0; | 468 metrics->plugin_crash_count = 0; |
| 469 | 469 |
| 470 if (!metrics->browser_clean_exit) | 470 if (!metrics->browser_clean_exit) |
| 471 metrics->browser_crash_count++; | 471 metrics->browser_crash_count++; |
| 472 } | 472 } |
| 473 | 473 |
| 474 FilePath GetSampleDataDir() { | 474 base::FilePath GetSampleDataDir() { |
| 475 FilePath test_dir; | 475 base::FilePath test_dir; |
| 476 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); | 476 PathService::Get(chrome::DIR_TEST_DATA, &test_dir); |
| 477 test_dir = test_dir.AppendASCII("reliability"); | 477 test_dir = test_dir.AppendASCII("reliability"); |
| 478 test_dir = test_dir.AppendASCII("sample_pages"); | 478 test_dir = test_dir.AppendASCII("sample_pages"); |
| 479 return test_dir; | 479 return test_dir; |
| 480 } | 480 } |
| 481 | 481 |
| 482 // The pathname of Chrome's crash dumps directory. | 482 // The pathname of Chrome's crash dumps directory. |
| 483 FilePath crash_dumps_dir_path_; | 483 base::FilePath crash_dumps_dir_path_; |
| 484 | 484 |
| 485 // The set of all the crash dumps we have seen. Each crash generates a | 485 // The set of all the crash dumps we have seen. Each crash generates a |
| 486 // .dmp and a .txt file in the crash dumps directory. We only store the | 486 // .dmp and a .txt file in the crash dumps directory. We only store the |
| 487 // .dmp files in this set. | 487 // .dmp files in this set. |
| 488 // | 488 // |
| 489 // The set is implemented as a std::map. The key is the file name, and | 489 // The set is implemented as a std::map. The key is the file name, and |
| 490 // the value is false (the file is not in the set) or true (the file is | 490 // the value is false (the file is not in the set) or true (the file is |
| 491 // in the set). The initial value for any key in std::map is 0 (false), | 491 // in the set). The initial value for any key in std::map is 0 (false), |
| 492 // which in this case means a new file is not in the set initially, | 492 // which in this case means a new file is not in the set initially, |
| 493 // exactly the semantics we want. | 493 // exactly the semantics we want. |
| 494 std::map<FilePath, bool> crash_dumps_; | 494 std::map<base::FilePath, bool> crash_dumps_; |
| 495 }; | 495 }; |
| 496 | 496 |
| 497 TEST_F(PageLoadTest, IEFullTabMode_Reliability) { | 497 TEST_F(PageLoadTest, IEFullTabMode_Reliability) { |
| 498 std::ofstream log_file; | 498 std::ofstream log_file; |
| 499 | 499 |
| 500 if (!g_log_file_path.empty()) { | 500 if (!g_log_file_path.empty()) { |
| 501 log_file.open(g_log_file_path.value().c_str()); | 501 log_file.open(g_log_file_path.value().c_str()); |
| 502 } | 502 } |
| 503 | 503 |
| 504 EXPECT_FALSE(g_url_file_path.empty()); | 504 EXPECT_FALSE(g_url_file_path.empty()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 if (parsed_command_line.HasSwitch(switches::kNoSandbox)) { | 582 if (parsed_command_line.HasSwitch(switches::kNoSandbox)) { |
| 583 PathService::Get(base::DIR_CURRENT, &g_v8_log_path); | 583 PathService::Get(base::DIR_CURRENT, &g_v8_log_path); |
| 584 g_v8_log_path = g_v8_log_path.AppendASCII(kV8LogFileDefaultName); | 584 g_v8_log_path = g_v8_log_path.AppendASCII(kV8LogFileDefaultName); |
| 585 // The command line switch may override the default v8 log path. | 585 // The command line switch may override the default v8 log path. |
| 586 if (parsed_command_line.HasSwitch(switches::kJavaScriptFlags)) { | 586 if (parsed_command_line.HasSwitch(switches::kJavaScriptFlags)) { |
| 587 CommandLine v8_command_line( | 587 CommandLine v8_command_line( |
| 588 parsed_command_line.GetSwitchValuePath(switches::kJavaScriptFlags)); | 588 parsed_command_line.GetSwitchValuePath(switches::kJavaScriptFlags)); |
| 589 if (v8_command_line.HasSwitch(kV8LogFileSwitch)) { | 589 if (v8_command_line.HasSwitch(kV8LogFileSwitch)) { |
| 590 g_v8_log_path = v8_command_line.GetSwitchValuePath(kV8LogFileSwitch); | 590 g_v8_log_path = v8_command_line.GetSwitchValuePath(kV8LogFileSwitch); |
| 591 if (!file_util::AbsolutePath(&g_v8_log_path)) | 591 if (!file_util::AbsolutePath(&g_v8_log_path)) |
| 592 g_v8_log_path = FilePath(); | 592 g_v8_log_path = base::FilePath(); |
| 593 } | 593 } |
| 594 } | 594 } |
| 595 } | 595 } |
| 596 } | 596 } |
| 597 } | 597 } |
| OLD | NEW |