summaryrefslogtreecommitdiffstats
path: root/chrome/test/data
diff options
context:
space:
mode:
authorerikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-09 15:40:40 +0000
committererikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-09 15:40:40 +0000
commitfd1b644e55267bb83696fb970acb01856f65006c (patch)
treedd6a9861c8c93ad63b08f636331740400e130ece /chrome/test/data
parentbcc8b8a737f50542a60aacc771e05ea26c4a603b (diff)
downloadchromium_src-fd1b644e55267bb83696fb970acb01856f65006c.zip
chromium_src-fd1b644e55267bb83696fb970acb01856f65006c.tar.gz
chromium_src-fd1b644e55267bb83696fb970acb01856f65006c.tar.bz2
Copy subscribe_page_action to a new directory. Step 1 of a move to appease the try server and svn.
BUG=26106 TEST=none TBR=finnur Review URL: http://codereview.chromium.org/373021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31427 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data')
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/background.html50
-rwxr-xr-xchrome/test/data/extensions/subscribe_page_action/feed-icon-128x128.pngbin0 -> 39220 bytes
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16-subscribed.pngbin0 -> 450 bytes
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16.pngbin0 -> 796 bytes
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/feed-icon-64x64.pngbin0 -> 2902 bytes
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/feed_finder.js24
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/iframe.js98
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/manifest.json23
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/style.css22
-rw-r--r--chrome/test/data/extensions/subscribe_page_action/subscribe.html212
10 files changed, 429 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/subscribe_page_action/background.html b/chrome/test/data/extensions/subscribe_page_action/background.html
new file mode 100644
index 0000000..a5d6772
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/background.html
@@ -0,0 +1,50 @@
+<html>
+<head>
+<script>
+ // A dictionary keyed off of tabId that keeps track of data per tab (for
+ // example what feedUrl was detected in the tab).
+ var feedData = {};
+
+ chrome.extension.onConnect.addListener(function(port) {
+ var tab = port.sender.tab;
+
+ // This will get called from the content script using PostMessage.
+ // |feedUrls| is a list of URL feeds found on the page. We only need 1 to
+ // enable the PageAction icon in the Omnibox.
+ port.onMessage.addListener(function(feedUrls) {
+ feedUrl = feedUrls[0];
+ // Let Chrome know that the PageAction needs to be enabled for this tabId
+ // and for the url of this page.
+ if (feedUrl) {
+ feedData[tab.id] = { pageUrl: tab.url,
+ feedUrl: feedUrl };
+
+ chrome.pageAction.setTitle({ tabId: tab.id,
+ title: "Click to subscribe..." });
+ chrome.pageAction.show(tab.id);
+ }
+ });
+ });
+
+ // Chrome will call into us when the user clicks on the icon in the OmniBox.
+ chrome.pageAction.onClicked.addListener(function(tab) {
+ chrome.windows.get(tab.windowId, function(window) {
+ // We need to know if we are the active window, because the tab may
+ // have moved to another window and we don't want to execute this
+ // action multiple times.
+ if (window.focused) {
+ // Create a new tab showing the subscription page with the right
+ // feed URL.
+ var url = "subscribe.html?" +
+ encodeURIComponent(feedData[tab.id].feedUrl);
+ chrome.tabs.create({url: url, windowId: window.id});
+ }
+ });
+ });
+
+ chrome.tabs.onRemoved.addListener(function(reply) {
+ feedData[reply.tabId] = null;
+ });
+</script>
+</head>
+</html>
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed-icon-128x128.png b/chrome/test/data/extensions/subscribe_page_action/feed-icon-128x128.png
new file mode 100755
index 0000000..31b6dfc
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/feed-icon-128x128.png
Binary files differ
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16-subscribed.png b/chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16-subscribed.png
new file mode 100644
index 0000000..0369a6b37
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16-subscribed.png
Binary files differ
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16.png b/chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16.png
new file mode 100644
index 0000000..4d5673f
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/feed-icon-16x16.png
Binary files differ
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed-icon-64x64.png b/chrome/test/data/extensions/subscribe_page_action/feed-icon-64x64.png
new file mode 100644
index 0000000..3eebee5
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/feed-icon-64x64.png
Binary files differ
diff --git a/chrome/test/data/extensions/subscribe_page_action/feed_finder.js b/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
new file mode 100644
index 0000000..d5c4f2a
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/feed_finder.js
@@ -0,0 +1,24 @@
+// Copyright (c) 2009 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.
+
+if (window == top) {
+ findFeeds();
+ window.addEventListener("focus", findFeeds);
+}
+
+function findFeeds() {
+ // Find all the RSS link elements.
+ var result = document.evaluate(
+ '//link[@rel="alternate"][contains(@type, "rss") or ' +
+ 'contains(@type, "atom") or contains(@type, "rdf")]',
+ document, null, 0, null);
+
+ var feeds = [];
+ var item;
+ while (item = result.iterateNext())
+ feeds.push(item.href);
+
+ // Notify the extension of the feed URLs we found.
+ chrome.extension.connect().postMessage(feeds);
+}
diff --git a/chrome/test/data/extensions/subscribe_page_action/iframe.js b/chrome/test/data/extensions/subscribe_page_action/iframe.js
new file mode 100644
index 0000000..475ce52
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/iframe.js
@@ -0,0 +1,98 @@
+/* Use only multi-line comments in this file, since during testing
+ its contents will get read from disk and stuffed into the
+ iframe .src tag, which is a process that doesn't preserve line
+ breaks and makes single-line comment out the rest of the code.
+*/
+
+/* The maximum number of feed items to show in the preview. */
+var maxFeedItems = 10;
+
+/* The maximum number of characters to show in the feed item title. */
+var maxTitleCount = 64;
+
+window.addEventListener("message", function(e) {
+ var parser = new DOMParser();
+ var doc = parser.parseFromString(e.data, "text/xml");
+
+ if (doc) {
+ buildPreview(doc);
+ } else {
+ /* Already handled in subscribe.html */
+ }
+}, false);
+
+function buildPreview(doc) {
+ /* Start building the part we render inside an IFRAME. We use a table to
+ ensure that items are separated vertically from each other. */
+ var table = document.createElement("table");
+ var tbody = document.createElement("tbody");
+ table.appendChild(tbody);
+
+ /* Now parse the rest. Some use <entry> for each feed item, others use
+ <channel><item>. */
+ var entries = doc.getElementsByTagName('entry');
+ if (entries.length == 0)
+ entries = doc.getElementsByTagName('item');
+
+ for (i = 0; i < entries.length && i < maxFeedItems; ++i) {
+ item = entries.item(i);
+
+ /* Grab the title for the feed item. */
+ var itemTitle = item.getElementsByTagName('title')[0];
+ if (itemTitle)
+ itemTitle = itemTitle.textContent;
+ else
+ itemTitle = "Unknown title";
+
+ /* Ensure max length for title. */
+ if (itemTitle.length > maxTitleCount)
+ itemTitle = itemTitle.substring(0, maxTitleCount) + "...";
+
+ /* Grab the description.
+ TODO(aa): Do we need to check for type=html here? */
+ 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 = "";
+
+ /* Grab the link URL. */
+ var itemLink = item.getElementsByTagName('link');
+ var link = itemLink[0].childNodes[0];
+ if (link)
+ link = itemLink[0].childNodes[0].nodeValue;
+ else
+ link = itemLink[0].getAttribute('href');
+
+ var tr = document.createElement("tr");
+ var td = document.createElement("td");
+
+ var anchor = document.createElement("a");
+ anchor.id = "anchor_" + String(i);
+ anchor.href = link;
+ anchor.appendChild(document.createTextNode(itemTitle));
+ anchor.className = "item_title";
+
+ var span = document.createElement("span");
+ span.id = "desc_" + String(i);
+ span.className = "item_desc";
+ span.innerHTML = itemDesc;
+
+ td.appendChild(anchor);
+ td.appendChild(document.createElement("br"));
+ td.appendChild(span);
+ td.appendChild(document.createElement("br"));
+ td.appendChild(document.createElement("br"));
+
+ tr.appendChild(td);
+ tbody.appendChild(tr);
+ }
+
+ table.appendChild(tbody);
+ document.body.appendChild(table);
+}
diff --git a/chrome/test/data/extensions/subscribe_page_action/manifest.json b/chrome/test/data/extensions/subscribe_page_action/manifest.json
new file mode 100644
index 0000000..ceb3bfe
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/manifest.json
@@ -0,0 +1,23 @@
+{
+ "name": "RSS Subscription Extension",
+ "description": "Adds one-click subscription to your toolbar",
+ "version": "1.4",
+ "permissions": [
+ "tabs",
+ "http://*/*"
+ ],
+ "background_page": "background.html",
+ "content_scripts": [
+ {
+ "matches": ["http://*/*", "file://*.*"],
+ "js": ["feed_finder.js"]
+ }
+ ],
+ "icons": { "128": "feed-icon-128x128.png" },
+ "page_actions": [
+ {
+ "default_title": "Subscribe to this feed",
+ "default_icon": "feed-icon-16x16.png"
+ }
+ ]
+} \ No newline at end of file
diff --git a/chrome/test/data/extensions/subscribe_page_action/style.css b/chrome/test/data/extensions/subscribe_page_action/style.css
new file mode 100644
index 0000000..f5ef149
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/style.css
@@ -0,0 +1,22 @@
+/**
+ * Styles that are shared between the iframe and the parent document.
+ */
+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;
+}
+.item_title {
+ font-size: 12px;
+}
+.item_desc {
+ font-size: 12px;
+}
diff --git a/chrome/test/data/extensions/subscribe_page_action/subscribe.html b/chrome/test/data/extensions/subscribe_page_action/subscribe.html
new file mode 100644
index 0000000..0863170
--- /dev/null
+++ b/chrome/test/data/extensions/subscribe_page_action/subscribe.html
@@ -0,0 +1,212 @@
+<html>
+<head>
+<title>Subscribe to feed</title>
+
+<script type="text/javascript">
+ // Grab the querystring, removing question mark at the front and splitting on
+ // the ampersand.
+ var queryString = location.search.substring(1).split("&");
+
+ // 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, and (if
+ // testing) also the style sheet and the frame js.
+ var req;
+
+ // Depending on whether this is run from a test or from the extension, this
+ // will either be a link to the css file within the extension or contain the
+ // contents of the style sheet, fetched through XmlHttpRequest.
+ var styleSheet = "";
+
+ // Depending on whether this is run from a test or from the extension, this
+ // will either be a link to the js file within the extension or contain the
+ // contents of the style sheet, fetched through XmlHttpRequest.
+ var frameScript = "";
+
+ // What to show when we cannot parse the feed name.
+ var unknownName = "Unknown feed name";
+
+ // Navigates to the reader of the user's choice (for subscribing to the feed).
+ function navigate() {
+ var select = document.getElementById('readers');
+ var url = select.options[select.selectedIndex].value + feedUrl;
+ document.location = url;
+ }
+
+ function main() {
+ req = new XMLHttpRequest();
+ if (synchronousRequest) {
+ // Tests that load the html page directly through a file:// url don't have
+ // access to the js and css from the frame so we must load them first and
+ // inject them into the src for the iframe.
+ req.open("GET", "style.css", false);
+ req.send(null);
+
+ styleSheet = "<style>" + req.responseText + "</style>";
+
+ req.open("GET", "iframe.js", false);
+ req.send(null);
+
+ frameScript = "<script>" + req.responseText +
+ "<" + "/script>";
+ } else {
+ // Normal loading just requires links to the css and the js file.
+ styleSheet = "<link rel='stylesheet' type='text/css' href='" +
+ chrome.extension.getURL("style.css") + "'>";
+ frameScript = "<script src='" + chrome.extension.getURL("iframe.js") +
+ "'></" + "script>";
+ }
+
+ feedUrl = decodeURIComponent(feedUrl);
+ req.onload = handleResponse;
+ req.onerror = handleError;
+ req.open("GET", feedUrl, !synchronousRequest);
+ req.send(null);
+ }
+
+ // Sets the title for the feed.
+ function setFeedTitle(title) {
+ var titleTag = document.getElementById('title');
+ titleTag.textContent = "Feed for '" + title + "'";
+ }
+
+ // Handles errors during the XMLHttpRequest.
+ function handleError() {
+ handleFeedParsingFailed("Error fetching feed");
+ }
+
+ // Handles feed parsing errors.
+ function handleFeedParsingFailed(error) {
+ setFeedTitle(unknownName);
+
+ // The tests always expect an IFRAME, so add one showing the error.
+ var html = "<body><span id=\"error\" class=\"item_desc\">" + error +
+ "</span></body>";
+
+ var error_frame = createFrame('error', html);
+ var itemsTag = document.getElementById('items');
+ itemsTag.appendChild(error_frame);
+ }
+
+ function createFrame(frame_id, html) {
+ frame = document.createElement('iframe');
+ frame.id = frame_id;
+ frame.src = "data:text/html;charset=utf-8,<html>" + styleSheet + html +
+ "</html>";
+ frame.scrolling = "auto";
+ frame.frameBorder = "0";
+ frame.marginWidth = "0";
+ return frame;
+ }
+
+ function embedAsIframe(rssText) {
+ var itemsTag = document.getElementById('items');
+
+ // TODO(aa): Add base URL tag
+ iframe = createFrame('rss', styleSheet + frameScript);
+ itemsTag.appendChild(iframe);
+
+ iframe.onload = function() {
+ iframe.contentWindow.postMessage(rssText, "*");
+ }
+ }
+
+ // Handles parsing the feed data we got back from XMLHttpRequest.
+ function handleResponse() {
+ // Uncomment these three lines to see what the feed data looks like.
+ // var itemsTag = document.getElementById('items');
+ // itemsTag.textContent = req.responseText;
+ // return;
+
+ var doc = req.responseXML;
+ if (!doc) {
+ handleFeedParsingFailed("Not a valid feed.");
+ return;
+ }
+
+ // We must find at least one 'entry' or 'item' element before proceeding.
+ var entries = doc.getElementsByTagName('entry');
+ if (entries.length == 0)
+ entries = doc.getElementsByTagName('item');
+ if (entries.length == 0) {
+ handleFeedParsingFailed("This feed contains no entries.")
+ return;
+ }
+
+ // Figure out what the title of the whole feed is.
+ var title = doc.getElementsByTagName('title')[0];
+ if (title)
+ setFeedTitle(title.textContent);
+ else
+ setFeedTitle(unknownName);
+
+ // Add an IFRAME with the html contents.
+ embedAsIframe(req.responseText);
+ }
+</script>
+<link rel="stylesheet" href="style.css" type="text/css" />
+<style>
+body {
+ display:-webkit-box;
+ -webkit-box-orient:vertical;
+}
+body>* {
+ display:-webkit-box;
+}
+#items {
+ -webkit-box-flex:1;
+ -webkit-box-orient:vertical;
+ -webkit-box-align:stretch;
+}
+iframe {
+ display:-webkit-box;
+ -webkit-box-flex:1;
+}
+.splitter {
+ padding: 2px 8px 2px 5px;
+ border-top: solid 1px #9CC2EF;
+ background: #EBEFF9;
+ font-size: 13px;
+ font-weight:bold;
+}
+</style>
+</head>
+
+<body onload="main();">
+ <table>
+ <tr>
+ <td width="75">
+ <img src="feed-icon-64x64.png" alt="feed-icon" align="absmiddle" />
+ </td>
+ <td>
+ <b><span id="title"></span></b><br>
+ <span>Subscribe to this feed using:</span>
+ <select id="readers">
+ <option value="http://www.google.com/reader/view/feed/">
+ Google Reader
+ </option>
+ <option value="http://www.google.com/ig/adde?moduleurl=">
+ iGoogle
+ </option>
+ <option value="http://www.bloglines.com/login?r=/sub/">
+ Bloglines
+ </option>
+ <option value="http://add.my.yahoo.com/rss?url=">
+ My Yahoo
+ </option>
+ </select>
+ <button onclick="navigate();">Subscribe Now</button>
+ </td>
+ </tr>
+ </table>
+
+ <div>&nbsp;</div>
+ <div class="splitter"><b>Feed preview</b></div><br>
+ <div id="items"></div>
+</body>
+</html>