diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 21:30:53 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-09 21:30:53 +0000 |
commit | 361b28a80cfd2a9a0db454c7ebdb9c95ea55840c (patch) | |
tree | a6cf253e64ded952e1a5518f8d25ac8848c6200b /chrome/browser/extensions/extension_browsertests_misc.cc | |
parent | 76b118a0f798a2e88103492173225e57b2062a37 (diff) | |
download | chromium_src-361b28a80cfd2a9a0db454c7ebdb9c95ea55840c.zip chromium_src-361b28a80cfd2a9a0db454c7ebdb9c95ea55840c.tar.gz chromium_src-361b28a80cfd2a9a0db454c7ebdb9c95ea55840c.tar.bz2 |
Add a rudamentary feed preview to the RSS extension. It
doesn't handle inline HTML in the item description (it just
dumps it as text) and the feed needs to be valid XML for it
to show any preview, but it is better than nothing. We can
easily change it to display the HTML but we want to (at some
point) try to use a separate origin so that we can render
the HTML code from untrusted sources safely.
Also fix a bug in the image tracker. It should not try
to communicate with the view if the view has gone away
(which was the whole point of the image tracker...)
BUG=None
TEST=Install the extension, browse to a page with a feed
and click onthe rss icon in the Omnibox. An interstitial
page should appear with a preview of the feed.
Review URL: http://codereview.chromium.org/155180
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20316 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_browsertests_misc.cc')
-rw-r--r-- | chrome/browser/extensions/extension_browsertests_misc.cc | 136 |
1 files changed, 135 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 0211b96..f17e5d5 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -117,6 +117,140 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, TabContents) { EXPECT_TRUE(result); } +// Tests that we can load page actions in the Omnibox. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("samples") + .AppendASCII("subscribe_page_action"))); + + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); + + // Navigate to the feed page. + FilePath test_dir; + PathService::Get(chrome::DIR_TEST_DATA, &test_dir); + FilePath feed = test_dir.AppendASCII("feeds") + .AppendASCII("feed.html"); + + ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(feed)); + + // We should now have one page action ready to go in the LocationBar. + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(1)); + + FilePath no_feed = test_dir.AppendASCII("feeds") + .AppendASCII("nofeed.html"); + + // Make sure the page action goes away. + ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(no_feed)); + ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); +} + +GURL GetFeedUrl(const std::string& feed_page) { + FilePath test_dir; + PathService::Get(chrome::DIR_TEST_DATA, &test_dir); + + FilePath subscribe; + subscribe = test_dir.AppendASCII("extensions") + .AppendASCII("samples") + .AppendASCII("subscribe_page_action") + .AppendASCII("subscribe.html"); + subscribe = subscribe.StripTrailingSeparators(); + + FilePath feed_dir = test_dir.AppendASCII("feeds") + .AppendASCII(feed_page.c_str()); + + return GURL(net::FilePathToFileURL(subscribe).spec() + + std::string("?") + + net::FilePathToFileURL(feed_dir).spec()); +} + +static const wchar_t* jscript_feed_title = + L"window.domAutomationController.send(" + L" document.getElementById('title') ? " + L" document.getElementById('title').textContent : " + L" \"element 'title' not found\"" + L");"; +static const wchar_t* jscript_anchor = + L"window.domAutomationController.send(" + L" document.getElementById('anchor_0') ? " + L" document.getElementById('anchor_0').textContent : " + L" \"element 'anchor_0' not found\"" + L");"; +static const wchar_t* jscript_desc = + L"window.domAutomationController.send(" + L" document.getElementById('desc_0') ? " + L" document.getElementById('desc_0').textContent : " + L" \"element 'desc_0' not found\"" + L");"; +static const wchar_t* jscript_error = + L"window.domAutomationController.send(" + L" document.getElementById('error') ? " + L" document.getElementById('error').textContent : " + L" \"No error\"" + L");"; + +void GetParsedFeedData(Browser* browser, std::string* feed_title, + std::string* item_title, std::string* item_desc, + std::string* error) { + ui_test_utils::ExecuteJavaScriptAndExtractString( + browser->GetSelectedTabContents()->render_view_host(), L"", + jscript_feed_title, feed_title); + ui_test_utils::ExecuteJavaScriptAndExtractString( + browser->GetSelectedTabContents()->render_view_host(), L"", + jscript_anchor, item_title); + ui_test_utils::ExecuteJavaScriptAndExtractString( + browser->GetSelectedTabContents()->render_view_host(), L"", + jscript_desc, item_desc); + ui_test_utils::ExecuteJavaScriptAndExtractString( + browser->GetSelectedTabContents()->render_view_host(), L"", + jscript_error, error); +} + +// Tests that we can parse feeds. +IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeed) { + std::string feed_title; + std::string item_title; + std::string item_desc; + std::string error; + + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed1.xml")); + GetParsedFeedData(browser(), &feed_title, &item_title, &item_desc, &error); + EXPECT_STREQ("Feed for 'MyFeedTitle'", feed_title.c_str()); + EXPECT_STREQ("Title 1", item_title.c_str()); + EXPECT_STREQ("Desc", item_desc.c_str()); + EXPECT_STREQ("No error", error.c_str()); + + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed2.xml")); + GetParsedFeedData(browser(), &feed_title, &item_title, &item_desc, &error); + EXPECT_STREQ("Feed for 'MyFeed2'", feed_title.c_str()); + EXPECT_STREQ("My item title1", item_title.c_str()); + EXPECT_STREQ("This is a summary.", item_desc.c_str()); + EXPECT_STREQ("No error", error.c_str()); + + // Try a feed that doesn't exist. + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed_nonexistant.xml")); + GetParsedFeedData(browser(), &feed_title, &item_title, &item_desc, &error); + EXPECT_STREQ("Feed for 'Unknown feed name'", feed_title.c_str()); + EXPECT_STREQ("element 'anchor_0' not found", item_title.c_str()); + EXPECT_STREQ("element 'desc_0' not found", item_desc.c_str()); + EXPECT_STREQ("Not a valid feed", error.c_str()); + + // Try an empty feed. + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed_invalid1.xml")); + GetParsedFeedData(browser(), &feed_title, &item_title, &item_desc, &error); + EXPECT_STREQ("Feed for 'Unknown feed name'", feed_title.c_str()); + EXPECT_STREQ("element 'anchor_0' not found", item_title.c_str()); + EXPECT_STREQ("element 'desc_0' not found", item_desc.c_str()); + EXPECT_STREQ("Not a valid feed", error.c_str()); + + // Try a garbage feed. + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed_invalid2.xml")); + GetParsedFeedData(browser(), &feed_title, &item_title, &item_desc, &error); + EXPECT_STREQ("Feed for 'Unknown feed name'", feed_title.c_str()); + EXPECT_STREQ("element 'anchor_0' not found", item_title.c_str()); + EXPECT_STREQ("element 'desc_0' not found", item_desc.c_str()); + EXPECT_STREQ("Not a valid feed", error.c_str()); +} + // Tests that message passing between extensions and tabs works. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MessagingExtensionTab) { ASSERT_TRUE(LoadExtension( @@ -214,4 +348,4 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, MessagingContentScript) { host->render_view_host(), L"", L"testDisconnectOnClose()", &result); EXPECT_TRUE(result); } -#endif
\ No newline at end of file +#endif |