Merge lp:~vrruiz/unity-webapps-yahoonews/fix-1188591 into lp:unity-webapps-yahoonews

Proposed by Víctor R. Ruiz
Status: Needs review
Proposed branch: lp:~vrruiz/unity-webapps-yahoonews/fix-1188591
Merge into: lp:unity-webapps-yahoonews
Diff against target: 114 lines (+51/-22)
2 files modified
YahooNews.test.js (+5/-2)
YahooNews.user.js (+46/-20)
To merge this branch: bzr merge lp:~vrruiz/unity-webapps-yahoonews/fix-1188591
Reviewer Review Type Date Requested Status
Alexandre Abreu (community) Needs Fixing
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+177864@code.launchpad.net

Commit message

Fix integration.

Description of the change

Fix integration.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
55. By Víctor R. Ruiz

Fix YahooNews.user.js:62->'res' is already defined

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
56. By Víctor R. Ruiz

jslint fixes in YahooNews.test.js

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Bruce Park (robru) wrote :

Will this need to be SRU'd?

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

> Will this need to be SRU'd?

yes :)

Revision history for this message
Robert Bruce Park (robru) wrote :

Ok. I'm at GUADEC right now but I'll try to get to this soon.​

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

as usual w/ the yahoo stuff, I don't think that news are dynamically pulled & updated, so it'll be as you browser which renders the setInterval useless ..

review: Needs Fixing
Revision history for this message
Robert Bruce Park (robru) wrote :

Whatever happened to this? Did it get fixed? Should I land/release/SRU this?

Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

Alex: In http://news.yahoo.com/ The headlines for "All News", "Yahoo Originals", and related tabs are loaded dinamically, that's why I used the timer.

Unmerged revisions

56. By Víctor R. Ruiz

jslint fixes in YahooNews.test.js

55. By Víctor R. Ruiz

Fix YahooNews.user.js:62->'res' is already defined

54. By Víctor R. Ruiz

Fix Yahoo News integration. Test fixes

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'YahooNews.test.js'
--- YahooNews.test.js 2013-04-30 20:42:47 +0000
+++ YahooNews.test.js 2013-07-31 15:58:54 +0000
@@ -14,9 +14,12 @@
14 },14 },
1515
16 validateCallLog: function (log) {16 validateCallLog: function (log) {
17 var i;
17 assertEquals('Unity.init', log[0].func, 'Unity.init');18 assertEquals('Unity.init', log[0].func, 'Unity.init');
18 assertEquals('Unity.Notification.showNotification', log[1].func, 'Unity.Notification.showNotification');19 assert('log.length', log.length > 1);
19 assertFalse('log.length', log.length < 3);20 for (i = 1; i < log.length; i++) {
21 assertEquals('log[' + i + '] = Unity.Notification.showNotification', log[i].func, 'Unity.Notification.showNotification');
22 }
20 },23 },
2124
22 scriptName: 'YahooNews.user.js'25 scriptName: 'YahooNews.user.js'
2326
=== modified file 'YahooNews.user.js'
--- YahooNews.user.js 2013-06-18 07:37:48 +0000
+++ YahooNews.user.js 2013-07-31 15:58:54 +0000
@@ -11,30 +11,34 @@
11));11));
1212
13window.Unity = external.getUnityObject(1);13window.Unity = external.getUnityObject(1);
14var timer;
15
16function getFeaturedTitles() {
17 return document.getElementsByClassName('yom-lead-featured-title');
18}
19
20/**
21 * Validates the page for functional tests
22 */
23function selfTest() {
24 if (!getFeaturedTitles()) {
25 reportTestState('FAILED: getFeaturedTitles is null');
26 return;
27 }
28 reportTestState('PASS SELF TEST');
29}
1430
15function isCorrectPage() {31function isCorrectPage() {
16 if (!document.getElementById('mediamegatron') && !document.getElementById('mediablistmixednewsforyoucatemp') && !document.getElementById('mediatabs')) {32 if (!getFeaturedTitles()) {
17 return false;33 return false;
18 }34 }
19
20 return true;35 return true;
21}36}
2237
23function messagingIndicatorSetup() {38function showNotifications(res) {
24 var i, res = document.evaluate('//*[@id="mediatabs"]/div[@class="bd"]/div/div/div/div/div/div[@class="bd"]/ul/li/div/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);39 var i = 0;
25 if (!res.snapshotLength) {40 // Display up to 5 notifications
26 res = document.evaluate('//*[@id="mediamegatron"]/div[@class="bd"]/div[@class="feature"]/div[@class="meta"]/div[@class="bd"]/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);41 while (i < res.snapshotLength && i < 5) {
27 }
28
29 if (!res.snapshotLength) {
30 res = document.evaluate('//*[@id="mediablistmixednewsforyoucatemp"]/div[@class="bd"]/ul/li/div/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
31 }
32
33 if (!res.snapshotLength) {
34 res = document.evaluate('//ul[@class="tpl-thumb_100x75_title yom-list yom-list-large"]/li/div/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
35 }
36
37 for (i = 0; i < res.snapshotLength; i++) {
38 var node = res.snapshotItem(i);42 var node = res.snapshotItem(i);
39 var title = node.textContent;43 var title = node.textContent;
4044
@@ -42,14 +46,36 @@
42 localStorage.setItem(title, true);46 localStorage.setItem(title, true);
43 Unity.Notification.showNotification(_("Yahoo News"), title, null);47 Unity.Notification.showNotification(_("Yahoo News"), title, null);
44 }48 }
45 }49 i++;
50 }
51}
52
53function checkHeadlines() {
54 // Frontpage headlines
55 var res = document.evaluate('//*[@class="yom-lead-featured-title"]/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
56 if (res.snapshotLength > 0) {
57 showNotifications(res);
58 }
59
60 // "All news" headlines. This are loaded using JavaScript
61 res = document.evaluate('//*[@class="body-wrap"]/h3/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
62 if (res.snapshotLength > 0) {
63 showNotifications(res);
64 }
65}
66
67function messagingIndicatorSetup() {
68 checkHeadlines();
69 timer = setInterval(checkHeadlines, 5000); // Re-check every 5 seconds
70
71 selfTest();
46}72}
4773
48if (isCorrectPage()) {74if (isCorrectPage()) {
49 Unity.init({75 Unity.init({
50 name: _("Yahoo News"),76 name: _("Yahoo News"),
51 domain: 'yahoo.com',77 domain: 'news.yahoo.com',
52 homepage: 'news.yahoo.com',78 homepage: 'http://news.yahoo.com/',
53 iconUrl: "icon://unity-webapps-yahoonews",79 iconUrl: "icon://unity-webapps-yahoonews",
54 onInit: wrapCallback(messagingIndicatorSetup)80 onInit: wrapCallback(messagingIndicatorSetup)
55 });81 });

Subscribers

People subscribed via source and target branches

to all changes: