1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/tests/test_network_proxy.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/network_proxy.h"
#include "ppapi/cpp/var.h"
#include "ppapi/tests/testing_instance.h"
REGISTER_TEST_CASE(NetworkProxy);
TestNetworkProxy::TestNetworkProxy(TestingInstance* instance)
: TestCase(instance) {
}
void TestNetworkProxy::RunTests(const std::string& filter) {
RUN_CALLBACK_TEST(TestNetworkProxy, GetProxyForURL, filter);
}
std::string TestNetworkProxy::TestGetProxyForURL() {
TestCompletionCallbackWithOutput<pp::Var> callback(instance_->pp_instance(),
callback_type());
callback.WaitForResult(
pp::NetworkProxy::GetProxyForURL(instance_,
pp::Var("http://127.0.0.1/foobar/"),
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
pp::Var output = callback.output();
ASSERT_TRUE(output.is_string());
// Assume no one configures a proxy for localhost.
ASSERT_EQ("DIRECT", callback.output().AsString());
callback.WaitForResult(
pp::NetworkProxy::GetProxyForURL(instance_,
pp::Var("http://www.google.com"),
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
output = callback.output();
// Don't know what the proxy might be, but it should be a valid result.
ASSERT_TRUE(output.is_string());
callback.WaitForResult(
pp::NetworkProxy::GetProxyForURL(instance_,
pp::Var("file:///tmp"),
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_OK, callback.result());
output = callback.output();
ASSERT_TRUE(output.is_string());
// Should get "DIRECT" for file:// URLs.
ASSERT_EQ("DIRECT", output.AsString());
callback.WaitForResult(
pp::NetworkProxy::GetProxyForURL(instance_,
pp::Var("this isn't a url"),
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
ASSERT_TRUE(callback.output().is_undefined());
callback.WaitForResult(
pp::NetworkProxy::GetProxyForURL(instance_,
pp::Var(42), // non-string Var
callback.GetCallback()));
CHECK_CALLBACK_BEHAVIOR(callback);
ASSERT_EQ(PP_ERROR_BADARGUMENT, callback.result());
ASSERT_TRUE(callback.output().is_undefined());
PASS();
}
|