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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "components/dom_distiller/core/fake_distiller_page.h" | 27 #include "components/dom_distiller/core/fake_distiller_page.h" |
28 #include "components/dom_distiller/core/task_tracker.h" | 28 #include "components/dom_distiller/core/task_tracker.h" |
29 #include "components/dom_distiller/core/url_constants.h" | 29 #include "components/dom_distiller/core/url_constants.h" |
30 #include "components/dom_distiller/core/url_utils.h" | 30 #include "components/dom_distiller/core/url_utils.h" |
31 #include "components/leveldb_proto/testing/fake_db.h" | 31 #include "components/leveldb_proto/testing/fake_db.h" |
32 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
33 #include "content/public/browser/url_data_source.h" | 33 #include "content/public/browser/url_data_source.h" |
34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
35 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
36 #include "content/public/common/isolated_world_ids.h" | 36 #include "content/public/common/isolated_world_ids.h" |
| 37 #include "content/public/common/service_registry.h" |
37 #include "content/public/test/browser_test_utils.h" | 38 #include "content/public/test/browser_test_utils.h" |
38 #include "grit/components_strings.h" | 39 #include "grit/components_strings.h" |
39 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
42 | 43 |
43 namespace dom_distiller { | 44 namespace dom_distiller { |
44 | 45 |
45 using leveldb_proto::test::FakeDB; | 46 using leveldb_proto::test::FakeDB; |
46 using test::FakeDistiller; | 47 using test::FakeDistiller; |
(...skipping 11 matching lines...) Expand all Loading... |
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 Loading... |
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(¶ms); |
| 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 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 340 contents, kTestDistillerObject, &result)); |
| 341 EXPECT_TRUE(result); |
| 342 } |
| 343 |
| 344 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, |
| 345 DistillerJavaScriptNotExposed) { |
| 346 // Navigate to a non-distiller URL. |
| 347 GURL url("http://url"); |
| 348 chrome::NavigateParams params(browser(), url, ui::PAGE_TRANSITION_TYPED); |
| 349 chrome::Navigate(¶ms); |
| 350 |
| 351 content::WebContents* contents = |
| 352 browser()->tab_strip_model()->GetActiveWebContents(); |
| 353 |
| 354 // Wait for the page load to complete. |
| 355 content::WaitForLoadStop(contents); |
| 356 |
| 357 bool result; |
| 358 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 359 contents, kTestDistillerObject, &result)); |
| 360 EXPECT_FALSE(result); |
| 361 } |
| 362 |
| 363 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, MultiPageArticle) { |
322 expect_distillation_ = false; | 364 expect_distillation_ = false; |
323 expect_distiller_page_ = true; | 365 expect_distiller_page_ = true; |
324 dom_distiller::DomDistillerServiceFactory::GetInstance() | 366 dom_distiller::DomDistillerServiceFactory::GetInstance() |
325 ->SetTestingFactoryAndUse(browser()->profile(), &Build); | 367 ->SetTestingFactoryAndUse(browser()->profile(), &Build); |
326 | 368 |
327 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = | 369 scoped_refptr<content::MessageLoopRunner> distillation_done_runner = |
328 new content::MessageLoopRunner; | 370 new content::MessageLoopRunner; |
329 | 371 |
330 FakeDistiller* distiller = new FakeDistiller( | 372 FakeDistiller* distiller = new FakeDistiller( |
331 false, | 373 false, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 EXPECT_EQ("dark sans-serif", result); | 482 EXPECT_EQ("dark sans-serif", result); |
441 | 483 |
442 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); | 484 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); |
443 base::RunLoop().RunUntilIdle(); | 485 base::RunLoop().RunUntilIdle(); |
444 EXPECT_TRUE( | 486 EXPECT_TRUE( |
445 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); | 487 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); |
446 EXPECT_EQ("dark serif", result); | 488 EXPECT_EQ("dark serif", result); |
447 } | 489 } |
448 | 490 |
449 } // namespace dom_distiller | 491 } // namespace dom_distiller |
OLD | NEW |