Skip to content

Commit

Permalink
Fixed another test that wouldn't run in the browser. Found problem in…
Browse files Browse the repository at this point in the history
…troduced

in one of my earlier fixes to 'html' tests (ant-build only, couldn't get
"head" element of the document because boot.js didn't set location= to the
test's index.html.  alas).
  • Loading branch information
gleneivey committed Apr 15, 2010
1 parent d0e7276 commit 8eb2224
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 111 deletions.
5 changes: 5 additions & 0 deletions specs/helpers.js
@@ -0,0 +1,5 @@
// helpers available to all tests

function runningUnderEnvjs(){
return navigator.userAgent.search( /Envjs/ ) > -1;
}
11 changes: 10 additions & 1 deletion specs/html/boot.js
Expand Up @@ -5,6 +5,7 @@

load('specs/qunit.js');
load('specs/env.qunit.js');
load('specs/helpers.js');
QUnit.init();

load('dist/platform/core.js');
Expand All @@ -13,6 +14,14 @@ load('dist/console.js');
load('dist/dom.js');
load('dist/event.js');
load('dist/html.js');
load('dist/timer.js');
load('dist/parser.js');
load('dist/xhr.js');
load('dist/window.js');

load('local_settings.js');
load('specs/html/spec.js');
start();


location = 'specs/html/index.html';
start();
2 changes: 2 additions & 0 deletions specs/html/index.html
Expand Up @@ -9,6 +9,8 @@

<script src="../qunit.js"
type="text/javascript" ></script>
<script src="../helpers.js"
type="text/javascript" ></script>
<script src="spec.js"
type="text/javascript" ></script>

Expand Down
6 changes: 2 additions & 4 deletions specs/html/spec.js
Expand Up @@ -2,9 +2,7 @@ QUnit.module('html');

test('HTML Interfaces Available', function(){

var areInEnvjs = navigator.userAgent.search( /Envjs/ ) > -1;

if (areInEnvjs)
if (runningUnderEnvjs())
expect(53);
else
expect(51);
Expand Down Expand Up @@ -54,7 +52,7 @@ test('HTML Interfaces Available', function(){
ok(HTMLTableSectionElement, 'HTMLTableSectionElement defined');
ok(HTMLTableCellElement, 'HTMLTableCellElement defined');

if (areInEnvjs){
if (runningUnderEnvjs()){
ok(HTMLTableDataCellElement, 'HTMLTableDataCellElement defined');
ok(HTMLTableHeaderCellElement, 'HTMLTableHeaderCellElement defined');
}
Expand Down
1 change: 1 addition & 0 deletions specs/window/boot.js
Expand Up @@ -15,6 +15,7 @@ load('dist/window.js');

load('specs/qunit.js');
load('specs/env.qunit.js');
load('specs/helpers.js');

load('local_settings.js');
load('specs/window/spec.js');
Expand Down
2 changes: 2 additions & 0 deletions specs/window/index.html
Expand Up @@ -10,6 +10,8 @@

<script src="../qunit.js"
type="text/javascript" ></script>
<script src="../helpers.js"
type="text/javascript" ></script>
<script src="spec.js"
type="text/javascript" ></script>
<script type="text/javascript">
Expand Down
224 changes: 118 additions & 106 deletions specs/window/spec.js
Expand Up @@ -188,111 +188,123 @@ test('window.location', function(){
//ok(location.assign, 'location.resolveURL');
});

test('Location object', function() {
// to use the example from
// https://developer.mozilla.org/En/DOM/Window.location
var x = Location('http://www.google.com:80/search?q=devmo#test');

// we are modifying x.assign to we can intercept the new
// reconstituted url
x.assign = function(url) {};

// test basic parsing
equals(x.hash, '#test');
equals(x.host, 'www.google.com:80');
equals(x.hostname, 'www.google.com');
equals(x.href, 'http://www.google.com:80/search?q=devmo#test');
equals(x.pathname, '/search');
equals(x.protocol, 'http:');
equals(x.port, '80');
equals(typeof x.port, 'string');
equals(x.search, '?q=devmo');

// setter for hostname
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
// TBD, not clear what should happen
// SafarI 4: accept
// Firefox 3.6: Error
x.protocol = '';
// envjs crash
//equals(x.protocol, 'http:', 'Setting protocol to emptry string is ignored');
x.protocol = 'https:';
equals(x.protocol, 'https:', 'Setting protocol with trailing colon');
x.protocol = 'http';
equals(x.protocol, 'http:', 'Setting protocol without trailing colon');

// setter for host
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.host = '';
// SafarI 4: accept (infinite loop)
// Firefox 3.6: Error
equals(x.host, 'www.google.com:80', 'Setting host to emptry string is ignored');

x.host = 'www.yahoo.com';
equals(x.host, 'www.yahoo.com', 'Setting host with no port')
equals(x.hostname, 'www.yahoo.com', 'Setting host updates hostname');
equals(x.port, '', 'Setting host updates port');
equals(x.href, 'http://www.yahoo.com/search?q=devmo#test');

x.host = 'www.google.com:80';
equals(x.host, 'www.google.com:80', 'Setting host with port');
equals(x.hostname,'www.google.com', 'Setting host updates hostname');
equals(x.port, '80', 'Setting host updates port');
equals(x.href, 'http://www.google.com:80/search?q=devmo#test');

// setter for host
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.host = 'www.yahoo.com';
equals(x.host, 'www.yahoo.com');

// setter for port
// Safari 4: file://:90/Users/nickg/javascript.html
// Firefox: Error
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.port = 81;
equals(x.port, 81, 'Setting port as integer');
equals(x.host, 'www.google.com:81');
equals(x.href, 'http://www.google.com:81/search?q=devmo#test');
x.port = '82';
equals(x.port, '82', 'Setting port as string');
equals(x.host, 'www.google.com:82');
equals(x.href, 'http://www.google.com:82/search?q=devmo#test');

// setter for path
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.pathname = '/foo';
equals(x.pathname, '/foo', 'Setting path starting with "/"');
equals(x.href, 'http://www.google.com:80/foo?q=devmo#test');
x.pathname = 'foobar';
equals(x.pathname, '/foobar', 'Setting path starting without "/"');
equals(x.href, 'http://www.google.com:80/foobar?q=devmo#test');

// setter for search (query string)
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.search='?q=foo';
equals(x.search, '?q=foo', 'Setting search with starting "?"');
equals(x.href, 'http://www.google.com:80/search?q=foo#test');
x.search='q=bar';
equals(x.search, '?q=bar', 'Setting search without starting "?"');
equals(x.href, 'http://www.google.com:80/search?q=bar#test');

// setter for hash (fragment)
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.hash = '#foo';
equals(x.hash, '#foo', 'Setting hash with starting "#"');
equals(x.href, 'http://www.google.com:80/search?q=devmo#foo');
x.hash = '#bar';
equals(x.hash, '#bar', 'Setting hash without starting "#"');
equals(x.href, 'http://www.google.com:80/search?q=devmo#bar');
});
if (runningUnderEnvjs()){
/* This test won't run in a browser. In-browser testing with
* modern versions of IE, Safari, and FF shows that "Location"
* ranges from being entirely undefined to not callable as an
* object constructor, but Envjs seems to be the only system that
* allows for instances of the Location object outside of being a
* member of the 'window' object. I'm leaving the test as it is
* written, however, because performing these validations on
* window.location itself would cause the browser (simulation) to
* attempt to navigate all over the place creating huge problems.
*/

test('Location object', function() {
// to use the example from
// https://developer.mozilla.org/En/DOM/Window.location
var x = new Location('http://www.google.com:80/search?q=devmo#test');

// we are modifying x.assign to we can intercept the new
// reconstituted url
x.assign = function(url) {};

// test basic parsing
equals(x.hash, '#test');
equals(x.host, 'www.google.com:80');
equals(x.hostname, 'www.google.com');
equals(x.href, 'http://www.google.com:80/search?q=devmo#test');
equals(x.pathname, '/search');
equals(x.protocol, 'http:');
equals(x.port, '80');
equals(typeof x.port, 'string');
equals(x.search, '?q=devmo');

// setter for hostname
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
// TBD, not clear what should happen
// SafarI 4: accept
// Firefox 3.6: Error
x.protocol = '';
// envjs crash
//equals(x.protocol, 'http:', 'Setting protocol to emptry string is ignored');
x.protocol = 'https:';
equals(x.protocol, 'https:', 'Setting protocol with trailing colon');
x.protocol = 'http';
equals(x.protocol, 'http:', 'Setting protocol without trailing colon');

// setter for host
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.host = '';
// SafarI 4: accept (infinite loop)
// Firefox 3.6: Error
equals(x.host, 'www.google.com:80', 'Setting host to emptry string is ignored');

x.host = 'www.yahoo.com';
equals(x.host, 'www.yahoo.com', 'Setting host with no port')
equals(x.hostname, 'www.yahoo.com', 'Setting host updates hostname');
equals(x.port, '', 'Setting host updates port');
equals(x.href, 'http://www.yahoo.com/search?q=devmo#test');

x.host = 'www.google.com:80';
equals(x.host, 'www.google.com:80', 'Setting host with port');
equals(x.hostname,'www.google.com', 'Setting host updates hostname');
equals(x.port, '80', 'Setting host updates port');
equals(x.href, 'http://www.google.com:80/search?q=devmo#test');

// setter for host
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.host = 'www.yahoo.com';
equals(x.host, 'www.yahoo.com');

// setter for port
// Safari 4: file://:90/Users/nickg/javascript.html
// Firefox: Error
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.port = 81;
equals(x.port, 81, 'Setting port as integer');
equals(x.host, 'www.google.com:81');
equals(x.href, 'http://www.google.com:81/search?q=devmo#test');
x.port = '82';
equals(x.port, '82', 'Setting port as string');
equals(x.host, 'www.google.com:82');
equals(x.href, 'http://www.google.com:82/search?q=devmo#test');

// setter for path
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.pathname = '/foo';
equals(x.pathname, '/foo', 'Setting path starting with "/"');
equals(x.href, 'http://www.google.com:80/foo?q=devmo#test');
x.pathname = 'foobar';
equals(x.pathname, '/foobar', 'Setting path starting without "/"');
equals(x.href, 'http://www.google.com:80/foobar?q=devmo#test');

// setter for search (query string)
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.search='?q=foo';
equals(x.search, '?q=foo', 'Setting search with starting "?"');
equals(x.href, 'http://www.google.com:80/search?q=foo#test');
x.search='q=bar';
equals(x.search, '?q=bar', 'Setting search without starting "?"');
equals(x.href, 'http://www.google.com:80/search?q=bar#test');

// setter for hash (fragment)
x = Location('http://www.google.com:80/search?q=devmo#test');
x.assign = function(url) {};
x.hash = '#foo';
equals(x.hash, '#foo', 'Setting hash with starting "#"');
equals(x.href, 'http://www.google.com:80/search?q=devmo#foo');
x.hash = '#bar';
equals(x.hash, '#bar', 'Setting hash without starting "#"');
equals(x.href, 'http://www.google.com:80/search?q=devmo#bar');
});
}

test('window.screen', function(){

Expand Down Expand Up @@ -570,7 +582,7 @@ test('Form Named Element Lookup', function(){
elements = doc.bar.elements;
equals(elements.length, 1);
equals(form.length, 1);
print('element is : ' + elements.input1);
//print('element is : ' + elements.input1);
ok(elements.input1 instanceof HTMLInputElement);
ok(form.input1 instanceof HTMLInputElement);

Expand All @@ -579,4 +591,4 @@ test('Form Named Element Lookup', function(){
node2 = doc.foo;
ok(! node2, 'old named element is gone');
*/
});
});

0 comments on commit 8eb2224

Please sign in to comment.