summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/extensions/hotword_browsertest.cc87
-rw-r--r--chrome/browser/resources/hotword_helper/manager.js45
-rw-r--r--chrome/browser/resources/hotword_helper/manifest.json4
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/test/data/extensions/hotword/manifest.json11
-rw-r--r--chrome/test/data/extensions/hotword/test.js17
6 files changed, 152 insertions, 13 deletions
diff --git a/chrome/browser/extensions/hotword_browsertest.cc b/chrome/browser/extensions/hotword_browsertest.cc
new file mode 100644
index 0000000..e26a736
--- /dev/null
+++ b/chrome/browser/extensions/hotword_browsertest.cc
@@ -0,0 +1,87 @@
+// 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 "content/public/common/content_switches.h"
+#include "extensions/common/extension.h"
+#include "extensions/test/extension_test_message_listener.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+
+namespace extensions {
+
+static const char* kHotwordHelperExtensionId =
+ "dnhpdliibojhegemfjheidglijccjfmc";
+
+class HotwordBrowserTest : public ExtensionBrowserTest {
+ public:
+ HotwordBrowserTest() : error_console_(NULL) { }
+ virtual ~HotwordBrowserTest() { }
+
+ protected:
+ virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
+ ExtensionBrowserTest::SetUpInProcessBrowserTestFixture();
+
+ // Force the VoiceTrigger field trial on to enable the hotword_helper
+ // extension.
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kForceFieldTrials, "VoiceTrigger/Install/");
+ // 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_);
+ }
+
+ 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(kHotwordHelperExtensionId, true);
+
+ ExtensionTestMessageListener doneListener("done", false);
+ const Extension* extension = extension_service()->GetExtensionById(
+ kHotwordHelperExtensionId, false);
+ ASSERT_TRUE(extension);
+ const Extension* test_extension = LoadExtension(
+ test_data_dir_.AppendASCII("hotword"));
+ ASSERT_TRUE(test_extension);
+
+ ASSERT_TRUE(doneListener.WaitUntilSatisfied());
+ ASSERT_TRUE(error_console()->GetErrorsForExtension(extension->id()).empty());
+}
+
+} // namespace extensions
diff --git a/chrome/browser/resources/hotword_helper/manager.js b/chrome/browser/resources/hotword_helper/manager.js
index 4ce86db..edaecae 100644
--- a/chrome/browser/resources/hotword_helper/manager.js
+++ b/chrome/browser/resources/hotword_helper/manager.js
@@ -32,6 +32,14 @@ OptInManager.HOTWORD_EXTENSION_ID_ = 'bepbmhgboaologfdajaanbcjmnhjmhfn';
/**
+ * Test extension ID.
+ * @const {string}
+ * @private
+ */
+OptInManager.TEST_EXTENSION_ID_ = 'cpfhkdbjfdgdebcjlifoldbijinjfifp';
+
+
+/**
* Commands sent from the page to this content script.
* @enum {string}
*/
@@ -58,19 +66,27 @@ OptInManager.CommandFromPage = {
*/
OptInManager.prototype.injectTab_ = function(
tab, sendResponse, hotwordStatus) {
- if (tab.incognito || !hotwordStatus.available) {
- sendResponse({'doNotShowOptinMessage': true});
- return;
- }
+ var response = {'doNotShowOptinMessage': true};
- if (!hotwordStatus.enabledSet) {
- sendResponse(hotwordStatus);
- return;
+ if (!tab.incognito && hotwordStatus.available) {
+ if (!hotwordStatus.enabledSet)
+ response = hotwordStatus;
+ else if (hotwordStatus.enabled)
+ chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'});
}
- if (hotwordStatus.enabled)
- chrome.tabs.executeScript(tab.id, {'file': 'audio_client.js'});
- sendResponse({'doNotShowOptinMessage': true});
+ try {
+ sendResponse(response);
+ } catch (err) {
+ // Suppress the exception thrown by sendResponse() when the page doesn't
+ // specify a response callback in the call to chrome.runtime.sendMessage().
+ // Unfortunately, there doesn't appear to be a way to detect one-way
+ // messages without explicitly saying in the message itself. This message
+ // is defined as a constant in extensions/renderer/messaging_bindings.cc
+ if (err.message == 'Attempting to use a disconnected port object')
+ return;
+ throw err;
+ }
};
@@ -88,11 +104,14 @@ OptInManager.prototype.handleMessage_ = function(
switch (request.type) {
case OptInManager.CommandFromPage.PAGE_WAKEUP:
if (((sender.tab && this.isEligibleUrl(sender.tab.url)) ||
- sender.id == OptInManager.HOTWORD_EXTENSION_ID_) &&
+ sender.id == OptInManager.HOTWORD_EXTENSION_ID_ ||
+ sender.id == OptInManager.TEST_EXTENSION_ID_) &&
chrome.hotwordPrivate && chrome.hotwordPrivate.getStatus) {
chrome.hotwordPrivate.getStatus(
- this.injectTab_.bind(this, request.tab || sender.tab,
- sendResponse));
+ this.injectTab_.bind(
+ this,
+ request.tab || sender.tab || {incognito: true},
+ sendResponse));
return true;
}
break;
diff --git a/chrome/browser/resources/hotword_helper/manifest.json b/chrome/browser/resources/hotword_helper/manifest.json
index 889cf30..9439be3 100644
--- a/chrome/browser/resources/hotword_helper/manifest.json
+++ b/chrome/browser/resources/hotword_helper/manifest.json
@@ -30,6 +30,10 @@
"*://*.google.fr/*",
"*://*.google.de/*",
"chrome://newtab/"
+ ],
+ "ids": [
+ // Test extension.
+ "cpfhkdbjfdgdebcjlifoldbijinjfifp"
]
},
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index bd9fd90..ae75ecd 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -1244,6 +1244,7 @@
'browser/extensions/extension_websocket_apitest.cc',
'browser/extensions/extension_webui_apitest.cc',
'browser/extensions/gpu_browsertest.cc',
+ 'browser/extensions/hotword_browsertest.cc',
'browser/extensions/isolated_app_browsertest.cc',
'browser/extensions/lazy_background_page_apitest.cc',
'browser/extensions/lazy_background_page_test_util.h',
diff --git a/chrome/test/data/extensions/hotword/manifest.json b/chrome/test/data/extensions/hotword/manifest.json
new file mode 100644
index 0000000..c99d6f1
--- /dev/null
+++ b/chrome/test/data/extensions/hotword/manifest.json
@@ -0,0 +1,11 @@
+{
+ // chrome-extension://cpfhkdbjfdgdebcjlifoldbijinjfifp/
+ "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCXAxIB5iu+XGtMYYJgSwMrqO+zNa3FlWeMJLOV+U1T2VL6wDU3WD9YNlioI6a6wG49AFquEbRxQwwxlvAZC1c95LBvRlnQAkEVum0KbrJ8WHTxxDEPOfITE0J1AP5j8V0WQ9jbYvUxgefIPhDPXHpdPRAxDotygTrPa33x1075wIDAQAB",
+ "name": "Hotword Helper Test Extension",
+ "version": "0.1",
+ "manifest_version": 2,
+ "description": "Browser test for hotword helper extension",
+ "background" : {
+ "scripts": ["test.js"]
+ }
+}
diff --git a/chrome/test/data/extensions/hotword/test.js b/chrome/test/data/extensions/hotword/test.js
new file mode 100644
index 0000000..51a8c80
--- /dev/null
+++ b/chrome/test/data/extensions/hotword/test.js
@@ -0,0 +1,17 @@
+// 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.
+
+// Send a WAKE_UP command to the hotword helper extension.
+chrome.runtime.sendMessage(
+ 'dnhpdliibojhegemfjheidglijccjfmc',
+ {type: 'wu'});
+
+// Assume messages are delivered in-order. In this case, this message will be
+// handled after the previous one, and indicates the test case has completed.
+chrome.runtime.sendMessage(
+ 'dnhpdliibojhegemfjheidglijccjfmc',
+ {type: 'wu'},
+ function() {
+ chrome.test.sendMessage("done");
+ });