diff options
author | sky <sky@chromium.org> | 2015-06-29 15:50:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-29 22:50:46 +0000 |
commit | 89d6be01582ba5dacbcb3c7fdaa7dd54829d757b (patch) | |
tree | 7ea49d0405def9261afc3d3e0c620d3faa25acb8 /components/html_viewer/html_document_oopif.cc | |
parent | 69475131d1707afa5935dbccd98092f464459bdb (diff) | |
download | chromium_src-89d6be01582ba5dacbcb3c7fdaa7dd54829d757b.zip chromium_src-89d6be01582ba5dacbcb3c7fdaa7dd54829d757b.tar.gz chromium_src-89d6be01582ba5dacbcb3c7fdaa7dd54829d757b.tar.bz2 |
Adds a frame based test for html_viewer
I'm making the test code use mandoline/tab as that dramatically
simplifies things, and lets me test that code too.
I'm also creating a testing interface for HTMLViewer. It's only
available if a command line flag is supplied. For now it's simple, but
I'm going to add more to it (such as injecting JS).
BUG=479172,490221
TEST=mostly test change
R=ben@chromium.org
Review URL: https://codereview.chromium.org/1210323002
Cr-Commit-Position: refs/heads/master@{#336668}
Diffstat (limited to 'components/html_viewer/html_document_oopif.cc')
-rw-r--r-- | components/html_viewer/html_document_oopif.cc | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/components/html_viewer/html_document_oopif.cc b/components/html_viewer/html_document_oopif.cc index 9bd2ab6..1dfc61b 100644 --- a/components/html_viewer/html_document_oopif.cc +++ b/components/html_viewer/html_document_oopif.cc @@ -17,6 +17,7 @@ #include "components/html_viewer/frame.h" #include "components/html_viewer/frame_tree_manager.h" #include "components/html_viewer/global_state.h" +#include "components/html_viewer/test_html_viewer_impl.h" #include "components/html_viewer/web_url_loader_impl.h" #include "components/view_manager/ids.h" #include "components/view_manager/public/cpp/view.h" @@ -36,6 +37,13 @@ using mojo::View; namespace html_viewer { namespace { +const char kEnableTestInterface[] = "enable-html-viewer-test-interface"; + +bool IsTestInterfaceEnabled() { + return base::CommandLine::ForCurrentProcess()->HasSwitch( + kEnableTestInterface); +} + bool EnableRemoteDebugging() { return base::CommandLine::ForCurrentProcess()->HasSwitch( devtools_service::kRemoteDebuggingPort); @@ -43,6 +51,14 @@ bool EnableRemoteDebugging() { } // namespace +HTMLDocumentOOPIF::BeforeLoadCache::BeforeLoadCache() { +} + +HTMLDocumentOOPIF::BeforeLoadCache::~BeforeLoadCache() { + STLDeleteElements(&ax_provider_requests); + STLDeleteElements(&test_interface_requests); +} + HTMLDocumentOOPIF::HTMLDocumentOOPIF(mojo::ApplicationImpl* html_document_app, mojo::ApplicationConnection* connection, mojo::URLResponsePtr response, @@ -62,6 +78,10 @@ HTMLDocumentOOPIF::HTMLDocumentOOPIF(mojo::ApplicationImpl* html_document_app, static_cast<mojo::InterfaceFactory<mandoline::FrameTreeClient>*>(this)); connection->AddService(static_cast<InterfaceFactory<AxProvider>*>(this)); connection->AddService(&view_manager_client_factory_); + if (IsTestInterfaceEnabled()) { + connection->AddService( + static_cast<mojo::InterfaceFactory<TestHTMLViewer>*>(this)); + } resource_waiter_.reset( new DocumentResourceWaiter(global_state_, response.Pass(), this)); @@ -93,7 +113,6 @@ HTMLDocumentOOPIF::~HTMLDocumentOOPIF() { delete_callback_.Run(this); STLDeleteElements(&ax_providers_); - STLDeleteElements(&ax_provider_requests_); } void HTMLDocumentOOPIF::LoadIfNecessary() { @@ -153,6 +172,13 @@ void HTMLDocumentOOPIF::Load() { frame_tree_manager_->GetLocalWebFrame()->loadRequest(web_request); } +HTMLDocumentOOPIF::BeforeLoadCache* HTMLDocumentOOPIF::GetBeforeLoadCache() { + CHECK(!did_finish_local_frame_load_); + if (!before_load_cache_.get()) + before_load_cache_.reset(new BeforeLoadCache); + return before_load_cache_.get(); +} + void HTMLDocumentOOPIF::OnEmbed(View* root) { // We're an observer until the document is loaded. root->AddObserver(this); @@ -184,30 +210,54 @@ bool HTMLDocumentOOPIF::ShouldNavigateLocallyInMainFrame() { void HTMLDocumentOOPIF::OnFrameDidFinishLoad(Frame* frame) { // TODO(msw): Notify AxProvider clients of updates on child frame loads. - if (frame != frame_tree_manager_->GetLocalFrame()) + if (frame_tree_manager_ && + frame != frame_tree_manager_->GetLocalFrame()) { return; + } - did_finish_main_frame_load_ = true; + did_finish_local_frame_load_ = true; + scoped_ptr<BeforeLoadCache> before_load_cache = before_load_cache_.Pass(); + if (!before_load_cache) + return; - // Bind any pending AxProviderImpl interface requests. - for (auto it : ax_provider_requests_) - ax_providers_.insert(new AxProviderImpl(frame->web_view(), it->Pass())); - STLDeleteElements(&ax_provider_requests_); + // Bind any pending AxProvider and TestHTMLViewer interface requests. + for (auto it : before_load_cache->ax_provider_requests) { + ax_providers_.insert( + new AxProviderImpl(frame_tree_manager_->GetWebView(), it->Pass())); + } + for (auto it : before_load_cache->test_interface_requests) { + CHECK(IsTestInterfaceEnabled()); + test_html_viewers_.push_back(new TestHTMLViewerImpl( + frame_tree_manager_->GetLocalWebFrame(), it->Pass())); + } } void HTMLDocumentOOPIF::Create(mojo::ApplicationConnection* connection, mojo::InterfaceRequest<AxProvider> request) { - if (!did_finish_main_frame_load_) { + if (!did_finish_local_frame_load_) { // Cache AxProvider interface requests until the document finishes loading. auto cached_request = new mojo::InterfaceRequest<AxProvider>(); *cached_request = request.Pass(); - ax_provider_requests_.insert(cached_request); + GetBeforeLoadCache()->ax_provider_requests.insert(cached_request); } else { ax_providers_.insert(new AxProviderImpl( frame_tree_manager_->GetLocalFrame()->web_view(), request.Pass())); } } +void HTMLDocumentOOPIF::Create(mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<TestHTMLViewer> request) { + CHECK(IsTestInterfaceEnabled()); + if (!did_finish_local_frame_load_) { + auto cached_request = new mojo::InterfaceRequest<TestHTMLViewer>(); + *cached_request = request.Pass(); + GetBeforeLoadCache()->test_interface_requests.insert(cached_request); + } else { + test_html_viewers_.push_back(new TestHTMLViewerImpl( + frame_tree_manager_->GetLocalWebFrame(), request.Pass())); + } +} + void HTMLDocumentOOPIF::Create( mojo::ApplicationConnection* connection, mojo::InterfaceRequest<mandoline::FrameTreeClient> request) { |