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

Side by Side Diff: chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc

Issue 1130703003: Show template before distiller finishes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ios-superclass
Patch Set: Rebase and add file to gypi Created 5 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
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 <string.h> 5 #include <string.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" 10 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 250 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
251 InvalidURLShouldNotCrash) { 251 InvalidURLShouldNotCrash) {
252 // This is a bogus URL, so no distillation will happen. 252 // This is a bogus URL, so no distillation will happen.
253 expect_distillation_ = false; 253 expect_distillation_ = false;
254 expect_distiller_page_ = false; 254 expect_distiller_page_ = false;
255 const GURL url(std::string(kDomDistillerScheme) + "://bogus/foobar"); 255 const GURL url(std::string(kDomDistillerScheme) + "://bogus/foobar");
256 ViewSingleDistilledPage(url, "text/html"); 256 ViewSingleDistilledPage(url, "text/html");
257 } 257 }
258 258
259 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 259 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
260 EarlyTemplateLoad) {
261 dom_distiller::DomDistillerServiceFactory::GetInstance()
262 ->SetTestingFactoryAndUse(browser()->profile(), &Build);
263
264 scoped_refptr<content::MessageLoopRunner> distillation_done_runner =
265 new content::MessageLoopRunner;
266
267 FakeDistiller* distiller = new FakeDistiller(
268 false,
269 distillation_done_runner->QuitClosure());
270 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
271 .WillOnce(testing::Return(distiller));
272
273 // Setup observer to inspect the RenderViewHost after committed navigation.
cjhopman 2015/05/21 20:53:44 This comment doesn't make sense to me we aren't se
mdjones 2015/05/22 00:44:48 Done.
274 content::WebContents* contents =
275 browser()->tab_strip_model()->GetActiveWebContents();
276
277 // Navigate to a URL.
278 GURL url(dom_distiller::url_utils::GetDistillerViewUrlFromUrl(
279 kDomDistillerScheme, GURL("http://urlthatlooksvalid.com")));
280 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
281 chrome::Navigate(&params);
282 distillation_done_runner->Run();
283
284 // Wait for the page load to complete (should only be template).
285 content::WaitForLoadStop(contents);
286 std::string result;
287 // Loading spinner should be on screen at this point.
288 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
289 contents, kGetLoadIndicatorClassName , &result));
290 EXPECT_EQ("visible", result);
291
292 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
293 contents, kGetContent , &result));
294 EXPECT_THAT(result, Not(HasSubstr("content")));
295
296 // Finish distillation and make sure the spinner has been replaced by text.
297 std::vector<scoped_refptr<ArticleDistillationUpdate::RefCountedPageProto> >
298 update_pages;
299 scoped_ptr<DistilledArticleProto> article(new DistilledArticleProto());
300
301 scoped_refptr<base::RefCountedData<DistilledPageProto> > page_proto =
302 new base::RefCountedData<DistilledPageProto>();
303 page_proto->data.set_url("http://foo.html");
304 page_proto->data.set_html("<div>content</div>");
305 update_pages.push_back(page_proto);
306 *(article->add_pages()) = page_proto->data;
307
308 ArticleDistillationUpdate update(update_pages, true, false);
309 distiller->RunDistillerUpdateCallback(update);
310
311 content::WaitForLoadStop(contents);
312
313 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
314 contents, kGetContent , &result));
315 EXPECT_THAT(result, HasSubstr("content"));
316 }
317
318 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
260 MultiPageArticle) { 319 MultiPageArticle) {
261 expect_distillation_ = false; 320 expect_distillation_ = false;
262 expect_distiller_page_ = true; 321 expect_distiller_page_ = true;
263 dom_distiller::DomDistillerServiceFactory::GetInstance() 322 dom_distiller::DomDistillerServiceFactory::GetInstance()
264 ->SetTestingFactoryAndUse(browser()->profile(), &Build); 323 ->SetTestingFactoryAndUse(browser()->profile(), &Build);
265 324
266 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = 325 scoped_refptr<content::MessageLoopRunner> distillation_done_runner =
267 new content::MessageLoopRunner; 326 new content::MessageLoopRunner;
268 327
269 FakeDistiller* distiller = new FakeDistiller( 328 FakeDistiller* distiller = new FakeDistiller(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 EXPECT_EQ("dark sans-serif", result); 438 EXPECT_EQ("dark sans-serif", result);
380 439
381 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); 440 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF);
382 base::RunLoop().RunUntilIdle(); 441 base::RunLoop().RunUntilIdle();
383 EXPECT_TRUE( 442 EXPECT_TRUE(
384 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); 443 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result));
385 EXPECT_EQ("dark serif", result); 444 EXPECT_EQ("dark serif", result);
386 } 445 }
387 446
388 } // namespace dom_distiller 447 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698