Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/json/json_file_value_serializer.h" | |
| 7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/stringprintf.h" | |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/common/chrome_paths.h" | 11 #include "chrome/common/chrome_paths.h" |
| 10 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
| 12 #include "chrome/common/extensions/features/feature.h" | 14 #include "chrome/common/extensions/features/feature.h" |
| 13 | 15 |
| 14 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) { | 16 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) { |
| 15 CommandLine::ForCurrentProcess()->AppendSwitch( | 17 const char kHostName[] = "com.google.chrome.test.echo"; |
| 16 switches::kEnableNativeMessaging); | 18 |
| 17 // Override the user data dir to point to our native app. | 19 base::ScopedTempDir temp_dir; |
| 18 extensions::Feature::ScopedCurrentChannel | 20 FilePath manifest_path = |
| 19 current_channel(chrome::VersionInfo::CHANNEL_DEV); | 21 temp_dir.path().AppendASCII(std::string(kHostName) + ".json"); |
| 22 | |
| 23 scoped_ptr<base::DictionaryValue> manifest(new base::DictionaryValue()); | |
| 24 manifest->SetString("name", kHostName); | |
| 25 manifest->SetString("description", "Native Messaging Echo Test"); | |
| 26 manifest->SetString("type", "stdio"); | |
| 27 | |
| 20 FilePath test_user_data_dir; | 28 FilePath test_user_data_dir; |
| 21 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir)); | 29 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir)); |
| 22 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging"); | 30 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging"); |
| 23 ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, test_user_data_dir)); | 31 #ifdef OS_POSIX |
| 32 FilePath host_path = test_user_data_dir.AppendASCII("echo.py"); | |
| 33 #else | |
| 34 FilePath host_path = test_user_data_dir.AppendASCII("echo.bat"); | |
| 35 #endif | |
| 36 manifest->SetString("path", host_path.AsUTF8Unsafe()); | |
| 37 | |
| 38 scoped_ptr<base::ListValue> origins(new base::ListValue()); | |
| 39 origins->AppendString("knldjmfmopnpolahpmmgbagdohdnhkik"); | |
| 40 manifest->Set("allowed_origins", origins.release()); | |
| 41 | |
| 42 JSONFileValueSerializer serializer(manifest_path); | |
| 43 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.
| |
| 44 | |
| 45 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 46 switches::kEnableNativeMessaging); | |
| 47 | |
| 48 std::string hosts_option = base::StringPrintf( | |
| 49 "%s=%s", kHostName, manifest_path.AsUTF8Unsafe().c_str()); | |
| 50 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
| 51 switches::kNativeMessagingHosts, hosts_option); | |
| 52 | |
| 24 ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_; | 53 ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_; |
| 25 } | 54 } |
| OLD | NEW |