зеркало из https://github.com/mozilla/popcorn-js.git
starting tests
This commit is contained in:
Родитель
93059f825e
Коммит
3821b595bd
|
@ -11,10 +11,16 @@
|
|||
.volume(0)
|
||||
.play()
|
||||
.wikipedia({
|
||||
start: 10, // seconds
|
||||
end: 50, // seconds
|
||||
start: 5, // seconds
|
||||
end: 10, // seconds
|
||||
src: 'http://en.wikipedia.org/wiki/Cape_Town',
|
||||
target: 'wikidiv'
|
||||
} )
|
||||
.wikipedia({
|
||||
start: 12, // seconds
|
||||
end: 20, // seconds
|
||||
src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo',
|
||||
target: 'wikidiv2'
|
||||
} );
|
||||
|
||||
}, false);
|
||||
|
@ -23,11 +29,11 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Popcorn WebPage Plug-in Demo</h1>
|
||||
<p> A Webpage displaying webmademovies.org will appear at 5 seconds and disappear at 15 seconds.</p>
|
||||
<p> A Webpage displaying zenit Processing.js wiki will appear at 20 seconds and disappear at 45 seconds.</p>
|
||||
<p> A Wiki article about Cape Town will appear at 5 seconds and disappear at 10 seconds.</p>
|
||||
<p> A Wiki article about Sao Paolo will appear at 12 seconds and disappear at 20 seconds.</p>
|
||||
<div>
|
||||
<video id='video'
|
||||
controls preload='none'
|
||||
controls
|
||||
width= '250px'
|
||||
poster="../../test/poster.png">
|
||||
|
||||
|
@ -44,6 +50,9 @@
|
|||
</video>
|
||||
</div>
|
||||
<div id="wikidiv" width="50%" height="50%">
|
||||
|
||||
|
||||
</div>
|
||||
<div id="wikidiv2" width="50%" height="50%"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,12 +1,7 @@
|
|||
// PLUGIN: WIKIPEDIA
|
||||
|
||||
|
||||
// wikipedia callback functions executes when data is retrieved from the wiki
|
||||
// stores the data in a global variable
|
||||
var wikidatastring;
|
||||
var wikiCallback = function (data) {
|
||||
wikidatastring = data;
|
||||
};
|
||||
var wikiCallback;
|
||||
|
||||
(function (Popcorn) {
|
||||
|
||||
|
@ -61,28 +56,22 @@ var wikiCallback = function (data) {
|
|||
var getJson = function(url) {
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
var script = document.createElement("script");
|
||||
// once you get the data store it
|
||||
script.onload = function () {
|
||||
if (wikidatastring) {
|
||||
// create a link that the user can use to view the whole article
|
||||
link = document.createElement('a');
|
||||
link.setAttribute('href', options.src);
|
||||
link.setAttribute('target', '_blank');
|
||||
// create a paragraph that the title of the article can go into
|
||||
p = document.createElement('p');
|
||||
p.innerHTML = wikidatastring.parse.displaytitle;
|
||||
link.appendChild(p);
|
||||
// get the first 140 characters of the wiki content
|
||||
desc = document.createElement('p');
|
||||
text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('<p>'));
|
||||
text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
|
||||
desc.innerHTML = text.substr(0, length ) + " ...";
|
||||
}
|
||||
};
|
||||
script.src = url;
|
||||
head.insertBefore( script, head.firstChild );
|
||||
};
|
||||
|
||||
wikiCallback = function (data) {
|
||||
wikidatastring = data;
|
||||
link = document.createElement('a');
|
||||
link.setAttribute('href', options.src);
|
||||
link.setAttribute('target', '_blank');
|
||||
// add the title of the article to the link
|
||||
link.innerHTML = wikidatastring.parse.displaytitle;
|
||||
// get the content of the wiki article
|
||||
desc = document.createElement('p');
|
||||
text = wikidatastring.parse.text["*"].substr(wikidatastring.parse.text["*"].indexOf('<p>'));
|
||||
text = text.replace(/((<(.|\n)+?>)|(\((.*?)\) )|(\[(.*?)\]))/g, "");
|
||||
desc.innerHTML = text.substr(0, length ) + " ...";
|
||||
};
|
||||
},
|
||||
/**
|
||||
* @member wikipedia
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
-->
|
||||
|
||||
<script src="../../popcorn.js"></script>
|
||||
<script src="popcorn.webpage.js"></script>
|
||||
<script src="popcorn.wikipedia.js"></script>
|
||||
|
||||
<script src="popcorn.webpage.unit.js"></script>
|
||||
<script src="popcorn.wikipedia.unit.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">Popcorn Webpage UI</h1>
|
||||
<h1 id="qunit-header">Popcorn wikipedia UI</h1>
|
||||
<h2 id="qunit-banner"></h2>
|
||||
<div id="qunit-testrunner-toolbar"></div>
|
||||
<h2 id="qunit-userAgent"></h2>
|
||||
|
@ -23,7 +23,7 @@
|
|||
<div id="qunit-fixture"> </div>
|
||||
|
||||
<video id='video'
|
||||
controls preload='none'
|
||||
controls
|
||||
width= '250px'
|
||||
poster="../../test/poster.png">
|
||||
|
||||
|
@ -38,6 +38,6 @@
|
|||
<p>Your user agent does not support the HTML5 Video element.</p>
|
||||
|
||||
</video>
|
||||
<div id="webpagediv"></div>
|
||||
<div id="wikidiv"></div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
test("Popcorn Webpage Plugin", function () {
|
||||
test("Popcorn wikipedia Plugin", function () {
|
||||
|
||||
var popped = Popcorn("#video"),
|
||||
expects = 11,
|
||||
expects = 5,
|
||||
count = 0,
|
||||
iframeInterval,
|
||||
iframeInterval2,
|
||||
iframeInterval3,
|
||||
iframeInterval4;
|
||||
theiFrame = document.getElementsByTagName('iframe');
|
||||
wikiInterval,
|
||||
wikiInterval2,
|
||||
wikiInterval3,
|
||||
wikiInterval4;
|
||||
theArticle = document.getElementById('wikidiv');
|
||||
|
||||
expect(expects);
|
||||
|
||||
function plus() {
|
||||
|
@ -18,63 +19,57 @@ test("Popcorn Webpage Plugin", function () {
|
|||
|
||||
stop();
|
||||
|
||||
ok ('webpage' in popped, "webpages is a mehtod of the popped instance");
|
||||
ok ('wikipedia' in popped, "wikipedia is a mehtod of the popped instance");
|
||||
plus();
|
||||
|
||||
equals (theiFrame.length, 0, "initially, there is no iframes on the page" );
|
||||
equals (theArticle.innerHTML, "", "initially, there is nothing in the wikidiv" );
|
||||
plus();
|
||||
|
||||
popped.webpage({
|
||||
id: "webpages-a",
|
||||
popped.wikipedia({
|
||||
start: 5, // seconds
|
||||
end: 25, // seconds
|
||||
src: 'http://webmademovies.org',
|
||||
target: 'webpagediv'
|
||||
})
|
||||
.webpage({
|
||||
id: "webpages-b",
|
||||
start: 35, // seconds
|
||||
end: 50, // seconds
|
||||
src: 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js',
|
||||
target: 'webpagediv'
|
||||
})
|
||||
end: 10, // seconds
|
||||
src: 'http://en.wikipedia.org/wiki/Cape_Town',
|
||||
target: 'wikidiv'
|
||||
} )
|
||||
.wikipedia({
|
||||
start: 12, // seconds
|
||||
end: 20, // seconds
|
||||
src: 'http://en.wikipedia.org/wiki/S%C3%A3o_Paulo',
|
||||
target: 'wikidiv'
|
||||
} )
|
||||
.play();
|
||||
|
||||
|
||||
iframeInterval = setInterval( function() {
|
||||
if( popped.currentTime() > 7 && popped.currentTime() <= 25 ) {
|
||||
ok (!!theiFrame[0], "iframe was created" );
|
||||
wikiInterval = setInterval( function() {
|
||||
if( popped.currentTime() > 7 && popped.currentTime() <= 10 ) {
|
||||
ok (theArticle.innerHTML !== "", "wikidiv now contains information" );
|
||||
plus();
|
||||
equals (theiFrame.length, 1, "there is only one iframe on the page" );
|
||||
equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
||||
plus();
|
||||
equals (theiFrame[0].id, "webpages-a", "iframe has the id 'webpages-a'" );
|
||||
plus();
|
||||
equals (theiFrame[0].src, "http://webmademovies.org/", "iframe has the src 'http://webmademovies.org/'" );
|
||||
plus();
|
||||
clearInterval( iframeInterval );
|
||||
|
||||
clearInterval( wikiInterval );
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
iframeInterval2 = setInterval( function() {
|
||||
if( popped.currentTime() > 27 && popped.currentTime() < 35 ) {
|
||||
equals (theiFrame.length, 0, "the iframe has been removed" );
|
||||
wikiInterval2 = setInterval( function() {
|
||||
if( popped.currentTime() > 10 && popped.currentTime() < 12 ) {
|
||||
equals (theArticle.innerHTML, "", "wikidiv was cleared properly" );
|
||||
plus();
|
||||
clearInterval( iframeInterval2 );
|
||||
clearInterval( wikiInterval2 );
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
iframeInterval3 = setInterval( function() {
|
||||
if( popped.currentTime() > 37 && popped.currentTime() <= 50 ) {
|
||||
ok (!!theiFrame[0], "iframe was created" );
|
||||
wikiInterval3 = setInterval( function() {
|
||||
if( popped.currentTime() > 13 && popped.currentTime() <= 20 ) {
|
||||
ok (theArticle.innerHTML !== "", "wikidiv now contains information" );
|
||||
plus();
|
||||
equals (theiFrame.length, 1, "there is only one iframe on the page" );
|
||||
equals (theArticle.childElementCount, 2, "wikidiv now contains two child elements" );
|
||||
plus();
|
||||
equals (theiFrame[0].id, "webpages-b", "iframe has the id 'webpages-b'" );
|
||||
plus();
|
||||
equals (theiFrame[0].src,"http://zenit.senecac.on.ca/wiki/index.php/Processing.js", "iframe has the src 'http://zenit.senecac.on.ca/wiki/index.php/Processing.js'" );
|
||||
plus();
|
||||
clearInterval( iframeInterval3 );
|
||||
|
||||
clearInterval( wikiInterval3 );
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче