OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/extensions/error_console/error_console.h" | 5 #include "chrome/browser/extensions/error_console/error_console.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 waiting_(false), | 147 waiting_(false), |
148 error_console_(error_console) { | 148 error_console_(error_console) { |
149 error_console_->AddObserver(this); | 149 error_console_->AddObserver(this); |
150 } | 150 } |
151 virtual ~ErrorObserver() { | 151 virtual ~ErrorObserver() { |
152 if (error_console_) | 152 if (error_console_) |
153 error_console_->RemoveObserver(this); | 153 error_console_->RemoveObserver(this); |
154 } | 154 } |
155 | 155 |
156 // ErrorConsole::Observer implementation. | 156 // ErrorConsole::Observer implementation. |
157 virtual void OnErrorAdded(const ExtensionError* error) OVERRIDE { | 157 virtual void OnErrorAdded(const ExtensionError* error) override { |
158 ++errors_observed_; | 158 ++errors_observed_; |
159 if (errors_observed_ >= errors_expected_) { | 159 if (errors_observed_ >= errors_expected_) { |
160 if (waiting_) | 160 if (waiting_) |
161 base::MessageLoopForUI::current()->Quit(); | 161 base::MessageLoopForUI::current()->Quit(); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 virtual void OnErrorConsoleDestroyed() OVERRIDE { | 165 virtual void OnErrorConsoleDestroyed() override { |
166 error_console_ = NULL; | 166 error_console_ = NULL; |
167 } | 167 } |
168 | 168 |
169 // Spin until the appropriate number of errors have been observed. | 169 // Spin until the appropriate number of errors have been observed. |
170 void WaitForErrors() { | 170 void WaitForErrors() { |
171 if (errors_observed_ < errors_expected_) { | 171 if (errors_observed_ < errors_expected_) { |
172 waiting_ = true; | 172 waiting_ = true; |
173 content::RunMessageLoop(); | 173 content::RunMessageLoop(); |
174 waiting_ = false; | 174 waiting_ = false; |
175 } | 175 } |
(...skipping 16 matching lines...) Expand all Loading... |
192 ACTION_NAVIGATE, | 192 ACTION_NAVIGATE, |
193 // Simulate a browser action click. | 193 // Simulate a browser action click. |
194 ACTION_BROWSER_ACTION, | 194 ACTION_BROWSER_ACTION, |
195 // Navigate to the new tab page. | 195 // Navigate to the new tab page. |
196 ACTION_NEW_TAB, | 196 ACTION_NEW_TAB, |
197 // Do nothing (errors will be caused by a background script, | 197 // Do nothing (errors will be caused by a background script, |
198 // or by a manifest/loading warning). | 198 // or by a manifest/loading warning). |
199 ACTION_NONE | 199 ACTION_NONE |
200 }; | 200 }; |
201 | 201 |
202 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 202 virtual void SetUpInProcessBrowserTestFixture() override { |
203 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); | 203 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); |
204 | 204 |
205 // We need to enable the ErrorConsole FeatureSwitch in order to collect | 205 // We need to enable the ErrorConsole FeatureSwitch in order to collect |
206 // errors. This should be enabled on any channel <= Dev, but let's make | 206 // errors. This should be enabled on any channel <= Dev, but let's make |
207 // sure (in case a test is running on, e.g., a beta channel). | 207 // sure (in case a test is running on, e.g., a beta channel). |
208 FeatureSwitch::error_console()->SetOverrideValue( | 208 FeatureSwitch::error_console()->SetOverrideValue( |
209 FeatureSwitch::OVERRIDE_ENABLED); | 209 FeatureSwitch::OVERRIDE_ENABLED); |
210 } | 210 } |
211 | 211 |
212 virtual void SetUpOnMainThread() OVERRIDE { | 212 virtual void SetUpOnMainThread() override { |
213 ExtensionBrowserTest::SetUpOnMainThread(); | 213 ExtensionBrowserTest::SetUpOnMainThread(); |
214 | 214 |
215 // Errors are only kept if we have Developer Mode enabled. | 215 // Errors are only kept if we have Developer Mode enabled. |
216 profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true); | 216 profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true); |
217 | 217 |
218 error_console_ = ErrorConsole::Get(profile()); | 218 error_console_ = ErrorConsole::Get(profile()); |
219 CHECK(error_console_); | 219 CHECK(error_console_); |
220 | 220 |
221 test_data_dir_ = test_data_dir_.AppendASCII("error_console"); | 221 test_data_dir_ = test_data_dir_.AppendASCII("error_console"); |
222 } | 222 } |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 575 |
576 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); | 576 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); |
577 ASSERT_EQ(1u, stack_trace.size()); | 577 ASSERT_EQ(1u, stack_trace.size()); |
578 CheckStackFrame(stack_trace[0], | 578 CheckStackFrame(stack_trace[0], |
579 script_url, | 579 script_url, |
580 kAnonymousFunction, | 580 kAnonymousFunction, |
581 12u, 20u); | 581 12u, 20u); |
582 } | 582 } |
583 | 583 |
584 } // namespace extensions | 584 } // namespace extensions |
OLD | NEW |