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

Unified Diff: chrome/browser/extensions/hotword_browsertest.cc

Issue 587153002: Suppress the exception thrown when responding to message with no response callback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/hotword_browsertest.cc
diff --git a/chrome/browser/extensions/hotword_browsertest.cc b/chrome/browser/extensions/hotword_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d6c0321c2dbe6563d4b56549e12b008863c6dbe3
--- /dev/null
+++ b/chrome/browser/extensions/hotword_browsertest.cc
@@ -0,0 +1,96 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/files/file_path.h"
+#include "base/path_service.h"
+#include "base/prefs/pref_service.h"
+#include "chrome/browser/extensions/error_console/error_console.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "extensions/common/extension.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+
+namespace extensions {
+
+class HotwordBrowserTest : public ExtensionBrowserTest {
+ public:
+ HotwordBrowserTest() : error_console_(NULL) { }
+ virtual ~HotwordBrowserTest() { }
+
+ protected:
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+ ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
+
+ // We need to enable the ErrorConsole FeatureSwitch in order to collect
+ // errors. This should be enabled on any channel <= Dev, but let's make
+ // sure (in case a test is running on, e.g., a beta channel).
+ FeatureSwitch::error_console()->SetOverrideValue(
+ FeatureSwitch::OVERRIDE_ENABLED);
+ }
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ ExtensionBrowserTest::SetUpOnMainThread();
+
+ // Errors are only kept if we have Developer Mode enabled.
+ profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
+
+ error_console_ = ErrorConsole::Get(profile());
+ ASSERT_TRUE(error_console_);
+
+ ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT,
+ &component_extension_dir_));
+ component_extension_dir_ = component_extension_dir_
+ .AppendASCII("chrome")
+ .AppendASCII("browser")
+ .AppendASCII("resources");
+ }
+
+ void RunMessageLoopForMs(int ms) {
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
+ base::TimeDelta::FromMilliseconds(ms));
+ content::RunMessageLoop();
+ }
+
+ ErrorConsole* error_console() { return error_console_; }
+
+ const base::FilePath& component_extension_dir() const {
+ return component_extension_dir_;
+ }
+
+ private:
+ // Weak reference to the ErrorConsole.
+ ErrorConsole* error_console_;
+
+ // Base directory for component extensions.
+ base::FilePath component_extension_dir_;
Dan Beam 2014/09/24 04:58:27 nit: DISALLOW_COPY_AND_ASSIGN()
Anand Mistry (off Chromium) 2014/09/24 06:32:40 Done.
+};
+
+// Test we silently capture an exception from a message handler's response
+// callback. This happens when the caller to chrome.runtime.sendMessage()
+// doesn't specify a response callback.
+IN_PROC_BROWSER_TEST_F(HotwordBrowserTest, MessageSendResponseError) {
+ // Enable error reporting for the hotword helper extension.
+ error_console()->SetReportingAllForExtension(
+ "dnhpdliibojhegemfjheidglijccjfmc",
+ true);
+
+ const Extension* extension = LoadExtensionAsComponent(
+ component_extension_dir().AppendASCII("hotword_helper"));
+ ASSERT_TRUE(extension);
+ const Extension* test_extension = LoadExtension(
+ test_data_dir_.AppendASCII("hotword"));
+ ASSERT_TRUE(test_extension);
+
+ // We're testing that an error doesn't happen. Since there's no event we can
+ // wait for, just sleep for a bit and check.
+ RunMessageLoopForMs(200);
+
+ ASSERT_TRUE(error_console()->GetErrorsForExtension(extension->id()).empty());
+}
+
+} // namespace extensions
« no previous file with comments | « no previous file | chrome/browser/resources/hotword_helper/manager.js » ('j') | chrome/browser/resources/hotword_helper/manager.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698