diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 19:00:36 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-10 19:00:36 +0000 |
commit | 0f88d3274bd3c093744a2de1c5d8e9f5f2643a77 (patch) | |
tree | 74e2149246b07c2394916d57aeba778433f403f1 /chrome | |
parent | 81bb46ca1a4a1d22a032b69d44e4cec7763b9560 (diff) | |
download | chromium_src-0f88d3274bd3c093744a2de1c5d8e9f5f2643a77.zip chromium_src-0f88d3274bd3c093744a2de1c5d8e9f5f2643a77.tar.gz chromium_src-0f88d3274bd3c093744a2de1c5d8e9f5f2643a77.tar.bz2 |
move subscribe_page_action out of samples in preparation for removing
samples directory (part 2)
TEST=ExtensionBrowserTest.*PageAction
BUG=26106
TBR=finnur
Review URL: http://codereview.chromium.org/387004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31577 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/extensions/extension_browsertests_misc.cc | 8 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/background.html | 50 | ||||
-rwxr-xr-x | chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-128x128.png | bin | 9557 -> 0 bytes | |||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png | bin | 450 -> 0 bytes | |||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png | bin | 796 -> 0 bytes | |||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png | bin | 7310 -> 0 bytes | |||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js | 24 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/iframe.js | 98 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/manifest.json | 21 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/style.css | 22 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html | 212 |
11 files changed, 3 insertions, 432 deletions
diff --git a/chrome/browser/extensions/extension_browsertests_misc.cc b/chrome/browser/extensions/extension_browsertests_misc.cc index bd81487..0c02b92 100644 --- a/chrome/browser/extensions/extension_browsertests_misc.cc +++ b/chrome/browser/extensions/extension_browsertests_misc.cc @@ -28,7 +28,7 @@ #include "net/base/net_util.h" const std::wstring kSubscribePage = - L"files/extensions/samples/subscribe_page_action/subscribe.html"; + L"files/extensions/subscribe_page_action/subscribe.html"; const std::wstring kValidFeed0 = L"files/feeds/feed_script.xml"; const std::wstring kValidFeed1 = L"files/feeds/feed1.xml"; const std::wstring kValidFeed2 = L"files/feeds/feed2.xml"; @@ -214,8 +214,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { .AppendASCII("crash_25562"))); ASSERT_TRUE(LoadExtension( - test_data_dir_.AppendASCII("samples") - .AppendASCII("subscribe_page_action"))); + test_data_dir_.AppendASCII("subscribe_page_action"))); ASSERT_TRUE(WaitForPageActionVisibilityChangeTo(0)); @@ -240,8 +239,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, PageAction) { // Tests that the location bar forgets about unloaded page actions. IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, UnloadPageAction) { - FilePath extension_path(test_data_dir_.AppendASCII("samples") - .AppendASCII("subscribe_page_action")); + FilePath extension_path(test_data_dir_.AppendASCII("subscribe_page_action")); ASSERT_TRUE(LoadExtension(extension_path)); // Navigation prompts the location bar to load page actions. diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/background.html b/chrome/test/data/extensions/samples/subscribe_page_action/background.html deleted file mode 100644 index a5d6772..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/background.html +++ /dev/null @@ -1,50 +0,0 @@ -<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/samples/subscribe_page_action/feed-icon-128x128.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-128x128.png Binary files differdeleted file mode 100755 index fb381afc..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-128x128.png +++ /dev/null diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png Binary files differdeleted file mode 100644 index 0369a6b37..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png +++ /dev/null diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png Binary files differdeleted file mode 100644 index 4d5673f..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16.png +++ /dev/null diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png Binary files differdeleted file mode 100644 index 65ea32d..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-64x64.png +++ /dev/null diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js b/chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js deleted file mode 100644 index 91cea10..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/feed_finder.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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/samples/subscribe_page_action/iframe.js b/chrome/test/data/extensions/samples/subscribe_page_action/iframe.js deleted file mode 100644 index 475ce52..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/iframe.js +++ /dev/null @@ -1,98 +0,0 @@ -/* 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/samples/subscribe_page_action/manifest.json b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json deleted file mode 100644 index 4f1b10a..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "RSS Subscription Extension", - "description": "Adds one-click subscription to your toolbar", - "version": "1.5", - "permissions": [ - "tabs", - "http://*/*" - ], - "background_page": "background.html", - "content_scripts": [ - { - "matches": ["http://*/*", "file://*.*"], - "js": ["feed_finder.js"] - } - ], - "icons": { "128": "feed-icon-128x128.png" }, - "page_action": { - "default_title": "Subscribe to this feed", - "default_icon": "feed-icon-16x16.png" - } -} diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/style.css b/chrome/test/data/extensions/samples/subscribe_page_action/style.css deleted file mode 100644 index f5ef149..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/style.css +++ /dev/null @@ -1,22 +0,0 @@ -/** - * 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/samples/subscribe_page_action/subscribe.html b/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html deleted file mode 100644 index 0863170..0000000 --- a/chrome/test/data/extensions/samples/subscribe_page_action/subscribe.html +++ /dev/null @@ -1,212 +0,0 @@ -<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> </div> - <div class="splitter"><b>Feed preview</b></div><br> - <div id="items"></div> -</body> -</html> |