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

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

Issue 1231083007: Expose distiller functions to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-content
Patch Set: Function rename and remove unnecessary code Created 5 years, 4 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/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" 11 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_isolated_world_ids.h"
15 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" 19 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
19 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h " 20 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h "
20 #include "components/dom_distiller/core/article_entry.h" 21 #include "components/dom_distiller/core/article_entry.h"
21 #include "components/dom_distiller/core/distilled_page_prefs.h" 22 #include "components/dom_distiller/core/distilled_page_prefs.h"
22 #include "components/dom_distiller/core/distiller.h" 23 #include "components/dom_distiller/core/distiller.h"
23 #include "components/dom_distiller/core/dom_distiller_service.h" 24 #include "components/dom_distiller/core/dom_distiller_service.h"
24 #include "components/dom_distiller/core/dom_distiller_store.h" 25 #include "components/dom_distiller/core/dom_distiller_store.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 "document.getElementById('loadingIndicator').className)"; 59 "document.getElementById('loadingIndicator').className)";
59 60
60 const char kGetContent[] = 61 const char kGetContent[] =
61 "window.domAutomationController.send(" 62 "window.domAutomationController.send("
62 "document.getElementById('content').innerHTML)"; 63 "document.getElementById('content').innerHTML)";
63 64
64 const char kGetBodyClass[] = 65 const char kGetBodyClass[] =
65 "window.domAutomationController.send(" 66 "window.domAutomationController.send("
66 "document.body.className)"; 67 "document.body.className)";
67 68
69 const char kTestDistillerObject[] =
70 "window.domAutomationController.send("
71 "typeof distiller == 'object')";
72
68 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { 73 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) {
69 (*map)[e.entry_id()] = e; 74 (*map)[e.entry_id()] = e;
70 } 75 }
71 76
72 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { 77 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) {
73 ArticleEntry entry; 78 ArticleEntry entry;
74 entry.set_entry_id(entry_id); 79 entry.set_entry_id(entry_id);
75 if (!page_url.empty()) { 80 if (!page_url.empty()) {
76 ArticleEntryPage* page = entry.add_pages(); 81 ArticleEntryPage* page = entry.add_pages();
77 page->set_url(page_url); 82 page->set_url(page_url);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 distiller->RunDistillerUpdateCallback(update); 316 distiller->RunDistillerUpdateCallback(update);
312 317
313 content::WaitForLoadStop(contents); 318 content::WaitForLoadStop(contents);
314 319
315 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 320 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
316 contents, kGetContent , &result)); 321 contents, kGetContent , &result));
317 EXPECT_THAT(result, HasSubstr("content")); 322 EXPECT_THAT(result, HasSubstr("content"));
318 } 323 }
319 324
320 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 325 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
321 MultiPageArticle) { 326 DistillerJavaScriptExposed) {
327 // Navigate to a distiller URL.
328 GURL url(std::string(kDomDistillerScheme) + "://url");
329 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
330 chrome::Navigate(&params);
331
332 content::WebContents* contents =
333 browser()->tab_strip_model()->GetActiveWebContents();
334
335 // Wait for the page load to complete (this will be a distiller error page).
336 content::WaitForLoadStop(contents);
337
338 bool result;
339 // Execute in isolated world; where all distiller scripts are run.
340 EXPECT_TRUE(content::ExecuteScriptInIsolatedWorldAndExtractBool(
341 contents, chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL, kTestDistillerObject,
342 &result));
343 EXPECT_TRUE(result);
344 }
345
346 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
347 DistillerJavaScriptNotInMainWorld) {
348 // Navigate to a distiller URL.
349 GURL url(std::string(kDomDistillerScheme) + "://url");
350 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
351 chrome::Navigate(&params);
352
353 content::WebContents* contents =
354 browser()->tab_strip_model()->GetActiveWebContents();
355
356 // Wait for the page load to complete (this will be a distiller error page).
357 content::WaitForLoadStop(contents);
358
359 bool result;
360 // Execute in main world, the distiller object should not be here.
361 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
362 contents, kTestDistillerObject, &result));
363 EXPECT_FALSE(result);
364 }
365
366 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
367 DistillerJavaScriptNotExposed) {
368 // Navigate to a non-distiller URL.
369 GURL url("http://url");
370 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
371 chrome::Navigate(&params);
372
373 content::WebContents* contents =
374 browser()->tab_strip_model()->GetActiveWebContents();
375
376 // Wait for the page load to complete.
377 content::WaitForLoadStop(contents);
378
379 bool result;
380 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
381 contents, kTestDistillerObject, &result));
382 EXPECT_FALSE(result);
383 }
384
385 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, MultiPageArticle) {
322 expect_distillation_ = false; 386 expect_distillation_ = false;
323 expect_distiller_page_ = true; 387 expect_distiller_page_ = true;
324 dom_distiller::DomDistillerServiceFactory::GetInstance() 388 dom_distiller::DomDistillerServiceFactory::GetInstance()
325 ->SetTestingFactoryAndUse(browser()->profile(), &Build); 389 ->SetTestingFactoryAndUse(browser()->profile(), &Build);
326 390
327 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = 391 scoped_refptr<content::MessageLoopRunner> distillation_done_runner =
328 new content::MessageLoopRunner; 392 new content::MessageLoopRunner;
329 393
330 FakeDistiller* distiller = new FakeDistiller( 394 FakeDistiller* distiller = new FakeDistiller(
331 false, 395 false,
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 EXPECT_EQ("dark sans-serif", result); 504 EXPECT_EQ("dark sans-serif", result);
441 505
442 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); 506 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF);
443 base::RunLoop().RunUntilIdle(); 507 base::RunLoop().RunUntilIdle();
444 EXPECT_TRUE( 508 EXPECT_TRUE(
445 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); 509 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result));
446 EXPECT_EQ("dark serif", result); 510 EXPECT_EQ("dark serif", result);
447 } 511 }
448 512
449 } // namespace dom_distiller 513 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698