| 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 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | 5 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/location.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 10 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/test_timeouts.h" | 13 #include "base/test/test_timeouts.h" |
| 14 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/task_manager/resource_provider.h" | 18 #include "chrome/browser/task_manager/resource_provider.h" |
| 17 #include "chrome/browser/task_manager/task_manager.h" | 19 #include "chrome/browser/task_manager/task_manager.h" |
| 18 #include "chrome/grit/generated_resources.h" | 20 #include "chrome/grit/generated_resources.h" |
| 19 #include "extensions/strings/grit/extensions_strings.h" | 21 #include "extensions/strings/grit/extensions_strings.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 22 | 24 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 73 } |
| 72 | 74 |
| 73 timer_.Stop(); | 75 timer_.Stop(); |
| 74 } | 76 } |
| 75 | 77 |
| 76 private: | 78 private: |
| 77 void OnResourceChange() { | 79 void OnResourceChange() { |
| 78 if (!IsSatisfied()) | 80 if (!IsSatisfied()) |
| 79 return; | 81 return; |
| 80 | 82 |
| 81 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop_.QuitClosure()); | 83 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 84 run_loop_.QuitClosure()); |
| 82 } | 85 } |
| 83 | 86 |
| 84 bool IsSatisfied() { return CountMatches() == required_count_; } | 87 bool IsSatisfied() { return CountMatches() == required_count_; } |
| 85 | 88 |
| 86 int CountMatches() { | 89 int CountMatches() { |
| 87 int match_count = 0; | 90 int match_count = 0; |
| 88 for (int i = 0; i < model_->ResourceCount(); i++) { | 91 for (int i = 0; i < model_->ResourceCount(); i++) { |
| 89 if (!MatchPattern(model_->GetResourceTitle(i), title_pattern_)) | 92 if (!MatchPattern(model_->GetResourceTitle(i), title_pattern_)) |
| 90 continue; | 93 continue; |
| 91 | 94 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return "V8 Memory"; | 129 return "V8 Memory"; |
| 127 case V8_MEMORY_USED: | 130 case V8_MEMORY_USED: |
| 128 return "V8 Memory Used"; | 131 return "V8 Memory Used"; |
| 129 case SQLITE_MEMORY_USED: | 132 case SQLITE_MEMORY_USED: |
| 130 return "SQLite Memory Used"; | 133 return "SQLite Memory Used"; |
| 131 } | 134 } |
| 132 return "N/A"; | 135 return "N/A"; |
| 133 } | 136 } |
| 134 | 137 |
| 135 void OnTimeout() { | 138 void OnTimeout() { |
| 136 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop_.QuitClosure()); | 139 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 140 run_loop_.QuitClosure()); |
| 137 FAIL() << "Timed out.\n" << DumpTaskManagerModel(); | 141 FAIL() << "Timed out.\n" << DumpTaskManagerModel(); |
| 138 } | 142 } |
| 139 | 143 |
| 140 testing::Message DumpTaskManagerModel() { | 144 testing::Message DumpTaskManagerModel() { |
| 141 testing::Message task_manager_state_dump; | 145 testing::Message task_manager_state_dump; |
| 142 task_manager_state_dump << "Waiting for exactly " << required_count_ | 146 task_manager_state_dump << "Waiting for exactly " << required_count_ |
| 143 << " matches of wildcard pattern \"" | 147 << " matches of wildcard pattern \"" |
| 144 << base::UTF16ToASCII(title_pattern_) << "\""; | 148 << base::UTF16ToASCII(title_pattern_) << "\""; |
| 145 if (min_column_value_ > 0) { | 149 if (min_column_value_ > 0) { |
| 146 task_manager_state_dump << " && [" << GetColumnName() | 150 task_manager_state_dump << " && [" << GetColumnName() |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 base::string16 MatchUtility(const base::string16& title) { | 258 base::string16 MatchUtility(const base::string16& title) { |
| 255 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX, title); | 259 return l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_UTILITY_PREFIX, title); |
| 256 } | 260 } |
| 257 | 261 |
| 258 base::string16 MatchAnyUtility() { | 262 base::string16 MatchAnyUtility() { |
| 259 return MatchUtility(base::ASCIIToUTF16("*")); | 263 return MatchUtility(base::ASCIIToUTF16("*")); |
| 260 } | 264 } |
| 261 | 265 |
| 262 } // namespace browsertest_util | 266 } // namespace browsertest_util |
| 263 } // namespace task_manager | 267 } // namespace task_manager |
| OLD | NEW |