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