Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: apps/shell/browser/dns_apitest.cc

Issue 394103004: Move DnsApiTest.DnsResolveIPLiteral and DnsApiTest.DnsResolveHostname to app_shell_browsertests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
Yoyo Zhou 2014/07/16 02:30:25 I put this file in apps/shell/browser to avoid int
James Cook 2014/07/16 17:15:31 I think the time has come to move app_shell out of
Yoyo Zhou 2014/07/18 02:45:30 I'll move to src/extensions/shell after this CL. F
tfarina 2014/07/18 02:47:37 extensions/shell :) Cool!
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "apps/shell/test/shell_test.h"
6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h"
mmenke 2014/07/16 14:05:54 You're missing the header for OVERRIDE. Suggest j
Yoyo Zhou 2014/07/18 02:45:30 Done.
9 #include "extensions/browser/api/dns/dns_api.h"
10 #include "extensions/browser/api/dns/host_resolver_wrapper.h"
11 #include "extensions/browser/api/dns/mock_host_resolver_creator.h"
12 #include "extensions/browser/api_test_utils.h"
13 #include "extensions/browser/extension_function_dispatcher.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/extension_builder.h"
16 #include "net/base/net_errors.h"
17 #include "net/dns/mock_host_resolver.h"
mmenke 2014/07/16 14:05:54 Are you actual depending on this? Looks like you
Yoyo Zhou 2014/07/18 02:45:30 It's used in line 42.
mmenke 2014/07/18 21:32:30 Are you sure? resolver_creator_->CreateMockHostRe
Yoyo Zhou 2014/07/22 00:10:30 It turns out this is because the header was needed
18
19 using extensions::ExtensionFunctionDispatcher;
20 using extensions::api_test_utils::RunFunctionAndReturnSingleResult;
21
22 namespace {
23
24 class TestFunctionDispatcherDelegate
25 : public ExtensionFunctionDispatcher::Delegate {
26 public:
27 TestFunctionDispatcherDelegate() {}
28 virtual ~TestFunctionDispatcherDelegate() {}
29
30 // NULL implementation
31 private:
mmenke 2014/07/16 14:05:54 DISALLOW_COPY_AND_ASSIGN (And include the requisit
Yoyo Zhou 2014/07/18 02:45:30 Done.
32 };
33 }
mmenke 2014/07/16 14:05:54 nit: Linebreak before ending namespace.
mmenke 2014/07/16 14:05:54 nit: "} // namespace"
Yoyo Zhou 2014/07/18 02:45:30 Done.
34
35 class DnsApiTest : public apps::AppShellTest {
36 public:
37 DnsApiTest() : resolver_creator_(new extensions::MockHostResolverCreator()) {}
38
39 private:
40 virtual void SetUpOnMainThread() OVERRIDE {
41 apps::AppShellTest::SetUpOnMainThread();
42 extensions::HostResolverWrapper::GetInstance()->SetHostResolverForTesting(
43 resolver_creator_->CreateMockHostResolver());
44 }
45
46 virtual void TearDownOnMainThread() OVERRIDE {
47 extensions::HostResolverWrapper::GetInstance()->SetHostResolverForTesting(
48 NULL);
49 resolver_creator_->DeleteMockHostResolver();
50 apps::AppShellTest::TearDownOnMainThread();
51 }
52
53 // The MockHostResolver asserts that it's used on the same thread on which
54 // it's created, which is actually a stronger rule than its real counterpart.
55 // But that's fine; it's good practice.
56 scoped_refptr<extensions::MockHostResolverCreator> resolver_creator_;
57 };
58
59 IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveIPLiteral) {
60 scoped_refptr<extensions::DnsResolveFunction> resolve_function(
61 new extensions::DnsResolveFunction());
62 scoped_refptr<extensions::Extension> empty_extension(
63 extensions::ExtensionBuilder()
64 .SetManifest(extensions::DictionaryBuilder().Set("name", "Test").Set(
65 "version", "1.0"))
66 .Build());
67
68 resolve_function->set_extension(empty_extension.get());
James Cook 2014/07/16 17:15:31 The old code has set_has_callback(true) after this
Yoyo Zhou 2014/07/18 02:45:30 No. Don't know why it works without it, though. I'
69
70 TestFunctionDispatcherDelegate delegate;
Yoyo Zhou 2014/07/16 02:30:25 Some of this setup (like here) is more difficult t
71 scoped_ptr<ExtensionFunctionDispatcher> dispatcher(
72 new ExtensionFunctionDispatcher(browser_context(), &delegate));
73
74 scoped_ptr<base::Value> result(
75 RunFunctionAndReturnSingleResult(resolve_function.get(),
76 "[\"127.0.0.1\"]",
77 browser_context(),
78 dispatcher.Pass()));
79 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
80 base::DictionaryValue* value =
81 static_cast<base::DictionaryValue*>(result.get());
mmenke 2014/07/16 14:05:54 No need for a cast, just use: base::DictionaryVal
Yoyo Zhou 2014/07/18 02:45:31 Done.
82
83 int resultCode;
mmenke 2014/07/16 14:05:54 nit: result_code.
Yoyo Zhou 2014/07/18 02:45:30 Done.
84 EXPECT_TRUE(value->GetInteger("resultCode", &resultCode));
85 EXPECT_EQ(net::OK, resultCode);
mmenke 2014/07/16 14:05:54 We're exposing Chrome network error codes to exten
Yoyo Zhou 2014/07/18 02:45:30 Yes, in lots of places already; see https://code.g
mmenke 2014/07/18 21:32:30 I'm not really concerned about more stuff dependin
Yoyo Zhou 2014/07/22 00:10:30 This happens in other APIs too, I think, e.g. http
86
87 std::string address;
88 EXPECT_TRUE(value->GetString("address", &address));
89 EXPECT_EQ("127.0.0.1", address);
90 }
91
92 IN_PROC_BROWSER_TEST_F(DnsApiTest, DnsResolveHostname) {
93 scoped_refptr<extensions::DnsResolveFunction> resolve_function(
94 new extensions::DnsResolveFunction());
95 scoped_refptr<extensions::Extension> empty_extension(
96 extensions::ExtensionBuilder()
97 .SetManifest(extensions::DictionaryBuilder().Set("name", "Test").Set(
98 "version", "1.0"))
99 .Build());
100
101 resolve_function->set_extension(empty_extension.get());
102 resolve_function->set_has_callback(true);
103
104 TestFunctionDispatcherDelegate delegate;
105 scoped_ptr<ExtensionFunctionDispatcher> dispatcher(
106 new ExtensionFunctionDispatcher(browser_context(), &delegate));
107
108 std::string function_arguments("[\"");
109 function_arguments += extensions::MockHostResolverCreator::kHostname;
110 function_arguments += "\"]";
111 scoped_ptr<base::Value> result(
112 RunFunctionAndReturnSingleResult(resolve_function.get(),
113 function_arguments,
114 browser_context(),
115 dispatcher.Pass()));
116 ASSERT_EQ(base::Value::TYPE_DICTIONARY, result->GetType());
117 base::DictionaryValue* value =
118 static_cast<base::DictionaryValue*>(result.get());
James Cook 2014/07/16 17:15:31 ditto
Yoyo Zhou 2014/07/18 02:45:30 Done.
119
120 int resultCode;
James Cook 2014/07/16 17:15:31 ditto
Yoyo Zhou 2014/07/18 02:45:30 Done.
121 EXPECT_TRUE(value->GetInteger("resultCode", &resultCode));
122 EXPECT_EQ(net::OK, resultCode);
123
124 std::string address;
125 EXPECT_TRUE(value->GetString("address", &address));
126 EXPECT_EQ(extensions::MockHostResolverCreator::kAddress, address);
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698