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

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: Update to use StrongBinding and rebase 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
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"
15 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
17 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" 19 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
18 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h " 20 #include "components/dom_distiller/content/browser/dom_distiller_viewer_source.h "
19 #include "components/dom_distiller/core/article_entry.h" 21 #include "components/dom_distiller/core/article_entry.h"
20 #include "components/dom_distiller/core/distilled_page_prefs.h" 22 #include "components/dom_distiller/core/distilled_page_prefs.h"
21 #include "components/dom_distiller/core/distiller.h" 23 #include "components/dom_distiller/core/distiller.h"
22 #include "components/dom_distiller/core/dom_distiller_service.h" 24 #include "components/dom_distiller/core/dom_distiller_service.h"
23 #include "components/dom_distiller/core/dom_distiller_store.h" 25 #include "components/dom_distiller/core/dom_distiller_store.h"
24 #include "components/dom_distiller/core/dom_distiller_switches.h" 26 #include "components/dom_distiller/core/dom_distiller_switches.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 const char kGetContent[] = 62 const char kGetContent[] =
61 "window.domAutomationController.send(" 63 "window.domAutomationController.send("
62 "document.getElementById('content').innerHTML)"; 64 "document.getElementById('content').innerHTML)";
63 65
64 const char kGetBodyClass[] = 66 const char kGetBodyClass[] =
65 "window.domAutomationController.send(" 67 "window.domAutomationController.send("
66 "document.body.className)"; 68 "document.body.className)";
67 69
68 const unsigned kDarkToolbarThemeColor = 0xFF1A1A1A; 70 const unsigned kDarkToolbarThemeColor = 0xFF1A1A1A;
69 71
72 const char kTestDistillerObject[] =
73 "window.domAutomationController.send("
74 "typeof distiller == 'object')";
75
70 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { 76 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) {
71 (*map)[e.entry_id()] = e; 77 (*map)[e.entry_id()] = e;
72 } 78 }
73 79
74 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { 80 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) {
75 ArticleEntry entry; 81 ArticleEntry entry;
76 entry.set_entry_id(entry_id); 82 entry.set_entry_id(entry_id);
77 if (!page_url.empty()) { 83 if (!page_url.empty()) {
78 ArticleEntryPage* page = entry.add_pages(); 84 ArticleEntryPage* page = entry.add_pages();
79 page->set_url(page_url); 85 page->set_url(page_url);
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 distiller->RunDistillerUpdateCallback(update); 319 distiller->RunDistillerUpdateCallback(update);
314 320
315 content::WaitForLoadStop(contents); 321 content::WaitForLoadStop(contents);
316 322
317 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 323 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
318 contents, kGetContent , &result)); 324 contents, kGetContent , &result));
319 EXPECT_THAT(result, HasSubstr("content")); 325 EXPECT_THAT(result, HasSubstr("content"));
320 } 326 }
321 327
322 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 328 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
323 MultiPageArticle) { 329 DistillerJavaScriptExposed) {
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) {
324 expect_distillation_ = false; 389 expect_distillation_ = false;
325 expect_distiller_page_ = true; 390 expect_distiller_page_ = true;
326 dom_distiller::DomDistillerServiceFactory::GetInstance() 391 dom_distiller::DomDistillerServiceFactory::GetInstance()
327 ->SetTestingFactoryAndUse(browser()->profile(), &Build); 392 ->SetTestingFactoryAndUse(browser()->profile(), &Build);
328 393
329 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = 394 scoped_refptr<content::MessageLoopRunner> distillation_done_runner =
330 new content::MessageLoopRunner; 395 new content::MessageLoopRunner;
331 396
332 FakeDistiller* distiller = new FakeDistiller( 397 FakeDistiller* distiller = new FakeDistiller(
333 false, 398 false,
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 EXPECT_EQ(kDarkToolbarThemeColor, contents->GetThemeColor()); 510 EXPECT_EQ(kDarkToolbarThemeColor, contents->GetThemeColor());
446 511
447 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); 512 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF);
448 base::RunLoop().RunUntilIdle(); 513 base::RunLoop().RunUntilIdle();
449 EXPECT_TRUE( 514 EXPECT_TRUE(
450 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); 515 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result));
451 EXPECT_EQ("dark serif", result); 516 EXPECT_EQ("dark serif", result);
452 } 517 }
453 518
454 } // namespace dom_distiller 519 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698