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

Unified Diff: mojo/services/html_viewer/html_viewer.cc

Issue 1049013004: Add some simple HTMLViewer apptests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use net::SpawnedTestServer instead of mojo:http_server. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/services/html_viewer/html_document.cc ('k') | mojo/services/html_viewer/html_viewer_apptest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/services/html_viewer/html_viewer.cc
diff --git a/mojo/services/html_viewer/html_viewer.cc b/mojo/services/html_viewer/html_viewer.cc
index 1391c1c7372f501971e944e68dc8913ac67031c2..cf41968e9a132616670bcc4ee9e67962ce6ae3ef 100644
--- a/mojo/services/html_viewer/html_viewer.cc
+++ b/mojo/services/html_viewer/html_viewer.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
#include "gin/public/isolate_holder.h"
@@ -13,6 +14,7 @@
#include "mojo/services/html_viewer/discardable_memory_allocator.h"
#include "mojo/services/html_viewer/html_document.h"
#include "mojo/services/html_viewer/mojo_blink_platform_impl.h"
+#include "mojo/services/html_viewer/public/interfaces/html_viewer.mojom.h"
#include "mojo/services/html_viewer/webmediaplayer_factory.h"
#include "mojo/services/network/public/interfaces/network_service.mojom.h"
#include "third_party/WebKit/public/web/WebKit.h"
@@ -64,7 +66,10 @@ size_t kDesiredMaxMemory = 20 * 1024 * 1024;
class HTMLViewer;
-class HTMLViewerApplication : public mojo::Application {
+class HTMLViewerApplication
+ : public mojo::Application,
+ public mojo::InterfaceImpl<mojo::HTMLViewerTestAPI> {
+ //, public mojo::InterfaceFactory<mojo::HTMLViewerTestAPI> {
public:
HTMLViewerApplication(InterfaceRequest<Application> request,
URLResponsePtr response,
@@ -81,6 +86,12 @@ class HTMLViewerApplication : public mojo::Application {
void Initialize(ShellPtr shell,
Array<String> args,
const String& url) override {
+ // std::string test_api_arg "--html_viewer_test_api";
+ // std::vector<std::string> arguments = args.To<std::vector<std::string>>();
+ // if (std::find(arguments.begin(), arguments.end(), test_api_arg) != arguments.end()) {}
+ //ASSERT_TRUE(application_impl()->HasArg("--example_apptest_arg"));
+
+ printf("MSW HTMLViewerApplication::Initialize\n");
ServiceProviderPtr service_provider;
shell_ = shell.Pass();
shell_->ConnectToApplication("mojo:network_service",
@@ -92,10 +103,18 @@ class HTMLViewerApplication : public mojo::Application {
InterfaceRequest<ServiceProvider> services,
ServiceProviderPtr exposed_services,
const String& url) override {
+ //service_provider_.AddService<mojo::HTMLViewerTestAPI>(this);
+ service_provider_.Bind(services.Pass());
+
+ printf("MSW HTMLViewerApplication::AcceptConnection "
+ "requestor=[%s] url=[%s] (url_=[%s], initial_response_=[%d])\n",
+ requestor_url.data(), url.data(), url_.data(),
+ !initial_response_.is_null());
+
if (initial_response_) {
- OnResponseReceived(URLLoaderPtr(), services.Pass(),
- initial_response_.Pass());
+ OnResponseReceived(URLLoaderPtr(), initial_response_.Pass());
} else {
+ // TODO(msw): Is this dead code? When is this called?
URLLoaderPtr loader;
network_service_->CreateURLLoader(GetProxy(&loader));
mojo::URLRequestPtr request(mojo::URLRequest::New());
@@ -109,30 +128,66 @@ class HTMLViewerApplication : public mojo::Application {
raw_loader->Start(
request.Pass(),
base::Bind(&HTMLViewerApplication::OnResponseReceived,
- base::Unretained(this), base::Passed(&loader),
- base::Passed(&services)));
+ base::Unretained(this), base::Passed(&loader)));
}
}
void RequestQuit() override {}
+ //// mojo::InterfaceImpl<mojo::HTMLViewerTestAPI>:
+ // void WaitForHTMLDocument(
+ // const WaitForHTMLDocumentCallback& callback) override {
+
+ // // TODO(msw): How can we wait for document load/layout?
+ // //base::RunLoop run_loop;
+ // //run_loop.RunUntilIdle();
+ // //base::MessageLoop::current()->RunUntilIdle();
+ // //base::MessageLoop::current()->Run();
+
+
+ // printf("MSW HTMLViewerApplication::WaitForHTMLDocument:%d\n",
+ // html_document_created_);
+ // if (html_document_created_) {
+ // callback.Run();
+ // return;
+ // }
+ // DCHECK(wait_for_html_document_callback_.is_null());
+ // wait_for_html_document_callback_ = callback;
+ // }
+
+ // // mojo::InterfaceFactory<mojo::HTMLViewerTestAPI>:
+ // void Create(
+ // ApplicationConnection* connection,
+ // mojo::InterfaceRequest<mojo::HTMLViewerTestAPI> request) override {
+ // printf("MSW HTMLViewerApplication::Create (HTMLViewerTestAPI)\n");
+ // // TODO(msw): Do not offer this service without --html-viewer-test-flag...
+ // // TODO(msw): Is this safe/correct? Can we avoid InterfaceFactory?
+ // // (getting flaky shutdown crashes w/base::MessageLoop dtor...)
+ // BindToRequest(this, &request);
+ // }
+
private:
- void OnResponseReceived(URLLoaderPtr loader,
- InterfaceRequest<ServiceProvider> services,
- URLResponsePtr response) {
- new HTMLDocument(services.Pass(), response.Pass(), shell_.get(),
+ void OnResponseReceived(URLLoaderPtr loader, URLResponsePtr response) {
+ printf("MSW HTMLViewerApplication::OnResponseReceived\n");
+ new HTMLDocument(&service_provider_, response.Pass(), shell_.get(),
compositor_thread_, web_media_player_factory_,
is_headless_);
+ // html_document_created_ = true;
+ // if (!wait_for_html_document_callback_.is_null())
+ // wait_for_html_document_callback_.Run();
}
String url_;
mojo::StrongBinding<mojo::Application> binding_;
+ mojo::ServiceProviderImpl service_provider_;
ShellPtr shell_;
mojo::NetworkServicePtr network_service_;
URLResponsePtr initial_response_;
scoped_refptr<base::MessageLoopProxy> compositor_thread_;
WebMediaPlayerFactory* web_media_player_factory_;
bool is_headless_;
+ //bool html_document_created_ = false;
+ //WaitForHTMLDocumentCallback wait_for_html_document_callback_;
};
class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> {
@@ -142,13 +197,16 @@ class ContentHandlerImpl : public mojo::InterfaceImpl<ContentHandler> {
bool is_headless)
: compositor_thread_(compositor_thread),
web_media_player_factory_(web_media_player_factory),
- is_headless_(is_headless) {}
+ is_headless_(is_headless) {
+ printf("MSW ContentHandlerImpl::ContentHandlerImpl\n");
+ }
~ContentHandlerImpl() override {}
private:
// Overridden from ContentHandler:
void StartApplication(InterfaceRequest<mojo::Application> request,
URLResponsePtr response) override {
+ printf("MSW ContentHandlerImpl::StartApplication\n");
new HTMLViewerApplication(request.Pass(), response.Pass(),
compositor_thread_, web_media_player_factory_,
is_headless_);
@@ -236,6 +294,7 @@ class HTMLViewer : public mojo::ApplicationDelegate,
// Overridden from InterfaceFactory<ContentHandler>
void Create(ApplicationConnection* connection,
mojo::InterfaceRequest<ContentHandler> request) override {
+ printf("MSW HTMLViewer::Create (ContentHandler)\n");
BindToRequest(
new ContentHandlerImpl(compositor_thread_.message_loop_proxy(),
web_media_player_factory_.get(), is_headless_),
@@ -262,6 +321,7 @@ class HTMLViewer : public mojo::ApplicationDelegate,
} // namespace html_viewer
MojoResult MojoMain(MojoHandle shell_handle) {
+ printf("MSW MojoMain\n");
mojo::ApplicationRunnerChromium runner(new html_viewer::HTMLViewer);
return runner.Run(shell_handle);
}
« no previous file with comments | « mojo/services/html_viewer/html_document.cc ('k') | mojo/services/html_viewer/html_viewer_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698