diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 23:12:35 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 23:12:35 +0000 |
commit | f5c8a1596de89f2f3010186b03cc2378d23254ae (patch) | |
tree | 097e39e5bf01d58f01170d22ae1bd177cd2ca2d9 /chrome | |
parent | 0044b810333212dda702cc6e22b042e8331df4fc (diff) | |
download | chromium_src-f5c8a1596de89f2f3010186b03cc2378d23254ae.zip chromium_src-f5c8a1596de89f2f3010186b03cc2378d23254ae.tar.gz chromium_src-f5c8a1596de89f2f3010186b03cc2378d23254ae.tar.bz2 |
The RSS extension now renders the RSS HTML preview inside an IFRAME.
BUG=None
TEST=See browser tests.
Review URL: http://codereview.chromium.org/242055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
5 files changed, 148 insertions, 85 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index 153d0a1..5d4ecdc 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -295,16 +295,20 @@ void GetParsedFeedData(Browser* browser, std::string* feed_title, std::string* item_title, std::string* item_desc, std::string* error) { ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( - browser->GetSelectedTabContents()->render_view_host(), L"", + browser->GetSelectedTabContents()->render_view_host(), + L"", // Title is on the main page, all the rest is in the IFRAME. jscript_feed_title, feed_title)); ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( - browser->GetSelectedTabContents()->render_view_host(), L"", + browser->GetSelectedTabContents()->render_view_host(), + L"//html/body/div/iframe[1]", jscript_anchor, item_title)); ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( - browser->GetSelectedTabContents()->render_view_host(), L"", + browser->GetSelectedTabContents()->render_view_host(), + L"//html/body/div/iframe[1]", jscript_desc, item_desc)); ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( - browser->GetSelectedTabContents()->render_view_host(), L"", + browser->GetSelectedTabContents()->render_view_host(), + L"//html/body/div/iframe[1]", jscript_error, error)); } @@ -329,6 +333,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeed) { EXPECT_STREQ("This is a summary.", item_desc.c_str()); EXPECT_STREQ("No error", error.c_str()); + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed3.xml")); + GetParsedFeedData(browser(), &feed_title, &item_title, &item_desc, &error); + EXPECT_STREQ("Feed for 'Google Code buglist rss feed'", feed_title.c_str()); + EXPECT_STREQ("My dear title", item_title.c_str()); + EXPECT_STREQ("My dear content", 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); @@ -352,6 +363,15 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ParseFeed) { 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 feed with a link with an onclick handler (before r27440 this would + // trigger a NOTREACHED). + ui_test_utils::NavigateToURL(browser(), GetFeedUrl("feed_script.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 VIDEO", item_desc.c_str()); + EXPECT_STREQ("No error", error.c_str()); } #if defined(OS_WIN) // TODO(port) - enable. diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/style.css b/chrome/test/data/extensions/samples/subscribe_page_action/style.css new file mode 100644 index 0000000..036a334 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/style.css @@ -0,0 +1,26 @@ +body { + font-family: arial, sans-serif; + font-size: 11px; +} +a { + color: #2244D2; + font-weight:bold; + text-decoration: none; +} +a:hover { + font-weight:bold; + text-decoration: underline; +} +.splitter { + padding: 2px 8px 2px 5px; + border-top: solid 1px #9CC2EF; + background: #EBEFF9; + font-size: 13px; + font-weight:bold; +} +.item_title { + font-size: 12px; +} +.item_desc { + font-size: 12px; +} diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html b/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html index 7a40fad..195bb75 100644 --- a/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html +++ b/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html @@ -9,13 +9,14 @@ // The feed URL is the first component and always present. var feedUrl = decodeURIComponent(queryString[0]); - + // We allow synchronous requests for testing. This component is only present // if true. var synchronousRequest = queryString[1] == "synchronous"; - + // The XMLHttpRequest object that tries to load and parse the feed. var req; + var reqStylesheet; // What to show when we cannot parse the feed name. var unknownName = "Unknown feed name"; @@ -26,8 +27,8 @@ // The maximum number of characters to show in the feed item title. var maxTitleCount = 64; - // The maximum number of characters to show for the feed item description. - var maxDescCount = 1024; + // The style sheet we use for both the subscribe page and the IFRAME. + var style_sheet = ""; // Populated later using a XMLHttpRequest. // Navigates to the reader of the user's choice (for subscribing to the feed). function navigate() { @@ -36,6 +37,19 @@ document.location = url; } + function loadStylesheet() { + reqStylesheet = new XMLHttpRequest(); + reqStylesheet.onload = handleCssLoaded; + reqStylesheet.onerror = loadFeed; // I ain't got no style, lets do without. + reqStylesheet.open("GET", "style.css", true); + reqStylesheet.send(null); + } + + function handleCssLoaded() { + style_sheet = reqStylesheet.responseText; + loadFeed(); + } + // Parses the feed specified. We will either end up in handleResponse or // handleError from here. function loadFeed() { @@ -62,29 +76,27 @@ function handleFeedParsingFailed(error) { setFeedTitle(unknownName); - // First part of the error message. - var spanErrorPrefix = document.createElement('span'); - spanErrorPrefix.setAttribute('class', 'item_desc'); - spanErrorPrefix.appendChild( - document.createTextNode("Unable to show feed preview (")); - - // The actual error. - var spanError = document.createElement('span'); - spanError.id = 'error'; - spanError.setAttribute('class', 'item_desc'); - spanError.appendChild(document.createTextNode(error)); - - // Closing braces, etc. - var spanErrorSuffix = document.createElement('span'); - spanErrorSuffix.setAttribute('class', 'item_desc'); - spanErrorSuffix.appendChild( - document.createTextNode(").")); - - // Add the error message. + // The tests always expect an IFRAME, so add an one showing the error. + var html = "<html><body><span id=\"error\" class=\"item_desc\">" + error + + "</span></html>"; + + embedAsIframe(html); + } + + function embedAsIframe(html) { var itemsTag = document.getElementById('items'); - itemsTag.appendChild(spanErrorPrefix); - itemsTag.appendChild(spanError); - itemsTag.appendChild(spanErrorSuffix); + html = html.replace(/"/g, "%22"); + + iframe = document.createElement('iframe'); + iframe.src = "data:text/html;charset=utf-8," + html; + iframe.id = "rss"; + iframe.height = "100%"; + iframe.width = "100%"; + iframe.scrolling = "auto"; + iframe.frameBorder = "0"; + iframe.marginWidth = "0"; + iframe.noResize = "noresize"; + itemsTag.appendChild(iframe); } // Handles parsing the feed data we got back from XMLHttpRequest. @@ -108,6 +120,21 @@ else setFeedTitle(unknownName); + // Obtain the base url so that we can show images using relative path. + var base_url = ""; + var slash = feedUrl.lastIndexOf("/"); + if (slash > -1) + base_url = feedUrl.substring(0, slash + 1); + else + base_url = feedUrl; + base_url = "<base href=\"" + base_url + "\" />"; + + // Start building the part we render inside an IFRAME. We use a table to + // ensure that items are separated vertically from each other. + var items_html = "<html><head>" + base_url + + "<style>" + style_sheet + "</style>" + "</head>" + + "<body><table>"; + // Now parse the rest. Some use <entry> for each feed item, others use // <channel><item>. var entries = doc.getElementsByTagName('entry'); @@ -132,16 +159,14 @@ var itemDesc = item.getElementsByTagName('description')[0]; if (!itemDesc) itemDesc = item.getElementsByTagName('summary')[0]; + if (!itemDesc) + itemDesc = item.getElementsByTagName('content')[0]; if (itemDesc) itemDesc = itemDesc.textContent; else itemDesc = ""; - // Ensure max length for description. - if (itemDesc.length > maxDescCount) - itemDesc = itemDesc.substring(0, maxDescCount) + "..."; - // Grab the link URL. var itemLink = item.getElementsByTagName('link'); var link = itemLink[0].childNodes[0]; @@ -150,62 +175,27 @@ else link = itemLink[0].getAttribute('href'); - // Create an anchor node for showing the title. - var anchorTitle = document.createElement('a'); - anchorTitle.id = 'anchor_' + String(i); - anchorTitle.setAttribute('class', 'item_title'); - anchorTitle.setAttribute('href', link); - anchorTitle.setAttribute('target', '_blank'); - anchorTitle.appendChild(document.createTextNode(itemTitle)); - - // Create a description node. - var spanDesc = document.createElement('span'); - spanDesc.id = 'desc_' + String(i); - spanDesc.setAttribute('class', 'item_desc'); - spanDesc.appendChild(document.createTextNode(itemDesc)); - - // Add this to the document. - itemsTag.appendChild(anchorTitle); - itemsTag.appendChild(document.createElement('br')); - itemsTag.appendChild(spanDesc); - itemsTag.appendChild(document.createElement('br')); - itemsTag.appendChild(document.createElement('br')); + items_html = items_html + + "<tr><td>" + + "<a id=\"anchor_" + String(i) + "\" href=\"" + link + "\" " + + "class=\"item_title\">" + + itemTitle + "</a><br>"; + + items_html = items_html + "<span class=\"item_desc\" " + + "id=\"desc_" + String(i) + "\">" + + itemDesc + "<br><br>" + + "</td></tr>"; } + items_html = items_html + "</table></body></html>"; + + // Add an IFRAME with the html contents. + embedAsIframe(items_html); } </script> - -<style> -body { - font-family: arial, sans-serif; - font-size: 11px; -} -a { - color: #2244D2; - font-weight:bold; - text-decoration: none; -} -a:hover { - font-weight:bold; - text-decoration: underline; -} - -.splitter { - padding: 2px 8px 2px 5px; - border-top: solid 1px #9CC2EF; - background: #EBEFF9; - font-size: 13px; - font-weight:bold; -} -.item_title { - font-size: 12px; -} -.item_desc { - font-size: 12px; -} -</style> + <link rel="stylesheet" href="style.css" type="text/css" /> </head> -<body onload="loadFeed();"> +<body onload="loadStylesheet();"> <table> <tr> <td width="75"> diff --git a/chrome/test/data/feeds/feed3.xml b/chrome/test/data/feeds/feed3.xml new file mode 100644 index 0000000..f8f5227 --- /dev/null +++ b/chrome/test/data/feeds/feed3.xml @@ -0,0 +1,17 @@ +<?xml version="1.0"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + <updated>2009-09-29T17:51:01Z</updated> + <id>http://code.google.com/feeds/p/chromium/issueupdates/basic</id> + <title>Google Code buglist rss feed</title> + + <entry> + <updated>2009-09-29T17:51:01Z</updated> + <id>http://code.google.com/feeds/p/chromium/issueupdates/basic/22699/9</id> + <link rel="alternate" type="text/html" href="http://code.google.com/p/chromium/issues/detail?id=22699#c9" /> + <title>My dear title</title> + <author> + <name>figarofigarofigaro@chrooooooooomium.org</name> + </author> + <content type="html">My dear content</content> + </entry> +</feed>
\ No newline at end of file diff --git a/chrome/test/data/feeds/feed_script.xml b/chrome/test/data/feeds/feed_script.xml new file mode 100644 index 0000000..da59879 --- /dev/null +++ b/chrome/test/data/feeds/feed_script.xml @@ -0,0 +1,10 @@ +<rss version="2.0"> +<channel> + <title>MyFeedTitle</title> + <item> + <title>Title 1</title> + <link>http://www.google.com</link> + <description>Desc <a href="#" onclick="videoMPlayer('111111111','');return false;"><b>VIDEO</b></a></description> + </item> +</channel> +</rss>
\ No newline at end of file |