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
1=== modified file 'YahooNews.test.js'
2--- YahooNews.test.js 2013-04-30 20:42:47 +0000
3+++ YahooNews.test.js 2013-07-31 15:58:54 +0000
4@@ -14,9 +14,12 @@
5 },
6
7 validateCallLog: function (log) {
8+ var i;
9 assertEquals('Unity.init', log[0].func, 'Unity.init');
10- assertEquals('Unity.Notification.showNotification', log[1].func, 'Unity.Notification.showNotification');
11- assertFalse('log.length', log.length < 3);
12+ assert('log.length', log.length > 1);
13+ for (i = 1; i < log.length; i++) {
14+ assertEquals('log[' + i + '] = Unity.Notification.showNotification', log[i].func, 'Unity.Notification.showNotification');
15+ }
16 },
17
18 scriptName: 'YahooNews.user.js'
19
20=== modified file 'YahooNews.user.js'
21--- YahooNews.user.js 2013-06-18 07:37:48 +0000
22+++ YahooNews.user.js 2013-07-31 15:58:54 +0000
23@@ -11,30 +11,34 @@
24 ));
25
26 window.Unity = external.getUnityObject(1);
27+var timer;
28+
29+function getFeaturedTitles() {
30+ return document.getElementsByClassName('yom-lead-featured-title');
31+}
32+
33+/**
34+ * Validates the page for functional tests
35+ */
36+function selfTest() {
37+ if (!getFeaturedTitles()) {
38+ reportTestState('FAILED: getFeaturedTitles is null');
39+ return;
40+ }
41+ reportTestState('PASS SELF TEST');
42+}
43
44 function isCorrectPage() {
45- if (!document.getElementById('mediamegatron') && !document.getElementById('mediablistmixednewsforyoucatemp') && !document.getElementById('mediatabs')) {
46+ if (!getFeaturedTitles()) {
47 return false;
48 }
49-
50 return true;
51 }
52
53-function messagingIndicatorSetup() {
54- 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);
55- if (!res.snapshotLength) {
56- 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);
57- }
58-
59- if (!res.snapshotLength) {
60- res = document.evaluate('//*[@id="mediablistmixednewsforyoucatemp"]/div[@class="bd"]/ul/li/div/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
61- }
62-
63- if (!res.snapshotLength) {
64- 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);
65- }
66-
67- for (i = 0; i < res.snapshotLength; i++) {
68+function showNotifications(res) {
69+ var i = 0;
70+ // Display up to 5 notifications
71+ while (i < res.snapshotLength && i < 5) {
72 var node = res.snapshotItem(i);
73 var title = node.textContent;
74
75@@ -42,14 +46,36 @@
76 localStorage.setItem(title, true);
77 Unity.Notification.showNotification(_("Yahoo News"), title, null);
78 }
79- }
80+ i++;
81+ }
82+}
83+
84+function checkHeadlines() {
85+ // Frontpage headlines
86+ var res = document.evaluate('//*[@class="yom-lead-featured-title"]/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
87+ if (res.snapshotLength > 0) {
88+ showNotifications(res);
89+ }
90+
91+ // "All news" headlines. This are loaded using JavaScript
92+ res = document.evaluate('//*[@class="body-wrap"]/h3/a', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
93+ if (res.snapshotLength > 0) {
94+ showNotifications(res);
95+ }
96+}
97+
98+function messagingIndicatorSetup() {
99+ checkHeadlines();
100+ timer = setInterval(checkHeadlines, 5000); // Re-check every 5 seconds
101+
102+ selfTest();
103 }
104
105 if (isCorrectPage()) {
106 Unity.init({
107 name: _("Yahoo News"),
108- domain: 'yahoo.com',
109- homepage: 'news.yahoo.com',
110+ domain: 'news.yahoo.com',
111+ homepage: 'http://news.yahoo.com/',
112 iconUrl: "icon://unity-webapps-yahoonews",
113 onInit: wrapCallback(messagingIndicatorSetup)
114 });

Subscribers

People subscribed via source and target branches

to all changes: