| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/pickle.h" | 7 #include "base/pickle.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "extensions/common/permissions/permissions_info.h" | 9 #include "extensions/common/permissions/permissions_info.h" |
| 10 #include "extensions/common/permissions/socket_permission.h" | 10 #include "extensions/common/permissions/socket_permission.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 param.reset(new SocketPermission::CheckParam( | 257 param.reset(new SocketPermission::CheckParam( |
| 258 SocketPermissionRequest::UDP_BIND, "127.0.0.1", 8800)); | 258 SocketPermissionRequest::UDP_BIND, "127.0.0.1", 8800)); |
| 259 EXPECT_FALSE(data.Check(param.get())); | 259 EXPECT_FALSE(data.Check(param.get())); |
| 260 param.reset(new SocketPermission::CheckParam( | 260 param.reset(new SocketPermission::CheckParam( |
| 261 SocketPermissionRequest::TCP_CONNECT, "127.0.0.1", 8800)); | 261 SocketPermissionRequest::TCP_CONNECT, "127.0.0.1", 8800)); |
| 262 EXPECT_FALSE(data.Check(param.get())); | 262 EXPECT_FALSE(data.Check(param.get())); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST(SocketPermissionTest, IPC) { | 265 TEST(SocketPermissionTest, IPC) { |
| 266 const APIPermissionInfo* permission_info = | 266 const APIPermissionInfo* permission_info = |
| 267 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 267 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 268 | 268 |
| 269 { | 269 { |
| 270 IPC::Message m; | 270 IPC::Message m; |
| 271 | 271 |
| 272 scoped_ptr<APIPermission> permission1( | 272 scoped_ptr<APIPermission> permission1( |
| 273 permission_info->CreateAPIPermission()); | 273 permission_info->CreateAPIPermission()); |
| 274 scoped_ptr<APIPermission> permission2( | 274 scoped_ptr<APIPermission> permission2( |
| 275 permission_info->CreateAPIPermission()); | 275 permission_info->CreateAPIPermission()); |
| 276 | 276 |
| 277 permission1->Write(&m); | 277 permission1->Write(&m); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 299 | 299 |
| 300 permission1->Write(&m); | 300 permission1->Write(&m); |
| 301 PickleIterator iter(m); | 301 PickleIterator iter(m); |
| 302 permission2->Read(&m, &iter); | 302 permission2->Read(&m, &iter); |
| 303 EXPECT_TRUE(permission1->Equal(permission2.get())); | 303 EXPECT_TRUE(permission1->Equal(permission2.get())); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 TEST(SocketPermissionTest, Value) { | 307 TEST(SocketPermissionTest, Value) { |
| 308 const APIPermissionInfo* permission_info = | 308 const APIPermissionInfo* permission_info = |
| 309 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); | 309 PermissionsInfo::GetInstance()->GetByID(APIPermission::kSocket); |
| 310 | 310 |
| 311 scoped_ptr<APIPermission> permission1( | 311 scoped_ptr<APIPermission> permission1(permission_info->CreateAPIPermission()); |
| 312 permission_info->CreateAPIPermission()); | 312 scoped_ptr<APIPermission> permission2(permission_info->CreateAPIPermission()); |
| 313 scoped_ptr<APIPermission> permission2( | |
| 314 permission_info->CreateAPIPermission()); | |
| 315 | 313 |
| 316 scoped_ptr<base::ListValue> value(new base::ListValue()); | 314 scoped_ptr<base::ListValue> value(new base::ListValue()); |
| 317 value->AppendString("tcp-connect:*.example.com:80"); | 315 value->AppendString("tcp-connect:*.example.com:80"); |
| 318 value->AppendString("udp-bind::8080"); | 316 value->AppendString("udp-bind::8080"); |
| 319 value->AppendString("udp-send-to::8888"); | 317 value->AppendString("udp-send-to::8888"); |
| 320 ASSERT_TRUE(permission1->FromValue(value.get(), NULL, NULL)); | 318 ASSERT_TRUE(permission1->FromValue(value.get(), NULL, NULL)); |
| 321 | 319 |
| 322 EXPECT_FALSE(permission1->Equal(permission2.get())); | 320 EXPECT_FALSE(permission1->Equal(permission2.get())); |
| 323 | 321 |
| 324 scoped_ptr<base::Value> vtmp(permission1->ToValue()); | 322 scoped_ptr<base::Value> vtmp(permission1->ToValue()); |
| 325 ASSERT_TRUE(vtmp); | 323 ASSERT_TRUE(vtmp); |
| 326 ASSERT_TRUE(permission2->FromValue(vtmp.get(), NULL, NULL)); | 324 ASSERT_TRUE(permission2->FromValue(vtmp.get(), NULL, NULL)); |
| 327 EXPECT_TRUE(permission1->Equal(permission2.get())); | 325 EXPECT_TRUE(permission1->Equal(permission2.get())); |
| 328 } | 326 } |
| 329 | 327 |
| 330 } // namespace | 328 } // namespace |
| 331 | 329 |
| 332 } // namespace extensions | 330 } // namespace extensions |
| 333 | |
| OLD | NEW |