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

Side by Side Diff: chrome/browser/extensions/api/messaging/native_messaging_apitest.cc

Issue 12374054: Update and enable NativeMessagingTest.EchoConnect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/json/json_file_value_serializer.h"
9 #include "base/path_service.h"
10 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/extensions/api/messaging/native_messaging_test_util.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/chrome_version_info.h" 12 #include "chrome/common/chrome_version_info.h"
15 #include "chrome/common/extensions/features/feature.h" 13 #include "chrome/common/extensions/features/feature.h"
16 14
17 namespace {
18
19 const char kHostName[] = "com.google.chrome.test.echo";
20
21 void CreateTestManifestFile(base::FilePath manifest_path) {
22 scoped_ptr<base::DictionaryValue> manifest(new base::DictionaryValue());
23 manifest->SetString("name", kHostName);
24 manifest->SetString("description", "Native Messaging Echo Test");
25 manifest->SetString("type", "stdio");
26
27 base::FilePath test_user_data_dir;
28 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir));
29 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging");
30 test_user_data_dir = test_user_data_dir.AppendASCII("native_hosts");
31 #ifdef OS_POSIX
32 base::FilePath host_path = test_user_data_dir.AppendASCII("echo.py");
33 #else
34 base::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("chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/");
40 manifest->Set("allowed_origins", origins.release());
41
42 JSONFileValueSerializer serializer(manifest_path);
43 ASSERT_TRUE(serializer.Serialize(*manifest));
44 }
45
46 } // namespace
47
48 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) { 15 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) {
49 base::ScopedTempDir temp_dir; 16 base::ScopedTempDir temp_dir;
50 base::FilePath manifest_path = 17 base::FilePath manifest_path = temp_dir.path().AppendASCII(
51 temp_dir.path().AppendASCII(std::string(kHostName) + ".json"); 18 std::string(extensions::kTestNativeMessagingHostName) + ".json");
52 19 ASSERT_NO_FATAL_FAILURE(
53 ASSERT_NO_FATAL_FAILURE(CreateTestManifestFile(manifest_path)); 20 extensions::CreateTestNativeHostManifest(manifest_path));
54 21
55 CommandLine::ForCurrentProcess()->AppendSwitch( 22 CommandLine::ForCurrentProcess()->AppendSwitch(
56 switches::kEnableNativeMessaging); 23 switches::kEnableNativeMessaging);
57 24
58 std::string hosts_option = base::StringPrintf( 25 std::string hosts_option = base::StringPrintf(
59 "%s=%s", kHostName, manifest_path.AsUTF8Unsafe().c_str()); 26 "%s=%s", extensions::kTestNativeMessagingHostName,
27 manifest_path.AsUTF8Unsafe().c_str());
60 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 28 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
61 switches::kNativeMessagingHosts, hosts_option); 29 switches::kNativeMessagingHosts, hosts_option);
62 30
63 ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_; 31 ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_;
64 } 32 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698