summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 20:08:51 +0000
committeryoz@chromium.org <yoz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-09 20:08:51 +0000
commit0a724b214d8c644bf65fd86a45447f6a868c05c5 (patch)
treeebdfb74c4ff93edc8ced221baf74c1f53a408965
parent772baef77e74bc7bd50f6380dee2283839d7351a (diff)
downloadchromium_src-0a724b214d8c644bf65fd86a45447f6a868c05c5.zip
chromium_src-0a724b214d8c644bf65fd86a45447f6a868c05c5.tar.gz
chromium_src-0a724b214d8c644bf65fd86a45447f6a868c05c5.tar.bz2
Make chrome.test functions only accessible to tests.
BUG=103867 TEST=Inspect an extension and try to call chrome.test functions; they should fail. Review URL: http://codereview.chromium.org/9124027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116904 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/extension_test_api.cc18
-rw-r--r--chrome/browser/extensions/extension_test_api.h21
2 files changed, 32 insertions, 7 deletions
diff --git a/chrome/browser/extensions/extension_test_api.cc b/chrome/browser/extensions/extension_test_api.cc
index a8f85fc..2991708 100644
--- a/chrome/browser/extensions/extension_test_api.cc
+++ b/chrome/browser/extensions/extension_test_api.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -6,6 +6,7 @@
#include <string>
+#include "base/command_line.h"
#include "base/memory/singleton.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_function_dispatcher.h"
@@ -13,6 +14,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/chrome_switches.h"
#include "content/public/browser/notification_service.h"
namespace {
@@ -23,8 +25,22 @@ namespace {
// in test set up.
const char kNoTestConfigDataError[] = "Test configuration was not set.";
+const char kNotTestProcessError[] =
+ "The chrome.test namespace is only available in tests.";
+
} // namespace
+TestExtensionFunction::~TestExtensionFunction() {}
+
+void TestExtensionFunction::Run() {
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kTestType)) {
+ error_ = kNotTestProcessError;
+ SendResponse(false);
+ return;
+ }
+ SendResponse(RunImpl());
+}
+
ExtensionTestPassFunction::~ExtensionTestPassFunction() {}
bool ExtensionTestPassFunction::RunImpl() {
diff --git a/chrome/browser/extensions/extension_test_api.h b/chrome/browser/extensions/extension_test_api.h
index cdae81c..6b653a9 100644
--- a/chrome/browser/extensions/extension_test_api.h
+++ b/chrome/browser/extensions/extension_test_api.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 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.
@@ -11,31 +11,40 @@
template <typename T> struct DefaultSingletonTraits;
-class ExtensionTestPassFunction : public SyncExtensionFunction {
+// A function that is only available in tests.
+// Prior to running, checks that we are in an extension process.
+class TestExtensionFunction : public SyncExtensionFunction {
+ public:
+ virtual ~TestExtensionFunction();
+
+ virtual void Run() OVERRIDE;
+};
+
+class ExtensionTestPassFunction : public TestExtensionFunction {
virtual ~ExtensionTestPassFunction();
virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("test.notifyPass")
};
-class ExtensionTestFailFunction : public SyncExtensionFunction {
+class ExtensionTestFailFunction : public TestExtensionFunction {
virtual ~ExtensionTestFailFunction();
virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("test.notifyFail")
};
-class ExtensionTestLogFunction : public SyncExtensionFunction {
+class ExtensionTestLogFunction : public TestExtensionFunction {
virtual ~ExtensionTestLogFunction();
virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("test.log")
};
-class ExtensionTestQuotaResetFunction : public SyncExtensionFunction {
+class ExtensionTestQuotaResetFunction : public TestExtensionFunction {
virtual ~ExtensionTestQuotaResetFunction();
virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("test.resetQuota")
};
-class ExtensionTestCreateIncognitoTabFunction : public SyncExtensionFunction {
+class ExtensionTestCreateIncognitoTabFunction : public TestExtensionFunction {
virtual ~ExtensionTestCreateIncognitoTabFunction();
virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("test.createIncognitoTab")