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

Side by Side Diff: content/browser/webui/web_ui_mojo_browsertest.cc

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <limits> 5 #include <limits>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "content/browser/webui/web_ui_controller_factory_registry.h" 13 #include "content/browser/webui/web_ui_controller_factory_registry.h"
14 #include "content/public/browser/browser_context.h" 14 #include "content/public/browser/browser_context.h"
15 #include "content/public/browser/render_view_host.h" 15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_ui_controller.h" 17 #include "content/public/browser/web_ui_controller.h"
18 #include "content/public/browser/web_ui_data_source.h" 18 #include "content/public/browser/web_ui_data_source.h"
19 #include "content/public/common/content_paths.h" 19 #include "content/public/common/content_paths.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "content/public/common/url_utils.h" 21 #include "content/public/common/url_utils.h"
22 #include "content/public/test/content_browser_test.h" 22 #include "content/public/test/content_browser_test.h"
23 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" 24 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h"
25 #include "grit/content_resources.h" 25 #include "grit/content_resources.h"
26 #include "mojo/common/test/test_utils.h" 26 #include "mojo/common/test/test_utils.h"
27 #include "mojo/public/cpp/bindings/allocation_scope.h" 27 #include "mojo/public/cpp/bindings/allocation_scope.h"
28 #include "mojo/public/cpp/bindings/remote_ptr.h"
29 #include "mojo/public/js/bindings/constants.h" 28 #include "mojo/public/js/bindings/constants.h"
30 29
31 namespace content { 30 namespace content {
32 namespace { 31 namespace {
33 32
34 bool got_message = false; 33 bool got_message = false;
35 34
36 // The bindings for the page are generated from a .mojom file. This code looks 35 // The bindings for the page are generated from a .mojom file. This code looks
37 // up the generated file from disk and returns it. 36 // up the generated file from disk and returns it.
38 bool GetResource(const std::string& id, 37 bool GetResource(const std::string& id,
39 const WebUIDataSource::GotDataCallback& callback) { 38 const WebUIDataSource::GotDataCallback& callback) {
40 // These are handled by the WebUIDataSource that AddMojoDataSource() creates. 39 // These are handled by the WebUIDataSource that AddMojoDataSource() creates.
41 if (id == mojo::kCodecModuleName || 40 if (id == mojo::kCodecModuleName ||
42 id == mojo::kConnectionModuleName || 41 id == mojo::kConnectionModuleName ||
43 id == mojo::kConnectorModuleName || 42 id == mojo::kConnectorModuleName ||
44 id == mojo::kRouterModuleName) 43 id == mojo::kRouterModuleName)
45 return false; 44 return false;
46 45
47 std::string contents; 46 std::string contents;
48 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), 47 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id),
49 &contents, 48 &contents,
50 std::string::npos)) << id; 49 std::string::npos)) << id;
51 base::RefCountedString* ref_contents = new base::RefCountedString; 50 base::RefCountedString* ref_contents = new base::RefCountedString;
52 ref_contents->data() = contents; 51 ref_contents->data() = contents;
53 callback.Run(ref_contents); 52 callback.Run(ref_contents);
54 return true; 53 return true;
55 } 54 }
56 55
57 class BrowserTargetImpl : public mojo::BrowserTarget { 56 class BrowserTargetImpl : public BrowserTarget {
58 public: 57 public:
59 BrowserTargetImpl(mojo::ScopedRendererTargetHandle& handle, 58 BrowserTargetImpl(mojo::ScopedMessagePipeHandle handle,
60 base::RunLoop* run_loop) 59 base::RunLoop* run_loop)
61 : client_(handle.Pass(), this), 60 : renderer_(mojo::MakeProxy<RendererTarget>(handle.Pass())),
62 run_loop_(run_loop) { 61 run_loop_(run_loop) {
62 renderer_->SetClient(this);
63 } 63 }
64 64
65 virtual ~BrowserTargetImpl() {} 65 virtual ~BrowserTargetImpl() {}
66 66
67 // mojo::BrowserTarget overrides: 67 // BrowserTarget overrides:
68 virtual void PingResponse() OVERRIDE { 68 virtual void PingResponse() OVERRIDE {
69 NOTREACHED(); 69 NOTREACHED();
70 } 70 }
71 71
72 protected: 72 protected:
73 mojo::RemotePtr<mojo::RendererTarget> client_; 73 RendererTargetPtr renderer_;
74 base::RunLoop* run_loop_; 74 base::RunLoop* run_loop_;
75 75
76 private: 76 private:
77 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); 77 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl);
78 }; 78 };
79 79
80 class PingBrowserTargetImpl : public BrowserTargetImpl { 80 class PingBrowserTargetImpl : public BrowserTargetImpl {
81 public: 81 public:
82 PingBrowserTargetImpl(mojo::ScopedRendererTargetHandle handle, 82 PingBrowserTargetImpl(mojo::ScopedMessagePipeHandle handle,
83 base::RunLoop* run_loop) 83 base::RunLoop* run_loop)
84 : BrowserTargetImpl(handle, run_loop) { 84 : BrowserTargetImpl(handle.Pass(), run_loop) {
85 client_->Ping(); 85 renderer_->Ping();
86 } 86 }
87 87
88 virtual ~PingBrowserTargetImpl() {} 88 virtual ~PingBrowserTargetImpl() {}
89 89
90 // mojo::BrowserTarget overrides: 90 // BrowserTarget overrides:
91 // Quit the RunLoop when called. 91 // Quit the RunLoop when called.
92 virtual void PingResponse() OVERRIDE { 92 virtual void PingResponse() OVERRIDE {
93 got_message = true; 93 got_message = true;
94 run_loop_->Quit(); 94 run_loop_->Quit();
95 } 95 }
96 96
97 private: 97 private:
98 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl); 98 DISALLOW_COPY_AND_ASSIGN(PingBrowserTargetImpl);
99 }; 99 };
100 100
(...skipping 20 matching lines...) Expand all
121 // TestWebUIController that additionally creates the ping test BrowserTarget 121 // TestWebUIController that additionally creates the ping test BrowserTarget
122 // implementation at the right time. 122 // implementation at the right time.
123 class PingTestWebUIController : public TestWebUIController { 123 class PingTestWebUIController : public TestWebUIController {
124 public: 124 public:
125 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) 125 PingTestWebUIController(WebUI* web_ui, base::RunLoop* run_loop)
126 : TestWebUIController(web_ui, run_loop) { 126 : TestWebUIController(web_ui, run_loop) {
127 } 127 }
128 128
129 // WebUIController overrides: 129 // WebUIController overrides:
130 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE { 130 virtual void RenderViewCreated(RenderViewHost* render_view_host) OVERRIDE {
131 mojo::InterfacePipe<mojo::BrowserTarget, mojo::RendererTarget> pipe; 131 mojo::MessagePipe pipe;
132 browser_target_.reset(new PingBrowserTargetImpl( 132 browser_target_.reset(
133 pipe.handle_to_peer.Pass(), run_loop_)); 133 new PingBrowserTargetImpl(pipe.handle0.Pass(), run_loop_));
134 render_view_host->SetWebUIHandle( 134 render_view_host->SetWebUIHandle(pipe.handle1.Pass());
135 mojo::ScopedMessagePipeHandle(pipe.handle_to_self.release()));
136 } 135 }
137 136
138 private: 137 private:
139 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController); 138 DISALLOW_COPY_AND_ASSIGN(PingTestWebUIController);
140 }; 139 };
141 140
142 // WebUIControllerFactory that creates TestWebUIController. 141 // WebUIControllerFactory that creates TestWebUIController.
143 class TestWebUIControllerFactory : public WebUIControllerFactory { 142 class TestWebUIControllerFactory : public WebUIControllerFactory {
144 public: 143 public:
145 TestWebUIControllerFactory() : run_loop_(NULL) {} 144 TestWebUIControllerFactory() : run_loop_(NULL) {}
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 factory()->set_run_loop(&run_loop); 209 factory()->set_run_loop(&run_loop);
211 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping")); 210 GURL test_url(test_server()->GetURL("files/web_ui_mojo.html?ping"));
212 NavigateToURL(shell(), test_url); 211 NavigateToURL(shell(), test_url);
213 // RunLoop is quit when message received from page. 212 // RunLoop is quit when message received from page.
214 run_loop.Run(); 213 run_loop.Run();
215 EXPECT_TRUE(got_message); 214 EXPECT_TRUE(got_message);
216 } 215 }
217 216
218 } // namespace 217 } // namespace
219 } // namespace content 218 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698