Chromium Code Reviews| 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..f176d19e8b5765d3f143e1b39402dbb9dce4f029 |
| --- /dev/null |
| +++ b/chrome/browser/extensions/hotword_browsertest.cc |
| @@ -0,0 +1,92 @@ |
| +// 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/component_loader.h" |
| +#include "chrome/browser/extensions/error_console/error_console.h" |
| +#include "chrome/browser/extensions/extension_browsertest.h" |
| +#include "chrome/browser/extensions/extension_service.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 a special flag to enable the hotword_helper extension. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| + "force-fieldtrials", "VoiceTrigger/Install/"); |
|
asargent_no_longer_on_chrome
2014/09/24 19:19:59
nit: Are there constants either of these strings t
Anand Mistry (off Chromium)
2014/09/25 00:53:23
Yes for the first, no for the second.
|
| + // Load the hotword_helper extension. |
| + ComponentLoader::EnableBackgroundExtensionsForTesting(); |
| + |
| + // 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_); |
| + } |
| + |
| + 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_; } |
| + |
| + private: |
| + // Weak reference to the ErrorConsole. |
| + ErrorConsole* error_console_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(HotwordBrowserTest); |
| +}; |
| + |
| +// 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 = extension_service()->GetExtensionById( |
| + "dnhpdliibojhegemfjheidglijccjfmc", false); |
|
asargent_no_longer_on_chrome
2014/09/24 19:19:59
nit: use a constant to avoid the id string duplica
Anand Mistry (off Chromium)
2014/09/25 00:53:23
Done.
|
| + 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); |
|
asargent_no_longer_on_chrome
2014/09/24 19:19:59
In the past doing this sort of "sleep for a fixed
Anand Mistry (off Chromium)
2014/09/25 00:53:23
Done.
|
| + |
| + ASSERT_TRUE(error_console()->GetErrorsForExtension(extension->id()).empty()); |
| +} |
| + |
| +} // namespace extensions |