diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 23:49:47 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 23:49:47 +0000 |
commit | 40216b70b25e2cbfcff19eadbc2c246e98b2a3b8 (patch) | |
tree | ed3cb4150f64c0c4fc2a3174e608d4ba4a5a6e28 | |
parent | 07fdd98e4a7cb1b26d74138c3efc3fc55aa765b2 (diff) | |
download | chromium_src-40216b70b25e2cbfcff19eadbc2c246e98b2a3b8.zip chromium_src-40216b70b25e2cbfcff19eadbc2c246e98b2a3b8.tar.gz chromium_src-40216b70b25e2cbfcff19eadbc2c246e98b2a3b8.tar.bz2 |
Various fixes to gmail sample:
- Handle the case where we never get a response, which happens if
you're not logged in.
- Lengthen the poll timeout to something reasonable.
Review URL: http://codereview.chromium.org/100270
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15124 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/data/extensions/samples/gmail/gmail_checker.html | 45 | ||||
-rw-r--r-- | chrome/test/data/extensions/samples/gmail/manifest.json | 7 |
2 files changed, 32 insertions, 20 deletions
diff --git a/chrome/test/data/extensions/samples/gmail/gmail_checker.html b/chrome/test/data/extensions/samples/gmail/gmail_checker.html index e0cbb9d..e52d78d 100644 --- a/chrome/test/data/extensions/samples/gmail/gmail_checker.html +++ b/chrome/test/data/extensions/samples/gmail/gmail_checker.html @@ -3,7 +3,7 @@ <link rel="stylesheet" type="text/css" href="styles.css"> <script> gmail_atom_href = "http://mail.google.com/mail/feed/atom"; -var poll_timeout = 2000; +var poll_timeout = 1000 * 60; // 1 minute var unreadCount; var debug = true; @@ -14,6 +14,8 @@ function gmailNSResolver(prefix) { } function startFlip() { + document.getElementById("notLoggedIn").style.display = "none"; + document.getElementById("loggedIn").style.display = ""; document.getElementById("unreadCount").className = 'mid-flip'; setTimeout("midFlip();", 500); } @@ -42,16 +44,20 @@ function requestUnreadFeed() { xhr.onreadystatechange = function(){ console.log("readystate: " + xhr.readyState); if (xhr.readyState == 4) { - console.log("response.."); - var xmlDoc = xhr.responseXML; - var fullCountSet = xmlDoc.evaluate("/gmail:feed/gmail:fullcount", - xmlDoc, gmailNSResolver, XPathResult.ANY_TYPE, null); - var fullCountNode = fullCountSet.iterateNext(); - if (fullCountNode) { - updateUnreadCount(fullCountNode.textContent); - } else { - console.log("fullcount not found!"); - console.error("Error: feed retrieved, but no <fullcount> node found"); + if (xhr.responseXML) { + window.clearTimeout(timerId); + + console.log("response.."); + var xmlDoc = xhr.responseXML; + var fullCountSet = xmlDoc.evaluate("/gmail:feed/gmail:fullcount", + xmlDoc, gmailNSResolver, XPathResult.ANY_TYPE, null); + var fullCountNode = fullCountSet.iterateNext(); + if (fullCountNode) { + updateUnreadCount(fullCountNode.textContent); + } else { + console.log("fullcount not found!"); + console.error("Error: feed retrieved, but no <fullcount> node found"); + } } window.setTimeout(requestUnreadFeed, poll_timeout); @@ -59,13 +65,19 @@ function requestUnreadFeed() { } xhr.onerror = function(error) { - debugger; console.log("error: " + error); window.setTimeout(requestUnreadFeed, poll_timeout); } - xhr.open("GET", gmail_atom_href); - xhr.send({}); + xhr.open("GET", gmail_atom_href, true); + xhr.send(null); + + // Give up after 5 seconds + var timerId = window.setTimeout(function() { + document.getElementById("loggedIn").style.display = "none"; + document.getElementById("notLoggedIn").style.display = ""; + xhr.abort(); + }, 5000); } catch(e) { console.log("ex: " + e); console.error("exception: " + e); @@ -79,10 +91,11 @@ function goToInbox() { </script> </head> -<body onload="requestUnreadFeed();" onclick="goToInbox()"> +<body onload="window.setTimeout(requestUnreadFeed, 0)" onclick="goToInbox()"> <div class="toolstrip-button"> <img src="gmail.png" style="width:auto; height:auto"> - <span>Gmail - Inbox <span style="display: inline-block;" id="unreadCount" class="base-flip" onclick="startFlip();"></span></span> + <span id="notLoggedIn" style="display:none;">Login</span> + <span id="loggedIn">Gmail - Inbox <span style="display: inline-block;" id="unreadCount" class="base-flip" onclick="startFlip();"></span></span> </div> </body> </html> diff --git a/chrome/test/data/extensions/samples/gmail/manifest.json b/chrome/test/data/extensions/samples/gmail/manifest.json index bf7faf7..bddfec1 100644 --- a/chrome/test/data/extensions/samples/gmail/manifest.json +++ b/chrome/test/data/extensions/samples/gmail/manifest.json @@ -1,13 +1,12 @@ { - "description": "Displays number of unread Gmail messages", - "id": "DE6C0EDB5E435EC06E4E0E36E77EB241E1831273", "name": "Gmail Checker", + "version": "0.1", + "description": "Displays number of unread Gmail messages", "permissions": [ "http://*.google.com/*", "https://*.google.com/*" ], "toolstrips": [ "gmail_checker.html" - ], - "version": "0.1" + ] }
\ No newline at end of file |