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

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

Issue 1336433002: Revert of Expose distiller functions to JavaScript (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-content
Patch Set: Created 5 years, 3 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
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h" 16 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" 17 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
20 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h " 18 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h "
21 #include "components/dom_distiller/core/article_entry.h" 19 #include "components/dom_distiller/core/article_entry.h"
22 #include "components/dom_distiller/core/distilled_page_prefs.h" 20 #include "components/dom_distiller/core/distilled_page_prefs.h"
23 #include "components/dom_distiller/core/distiller.h" 21 #include "components/dom_distiller/core/distiller.h"
24 #include "components/dom_distiller/core/dom_distiller_service.h" 22 #include "components/dom_distiller/core/dom_distiller_service.h"
25 #include "components/dom_distiller/core/dom_distiller_store.h" 23 #include "components/dom_distiller/core/dom_distiller_store.h"
26 #include "components/dom_distiller/core/dom_distiller_switches.h" 24 #include "components/dom_distiller/core/dom_distiller_switches.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const char kGetContent[] = 60 const char kGetContent[] =
63 "window.domAutomationController.send(" 61 "window.domAutomationController.send("
64 "document.getElementById('content').innerHTML)"; 62 "document.getElementById('content').innerHTML)";
65 63
66 const char kGetBodyClass[] = 64 const char kGetBodyClass[] =
67 "window.domAutomationController.send(" 65 "window.domAutomationController.send("
68 "document.body.className)"; 66 "document.body.className)";
69 67
70 const unsigned kDarkToolbarThemeColor = 0xFF1A1A1A; 68 const unsigned kDarkToolbarThemeColor = 0xFF1A1A1A;
71 69
72 const char kTestDistillerObject[] =
73 "window.domAutomationController.send("
74 "typeof distiller == 'object')";
75
76 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { 70 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) {
77 (*map)[e.entry_id()] = e; 71 (*map)[e.entry_id()] = e;
78 } 72 }
79 73
80 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { 74 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) {
81 ArticleEntry entry; 75 ArticleEntry entry;
82 entry.set_entry_id(entry_id); 76 entry.set_entry_id(entry_id);
83 if (!page_url.empty()) { 77 if (!page_url.empty()) {
84 ArticleEntryPage* page = entry.add_pages(); 78 ArticleEntryPage* page = entry.add_pages();
85 page->set_url(page_url); 79 page->set_url(page_url);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 distiller->RunDistillerUpdateCallback(update); 313 distiller->RunDistillerUpdateCallback(update);
320 314
321 content::WaitForLoadStop(contents); 315 content::WaitForLoadStop(contents);
322 316
323 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 317 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
324 contents, kGetContent , &result)); 318 contents, kGetContent , &result));
325 EXPECT_THAT(result, HasSubstr("content")); 319 EXPECT_THAT(result, HasSubstr("content"));
326 } 320 }
327 321
328 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 322 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
329 DistillerJavaScriptExposed) { 323 MultiPageArticle) {
330 // Navigate to a distiller URL.
331 GURL url(std::string(kDomDistillerScheme) + "://url");
332 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
333 chrome::Navigate(&params);
334
335 content::WebContents* contents =
336 browser()->tab_strip_model()->GetActiveWebContents();
337
338 // Wait for the page load to complete (this will be a distiller error page).
339 content::WaitForLoadStop(contents);
340
341 bool result;
342 // Execute in isolated world; where all distiller scripts are run.
343 EXPECT_TRUE(content::ExecuteScriptInIsolatedWorldAndExtractBool(
344 contents, chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL, kTestDistillerObject,
345 &result));
346 EXPECT_TRUE(result);
347 }
348
349 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
350 DistillerJavaScriptNotInMainWorld) {
351 // Navigate to a distiller URL.
352 GURL url(std::string(kDomDistillerScheme) + "://url");
353 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
354 chrome::Navigate(&params);
355
356 content::WebContents* contents =
357 browser()->tab_strip_model()->GetActiveWebContents();
358
359 // Wait for the page load to complete (this will be a distiller error page).
360 content::WaitForLoadStop(contents);
361
362 bool result;
363 // Execute in main world, the distiller object should not be here.
364 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
365 contents, kTestDistillerObject, &result));
366 EXPECT_FALSE(result);
367 }
368
369 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
370 DistillerJavaScriptNotExposed) {
371 // Navigate to a non-distiller URL.
372 GURL url("http://url");
373 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED);
374 chrome::Navigate(&params);
375
376 content::WebContents* contents =
377 browser()->tab_strip_model()->GetActiveWebContents();
378
379 // Wait for the page load to complete.
380 content::WaitForLoadStop(contents);
381
382 bool result;
383 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
384 contents, kTestDistillerObject, &result));
385 EXPECT_FALSE(result);
386 }
387
388 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, MultiPageArticle) {
389 expect_distillation_ = false; 324 expect_distillation_ = false;
390 expect_distiller_page_ = true; 325 expect_distiller_page_ = true;
391 dom_distiller::DomDistillerServiceFactory::GetInstance() 326 dom_distiller::DomDistillerServiceFactory::GetInstance()
392 ->SetTestingFactoryAndUse(browser()->profile(), &Build); 327 ->SetTestingFactoryAndUse(browser()->profile(), &Build);
393 328
394 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = 329 scoped_refptr<content::MessageLoopRunner> distillation_done_runner =
395 new content::MessageLoopRunner; 330 new content::MessageLoopRunner;
396 331
397 FakeDistiller* distiller = new FakeDistiller( 332 FakeDistiller* distiller = new FakeDistiller(
398 false, 333 false,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 EXPECT_EQ(kDarkToolbarThemeColor, contents->GetThemeColor()); 445 EXPECT_EQ(kDarkToolbarThemeColor, contents->GetThemeColor());
511 446
512 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); 447 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF);
513 base::RunLoop().RunUntilIdle(); 448 base::RunLoop().RunUntilIdle();
514 EXPECT_TRUE( 449 EXPECT_TRUE(
515 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); 450 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result));
516 EXPECT_EQ("dark serif", result); 451 EXPECT_EQ("dark serif", result);
517 } 452 }
518 453
519 } // namespace dom_distiller 454 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698