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

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: Fix typo. Created 6 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/resources/hotword_helper/manager.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/component_loader.h"
9 #include "chrome/browser/extensions/error_console/error_console.h"
10 #include "chrome/browser/extensions/extension_browsertest.h"
11 #include "chrome/browser/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/common/content_switches.h"
16 #include "extensions/common/extension.h"
17 #include "extensions/test/extension_test_message_listener.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20
21 namespace extensions {
22
23 static const char* kHotwordHelperExtensionId =
24 "dnhpdliibojhegemfjheidglijccjfmc";
25
26 class HotwordBrowserTest : public ExtensionBrowserTest {
27 public:
28 HotwordBrowserTest() : error_console_(NULL) { }
29 virtual ~HotwordBrowserTest() { }
30
31 protected:
32 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
33 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
34
35 // Force the VoiceTrigger field trial on to enable the hotword_helper
36 // extension.
37 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
38 switches::kForceFieldTrials, "VoiceTrigger/Install/");
39 // Load the hotword_helper extension.
40 ComponentLoader::EnableBackgroundExtensionsForTesting();
41
42 // We need to enable the ErrorConsole FeatureSwitch in order to collect
43 // errors. This should be enabled on any channel <= Dev, but let's make
44 // sure (in case a test is running on, e.g., a beta channel).
45 FeatureSwitch::error_console()->SetOverrideValue(
46 FeatureSwitch::OVERRIDE_ENABLED);
47 }
48
49 virtual void SetUpOnMainThread() OVERRIDE {
50 ExtensionBrowserTest::SetUpOnMainThread();
51
52 // Errors are only kept if we have Developer Mode enabled.
53 profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode, true);
54
55 error_console_ = ErrorConsole::Get(profile());
56 ASSERT_TRUE(error_console_);
57 }
58
59 ErrorConsole* error_console() { return error_console_; }
60
61 private:
62 // Weak reference to the ErrorConsole.
63 ErrorConsole* error_console_;
64
65 DISALLOW_COPY_AND_ASSIGN(HotwordBrowserTest);
66 };
67
68 // Test we silently capture an exception from a message handler's response
69 // callback. This happens when the caller to chrome.runtime.sendMessage()
70 // doesn't specify a response callback.
71 IN_PROC_BROWSER_TEST_F(HotwordBrowserTest, MessageSendResponseError) {
72 // Enable error reporting for the hotword helper extension.
73 error_console()->SetReportingAllForExtension(kHotwordHelperExtensionId, true);
74
75 ExtensionTestMessageListener doneListener("done", false);
76 const Extension* extension = extension_service()->GetExtensionById(
77 kHotwordHelperExtensionId, false);
78 ASSERT_TRUE(extension);
79 const Extension* test_extension = LoadExtension(
80 test_data_dir_.AppendASCII("hotword"));
81 ASSERT_TRUE(test_extension);
82
83 ASSERT_TRUE(doneListener.WaitUntilSatisfied());
84 ASSERT_TRUE(error_console()->GetErrorsForExtension(extension->id()).empty());
85 }
86
87 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/hotword_helper/manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698