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

Side by Side Diff: chrome/browser/extensions/error_console/error_console_browsertest.cc

Issue 133003003: Make ErrorConsole catch errors from Extension WebContents Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
OLDNEW
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"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/extensions/extension_browsertest.h" 12 #include "chrome/browser/extensions/extension_browsertest.h"
13 #include "chrome/browser/extensions/extension_toolbar_model.h" 13 #include "chrome/browser/extensions/extension_toolbar_model.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
17 #include "extensions/browser/extension_error.h" 18 #include "extensions/browser/extension_error.h"
18 #include "extensions/common/constants.h" 19 #include "extensions/common/constants.h"
19 #include "extensions/common/error_utils.h" 20 #include "extensions/common/error_utils.h"
20 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
21 #include "extensions/common/extension_urls.h" 22 #include "extensions/common/extension_urls.h"
22 #include "extensions/common/feature_switch.h" 23 #include "extensions/common/feature_switch.h"
23 #include "extensions/common/manifest_constants.h" 24 #include "extensions/common/manifest_constants.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h" 25 #include "net/test/embedded_test_server/embedded_test_server.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 bool waiting_; 181 bool waiting_;
181 182
182 ErrorConsole* error_console_; 183 ErrorConsole* error_console_;
183 184
184 DISALLOW_COPY_AND_ASSIGN(ErrorObserver); 185 DISALLOW_COPY_AND_ASSIGN(ErrorObserver);
185 }; 186 };
186 187
187 // The type of action which we take after we load an extension in order to 188 // The type of action which we take after we load an extension in order to
188 // cause any errors. 189 // cause any errors.
189 enum Action { 190 enum Action {
190 ACTION_NAVIGATE, // navigate to a page to allow a content script to run. 191 // Navigate to a (non-chrome) page to allow a content script to run.
191 ACTION_BROWSER_ACTION, // simulate a browser action click. 192 ACTION_NAVIGATE,
192 ACTION_NONE // Do nothing (errors will be caused by a background script, 193 // Simulate a browser action click.
193 // or by a manifest/loading warning). 194 ACTION_BROWSER_ACTION,
195 // Navigate to the new tab page.
196 ACTION_NEW_TAB,
Yoyo Zhou 2014/01/22 01:38:19 I think this is ok, but in the future we might wan
Devlin 2014/01/22 01:58:10 Yeah, I was wondering the same thing. I think, fo
197 // Do nothing (errors will be caused by a background script,
198 // or by a manifest/loading warning).
199 ACTION_NONE
194 }; 200 };
195 201
196 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { 202 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
197 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture(); 203 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
198 204
199 // We need to enable the ErrorConsole FeatureSwitch in order to collect 205 // We need to enable the ErrorConsole FeatureSwitch in order to collect
200 // errors. 206 // errors.
201 FeatureSwitch::error_console()->SetOverrideValue( 207 FeatureSwitch::error_console()->SetOverrideValue(
202 FeatureSwitch::OVERRIDE_ENABLED); 208 FeatureSwitch::OVERRIDE_ENABLED);
203 } 209 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 switch (action) { 245 switch (action) {
240 case ACTION_NAVIGATE: { 246 case ACTION_NAVIGATE: {
241 ui_test_utils::NavigateToURL(browser(), GetTestURL()); 247 ui_test_utils::NavigateToURL(browser(), GetTestURL());
242 break; 248 break;
243 } 249 }
244 case ACTION_BROWSER_ACTION: { 250 case ACTION_BROWSER_ACTION: {
245 ExtensionToolbarModel::Get(profile())->ExecuteBrowserAction( 251 ExtensionToolbarModel::Get(profile())->ExecuteBrowserAction(
246 *extension, browser(), NULL, true); 252 *extension, browser(), NULL, true);
247 break; 253 break;
248 } 254 }
255 case ACTION_NEW_TAB: {
256 ui_test_utils::NavigateToURL(browser(),
257 GURL(chrome::kChromeUINewTabURL));
258 break;
259 }
249 case ACTION_NONE: 260 case ACTION_NONE:
250 break; 261 break;
251 default: 262 default:
252 NOTREACHED(); 263 NOTREACHED();
253 } 264 }
254 265
255 observer.WaitForErrors(); 266 observer.WaitForErrors();
256 267
257 // We should only have errors for a single extension, or should have no 268 // We should only have errors for a single extension, or should have no
258 // entries, if no errors were expected. 269 // entries, if no errors were expected.
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 1u); 524 1u);
514 525
515 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]); 526 const StackTrace& stack_trace = GetStackTraceFromError(errors[0]);
516 ASSERT_EQ(1u, stack_trace.size()); 527 ASSERT_EQ(1u, stack_trace.size());
517 CheckStackFrame(stack_trace[0], 528 CheckStackFrame(stack_trace[0],
518 script_url, 529 script_url,
519 kAnonymousFunction, 530 kAnonymousFunction,
520 5u, 1u); 531 5u, 1u);
521 } 532 }
522 533
534 IN_PROC_BROWSER_TEST_F(ErrorConsoleBrowserTest, BadExtensionPage) {
535 const Extension* extension = NULL;
536 LoadExtensionAndCheckErrors(
537 "bad_extension_page",
538 kNoFlags,
539 1, // One error: the page will load JS which has a reference error.
540 ACTION_NEW_TAB,
541 &extension);
542 }
543
523 } // namespace extensions 544 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698