OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 "document.getElementById('loadingIndicator').className)"; | 60 "document.getElementById('loadingIndicator').className)"; |
59 | 61 |
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 |
| 70 const char kTestDistillerObject[] = |
| 71 "window.domAutomationController.send(" |
| 72 "typeof distiller == 'object')"; |
| 73 |
68 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { | 74 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { |
69 (*map)[e.entry_id()] = e; | 75 (*map)[e.entry_id()] = e; |
70 } | 76 } |
71 | 77 |
72 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { | 78 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { |
73 ArticleEntry entry; | 79 ArticleEntry entry; |
74 entry.set_entry_id(entry_id); | 80 entry.set_entry_id(entry_id); |
75 if (!page_url.empty()) { | 81 if (!page_url.empty()) { |
76 ArticleEntryPage* page = entry.add_pages(); | 82 ArticleEntryPage* page = entry.add_pages(); |
77 page->set_url(page_url); | 83 page->set_url(page_url); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 distiller->RunDistillerUpdateCallback(update); | 317 distiller->RunDistillerUpdateCallback(update); |
312 | 318 |
313 content::WaitForLoadStop(contents); | 319 content::WaitForLoadStop(contents); |
314 | 320 |
315 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 321 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
316 contents, kGetContent , &result)); | 322 contents, kGetContent , &result)); |
317 EXPECT_THAT(result, HasSubstr("content")); | 323 EXPECT_THAT(result, HasSubstr("content")); |
318 } | 324 } |
319 | 325 |
320 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, | 326 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, |
321 MultiPageArticle) { | 327 DistillerJavaScriptExposed) { |
| 328 // Navigate to a distiller URL. |
| 329 GURL url(std::string(kDomDistillerScheme) + "://url"); |
| 330 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED); |
| 331 chrome::Navigate(¶ms); |
| 332 |
| 333 content::WebContents* contents = |
| 334 browser()->tab_strip_model()->GetActiveWebContents(); |
| 335 |
| 336 // Wait for the page load to complete (this will be a distiller error page). |
| 337 content::WaitForLoadStop(contents); |
| 338 |
| 339 bool result; |
| 340 // Execute in isolated world; where all distiller scripts are run. |
| 341 EXPECT_TRUE(content::ExecuteScriptInIsolatedWorldAndExtractBool( |
| 342 contents, chrome::ISOLATED_WORLD_ID_CHROME_INTERNAL, kTestDistillerObject, |
| 343 &result)); |
| 344 EXPECT_TRUE(result); |
| 345 } |
| 346 |
| 347 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, |
| 348 DistillerJavaScriptNotInMainWorld) { |
| 349 // Navigate to a distiller URL. |
| 350 GURL url(std::string(kDomDistillerScheme) + "://url"); |
| 351 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED); |
| 352 chrome::Navigate(¶ms); |
| 353 |
| 354 content::WebContents* contents = |
| 355 browser()->tab_strip_model()->GetActiveWebContents(); |
| 356 |
| 357 // Wait for the page load to complete (this will be a distiller error page). |
| 358 content::WaitForLoadStop(contents); |
| 359 |
| 360 bool result; |
| 361 // Execute in main world, the distiller object should not be here. |
| 362 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 363 contents, kTestDistillerObject, &result)); |
| 364 EXPECT_FALSE(result); |
| 365 } |
| 366 |
| 367 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, |
| 368 DistillerJavaScriptNotExposed) { |
| 369 // Navigate to a non-distiller URL. |
| 370 GURL url("http://url"); |
| 371 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED); |
| 372 chrome::Navigate(¶ms); |
| 373 |
| 374 content::WebContents* contents = |
| 375 browser()->tab_strip_model()->GetActiveWebContents(); |
| 376 |
| 377 // Wait for the page load to complete. |
| 378 content::WaitForLoadStop(contents); |
| 379 |
| 380 bool result; |
| 381 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 382 contents, kTestDistillerObject, &result)); |
| 383 EXPECT_FALSE(result); |
| 384 } |
| 385 |
| 386 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, MultiPageArticle) { |
322 expect_distillation_ = false; | 387 expect_distillation_ = false; |
323 expect_distiller_page_ = true; | 388 expect_distiller_page_ = true; |
324 dom_distiller::DomDistillerServiceFactory::GetInstance() | 389 dom_distiller::DomDistillerServiceFactory::GetInstance() |
325 ->SetTestingFactoryAndUse(browser()->profile(), &Build); | 390 ->SetTestingFactoryAndUse(browser()->profile(), &Build); |
326 | 391 |
327 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = | 392 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = |
328 new content::MessageLoopRunner; | 393 new content::MessageLoopRunner; |
329 | 394 |
330 FakeDistiller* distiller = new FakeDistiller( | 395 FakeDistiller* distiller = new FakeDistiller( |
331 false, | 396 false, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 EXPECT_EQ("dark sans-serif", result); | 505 EXPECT_EQ("dark sans-serif", result); |
441 | 506 |
442 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); | 507 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); |
443 base::RunLoop().RunUntilIdle(); | 508 base::RunLoop().RunUntilIdle(); |
444 EXPECT_TRUE( | 509 EXPECT_TRUE( |
445 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); | 510 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); |
446 EXPECT_EQ("dark serif", result); | 511 EXPECT_EQ("dark serif", result); |
447 } | 512 } |
448 | 513 |
449 } // namespace dom_distiller | 514 } // namespace dom_distiller |
OLD | NEW |