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

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

Issue 12386018: Revert 185189. (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"
8 #include "base/json/json_file_value_serializer.h"
9 #include "base/path_service.h" 7 #include "base/path_service.h"
10 #include "base/stringprintf.h"
11 #include "chrome/browser/extensions/extension_apitest.h" 8 #include "chrome/browser/extensions/extension_apitest.h"
12 #include "chrome/common/chrome_paths.h" 9 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/chrome_version_info.h" 11 #include "chrome/common/chrome_version_info.h"
15 #include "chrome/common/extensions/features/feature.h" 12 #include "chrome/common/extensions/features/feature.h"
16 13
17 namespace { 14 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, NativeMessageBasic) {
18 15 CommandLine::ForCurrentProcess()->AppendSwitch(
19 const char kHostName[] = "com.google.chrome.test.echo"; 16 switches::kEnableNativeMessaging);
20 17 // Override the user data dir to point to our native app.
21 void CreateTestManifestFile(base::FilePath manifest_path) { 18 extensions::Feature::ScopedCurrentChannel
22 scoped_ptr<base::DictionaryValue> manifest(new base::DictionaryValue()); 19 current_channel(chrome::VersionInfo::CHANNEL_DEV);
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; 20 base::FilePath test_user_data_dir;
28 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir)); 21 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_user_data_dir));
29 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging"); 22 test_user_data_dir = test_user_data_dir.AppendASCII("native_messaging");
30 test_user_data_dir = test_user_data_dir.AppendASCII("native_hosts"); 23 ASSERT_TRUE(PathService::Override(chrome::DIR_USER_DATA, test_user_data_dir));
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) {
49 base::ScopedTempDir temp_dir;
50 base::FilePath manifest_path =
51 temp_dir.path().AppendASCII(std::string(kHostName) + ".json");
52
53 ASSERT_NO_FATAL_FAILURE(CreateTestManifestFile(manifest_path));
54
55 CommandLine::ForCurrentProcess()->AppendSwitch(
56 switches::kEnableNativeMessaging);
57
58 std::string hosts_option = base::StringPrintf(
59 "%s=%s", kHostName, manifest_path.AsUTF8Unsafe().c_str());
60 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
61 switches::kNativeMessagingHosts, hosts_option);
62
63 ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_; 24 ASSERT_TRUE(RunExtensionTest("native_messaging")) << message_;
64 } 25 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698