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.
5 #include "base/files/file_path.h"
6 #include "base/prefs/pref_service.h"
7 #include "chrome/browser/extensions/component_loader.h"
8 #include "chrome/browser/extensions/error_console/error_console.h"
9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h"
14 #include "content/public/common/content_switches.h"
15 #include "extensions/common/extension.h"
16 #include "extensions/test/extension_test_message_listener.h"
17 #include "testing/gtest/include/gtest/gtest.h"
20 namespace extensions
{
22 static const char kHotwordHelperExtensionId
[] =
23 "dnhpdliibojhegemfjheidglijccjfmc";
25 class HotwordBrowserTest
: public ExtensionBrowserTest
{
27 HotwordBrowserTest() : error_console_(NULL
) { }
28 ~HotwordBrowserTest() override
{}
31 void SetUpInProcessBrowserTestFixture() override
{
32 ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
34 // Force the VoiceTrigger field trial on to enable the hotword_helper
36 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
37 switches::kForceFieldTrials
, "VoiceTrigger/Install/");
38 // Load the hotword_helper extension.
39 ComponentLoader::EnableBackgroundExtensionsForTesting();
41 // We need to enable the ErrorConsole FeatureSwitch in order to collect
42 // errors. This should be enabled on any channel <= Dev, but let's make
43 // sure (in case a test is running on, e.g., a beta channel).
44 FeatureSwitch::error_console()->SetOverrideValue(
45 FeatureSwitch::OVERRIDE_ENABLED
);
48 void SetUpOnMainThread() override
{
49 ExtensionBrowserTest::SetUpOnMainThread();
51 // Errors are only kept if we have Developer Mode enabled.
52 profile()->GetPrefs()->SetBoolean(prefs::kExtensionsUIDeveloperMode
, true);
54 error_console_
= ErrorConsole::Get(profile());
55 ASSERT_TRUE(error_console_
);
58 ErrorConsole
* error_console() { return error_console_
; }
61 // Weak reference to the ErrorConsole.
62 ErrorConsole
* error_console_
;
64 DISALLOW_COPY_AND_ASSIGN(HotwordBrowserTest
);
67 // Test we silently capture an exception from a message handler's response
68 // callback. This happens when the caller to chrome.runtime.sendMessage()
69 // doesn't specify a response callback.
70 // NOTE(amistry): Test is disabled instead of deleted since the functionality
71 // may still be required to implement crbug.com/436681
72 IN_PROC_BROWSER_TEST_F(HotwordBrowserTest
, DISABLED_MessageSendResponseError
) {
73 // Enable error reporting for the hotword helper extension.
74 error_console()->SetReportingAllForExtension(kHotwordHelperExtensionId
, true);
76 ExtensionTestMessageListener
doneListener("done", false);
77 const Extension
* extension
= extension_service()->GetExtensionById(
78 kHotwordHelperExtensionId
, false);
79 ASSERT_TRUE(extension
);
80 const Extension
* test_extension
= LoadExtension(
81 test_data_dir_
.AppendASCII("hotword"));
82 ASSERT_TRUE(test_extension
);
84 ASSERT_TRUE(doneListener
.WaitUntilSatisfied());
85 ASSERT_TRUE(error_console()->GetErrorsForExtension(extension
->id()).empty());
88 } // namespace extensions