| 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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 11 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 16 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" | 18 #include "components/dom_distiller/content/dom_distiller_viewer_source.h" |
| 18 #include "components/dom_distiller/core/article_entry.h" | 19 #include "components/dom_distiller/core/article_entry.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 void SetUpOnMainThread() override { | 87 void SetUpOnMainThread() override { |
| 87 database_model_ = new FakeDB<ArticleEntry>::EntryMap; | 88 database_model_ = new FakeDB<ArticleEntry>::EntryMap; |
| 88 } | 89 } |
| 89 | 90 |
| 90 void TearDownOnMainThread() override { delete database_model_; } | 91 void TearDownOnMainThread() override { delete database_model_; } |
| 91 | 92 |
| 92 void SetUpCommandLine(base::CommandLine* command_line) override { | 93 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 93 command_line->AppendSwitch(switches::kEnableDomDistiller); | 94 command_line->AppendSwitch(switches::kEnableDomDistiller); |
| 94 } | 95 } |
| 95 | 96 |
| 96 static KeyedService* Build(content::BrowserContext* context) { | 97 static scoped_ptr<KeyedService> Build(content::BrowserContext* context) { |
| 97 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(database_model_); | 98 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(database_model_); |
| 98 distiller_factory_ = new MockDistillerFactory(); | 99 distiller_factory_ = new MockDistillerFactory(); |
| 99 MockDistillerPageFactory* distiller_page_factory_ = | 100 MockDistillerPageFactory* distiller_page_factory_ = |
| 100 new MockDistillerPageFactory(); | 101 new MockDistillerPageFactory(); |
| 101 DomDistillerContextKeyedService* service = | 102 scoped_ptr<DomDistillerContextKeyedService> service( |
| 102 new DomDistillerContextKeyedService( | 103 new DomDistillerContextKeyedService( |
| 103 scoped_ptr<DomDistillerStoreInterface>( | 104 scoped_ptr<DomDistillerStoreInterface>(CreateStoreWithFakeDB( |
| 104 CreateStoreWithFakeDB(fake_db, | 105 fake_db, FakeDB<ArticleEntry>::EntryMap())), |
| 105 FakeDB<ArticleEntry>::EntryMap())), | |
| 106 scoped_ptr<DistillerFactory>(distiller_factory_), | 106 scoped_ptr<DistillerFactory>(distiller_factory_), |
| 107 scoped_ptr<DistillerPageFactory>(distiller_page_factory_), | 107 scoped_ptr<DistillerPageFactory>(distiller_page_factory_), |
| 108 scoped_ptr<DistilledPagePrefs>( | 108 scoped_ptr<DistilledPagePrefs>(new DistilledPagePrefs( |
| 109 new DistilledPagePrefs( | 109 Profile::FromBrowserContext(context)->GetPrefs())))); |
| 110 Profile::FromBrowserContext( | |
| 111 context)->GetPrefs()))); | |
| 112 fake_db->InitCallback(true); | 110 fake_db->InitCallback(true); |
| 113 fake_db->LoadCallback(true); | 111 fake_db->LoadCallback(true); |
| 114 if (expect_distillation_) { | 112 if (expect_distillation_) { |
| 115 // There will only be destillation of an article if the database contains | 113 // There will only be destillation of an article if the database contains |
| 116 // the article. | 114 // the article. |
| 117 FakeDistiller* distiller = new FakeDistiller(true); | 115 FakeDistiller* distiller = new FakeDistiller(true); |
| 118 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) | 116 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) |
| 119 .WillOnce(testing::Return(distiller)); | 117 .WillOnce(testing::Return(distiller)); |
| 120 } | 118 } |
| 121 if (expect_distiller_page_) { | 119 if (expect_distiller_page_) { |
| 122 MockDistillerPage* distiller_page = new MockDistillerPage(); | 120 MockDistillerPage* distiller_page = new MockDistillerPage(); |
| 123 EXPECT_CALL(*distiller_page_factory_, CreateDistillerPageImpl()) | 121 EXPECT_CALL(*distiller_page_factory_, CreateDistillerPageImpl()) |
| 124 .WillOnce(testing::Return(distiller_page)); | 122 .WillOnce(testing::Return(distiller_page)); |
| 125 } | 123 } |
| 126 return service; | 124 return service.Pass(); |
| 127 } | 125 } |
| 128 | 126 |
| 129 void ViewSingleDistilledPage(const GURL& url, | 127 void ViewSingleDistilledPage(const GURL& url, |
| 130 const std::string& expected_mime_type); | 128 const std::string& expected_mime_type); |
| 131 // Database entries. | 129 // Database entries. |
| 132 static FakeDB<ArticleEntry>::EntryMap* database_model_; | 130 static FakeDB<ArticleEntry>::EntryMap* database_model_; |
| 133 static bool expect_distillation_; | 131 static bool expect_distillation_; |
| 134 static bool expect_distiller_page_; | 132 static bool expect_distiller_page_; |
| 135 static MockDistillerFactory* distiller_factory_; | 133 static MockDistillerFactory* distiller_factory_; |
| 136 }; | 134 }; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 EXPECT_EQ("dark sans-serif", result); | 435 EXPECT_EQ("dark sans-serif", result); |
| 438 | 436 |
| 439 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); | 437 distilled_page_prefs->SetFontFamily(DistilledPagePrefs::SERIF); |
| 440 base::RunLoop().RunUntilIdle(); | 438 base::RunLoop().RunUntilIdle(); |
| 441 EXPECT_TRUE( | 439 EXPECT_TRUE( |
| 442 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); | 440 content::ExecuteScriptAndExtractString(contents, kGetBodyClass, &result)); |
| 443 EXPECT_EQ("dark serif", result); | 441 EXPECT_EQ("dark serif", result); |
| 444 } | 442 } |
| 445 | 443 |
| 446 } // namespace dom_distiller | 444 } // namespace dom_distiller |
| OLD | NEW |