| OLD | NEW | 
|    1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2013 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 "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
     .h" |    5 #include "chrome/browser/extensions/api/messaging/native_messaging_host_manifest
     .h" | 
|    6  |    6  | 
|    7 #include "base/files/file_path.h" |    7 #include "base/files/file_path.h" | 
|    8 #include "base/files/file_util.h" |    8 #include "base/files/file_util.h" | 
|    9 #include "base/files/scoped_temp_dir.h" |    9 #include "base/files/scoped_temp_dir.h" | 
|   10 #include "base/json/string_escape.h" |   10 #include "base/json/string_escape.h" | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   67   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a..b")); |   67   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a..b")); | 
|   68   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName(".a")); |   68   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName(".a")); | 
|   69   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("b.")); |   69   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("b.")); | 
|   70   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a*")); |   70   EXPECT_FALSE(NativeMessagingHostManifest::IsValidName("a*")); | 
|   71 } |   71 } | 
|   72  |   72  | 
|   73 TEST_F(NativeMessagingHostManifestTest, LoadValid) { |   73 TEST_F(NativeMessagingHostManifestTest, LoadValid) { | 
|   74   ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, kTestOrigin)); |   74   ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, kTestOrigin)); | 
|   75  |   75  | 
|   76   std::string error_message; |   76   std::string error_message; | 
|   77   scoped_ptr<NativeMessagingHostManifest> manifest = |   77   std::unique_ptr<NativeMessagingHostManifest> manifest = | 
|   78       NativeMessagingHostManifest::Load(manifest_path_, &error_message); |   78       NativeMessagingHostManifest::Load(manifest_path_, &error_message); | 
|   79   ASSERT_TRUE(manifest) << "Failed to load manifest: " << error_message; |   79   ASSERT_TRUE(manifest) << "Failed to load manifest: " << error_message; | 
|   80   EXPECT_TRUE(error_message.empty()); |   80   EXPECT_TRUE(error_message.empty()); | 
|   81  |   81  | 
|   82   EXPECT_EQ(manifest->name(), "com.chrome.test.native_host"); |   82   EXPECT_EQ(manifest->name(), "com.chrome.test.native_host"); | 
|   83   EXPECT_EQ(manifest->description(), "Native Messaging Test"); |   83   EXPECT_EQ(manifest->description(), "Native Messaging Test"); | 
|   84   EXPECT_EQ(manifest->interface(), |   84   EXPECT_EQ(manifest->interface(), | 
|   85             NativeMessagingHostManifest::HOST_INTERFACE_STDIO); |   85             NativeMessagingHostManifest::HOST_INTERFACE_STDIO); | 
|   86   EXPECT_EQ(manifest->path(), base::FilePath::FromUTF8Unsafe(kTestHostPath)); |   86   EXPECT_EQ(manifest->path(), base::FilePath::FromUTF8Unsafe(kTestHostPath)); | 
|   87   EXPECT_TRUE(manifest->allowed_origins().MatchesSecurityOrigin( |   87   EXPECT_TRUE(manifest->allowed_origins().MatchesSecurityOrigin( | 
|   88       GURL("chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"))); |   88       GURL("chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"))); | 
|   89   EXPECT_FALSE(manifest->allowed_origins().MatchesSecurityOrigin( |   89   EXPECT_FALSE(manifest->allowed_origins().MatchesSecurityOrigin( | 
|   90       GURL("chrome-extension://jnldjmfmopnpolahpmmgbagdohdnhkik/"))); |   90       GURL("chrome-extension://jnldjmfmopnpolahpmmgbagdohdnhkik/"))); | 
|   91 } |   91 } | 
|   92  |   92  | 
|   93 TEST_F(NativeMessagingHostManifestTest, InvalidName) { |   93 TEST_F(NativeMessagingHostManifestTest, InvalidName) { | 
|   94   ASSERT_TRUE(WriteManifest(".com.chrome.test.native_host", |   94   ASSERT_TRUE(WriteManifest(".com.chrome.test.native_host", | 
|   95                             kTestHostPath, kTestOrigin)); |   95                             kTestHostPath, kTestOrigin)); | 
|   96  |   96  | 
|   97   std::string error_message; |   97   std::string error_message; | 
|   98   scoped_ptr<NativeMessagingHostManifest> manifest = |   98   std::unique_ptr<NativeMessagingHostManifest> manifest = | 
|   99       NativeMessagingHostManifest::Load(manifest_path_, &error_message); |   99       NativeMessagingHostManifest::Load(manifest_path_, &error_message); | 
|  100   ASSERT_FALSE(manifest); |  100   ASSERT_FALSE(manifest); | 
|  101   EXPECT_FALSE(error_message.empty()); |  101   EXPECT_FALSE(error_message.empty()); | 
|  102 } |  102 } | 
|  103  |  103  | 
|  104 // Verify that match-all origins are rejected. |  104 // Verify that match-all origins are rejected. | 
|  105 TEST_F(NativeMessagingHostManifestTest, MatchAllOrigin) { |  105 TEST_F(NativeMessagingHostManifestTest, MatchAllOrigin) { | 
|  106   ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, |  106   ASSERT_TRUE(WriteManifest(kTestHostName, kTestHostPath, | 
|  107                             "chrome-extension://*/")); |  107                             "chrome-extension://*/")); | 
|  108  |  108  | 
|  109   std::string error_message; |  109   std::string error_message; | 
|  110   scoped_ptr<NativeMessagingHostManifest> manifest = |  110   std::unique_ptr<NativeMessagingHostManifest> manifest = | 
|  111       NativeMessagingHostManifest::Load(manifest_path_, &error_message); |  111       NativeMessagingHostManifest::Load(manifest_path_, &error_message); | 
|  112   ASSERT_FALSE(manifest); |  112   ASSERT_FALSE(manifest); | 
|  113   EXPECT_FALSE(error_message.empty()); |  113   EXPECT_FALSE(error_message.empty()); | 
|  114 } |  114 } | 
|  115  |  115  | 
|  116 }  // namespace extensions |  116 }  // namespace extensions | 
| OLD | NEW |