3b7f2b9c14c05085899ebbe09f46415d460c91c7
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / tests / unit / navigation / navigation_base.js
1 /*
2  * mobile navigation base tag unit tests
3  */
4 (function($){
5         var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
6                 contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir);
7
8         module('jquery.mobile.navigation.js - base tag', {
9                 setup: function(){
10                         if ( location.hash ) {
11                                 stop();
12                                 $(document).one("pagechange", function() {
13                                         start();
14                                 } );
15                                 location.hash = "";
16                         }
17                 }
18         });
19
20         asyncTest( "can navigate between internal and external pages", function(){
21                 $.testHelper.pageSequence([
22                         function(){
23                                 // Navigate from default internal page to another internal page.
24                                 $.testHelper.openPage( "#internal-page-2" );
25                         },
26
27                         function(){
28                                 // Verify that we are on the 2nd internal page.
29                                 $.testHelper.assertUrlLocation({
30                                         push: location.pathname + "#internal-page-2",
31                                         hash: "internal-page-2",
32                                         report: "navigate to internal page"
33                                 });
34
35                                 // Navigate to a page that is in the base directory. Note that the application
36                                 // document and this new page are *NOT* in the same directory.
37                                 $("#internal-page-2 .bp1").click();
38                         },
39
40                         function(){
41                                 // Verify that we are on the expected page.
42                                 $.testHelper.assertUrlLocation({
43                                         hashOrPush: baseDir + "base-page-1.html",
44                                         report: "navigate from internal page to page in base directory"
45                                 });
46
47                                 // Navigate to another page in the same directory as the current page.
48                                 $("#base-page-1 .bp2").click();
49                         },
50
51                         function(){
52                                 // Verify that we are on the expected page.
53                                 $.testHelper.assertUrlLocation({
54                                         hashOrPush: baseDir + "base-page-2.html",
55                                         report: "navigate from base directory page to another base directory page"
56                                 });
57
58                                 // Navigate to another page in a directory that is the sibling of the base.
59                                 $("#base-page-2 .cp1").click();
60                         },
61
62                         function(){
63                                 // Verify that we are on the expected page.
64                                 $.testHelper.assertUrlLocation({
65                                         hashOrPush: contentDir + "content-page-1.html",
66                                         report: "navigate from base directory page to a page in a different directory hierarchy"
67                                 });
68
69                                 // Navigate to another page in a directory that is the sibling of the base.
70                                 $("#content-page-1 .cp2").click();
71                         },
72
73                         function(){
74                                 // Verify that we are on the expected page.
75                                 $.testHelper.assertUrlLocation({
76                                         hashOrPush: contentDir + "content-page-2.html",
77                                         report: "navigate to another page within the same non-base directory hierarchy"
78                                 });
79
80                                 // Navigate to an internal page.
81                                 $("#content-page-2 .ip1").click();
82                         },
83
84                         function(){
85                                 // Verify that we are on the expected page.
86                                 // the hash based nav result (hash:) is dictate by the fact that #internal-page-1
87                                 // is the original root page element
88                                 $.testHelper.assertUrlLocation({
89                                         hashOrPush: location.pathname + location.search,
90                                         report: "navigate from a page in a non-base directory to an internal page"
91                                 });
92
93                                 // Try calling changePage() directly with a relative path.
94                                 $.mobile.changePage("base-page-1.html");
95                         },
96
97                         function(){
98                                 // Verify that we are on the expected page.
99                                 $.testHelper.assertUrlLocation({
100                                         hashOrPush: baseDir + "base-page-1.html",
101                                         report: "call changePage() with a filename (no path)"
102                                 });
103
104                                 // Try calling changePage() directly with a relative path.
105                                 $.mobile.changePage("../content/content-page-1.html");
106                         },
107
108                         function(){
109                                 // Verify that we are on the expected page.
110                                 $.testHelper.assertUrlLocation({
111                                         hashOrPush: contentDir + "content-page-1.html",
112                                         report: "call changePage() with a relative path containing up-level references"
113                                 });
114
115                                 // Try calling changePage() with an id
116                                 $.mobile.changePage("content-page-2.html");
117                         },
118
119                         function(){
120                                 // Verify that we are on the expected page.
121                                 $.testHelper.assertUrlLocation({
122                                         hashOrPush: contentDir + "content-page-2.html",
123                                         report: "call changePage() with a relative path should resolve relative to current page"
124                                 });
125
126                                 // test that an internal page works
127                                 $("a.ip2").click();
128                         },
129
130                         function(){
131                                 // Verify that we are on the expected page.
132                                 $.testHelper.assertUrlLocation({
133                                         hash:  "internal-page-2",
134                                         push: location.pathname + "#internal-page-2",
135                                         report: "call changePage() with a page id"
136                                 });
137
138                                 // Try calling changePage() with an id
139                                 $.mobile.changePage("internal-page-1");
140                         },
141
142                         function(){
143                                 // Verify that we are on the expected page.
144                                 $.testHelper.assertUrlLocation({
145                                         hash:  "internal-page-2",
146                                         push: location.pathname + "#internal-page-2",
147                                         report: "calling changePage() with a page id that is not prefixed with '#' should not change page"
148                                 });
149
150                                 // Previous load should have failed and left us on internal-page-2.
151                                 start();
152                         }
153                 ]);
154         });
155
156         asyncTest( "internal form with no action submits to document URL", function(){
157                 $.testHelper.pageSequence([
158                         // open our test page
159                         function(){
160                                 $.testHelper.openPage( "#internal-no-action-form-page" );
161                         },
162
163                         function(){
164                                 $( "#internal-no-action-form-page form" ).eq( 0 ).submit();
165                         },
166
167                         function(){
168                                 $.testHelper.assertUrlLocation({
169                                         hashOrPush: location.pathname + "?foo=1&bar=2",
170                                         report: "hash should match document url and not base url"
171                                 });
172
173                                 start();
174                         }
175                 ]);
176         });
177
178         asyncTest( "external page form with no action submits to external page URL", function(){
179                 $.testHelper.pageSequence([
180                         function(){
181                                 // Go to an external page that has a form.
182                                 $("#internal-page-1 .cp1").click();
183                         },
184
185                         function(){
186                                 // Make sure we actually navigated to the external page.
187                                 $.testHelper.assertUrlLocation({
188                                         hashOrPush: contentDir + "content-page-1.html",
189                                         report: "should be on content-page-1.html"
190                                 });
191
192                                 // Now submit the form in the external page.
193                                 $("#content-page-1 form").eq(0).submit();
194                         },
195
196                         function(){
197                                 $.testHelper.assertUrlLocation({
198                                         hashOrPush: contentDir + "content-page-1.html?foo=1&bar=2",
199                                         report: "hash should match page url and not document url"
200                                 });
201
202                                 start();
203                         }]);
204         });
205 })(jQuery);