Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add some tests for the use case where the document URL is different f…

…rom the document base.
  • Loading branch information...
commit 41349de54f3851c1eac483e49df3b83821e88617 1 parent aca0caa
@jblas jblas authored
View
59 tests/unit/navigation/base-tests.html
@@ -0,0 +1,59 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>jQuery Mobile Navigation Test Suite</title>
+
+ <script>
+
+ // This unit test requires a base tag to be set within the file.
+ // Most browsers require a base tag with an @href URL that is absolute.
+ // We need to dynamically inject the base tag so we can prefix it with
+ // the location of this test on the server without any server-side language
+ // requirements.
+
+ var baseUrl = location.href.replace(/[^\?\#\/]*(\?[^#]*)?(#.*)?$/, "");
+ document.write("<base href=\"" + baseUrl + "base-tests/app-base/\"/>\n");
+
+ </script>
+ <script src="../../../../../js/jquery.js"></script>
+ <script src="../../../jquery.setNameSpace.js"></script>
+ <script src="../../../../../js/"></script>
+ <script src="../../../../../tests/jquery.testHelper.js"></script>
+
+
+ <link rel="stylesheet" href="../../../../../themes/default/"/>
+ <link rel="stylesheet" href="../../../../../external/qunit.css"/>
+ <script src="../../../../../external/qunit.js"></script>
+
+ <script src="../../navigation_base.js"></script>
+</head>
+<body>
+
+<h1 id="qunit-header">jQuery Mobile Navigation Base Tag Test Suite</h1>
+<h2 id="qunit-banner"></h2>
+<h2 id="qunit-userAgent"></h2>
+<ol id="qunit-tests">
+</ol>
+
+<div id="internal-page-1" data-nstest-role="page">
+ <a href="base-page-1.html" class="bp1"></a>
+ <a href="base-page-2.html" class="bp2"></a>
+ <a href="../content/content-page-1.html" class="cp1"></a>
+ <a href="../content/content-page-2.html" class="cp2"></a>
+ <a href="#internal-page-2" class="ip2"></a>
+ <img src="images/internal-page-1.png">
+</div>
+
+<div id="internal-page-2" data-nstest-role="page">
+ <a href="base-page-1.html" class="bp1"></a>
+ <a href="base-page-2.html" class="bp2"></a>
+ <a href="../content/content-page-1.html" class="cp1"></a>
+ <a href="../content/content-page-2.html" class="cp2"></a>
+ <a href="#internal-page-1" class="ip1"></a>
+ <img src="images/internal-page-2.png">
+</div>
+
+</body>
+</html>
View
14 tests/unit/navigation/base-tests/app-base/base-page-1.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+ <div id="base-page-1" data-nstest-role="page">
+ <a href="base-page-2.html" class="bp2">Base Page 2</a>
+ <a href="../content/content-page-1.html" class="cp1">Content Page 1</a>
+ <a href="../../#internal-page-1" class="ip1">Internal Page 1</a>
+ <a href="../../#internal-page-2" class="ip2">Internal Page 2</a>
+ <img src="images/base-page-1.png">
+ </div>
+</body>
+</html>
View
14 tests/unit/navigation/base-tests/app-base/base-page-2.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+ <div id="base-page-2" data-nstest-role="page">
+ <a href="base-page-1.html" class="bp1">Base Page 1</a>
+ <a href="../content/content-page-1.html" class="cp1">Content Page 1</a>
+ <a href="../../#internal-page-1" class="ip1">Internal Page 1</a>
+ <a href="../../#internal-page-2" class="ip2">Internal Page 2</a>
+ <img src="images/base-page-2.png">
+ </div>
+</body>
+</html>
View
14 tests/unit/navigation/base-tests/content/content-page-1.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+ <div id="content-page-1" data-nstest-role="page">
+ <a href="content-page-2.html" class="cp2">Content Page 2</a>
+ <a href="../app-base/base-page-1.html" class="bp1">Base Page 1</a>
+ <a href="../../#internal-page-1" class="ip1">Internal Page 1</a>
+ <a href="../../#internal-page-2" class="ip2">Internal Page 2</a>
+ <img src="images/content-page-1.png">
+ </div>
+</body>
+</html>
View
14 tests/unit/navigation/base-tests/content/content-page-2.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+<body>
+ <div id="content-page-2" data-nstest-role="page">
+ <a href="content-page-1.html" class="cp1">Content Page 1</a>
+ <a href="../app-base/base-page-1.html" class="bp1">Base Page 1</a>
+ <a href="../../#internal-page-1" class="ip1">Internal Page 1</a>
+ <a href="../../#internal-page-2" class="ip2">Internal Page 2</a>
+ <img src="images/content-page-2.png">
+ </div>
+</body>
+</html>
View
114 tests/unit/navigation/navigation_base.js
@@ -0,0 +1,114 @@
+/*
+ * mobile navigation base tag unit tests
+ */
+(function($){
+ var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
+ contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir);
+
+ module('jquery.mobile.navigation.js - base tag', {
+ setup: function(){
+ if ( location.hash ) {
+ stop();
+ $(document).one("changepage", function() {
+ start();
+ } );
+ location.hash = "";
+ }
+ }
+ });
+
+ asyncTest( "can navigate between internal and external pages", function(){
+ $.testHelper.pageSequence([
+ function(){
+ // Navigate from default internal page to another internal page.
+ $.testHelper.openPage("#internal-page-2");
+ },
+
+ function(){
+ // Verify that we are on the 2nd internal page.
+ same(location.hash, "#internal-page-2", "navigate to internal page");
+
+ // Navigate to a page that is in the base directory. Note that the application
+ // document and this new page are *NOT* in the same directory.
+ $("#internal-page-2 .bp1").click();
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + baseDir + "base-page-1.html", "navigate from internal page to page in base directory");
+
+ // Navigate to another page in the same directory as the current page.
+ $("#base-page-1 .bp2").click();
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + baseDir + "base-page-2.html", "navigate from base directory page to another base directory page");
+
+ // Navigate to another page in a directory that is the sibling of the base.
+ $("#base-page-2 .cp1").click();
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + contentDir + "content-page-1.html", "navigate from base directory page to a page in a different directory hierarchy");
+
+ // Navigate to another page in a directory that is the sibling of the base.
+ $("#content-page-1 .cp2").click();
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + contentDir + "content-page-2.html", "navigate to another page within the same non-base directory hierarchy");
+
+ // Navigate to an internal page.
+ $("#content-page-2 .ip1").click();
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#internal-page-1", "navigate from a page in a non-base directory to an internal page");
+
+ // Try calling changePage() directly with a relative path.
+ $.mobile.changePage("base-page-1.html");
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + baseDir + "base-page-1.html", "call changePage() with a filename (no path)");
+
+ // Try calling changePage() directly with a relative path.
+ $.mobile.changePage("../content/content-page-1.html");
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + contentDir + "content-page-1.html", "call changePage() with a relative path containing up-level references");
+
+ // Try calling changePage() with an id
+ $.mobile.changePage("content-page-2.html");
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#" + contentDir + "content-page-2.html", "call changePage() with a relative path should resolve relative to current page");
+
+ // Try calling changePage() with an id
+ $.mobile.changePage("#internal-page-2");
+ },
+
+ function(){
+ // Verify that we are on the expected page.
+ same(location.hash, "#internal-page-2", "call changePage() with a page id");
+
+ // Try calling changePage() with an id
+ $.mobile.changePage("internal-page-1");
+ },
+
+ function(){
+ // Previous load should have failed and left us on internal-page-2.
+ same(location.hash, "#internal-page-2", "calling changePage() with a page id that is not prefixed with '#' should not change page");
+ start();
+ }]);
+ });
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.