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

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

Issue 1470823002: Enable builtin Mojo JS modules in layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@usb-testing
Patch Set: add 'define' to global interface expectations for AMD in layout tests Created 4 years, 11 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
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 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 13 matching lines...) Expand all
24 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
25 #include "content/public/common/service_registry.h" 25 #include "content/public/common/service_registry.h"
26 #include "content/public/common/url_utils.h" 26 #include "content/public/common/url_utils.h"
27 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
28 #include "content/public/test/content_browser_test.h" 28 #include "content/public/test/content_browser_test.h"
29 #include "content/public/test/content_browser_test_utils.h" 29 #include "content/public/test/content_browser_test_utils.h"
30 #include "content/shell/browser/shell.h" 30 #include "content/shell/browser/shell.h"
31 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h" 31 #include "content/test/data/web_ui_test_mojo_bindings.mojom.h"
32 #include "mojo/public/cpp/bindings/binding.h" 32 #include "mojo/public/cpp/bindings/binding.h"
33 #include "mojo/public/cpp/bindings/interface_request.h" 33 #include "mojo/public/cpp/bindings/interface_request.h"
34 #include "mojo/public/js/constants.h"
35 #include "mojo/test/test_utils.h" 34 #include "mojo/test/test_utils.h"
36 #include "net/test/embedded_test_server/embedded_test_server.h" 35 #include "net/test/embedded_test_server/embedded_test_server.h"
37 36
38 namespace content { 37 namespace content {
39 namespace { 38 namespace {
40 39
41 bool got_message = false; 40 bool got_message = false;
42 41
43 // The bindings for the page are generated from a .mojom file. This code looks 42 // The bindings for the page are generated from a .mojom file. This code looks
44 // up the generated file from disk and returns it. 43 // up the generated file from disk and returns it.
45 bool GetResource(const std::string& id, 44 bool GetResource(const std::string& id,
46 const WebUIDataSource::GotDataCallback& callback) { 45 const WebUIDataSource::GotDataCallback& callback) {
47 // These are handled by the WebUIDataSource that AddMojoDataSource() creates.
48 if (id == mojo::kBindingsModuleName ||
49 id == mojo::kBufferModuleName ||
50 id == mojo::kCodecModuleName ||
51 id == mojo::kConnectionModuleName ||
52 id == mojo::kConnectorModuleName ||
53 id == mojo::kUnicodeModuleName ||
54 id == mojo::kRouterModuleName ||
55 id == mojo::kValidatorModuleName)
56 return false;
57
58 if (id.find(".mojom") != std::string::npos) { 46 if (id.find(".mojom") != std::string::npos) {
59 std::string contents; 47 std::string contents;
60 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id), 48 CHECK(base::ReadFileToString(mojo::test::GetFilePathForJSResource(id),
61 &contents, std::string::npos)) 49 &contents, std::string::npos))
62 << id; 50 << id;
63 base::RefCountedString* ref_contents = new base::RefCountedString; 51 base::RefCountedString* ref_contents = new base::RefCountedString;
64 ref_contents->data() = contents; 52 ref_contents->data() = contents;
65 callback.Run(ref_contents); 53 callback.Run(ref_contents);
66 return true; 54 return true;
67 } 55 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl); 91 DISALLOW_COPY_AND_ASSIGN(BrowserTargetImpl);
104 }; 92 };
105 93
106 // WebUIController that sets up mojo bindings. 94 // WebUIController that sets up mojo bindings.
107 class TestWebUIController : public WebUIController { 95 class TestWebUIController : public WebUIController {
108 public: 96 public:
109 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop) 97 TestWebUIController(WebUI* web_ui, base::RunLoop* run_loop)
110 : WebUIController(web_ui), run_loop_(run_loop) { 98 : WebUIController(web_ui), run_loop_(run_loop) {
111 content::WebUIDataSource* data_source = 99 content::WebUIDataSource* data_source =
112 WebUIDataSource::Create("mojo-web-ui"); 100 WebUIDataSource::Create("mojo-web-ui");
113 data_source->AddMojoResources();
114 data_source->SetRequestFilter(base::Bind(&GetResource)); 101 data_source->SetRequestFilter(base::Bind(&GetResource));
115 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(), 102 content::WebUIDataSource::Add(web_ui->GetWebContents()->GetBrowserContext(),
116 data_source); 103 data_source);
117 } 104 }
118 105
119 protected: 106 protected:
120 base::RunLoop* run_loop_; 107 base::RunLoop* run_loop_;
121 scoped_ptr<BrowserTargetImpl> browser_target_; 108 scoped_ptr<BrowserTargetImpl> browser_target_;
122 109
123 private: 110 private:
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 GURL("chrome://mojo-web-ui/web_ui_mojo_shell_test.html")); 241 GURL("chrome://mojo-web-ui/web_ui_mojo_shell_test.html"));
255 242
256 DOMMessageQueue message_queue; 243 DOMMessageQueue message_queue;
257 std::string message; 244 std::string message;
258 ASSERT_TRUE(message_queue.WaitForMessage(&message)); 245 ASSERT_TRUE(message_queue.WaitForMessage(&message));
259 EXPECT_EQ("true", message); 246 EXPECT_EQ("true", message);
260 } 247 }
261 248
262 } // namespace 249 } // namespace
263 } // namespace content 250 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698