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

Side by Side Diff: components/dom_distiller/content/distiller_page_web_contents_browsertest.cc

Issue 666133002: Standardize usage of virtual/override/final in components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "components/dom_distiller/content/distiller_page_web_contents.h" 9 #include "components/dom_distiller/content/distiller_page_web_contents.h"
10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h" 10 #include "components/dom_distiller/content/web_contents_main_frame_observer.h"
(...skipping 20 matching lines...) Expand all
31 using testing::Not; 31 using testing::Not;
32 32
33 namespace dom_distiller { 33 namespace dom_distiller {
34 34
35 const char* kSimpleArticlePath = "/simple_article.html"; 35 const char* kSimpleArticlePath = "/simple_article.html";
36 const char* kVideoArticlePath = "/video_article.html"; 36 const char* kVideoArticlePath = "/video_article.html";
37 37
38 class DistillerPageWebContentsTest : public ContentBrowserTest { 38 class DistillerPageWebContentsTest : public ContentBrowserTest {
39 public: 39 public:
40 // ContentBrowserTest: 40 // ContentBrowserTest:
41 virtual void SetUpOnMainThread() override { 41 void SetUpOnMainThread() override {
42 AddComponentsResources(); 42 AddComponentsResources();
43 SetUpTestServer(); 43 SetUpTestServer();
44 ContentBrowserTest::SetUpOnMainThread(); 44 ContentBrowserTest::SetUpOnMainThread();
45 } 45 }
46 46
47 void DistillPage(const base::Closure& quit_closure, const std::string& url) { 47 void DistillPage(const base::Closure& quit_closure, const std::string& url) {
48 quit_closure_ = quit_closure; 48 quit_closure_ = quit_closure;
49 distiller_page_->DistillPage( 49 distiller_page_->DistillPage(
50 embedded_test_server()->GetURL(url), 50 embedded_test_server()->GetURL(url),
51 dom_distiller::proto::DomDistillerOptions(), 51 dom_distiller::proto::DomDistillerOptions(),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 TestDistillerPageWebContents( 96 TestDistillerPageWebContents(
97 content::BrowserContext* browser_context, 97 content::BrowserContext* browser_context,
98 const gfx::Size& render_view_size, 98 const gfx::Size& render_view_size,
99 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle, 99 scoped_ptr<SourcePageHandleWebContents> optional_web_contents_handle,
100 bool expect_new_web_contents) 100 bool expect_new_web_contents)
101 : DistillerPageWebContents(browser_context, render_view_size, 101 : DistillerPageWebContents(browser_context, render_view_size,
102 optional_web_contents_handle.Pass()), 102 optional_web_contents_handle.Pass()),
103 expect_new_web_contents_(expect_new_web_contents), 103 expect_new_web_contents_(expect_new_web_contents),
104 new_web_contents_created_(false) {} 104 new_web_contents_created_(false) {}
105 105
106 virtual void CreateNewWebContents(const GURL& url) override { 106 void CreateNewWebContents(const GURL& url) override {
107 ASSERT_EQ(true, expect_new_web_contents_); 107 ASSERT_EQ(true, expect_new_web_contents_);
108 new_web_contents_created_ = true; 108 new_web_contents_created_ = true;
109 // DistillerPageWebContents::CreateNewWebContents resets the scoped_ptr to 109 // DistillerPageWebContents::CreateNewWebContents resets the scoped_ptr to
110 // the WebContents, so intentionally leak WebContents here, since it is 110 // the WebContents, so intentionally leak WebContents here, since it is
111 // owned by the shell. 111 // owned by the shell.
112 content::WebContents* web_contents = web_contents_.release(); 112 content::WebContents* web_contents = web_contents_.release();
113 web_contents->GetLastCommittedURL(); 113 web_contents->GetLastCommittedURL();
114 DistillerPageWebContents::CreateNewWebContents(url); 114 DistillerPageWebContents::CreateNewWebContents(url);
115 } 115 }
116 116
117 virtual ~TestDistillerPageWebContents() { 117 ~TestDistillerPageWebContents() override {
118 if (!expect_new_web_contents_) { 118 if (!expect_new_web_contents_) {
119 // Intentionally leaking WebContents, since it is owned by the shell. 119 // Intentionally leaking WebContents, since it is owned by the shell.
120 content::WebContents* web_contents = web_contents_.release(); 120 content::WebContents* web_contents = web_contents_.release();
121 web_contents->GetLastCommittedURL(); 121 web_contents->GetLastCommittedURL();
122 } 122 }
123 } 123 }
124 124
125 bool new_web_contents_created() { return new_web_contents_created_; } 125 bool new_web_contents_created() { return new_web_contents_created_; }
126 126
127 private: 127 private:
128 bool expect_new_web_contents_; 128 bool expect_new_web_contents_;
129 bool new_web_contents_created_; 129 bool new_web_contents_created_;
130 }; 130 };
131 131
132 // Helper class to know how far in the loading process the current WebContents 132 // Helper class to know how far in the loading process the current WebContents
133 // has come. It will call the callback either after 133 // has come. It will call the callback either after
134 // DidCommitProvisionalLoadForFrame or DocumentLoadedInFrame is called for the 134 // DidCommitProvisionalLoadForFrame or DocumentLoadedInFrame is called for the
135 // main frame, based on the value of |wait_for_document_loaded|. 135 // main frame, based on the value of |wait_for_document_loaded|.
136 class WebContentsMainFrameHelper : public content::WebContentsObserver { 136 class WebContentsMainFrameHelper : public content::WebContentsObserver {
137 public: 137 public:
138 WebContentsMainFrameHelper(content::WebContents* web_contents, 138 WebContentsMainFrameHelper(content::WebContents* web_contents,
139 const base::Closure& callback, 139 const base::Closure& callback,
140 bool wait_for_document_loaded) 140 bool wait_for_document_loaded)
141 : WebContentsObserver(web_contents), 141 : WebContentsObserver(web_contents),
142 callback_(callback), 142 callback_(callback),
143 wait_for_document_loaded_(wait_for_document_loaded) {} 143 wait_for_document_loaded_(wait_for_document_loaded) {}
144 144
145 virtual void DidCommitProvisionalLoadForFrame( 145 void DidCommitProvisionalLoadForFrame(
146 content::RenderFrameHost* render_frame_host, 146 content::RenderFrameHost* render_frame_host,
147 const GURL& url, 147 const GURL& url,
148 ui::PageTransition transition_type) override { 148 ui::PageTransition transition_type) override {
149 if (wait_for_document_loaded_) 149 if (wait_for_document_loaded_)
150 return; 150 return;
151 if (!render_frame_host->GetParent()) 151 if (!render_frame_host->GetParent())
152 callback_.Run(); 152 callback_.Run();
153 } 153 }
154 154
155 virtual void DocumentLoadedInFrame( 155 void DocumentLoadedInFrame(
156 content::RenderFrameHost* render_frame_host) override { 156 content::RenderFrameHost* render_frame_host) override {
157 if (wait_for_document_loaded_) { 157 if (wait_for_document_loaded_) {
158 if (!render_frame_host->GetParent()) 158 if (!render_frame_host->GetParent())
159 callback_.Run(); 159 callback_.Run();
160 } 160 }
161 } 161 }
162 162
163 private: 163 private:
164 base::Closure callback_; 164 base::Closure callback_;
165 bool wait_for_document_loaded_; 165 bool wait_for_document_loaded_;
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(), 512 std::string html = viewer::GetUnsafePartialArticleHtml(page_proto.get(),
513 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF); 513 DistilledPagePrefs::LIGHT, DistilledPagePrefs::SERIF);
514 EXPECT_THAT(html, HasSubstr(some_title)); 514 EXPECT_THAT(html, HasSubstr(some_title));
515 EXPECT_THAT(html, HasSubstr(no_content)); 515 EXPECT_THAT(html, HasSubstr(no_content));
516 EXPECT_THAT(html, Not(HasSubstr(no_title))); 516 EXPECT_THAT(html, Not(HasSubstr(no_title)));
517 EXPECT_THAT(html, Not(HasSubstr(some_content))); 517 EXPECT_THAT(html, Not(HasSubstr(some_content)));
518 } 518 }
519 } 519 }
520 520
521 } // namespace dom_distiller 521 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698