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

Unified Diff: chrome/browser/extensions/api/messaging/native_messaging_apitest.cc

Issue 12285015: Require manifests for native messaging hosts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
diff --git a/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc b/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
index dd1723903759994af9a48209cacc92ebd247ff7c..74f704e4809f75e91385badbe6ce221f898ad0c7 100644
--- a/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
+++ b/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc
@@ -4,22 +4,60 @@
#include "base/command_line.h"
#include "base/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/json/json_file_value_serializer.h"
#include "base/path_service.h"
+#include "base/stringprintf.h"
#include "chrome/browser/extensions/extension_apitest.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/features/feature.h"
+namespace {
+
+const char kHostName[] = "com.google.chrome.test.echo";
+
+void CreateTestManifestFile(base::FilePath manifest_path) {
+ scoped_ptr<base::DictionaryValue> manifest(new base::DictionaryValue());
+ manifest->SetString("name", kHostName);
+ manifest->SetString("description", "Native Messaging Echo Test");
+ manifest->SetString("type", "stdio");
+
+ base::FilePath test_user_data_dir;
+ ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir));
+ test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging");
+#ifdef OS_POSIX
+ base::FilePath host_path = test_user_data_dir.AppendASCII("echo.py");
+#else
+ base::FilePath host_path = test_user_data_dir.AppendASCII("echo.bat");
+#endif
+ manifest->SetString("path", host_path.AsUTF8Unsafe());
+
+ scoped_ptr<base::ListValue> origins(new base::ListValue());
+ origins->AppendString("chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/");
+ manifest->Set("allowed_origins", origins.release());
+
+ JSONFileValueSerializer serializer(manifest_path);
+ ASSERT_TRUE(serializer.Serialize(*manifest));
+}
+
+} // namespace
+
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) {
+ base::ScopedTempDir temp_dir;
+ base::FilePath manifest_path =
+ temp_dir.path().AppendASCII(std::string(kHostName) + ".json");
+
+ ASSERT_NO_FATAL_FAILURE(CreateTestManifestFile(manifest_path));
+
CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kEnableNativeMessaging);
- // Override the user data dir to point to our native app.
- extensions::Feature::ScopedCurrentChannel
- current_channel(chrome::VersionInfo::CHANNEL_DEV);
- FilePath test_user_data_dir;
- ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir));
- test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging");
- ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, test_user_data_dir));
+
+ std::string hosts_option = base::StringPrintf(
+ "%s=%s", kHostName, manifest_path.AsUTF8Unsafe().c_str());
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kNativeMessagingHosts, hosts_option);
+
ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_;
}

Powered by Google App Engine
This is Rietveld 408576698