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 "base/command_line.h" | |
6 #include "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
7 #include "base/synchronization/waitable_event.h" | 6 #include "base/synchronization/waitable_event.h" |
8 #include "chrome/browser/extensions/api/dns/dns_api.h" | 7 #include "chrome/browser/extensions/api/dns/dns_api.h" |
9 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 9 #include "chrome/browser/extensions/extension_function_test_utils.h" |
11 #include "chrome/common/chrome_switches.h" | |
12 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
13 #include "net/base/host_resolver.h" | 11 #include "net/base/host_resolver.h" |
14 #include "net/base/mock_host_resolver.h" | 12 #include "net/base/mock_host_resolver.h" |
15 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
16 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
17 | 15 |
18 using content::BrowserThread; | 16 using content::BrowserThread; |
19 using extension_function_test_utils::CreateEmptyExtension; | 17 using extension_function_test_utils::CreateEmptyExtension; |
20 using extension_function_test_utils::RunFunctionAndReturnResult; | 18 using extension_function_test_utils::RunFunctionAndReturnResult; |
21 | 19 |
22 namespace { | 20 namespace { |
23 | 21 |
24 class DnsApiTest : public ExtensionApiTest { | 22 class DnsApiTest : public PlatformAppApiTest { |
25 public: | 23 public: |
26 static const std::string kHostname; | 24 static const std::string kHostname; |
27 static const std::string kAddress; | 25 static const std::string kAddress; |
28 | 26 |
29 DnsApiTest() : resolver_event_(true, false), | 27 DnsApiTest() : resolver_event_(true, false), |
30 mock_host_resolver_(NULL) { | 28 mock_host_resolver_(NULL) { |
31 } | 29 } |
32 | 30 |
33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
34 ExtensionApiTest::SetUpCommandLine(command_line); | |
35 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | |
36 command_line->AppendSwitch(switches::kEnablePlatformApps); | |
37 } | |
38 | |
39 virtual void SetUpOnMainThread() OVERRIDE { | 31 virtual void SetUpOnMainThread() OVERRIDE { |
40 CreateMockHostResolverOnIOThread(); | 32 CreateMockHostResolverOnIOThread(); |
41 extensions::DnsResolveFunction::set_host_resolver_for_testing( | 33 extensions::DnsResolveFunction::set_host_resolver_for_testing( |
42 get_mock_host_resolver()); | 34 get_mock_host_resolver()); |
43 } | 35 } |
44 | 36 |
45 virtual void CleanUpOnMainThread() OVERRIDE { | 37 virtual void CleanUpOnMainThread() OVERRIDE { |
46 if (mock_host_resolver_) { | 38 if (mock_host_resolver_) { |
47 extensions::DnsResolveFunction::set_host_resolver_for_testing(NULL); | 39 extensions::DnsResolveFunction::set_host_resolver_for_testing(NULL); |
48 DeleteMockHostResolverOnIOThread(); | 40 DeleteMockHostResolverOnIOThread(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // But that's fine; it's good practice. | 90 // But that's fine; it's good practice. |
99 // | 91 // |
100 // Plain pointer because we have to manage lifetime manually. | 92 // Plain pointer because we have to manage lifetime manually. |
101 net::MockHostResolver* mock_host_resolver_; | 93 net::MockHostResolver* mock_host_resolver_; |
102 }; | 94 }; |
103 const std::string DnsApiTest::kHostname = "www.sowbug.org"; | 95 const std::string DnsApiTest::kHostname = "www.sowbug.org"; |
104 const std::string DnsApiTest::kAddress = "9.8.7.6"; | 96 const std::string DnsApiTest::kAddress = "9.8.7.6"; |
105 | 97 |
106 } // namespace | 98 } // namespace |
107 | 99 |
| 100 IN_PROC_BROWSER_TEST_F(DnsApiTest, VerifyPermissions) { |
| 101 VerifyPermissions(test_data_dir_.AppendASCII("dns/api")); |
| 102 } |
| 103 |
108 IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) { | 104 IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) { |
109 scoped_refptr<extensions::DnsResolveFunction> resolve_function( | 105 scoped_refptr<extensions::DnsResolveFunction> resolve_function( |
110 new extensions::DnsResolveFunction()); | 106 new extensions::DnsResolveFunction()); |
111 scoped_refptr<Extension> empty_extension(CreateEmptyExtension()); | 107 scoped_refptr<Extension> empty_extension(CreateEmptyExtension()); |
112 | 108 |
113 resolve_function->set_extension(empty_extension.get()); | 109 resolve_function->set_extension(empty_extension.get()); |
114 resolve_function->set_has_callback(true); | 110 resolve_function->set_has_callback(true); |
115 | 111 |
116 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( | 112 scoped_ptr<base::Value> result(RunFunctionAndReturnResult( |
117 resolve_function, "[\"127.0.0.1\"]", browser())); | 113 resolve_function, "[\"127.0.0.1\"]", browser())); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 EXPECT_EQ(net::OK, resultCode); | 145 EXPECT_EQ(net::OK, resultCode); |
150 | 146 |
151 std::string address; | 147 std::string address; |
152 EXPECT_TRUE(value->GetString("address", &address)); | 148 EXPECT_TRUE(value->GetString("address", &address)); |
153 EXPECT_EQ(DnsApiTest::kAddress, address); | 149 EXPECT_EQ(DnsApiTest::kAddress, address); |
154 } | 150 } |
155 | 151 |
156 IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsExtension) { | 152 IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsExtension) { |
157 ASSERT_TRUE(RunExtensionTest("dns/api")) << message_; | 153 ASSERT_TRUE(RunExtensionTest("dns/api")) << message_; |
158 } | 154 } |
OLD | NEW |