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

Side by Side Diff: chrome/browser/dom_distiller/dom_distiller_viewer_source_browsertest.cc

Issue 330833002: Extract protobuf database into a new 'leveldb_proto' component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 6 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 | Annotate | Revision Log
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/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/distiller.h" 21 #include "components/dom_distiller/core/distiller.h"
21 #include "components/dom_distiller/core/dom_distiller_service.h" 22 #include "components/dom_distiller/core/dom_distiller_service.h"
22 #include "components/dom_distiller/core/dom_distiller_store.h" 23 #include "components/dom_distiller/core/dom_distiller_store.h"
23 #include "components/dom_distiller/core/dom_distiller_test_util.h" 24 #include "components/dom_distiller/core/dom_distiller_test_util.h"
24 #include "components/dom_distiller/core/fake_db.h"
25 #include "components/dom_distiller/core/fake_distiller.h" 25 #include "components/dom_distiller/core/fake_distiller.h"
26 #include "components/dom_distiller/core/fake_distiller_page.h" 26 #include "components/dom_distiller/core/fake_distiller_page.h"
27 #include "components/dom_distiller/core/task_tracker.h" 27 #include "components/dom_distiller/core/task_tracker.h"
28 #include "components/dom_distiller/core/url_constants.h" 28 #include "components/dom_distiller/core/url_constants.h"
29 #include "components/dom_distiller/core/url_utils.h" 29 #include "components/dom_distiller/core/url_utils.h"
30 #include "components/leveldb_proto/testing/fake_db.h"
30 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
31 #include "content/public/browser/url_data_source.h" 32 #include "content/public/browser/url_data_source.h"
32 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
33 #include "content/public/browser/web_contents_observer.h" 34 #include "content/public/browser/web_contents_observer.h"
34 #include "content/public/test/browser_test_utils.h" 35 #include "content/public/test/browser_test_utils.h"
35 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 namespace dom_distiller { 39 namespace dom_distiller {
39 40
40 using test::FakeDB; 41 using leveldb_proto::test::FakeDB;
41 using test::FakeDistiller; 42 using test::FakeDistiller;
42 using test::MockDistillerPage; 43 using test::MockDistillerPage;
43 using test::MockDistillerFactory; 44 using test::MockDistillerFactory;
44 using test::MockDistillerPageFactory; 45 using test::MockDistillerPageFactory;
45 using test::util::CreateStoreWithFakeDB; 46 using test::util::CreateStoreWithFakeDB;
46 using testing::HasSubstr; 47 using testing::HasSubstr;
47 using testing::Not; 48 using testing::Not;
48 49
49 namespace { 50 namespace {
50 51
51 const char kGetLoadIndicatorClassName[] = 52 const char kGetLoadIndicatorClassName[] =
52 "window.domAutomationController.send(" 53 "window.domAutomationController.send("
53 "document.getElementById('loadingIndicator').className)"; 54 "document.getElementById('loadingIndicator').className)";
54 55
55 const char kGetContent[] = 56 const char kGetContent[] =
56 "window.domAutomationController.send(" 57 "window.domAutomationController.send("
57 "document.getElementById('content').innerHTML)"; 58 "document.getElementById('content').innerHTML)";
58 59
59 void AddEntry(const ArticleEntry& e, FakeDB::EntryMap* map) { 60 void AddEntry(const ArticleEntry& e, FakeDB<ArticleEntry>::EntryMap* map) {
60 (*map)[e.entry_id()] = e; 61 (*map)[e.entry_id()] = e;
61 } 62 }
62 63
63 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) { 64 ArticleEntry CreateEntry(std::string entry_id, std::string page_url) {
64 ArticleEntry entry; 65 ArticleEntry entry;
65 entry.set_entry_id(entry_id); 66 entry.set_entry_id(entry_id);
66 if (!page_url.empty()) { 67 if (!page_url.empty()) {
67 ArticleEntryPage* page = entry.add_pages(); 68 ArticleEntryPage* page = entry.add_pages();
68 page->set_url(page_url); 69 page->set_url(page_url);
69 } 70 }
70 return entry; 71 return entry;
71 } 72 }
72 73
73 } // namespace 74 } // namespace
74 75
75 class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest { 76 class DomDistillerViewerSourceBrowserTest : public InProcessBrowserTest {
76 public: 77 public:
77 DomDistillerViewerSourceBrowserTest() {} 78 DomDistillerViewerSourceBrowserTest() {}
78 virtual ~DomDistillerViewerSourceBrowserTest() {} 79 virtual ~DomDistillerViewerSourceBrowserTest() {}
79 80
80 virtual void SetUpOnMainThread() OVERRIDE { 81 virtual void SetUpOnMainThread() OVERRIDE {
81 database_model_ = new FakeDB::EntryMap; 82 database_model_ = new FakeDB<ArticleEntry>::EntryMap;
82 } 83 }
83 84
84 virtual void CleanUpOnMainThread() OVERRIDE { delete database_model_; } 85 virtual void CleanUpOnMainThread() OVERRIDE { delete database_model_; }
85 86
86 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 87 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
87 command_line->AppendSwitch(switches::kEnableDomDistiller); 88 command_line->AppendSwitch(switches::kEnableDomDistiller);
88 } 89 }
89 90
90 static KeyedService* Build(content::BrowserContext* context) { 91 static KeyedService* Build(content::BrowserContext* context) {
91 FakeDB* fake_db = new FakeDB(database_model_); 92 FakeDB<ArticleEntry>* fake_db = new FakeDB<ArticleEntry>(database_model_);
92 distiller_factory_ = new MockDistillerFactory(); 93 distiller_factory_ = new MockDistillerFactory();
93 MockDistillerPageFactory* distiller_page_factory_ = 94 MockDistillerPageFactory* distiller_page_factory_ =
94 new MockDistillerPageFactory(); 95 new MockDistillerPageFactory();
95 DomDistillerContextKeyedService* service = 96 DomDistillerContextKeyedService* service =
96 new DomDistillerContextKeyedService( 97 new DomDistillerContextKeyedService(
97 scoped_ptr<DomDistillerStoreInterface>( 98 scoped_ptr<DomDistillerStoreInterface>(
98 CreateStoreWithFakeDB(fake_db, FakeDB::EntryMap())), 99 CreateStoreWithFakeDB(fake_db,
100 FakeDB<ArticleEntry>::EntryMap())),
99 scoped_ptr<DistillerFactory>(distiller_factory_), 101 scoped_ptr<DistillerFactory>(distiller_factory_),
100 scoped_ptr<DistillerPageFactory>(distiller_page_factory_)); 102 scoped_ptr<DistillerPageFactory>(distiller_page_factory_));
101 fake_db->InitCallback(true); 103 fake_db->InitCallback(true);
102 fake_db->LoadCallback(true); 104 fake_db->LoadCallback(true);
103 if (expect_distillation_) { 105 if (expect_distillation_) {
104 // There will only be destillation of an article if the database contains 106 // There will only be destillation of an article if the database contains
105 // the article. 107 // the article.
106 FakeDistiller* distiller = new FakeDistiller(true); 108 FakeDistiller* distiller = new FakeDistiller(true);
107 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl()) 109 EXPECT_CALL(*distiller_factory_, CreateDistillerImpl())
108 .WillOnce(testing::Return(distiller)); 110 .WillOnce(testing::Return(distiller));
109 } 111 }
110 if (expect_distiller_page_) { 112 if (expect_distiller_page_) {
111 MockDistillerPage* distiller_page = new MockDistillerPage(); 113 MockDistillerPage* distiller_page = new MockDistillerPage();
112 EXPECT_CALL(*distiller_page_factory_, CreateDistillerPageImpl()) 114 EXPECT_CALL(*distiller_page_factory_, CreateDistillerPageImpl())
113 .WillOnce(testing::Return(distiller_page)); 115 .WillOnce(testing::Return(distiller_page));
114 } 116 }
115 return service; 117 return service;
116 } 118 }
117 119
118 void ViewSingleDistilledPage(const GURL& url, 120 void ViewSingleDistilledPage(const GURL& url,
119 const std::string& expected_mime_type); 121 const std::string& expected_mime_type);
120 // Database entries. 122 // Database entries.
121 static FakeDB::EntryMap* database_model_; 123 static FakeDB<ArticleEntry>::EntryMap* database_model_;
122 static bool expect_distillation_; 124 static bool expect_distillation_;
123 static bool expect_distiller_page_; 125 static bool expect_distiller_page_;
124 static MockDistillerFactory* distiller_factory_; 126 static MockDistillerFactory* distiller_factory_;
125 }; 127 };
126 128
127 FakeDB::EntryMap* DomDistillerViewerSourceBrowserTest::database_model_; 129 FakeDB<ArticleEntry>::EntryMap*
130 DomDistillerViewerSourceBrowserTest::database_model_;
128 bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false; 131 bool DomDistillerViewerSourceBrowserTest::expect_distillation_ = false;
129 bool DomDistillerViewerSourceBrowserTest::expect_distiller_page_ = false; 132 bool DomDistillerViewerSourceBrowserTest::expect_distiller_page_ = false;
130 MockDistillerFactory* DomDistillerViewerSourceBrowserTest::distiller_factory_ = 133 MockDistillerFactory* DomDistillerViewerSourceBrowserTest::distiller_factory_ =
131 NULL; 134 NULL;
132 135
133 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings 136 // The DomDistillerViewerSource renders untrusted content, so ensure no bindings
134 // are enabled when the article exists in the database. 137 // are enabled when the article exists in the database.
135 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest, 138 IN_PROC_BROWSER_TEST_F(DomDistillerViewerSourceBrowserTest,
136 NoWebUIBindingsArticleExists) { 139 NoWebUIBindingsArticleExists) {
137 // Ensure there is one item in the database, which will trigger distillation. 140 // Ensure there is one item in the database, which will trigger distillation.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 315 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
313 contents, kGetLoadIndicatorClassName, &result)); 316 contents, kGetLoadIndicatorClassName, &result));
314 EXPECT_EQ("hidden", result); 317 EXPECT_EQ("hidden", result);
315 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 318 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
316 contents, kGetContent , &result)); 319 contents, kGetContent , &result));
317 EXPECT_THAT(result, HasSubstr("Page 1 content")); 320 EXPECT_THAT(result, HasSubstr("Page 1 content"));
318 EXPECT_THAT(result, HasSubstr("Page 2 content")); 321 EXPECT_THAT(result, HasSubstr("Page 2 content"));
319 } 322 }
320 323
321 } // namespace dom_distiller 324 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698