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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/files/file_path.h"
6 #include "base/path_service.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/extensions/error_console/error_console.h"
9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "extensions/common/extension.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16
17 namespace extensions {
18
19 class HotwordBrowserTest : public ExtensionBrowserTest {
20 public:
21 HotwordBrowserTest() : error_console_(NULL) { }
22 virtual ~HotwordBrowserTest() { }
23
24 protected:
25 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
26 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
27
28 // We need to enable the ErrorConsole FeatureSwitch in order to collect
29 // errors. This should be enabled on any channel <= Dev, but let's make
30 // sure (in case a test is running on, e.g., a beta channel).
31 FeatureSwitch::error_console()->SetOverrideValue(
32 FeatureSwitch::OVERRIDE_ENABLED);
33 }
34
35 virtual void SetUpOnMainThread() OVERRIDE {
36 ExtensionBrowserTest::SetUpOnMainThread();
37
38 // Errors are only kept if we have Developer Mode enabled.
39 profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
40
41 error_console_ = ErrorConsole::Get(profile());
42 ASSERT_TRUE(error_console_);
43
44 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT,
45 &component_extension_dir_));
46 component_extension_dir_ = component_extension_dir_
47 .AppendASCII("chrome")
48 .AppendASCII("browser")
49 .AppendASCII("resources");
50 }
51
52 void RunMessageLoopForMs(int ms) {
53 base::MessageLoop::current()->PostDelayedTask(
54 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
55 base::TimeDelta::FromMilliseconds(ms));
56 content::RunMessageLoop();
57 }
58
59 ErrorConsole* error_console() { return error_console_; }
60
61 const base::FilePath& component_extension_dir() const {
62 return component_extension_dir_;
63 }
64
65 private:
66 // Weak reference to the ErrorConsole.
67 ErrorConsole* error_console_;
68
69 // Base directory for component extensions.
70 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.
71 };
72
73 // Test we silently capture an exception from a message handler's response
74 // callback. This happens when the caller to chrome.runtime.sendMessage()
75 // doesn't specify a response callback.
76 IN_PROC_BROWSER_TEST_F(HotwordBrowserTest, MessageSendResponseError) {
77 // Enable error reporting for the hotword helper extension.
78 error_console()->SetReportingAllForExtension(
79 "dnhpdliibojhegemfjheidglijccjfmc",
80 true);
81
82 const Extension* extension = LoadExtensionAsComponent(
83 component_extension_dir().AppendASCII("hotword_helper"));
84 ASSERT_TRUE(extension);
85 const Extension* test_extension = LoadExtension(
86 test_data_dir_.AppendASCII("hotword"));
87 ASSERT_TRUE(test_extension);
88
89 // We're testing that an error doesn't happen. Since there's no event we can
90 // wait for, just sleep for a bit and check.
91 RunMessageLoopForMs(200);
92
93 ASSERT_TRUE(error_console()->GetErrorsForExtension(extension->id()).empty());
94 }
95
96 } // namespace extensions
OLDNEW
« 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