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..fef3b4085362cbc5a67315f7a5cffaa5e47c8a36 100644 |
--- a/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc |
+++ b/chrome/browser/extensions/api/messaging/native_messaging_apitest.cc |
@@ -4,7 +4,9 @@ |
#include "base/command_line.h" |
#include "base/file_path.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" |
@@ -12,14 +14,41 @@ |
#include "chrome/common/extensions/features/feature.h" |
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) { |
- 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); |
+ const char kHostName[] = "com.google.chrome.test.echo"; |
+ |
+ base::ScopedTempDir temp_dir; |
+ FilePath manifest_path = |
+ temp_dir.path().AppendASCII(std::string(kHostName) + ".json"); |
+ |
+ scoped_ptr<base::DictionaryValue> manifest(new base::DictionaryValue()); |
+ manifest->SetString("name", kHostName); |
+ manifest->SetString("description", "Native Messaging Echo Test"); |
+ manifest->SetString("type", "stdio"); |
+ |
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)); |
+#ifdef OS_POSIX |
+ FilePath host_path = test_user_data_dir.AppendASCII("echo.py"); |
+#else |
+ 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("knldjmfmopnpolahpmmgbagdohdnhkik"); |
+ manifest->Set("allowed_origins", origins.release()); |
+ |
+ JSONFileValueSerializer serializer(manifest_path); |
+ ASSERT_TRUE(serializer.Serialize(*manifest)); |
Matt Perry
2013/02/16 02:00:51
nit: maybe move all this to a helper function
Sergey Ulanov
2013/02/20 00:05:36
Done.
|
+ |
+ CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableNativeMessaging); |
+ |
+ 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_; |
} |