Delete unused downloads page asset.
[chromium-blink-merge.git] / ppapi / tests / extensions / no_socket_permissions / test_no_socket_permissions.cc
blob0e284ea47aec5a442903a76a05ad080138421b62
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/completion_callback.h"
6 #include "ppapi/cpp/instance.h"
7 #include "ppapi/cpp/module.h"
8 #include "ppapi/cpp/tcp_socket.h"
9 #include "ppapi/cpp/udp_socket.h"
10 #include "ppapi/utility/completion_callback_factory.h"
12 namespace {
14 class MyInstance : public pp::Instance {
15 public:
16 explicit MyInstance(PP_Instance instance)
17 : pp::Instance(instance),
18 tcp_socket_(this),
19 udp_socket_(this),
20 factory_(this) {}
21 virtual ~MyInstance() {}
23 void DidBindTCPSocket(int32_t result) {
24 // We should not be able to bind the TCP socket without permission.
25 if (result == PP_OK) {
26 PostMessage("FAIL");
27 return;
29 PP_NetAddress_IPv4 ipv4_address = {80, {127, 0, 0, 1}};
30 pp::NetAddress address(this, ipv4_address);
31 udp_socket_.Bind(address,
32 factory_.NewCallback(&MyInstance::DidBindUDPSocket));
35 void DidBindUDPSocket(int32_t result) {
36 // We should not be able to bind the UDP socket without permission.
37 if (result == PP_OK)
38 PostMessage("FAIL");
39 else
40 PostMessage("PASS");
43 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
44 PP_NetAddress_IPv4 ipv4_address = {80, {127, 0, 0, 1}};
45 pp::NetAddress address(this, ipv4_address);
46 tcp_socket_.Bind(address,
47 factory_.NewCallback(&MyInstance::DidBindTCPSocket));
48 return true;
51 private:
52 pp::TCPSocket tcp_socket_;
53 pp::UDPSocket udp_socket_;
54 pp::CompletionCallbackFactory<MyInstance> factory_;
57 class MyModule : public pp::Module {
58 public:
59 MyModule() : pp::Module() {}
60 virtual ~MyModule() {}
62 virtual pp::Instance* CreateInstance(PP_Instance instance) {
63 return new MyInstance(instance);
67 } // namespace
69 namespace pp {
71 Module* CreateModule() {
72 return new MyModule();
75 } // namespace pp