diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 03:53:00 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-15 03:53:00 +0000 |
commit | 917defe16badc44a0d24348739a1657d6c13aca5 (patch) | |
tree | 4aecf9a612aff48274a8df392ff037015c0ff3e9 /chrome/test | |
parent | cf9a246cf386c7af0fb6524ac5d025c0d4e8563a (diff) | |
download | chromium_src-917defe16badc44a0d24348739a1657d6c13aca5.zip chromium_src-917defe16badc44a0d24348739a1657d6c13aca5.tar.gz chromium_src-917defe16badc44a0d24348739a1657d6c13aca5.tar.bz2 |
Reverting 20714.
Rietveld showed all green try bots, but looks like one ui test is failing
Review URL: http://codereview.chromium.org/149668
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
3 files changed, 77 insertions, 27 deletions
diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/background.html b/chrome/test/data/extensions/samples/subscribe_page_action/background.html index 4d14440..94761ff 100644 --- a/chrome/test/data/extensions/samples/subscribe_page_action/background.html +++ b/chrome/test/data/extensions/samples/subscribe_page_action/background.html @@ -4,14 +4,53 @@ // The Page Action ID. var pageActionId = "RssPageAction"; - // The icon to use. This corresponds to the icon listed in the manifest. + // The icons to use. These correspond to the icons listed in the manifest. var subscribeId = 0; + var alreadySubscribedId = 1; - // A dictionary keyed off of tabId that keeps track of data per tab (for - // example what feedUrl was detected in the tab). - var feedData = {}; + // The window this Page Action is associated with. + var windowId = -1; + + // The TabId this Page Action is associated with. + var tabId = -1; + + // The URL of the page that contains the feed. + var pageUrl = ""; + + // The feed URL found on the page. + var feedUrl = ""; + + // The URL to use to check if user is subscribed already. + var subscribedUrl = "http://www.google.com/reader/api/0/subscribed?s=feed%2F"; + + // The XMLHttpRequest object that checks if you are already subscribed. + var req; + + // The status of whether you have already subscribed to this feed or not. + var alreadySubscribed = false; + + function EnableIcon(subscribed) { + alreadySubscribed = subscribed; + if (!alreadySubscribed) { + chrome.pageActions.enableForTab( + pageActionId, {tabId: tabId, + url: pageUrl, + title: "Click to subscribe...", + iconId: subscribeId}); + } else { + chrome.pageActions.enableForTab( + pageActionId, {tabId: tabId, + url: pageUrl, + title: "You are already subscribed to this feed", + iconId: alreadySubscribedId}); + } + } chrome.self.onConnect.addListener(function(port) { + windowId = port.tab.windowId; + tabId = port.tab.id; + pageUrl = port.tab.url; + // 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. @@ -20,39 +59,49 @@ // Let Chrome know that the PageAction needs to be enabled for this tabId // and for the url of this page. if (feedUrl) { - feedData[port.tab.id] = {pageUrl: port.tab.url, - feedUrl: feedUrl}; - - chrome.pageActions.enableForTab( - pageActionId, {tabId: port.tab.id, - url: port.tab.url, - title: "Click to subscribe...", - iconId: subscribeId}); + EnableIcon(false); // Not subscribed (as far as we know, might change). + + // But also check the server to see if we have already subscribed so + // that we can update the status. + feedUrl = encodeURIComponent(feedUrl); + req = new XMLHttpRequest(); + req.onload = handleResponse; + req.open("GET", subscribedUrl + feedUrl, false); + req.send(null); } }); }); + function handleResponse() { + if (req.responseText == "true") + EnableIcon(true); // true == Already suscribed. + } + // Chrome will call into us when the user clicks on the icon in the OmniBox. - chrome.pageActions["RssPageAction"].addListener(function(reply) { + chrome.pageActions.onExecute.addListener(function(reply) { chrome.windows.getCurrent(function(window) { chrome.tabs.get(reply.data.tabId, function(tab) { - // 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. - chrome.tabs.create({url: "subscribe.html?" + - feedData[reply.data.tabId].feedUrl, - windowId: window.windowId}); + if (!alreadySubscribed && window.focused) { + // 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 (reply.pageActionId == pageActionId && + reply.data.tabUrl == pageUrl) { + // Create a new tab showing the subscription page with the right + // feed URL. + chrome.tabs.create({url: "subscribe.html?" + feedUrl, + windowId: windowId}); + } else { + console.log("Ignoring execute event."); + console.log("PageActionId: " + reply.pageActionId + " == " + + pageActionId); + console.log("TabUrl : " + reply.data.tabUrl + " == " + + pageUrl); + } } }); }); }); - - 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-16x16-subscribed.png b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png Binary files differnew file mode 100644 index 0000000..0369a6b37 --- /dev/null +++ b/chrome/test/data/extensions/samples/subscribe_page_action/feed-icon-16x16-subscribed.png diff --git a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json index 7adaf8f..5807816 100644 --- a/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json +++ b/chrome/test/data/extensions/samples/subscribe_page_action/manifest.json @@ -17,7 +17,8 @@ "id": "RssPageAction", "name": "Subscribe to this feed", "icons": [ - "feed-icon-16x16.png" + "feed-icon-16x16.png", + "feed-icon-16x16-subscribed.png" ] } ] |