Index: components/dom_distiller/content/dom_distiller_viewer_source_unittest.cc |
diff --git a/components/dom_distiller/content/dom_distiller_viewer_source_unittest.cc b/components/dom_distiller/content/dom_distiller_viewer_source_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b8aec1658875178dae84f929bc39040c49465bc0 |
--- /dev/null |
+++ b/components/dom_distiller/content/dom_distiller_viewer_source_unittest.cc |
@@ -0,0 +1,117 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/dom_distiller/content/dom_distiller_viewer_source.h" |
+ |
+#include "base/callback.h" |
+#include "components/dom_distiller/core/article_entry.h" |
+#include "components/dom_distiller/core/dom_distiller_service.h" |
+#include "components/dom_distiller/core/dom_distiller_store.h" |
+#include "components/dom_distiller/core/dom_distiller_test_util.h" |
+#include "components/dom_distiller/core/fake_db.h" |
+#include "components/dom_distiller/core/fake_distiller.h" |
+#include "components/dom_distiller/core/task_tracker.h" |
+#include "components/dom_distiller/core/url_constants.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace dom_distiller { |
+ |
+class FakeViewRequestDelegate : public ViewRequestDelegate { |
+ public: |
+ virtual ~FakeViewRequestDelegate() {} |
+ MOCK_METHOD1(OnArticleReady, void(const DistilledArticleProto* proto)); |
+}; |
+ |
+class TestDomDistillerService : public DomDistillerServiceInterface { |
+ public: |
+ TestDomDistillerService() {} |
+ virtual ~TestDomDistillerService() {} |
+ |
+ MOCK_CONST_METHOD0(GetSyncableService, syncer::SyncableService*()); |
+ MOCK_METHOD2(AddToList, |
+ const std::string(const GURL&, const ArticleAvailableCallback&)); |
+ MOCK_CONST_METHOD0(GetEntries, std::vector<ArticleEntry>()); |
+ MOCK_METHOD1(AddObserver, void(DomDistillerObserver*)); |
+ MOCK_METHOD1(RemoveObserver, void(DomDistillerObserver*)); |
+ MOCK_METHOD0(ViewUrlImpl, ViewerHandle*()); |
+ virtual scoped_ptr<ViewerHandle> ViewUrl(ViewRequestDelegate*, const GURL&) { |
+ return scoped_ptr<ViewerHandle>(ViewUrlImpl()); |
+ } |
+ MOCK_METHOD0(ViewEntryImpl, ViewerHandle*()); |
+ virtual scoped_ptr<ViewerHandle> ViewEntry(ViewRequestDelegate*, |
+ const std::string&) { |
+ return scoped_ptr<ViewerHandle>(ViewEntryImpl()); |
+ } |
+ MOCK_METHOD0(RemoveEntryImpl, ArticleEntry*()); |
+ virtual scoped_ptr<ArticleEntry> RemoveEntry(const std::string&) { |
+ return scoped_ptr<ArticleEntry>(RemoveEntryImpl()); |
+ } |
+}; |
+ |
+class DomDistillerViewerSourceTest : public testing::Test {}; |
+ |
+TEST_F(DomDistillerViewerSourceTest, TestMimeType) { |
+ scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService()); |
+ DomDistillerViewerSource source(service.get(), "myscheme"); |
+ EXPECT_EQ("text/css", source.GetMimeType(kCssPath)); |
+ EXPECT_EQ("text/html", source.GetMimeType("anythingelse")); |
+} |
+ |
+TEST_F(DomDistillerViewerSourceTest, TestPathUtil) { |
+ scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService()); |
+ DomDistillerViewerSource source(service.get(), "myscheme"); |
+ const std::string single_key = "mypath?foo=bar"; |
+ EXPECT_EQ("bar", source.GetValueForKeyInURLPathQuery(single_key, "foo")); |
+ const std::string two_keys = "mypath?key1=foo&key2=bar"; |
+ EXPECT_EQ("foo", source.GetValueForKeyInURLPathQuery(two_keys, "key1")); |
+ EXPECT_EQ("bar", source.GetValueForKeyInURLPathQuery(two_keys, "key2")); |
+ const std::string multiple_same_key = "mypath?key=foo&key=bar"; |
+ EXPECT_EQ("foo", |
+ source.GetValueForKeyInURLPathQuery(multiple_same_key, "key")); |
+} |
+ |
+TEST_F(DomDistillerViewerSourceTest, TestCreatingViewUrlRequest) { |
+ scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService()); |
+ DomDistillerViewerSource source(service.get(), "myscheme"); |
+ scoped_ptr<FakeViewRequestDelegate> view_request_delegate( |
+ new FakeViewRequestDelegate()); |
+ ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); |
+ EXPECT_CALL(*service.get(), ViewUrlImpl()) |
+ .WillOnce(testing::Return(viewer_handle)); |
+ EXPECT_CALL(*service.get(), ViewEntryImpl()).Times(0); |
+ source.CreateViewRequest( |
+ std::string("?") + kUrlKey + "=http%3A%2F%2Fwww.example.com%2F", |
+ view_request_delegate.get()); |
+} |
+ |
+TEST_F(DomDistillerViewerSourceTest, TestCreatingViewEntryRequest) { |
+ scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService()); |
+ DomDistillerViewerSource source(service.get(), "myscheme"); |
+ scoped_ptr<FakeViewRequestDelegate> view_request_delegate( |
+ new FakeViewRequestDelegate()); |
+ ViewerHandle* viewer_handle(new ViewerHandle(ViewerHandle::CancelCallback())); |
+ EXPECT_CALL(*service.get(), ViewEntryImpl()) |
+ .WillOnce(testing::Return(viewer_handle)); |
+ EXPECT_CALL(*service.get(), ViewUrlImpl()).Times(0); |
+ source.CreateViewRequest(std::string("?") + kEntryIdKey + "=abc-def", |
+ view_request_delegate.get()); |
+} |
+ |
+TEST_F(DomDistillerViewerSourceTest, TestCreatingInvalidViewRequest) { |
+ scoped_ptr<TestDomDistillerService> service(new TestDomDistillerService()); |
+ DomDistillerViewerSource source(service.get(), "myscheme"); |
+ scoped_ptr<FakeViewRequestDelegate> view_request_delegate( |
+ new FakeViewRequestDelegate()); |
+ EXPECT_CALL(*service.get(), ViewEntryImpl()).Times(0); |
+ EXPECT_CALL(*service.get(), ViewUrlImpl()).Times(0); |
+ // Specify none of the required query parameters. |
+ source.CreateViewRequest("?foo=bar", view_request_delegate.get()); |
+ // Specify both of the required query parameters. |
+ source.CreateViewRequest("?" + std::string(kUrlKey) + |
+ "=http%3A%2F%2Fwww.example.com%2F&" + |
+ std::string(kEntryIdKey) + "=abc-def", |
+ view_request_delegate.get()); |
shashi
2014/02/25 21:48:08
Thank you for adding these tests :).
I was thinki
nyquist
2014/02/27 00:07:37
Added a unit test for both internal chrome:// page
|
+} |
+ |
+} // namespace dom_distiller |