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/path_service.h" | 9 #include "base/path_service.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_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | 19 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" |
20 #include "components/dom_distiller/core/article_entry.h" | 20 #include "components/dom_distiller/core/article_entry.h" |
| 21 #include "components/dom_distiller/core/distilled_page_prefs.h" |
21 #include "components/dom_distiller/core/distiller.h" | 22 #include "components/dom_distiller/core/distiller.h" |
22 #include "components/dom_distiller/core/dom_distiller_service.h" | 23 #include "components/dom_distiller/core/dom_distiller_service.h" |
23 #include "components/dom_distiller/core/dom_distiller_store.h" | 24 #include "components/dom_distiller/core/dom_distiller_store.h" |
24 #include "components/dom_distiller/core/dom_distiller_test_util.h" | 25 #include "components/dom_distiller/core/dom_distiller_test_util.h" |
25 #include "components/dom_distiller/core/fake_distiller.h" | 26 #include "components/dom_distiller/core/fake_distiller.h" |
26 #include "components/dom_distiller/core/fake_distiller_page.h" | 27 #include "components/dom_distiller/core/fake_distiller_page.h" |
27 #include "components/dom_distiller/core/task_tracker.h" | 28 #include "components/dom_distiller/core/task_tracker.h" |
28 #include "components/dom_distiller/core/url_constants.h" | 29 #include "components/dom_distiller/core/url_constants.h" |
29 #include "components/dom_distiller/core/url_utils.h" | 30 #include "components/dom_distiller/core/url_utils.h" |
30 #include "components/leveldb_proto/testing/fake_db.h" | 31 #include "components/leveldb_proto/testing/fake_db.h" |
(...skipping 19 matching lines...) Expand all Loading... |
50 namespace { | 51 namespace { |
51 | 52 |
52 const char kGetLoadIndicatorClassName[] = | 53 const char kGetLoadIndicatorClassName[] = |
53 "window.domAutomationController.send(" | 54 "window.domAutomationController.send(" |
54 "document.getElementById('loadingIndicator').className)"; | 55 "document.getElementById('loadingIndicator').className)"; |
55 | 56 |
56 const char kGetContent[] = | 57 const char kGetContent[] = |
57 "window.domAutomationController.send(" | 58 "window.domAutomationController.send(" |
58 "document.getElementById('content').innerHTML)"; | 59 "document.getElementById('content').innerHTML)"; |
59 | 60 |
| 61 const char kGetBodyClass[] = |
| 62 "window.domAutomationController.send(" |
| 63 "document.body.className)"; |
| 64 |
60 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { | 65 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) { |
61 (*map)[e.entry_id()] = e; | 66 (*map)[e.entry_id()] = e; |
62 } | 67 } |
63 | 68 |
64 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { | 69 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { |
65 ArticleEntry entry; | 70 ArticleEntry entry; |
66 entry.set_entry_id(entry_id); | 71 entry.set_entry_id(entry_id); |
67 if (!page_url.empty()) { | 72 if (!page_url.empty()) { |
68 ArticleEntryPage* page = entry.add_pages(); | 73 ArticleEntryPage* page = entry.add_pages(); |
69 page->set_url(page_url); | 74 page->set_url(page_url); |
(...skipping 22 matching lines...) Expand all Loading... |
92 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(database_model_); | 97 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(database_model_); |
93 distiller_factory_ = new MockDistillerFactory(); | 98 distiller_factory_ = new MockDistillerFactory(); |
94 MockDistillerPageFactory* distiller_page_factory_ = | 99 MockDistillerPageFactory* distiller_page_factory_ = |
95 new MockDistillerPageFactory(); | 100 new MockDistillerPageFactory(); |
96 DomDistillerContextKeyedService* service = | 101 DomDistillerContextKeyedService* service = |
97 new DomDistillerContextKeyedService( | 102 new DomDistillerContextKeyedService( |
98 scoped_ptr<DomDistillerStoreInterface>( | 103 scoped_ptr<DomDistillerStoreInterface>( |
99 CreateStoreWithFakeDB(fake_db, | 104 CreateStoreWithFakeDB(fake_db, |
100 FakeDB<ArticleEntry>::EntryMap())), | 105 FakeDB<ArticleEntry>::EntryMap())), |
101 scoped_ptr<DistillerFactory>(distiller_factory_), | 106 scoped_ptr<DistillerFactory>(distiller_factory_), |
102 scoped_ptr<DistillerPageFactory>(distiller_page_factory_)); | 107 scoped_ptr<DistillerPageFactory>(distiller_page_factory_), |
| 108 scoped_ptr<DistilledPagePrefs>( |
| 109 new DistilledPagePrefs( |
| 110 Profile::FromBrowserContext( |
| 111 context)->GetPrefs()))); |
103 fake_db->InitCallback(true); | 112 fake_db->InitCallback(true); |
104 fake_db->LoadCallback(true); | 113 fake_db->LoadCallback(true); |
105 if (expect_distillation_) { | 114 if (expect_distillation_) { |
106 // There will only be destillation of an article if the database contains | 115 // There will only be destillation of an article if the database contains |
107 // the article. | 116 // the article. |
108 FakeDistiller* distiller = new FakeDistiller(true); | 117 FakeDistiller* distiller = new FakeDistiller(true); |
109 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 118 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
110 .WillOnce(testing::Return(distiller)); | 119 .WillOnce(testing::Return(distiller)); |
111 } | 120 } |
112 if (expect_distiller_page_) { | 121 if (expect_distiller_page_) { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 std::string result; | 323 std::string result; |
315 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 324 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
316 contents, kGetLoadIndicatorClassName, &result)); | 325 contents, kGetLoadIndicatorClassName, &result)); |
317 EXPECT_EQ("hidden", result); | 326 EXPECT_EQ("hidden", result); |
318 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 327 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
319 contents, kGetContent , &result)); | 328 contents, kGetContent , &result)); |
320 EXPECT_THAT(result, HasSubstr("Page 1 content")); | 329 EXPECT_THAT(result, HasSubstr("Page 1 content")); |
321 EXPECT_THAT(result, HasSubstr("Page 2 content")); | 330 EXPECT_THAT(result, HasSubstr("Page 2 content")); |
322 } | 331 } |
323 | 332 |
| 333 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, PrefChange) { |
| 334 expect_distillation_ = true; |
| 335 expect_distiller_page_ = true; |
| 336 GURL view_url("http://www.example.com/1"); |
| 337 content::WebContents* contents = |
| 338 browser()->tab_strip_model()->GetActiveWebContents(); |
| 339 const GURL url = url_utils::GetDistillerViewUrlFromUrl( |
| 340 chrome::kDomDistillerScheme, view_url); |
| 341 ViewSingleDistilledPage(url, "text/html"); |
| 342 content::WaitForLoadStop(contents); |
| 343 std::string result; |
| 344 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 345 contents, kGetBodyClass, &result)); |
| 346 EXPECT_EQ("light", result); |
| 347 |
| 348 // Getting DistilledPagePrefs instance. |
| 349 DistilledPagePrefs* distilled_page_prefs = |
| 350 DomDistillerServiceFactory::GetForBrowserContext( |
| 351 browser()->profile())->GetDistilledPagePrefs(); |
| 352 |
| 353 distilled_page_prefs->SetTheme(DistilledPagePrefs::DARK); |
| 354 base::RunLoop().RunUntilIdle(); |
| 355 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 356 contents, kGetBodyClass, &result)); |
| 357 EXPECT_EQ("dark", result); |
| 358 } |
| 359 |
324 } // namespace dom_distiller | 360 } // namespace dom_distiller |
OLD | NEW |