Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: content/browser/session_history_browsertest.cc

Issue 10820043: Convert speech and session history browser_tests to run under content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/utf_string_conversions.h" 6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "content/public/browser/navigation_controller.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/browser_tabstrip.h"
10 #include "chrome/test/base/in_process_browser_test.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/notification_service.h" 8 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 9 #include "content/public/browser/notification_types.h"
14 #include "content/public/browser/web_contents.h" 10 #include "content/public/browser/web_contents.h"
15 #include "content/public/common/url_constants.h" 11 #include "content/public/common/url_constants.h"
16 #include "content/public/test/browser_test_utils.h" 12 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/test_utils.h"
14 #include "content/shell/shell.h"
15 #include "content/test/content_browser_test.h"
16 #include "content/test/content_browser_test_utils.h"
17 #include "net/test/test_server.h" 17 #include "net/test/test_server.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 class SessionHistoryTest : public InProcessBrowserTest { 20 namespace content {
21
22 class SessionHistoryTest : public ContentBrowserTest {
21 protected: 23 protected:
22 SessionHistoryTest() {} 24 SessionHistoryTest() {}
23 25
24 virtual void SetUpOnMainThread() { 26 virtual void SetUpOnMainThread() {
25 ASSERT_TRUE(test_server()->Start()); 27 ASSERT_TRUE(test_server()->Start());
28 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL));
26 } 29 }
27 30
28 // Simulate clicking a link. Only works on the frames.html testserver page. 31 // Simulate clicking a link. Only works on the frames.html testserver page.
29 void ClickLink(std::string node_id) { 32 void ClickLink(std::string node_id) {
30 GURL url("javascript:clickLink('" + node_id + "')"); 33 GURL url("javascript:clickLink('" + node_id + "')");
31 ui_test_utils::NavigateToURL(browser(), url); 34 NavigateToURL(shell(), url);
32 } 35 }
33 36
34 // Simulate filling in form data. Only works on the frames.html page with 37 // Simulate filling in form data. Only works on the frames.html page with
35 // subframe = form.html, and on form.html itself. 38 // subframe = form.html, and on form.html itself.
36 void FillForm(std::string node_id, std::string value) { 39 void FillForm(std::string node_id, std::string value) {
37 GURL url("javascript:fillForm('" + node_id + "', '" + value + "')"); 40 GURL url("javascript:fillForm('" + node_id + "', '" + value + "')");
38 // This will return immediately, but since the JS executes synchronously 41 // This will return immediately, but since the JS executes synchronously
39 // on the renderer, it will complete before the next navigate message is 42 // on the renderer, it will complete before the next navigate message is
40 // processed. 43 // processed.
41 ui_test_utils::NavigateToURLWithDisposition(browser(), url, CURRENT_TAB, 0); 44 NavigateToURL(shell(), url);
42 } 45 }
43 46
44 // Simulate submitting a form. Only works on the frames.html page with 47 // Simulate submitting a form. Only works on the frames.html page with
45 // subframe = form.html, and on form.html itself. 48 // subframe = form.html, and on form.html itself.
46 void SubmitForm(std::string node_id) { 49 void SubmitForm(std::string node_id) {
47 GURL url("javascript:submitForm('" + node_id + "')"); 50 GURL url("javascript:submitForm('" + node_id + "')");
48 ui_test_utils::NavigateToURL(browser(), url); 51 NavigateToURL(shell(), url);
49 } 52 }
50 53
51 // Navigate session history using history.go(distance). 54 // Navigate session history using history.go(distance).
52 void JavascriptGo(std::string distance) { 55 void JavascriptGo(std::string distance) {
53 GURL url("javascript:history.go('" + distance + "')"); 56 GURL url("javascript:history.go('" + distance + "')");
54 ui_test_utils::NavigateToURL(browser(), url); 57 NavigateToURL(shell(), url);
55 } 58 }
56 59
57 std::string GetTabTitle() { 60 std::string GetTabTitle() {
58 return UTF16ToASCII(chrome::GetActiveWebContents(browser())->GetTitle()); 61 return UTF16ToASCII(shell()->web_contents()->GetTitle());
59 } 62 }
60 63
61 GURL GetTabURL() { 64 GURL GetTabURL() {
62 return chrome::GetActiveWebContents(browser())->GetURL(); 65 return shell()->web_contents()->GetURL();
63 } 66 }
64 67
65 GURL GetURL(const std::string file) { 68 GURL GetURL(const std::string file) {
66 return test_server()->GetURL(std::string("files/session_history/") + file); 69 return test_server()->GetURL(std::string("files/session_history/") + file);
67 } 70 }
68 71
69 void NavigateAndCheckTitle(const char* filename, 72 void NavigateAndCheckTitle(const char* filename,
70 const std::string& expected_title) { 73 const std::string& expected_title) {
71 string16 expected_title16(ASCIIToUTF16(expected_title)); 74 string16 expected_title16(ASCIIToUTF16(expected_title));
72 content::TitleWatcher title_watcher( 75 TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
73 chrome::GetActiveWebContents(browser()), expected_title16); 76 NavigateToURL(shell(), GetURL(filename));
74 ui_test_utils::NavigateToURL(browser(), GetURL(filename));
75 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle()); 77 ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
76 } 78 }
77 79
80 bool CanGoBack() {
81 return shell()->web_contents()->GetController().CanGoBack();
82 }
83
84 bool CanGoForward() {
85 return shell()->web_contents()->GetController().CanGoForward();
86 }
87
78 void GoBack() { 88 void GoBack() {
79 content::WindowedNotificationObserver load_stop_observer( 89 WindowedNotificationObserver load_stop_observer(
80 content::NOTIFICATION_LOAD_STOP, 90 NOTIFICATION_LOAD_STOP,
81 content::NotificationService::AllSources()); 91 NotificationService::AllSources());
82 chrome::GoBack(browser(), CURRENT_TAB); 92 shell()->web_contents()->GetController().GoBack();
83 load_stop_observer.Wait(); 93 load_stop_observer.Wait();
84 } 94 }
85 95
86 void GoForward() { 96 void GoForward() {
87 content::WindowedNotificationObserver load_stop_observer( 97 WindowedNotificationObserver load_stop_observer(
88 content::NOTIFICATION_LOAD_STOP, 98 NOTIFICATION_LOAD_STOP,
89 content::NotificationService::AllSources()); 99 NotificationService::AllSources());
90 chrome::GoForward(browser(), CURRENT_TAB); 100 shell()->web_contents()->GetController().GoForward();
91 load_stop_observer.Wait(); 101 load_stop_observer.Wait();
92 } 102 }
93 }; 103 };
94 104
95 // If this flakes, use http://crbug.com/61619 on windows and 105 // If this flakes, use http://crbug.com/61619 on windows and
96 // http://crbug.com/102094 on mac. 106 // http://crbug.com/102094 on mac.
97 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) { 107 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) {
98 // about:blank should be loaded first. 108 ASSERT_FALSE(CanGoBack());
99 ASSERT_FALSE(chrome::CanGoBack(browser()));
100 EXPECT_EQ("about:blank", GetTabTitle());
101 109
102 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1")); 110 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1"));
103 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); 111 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2"));
104 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); 112 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
105 113
106 // history is [blank, bot1, bot2, *bot3] 114 // history is [blank, bot1, bot2, *bot3]
107 115
108 GoBack(); 116 GoBack();
109 EXPECT_EQ("bot2", GetTabTitle()); 117 EXPECT_EQ("bot2", GetTabTitle());
110 118
111 GoBack(); 119 GoBack();
112 EXPECT_EQ("bot1", GetTabTitle()); 120 EXPECT_EQ("bot1", GetTabTitle());
113 121
114 GoForward(); 122 GoForward();
115 EXPECT_EQ("bot2", GetTabTitle()); 123 EXPECT_EQ("bot2", GetTabTitle());
116 124
117 GoBack(); 125 GoBack();
118 EXPECT_EQ("bot1", GetTabTitle()); 126 EXPECT_EQ("bot1", GetTabTitle());
119 127
120 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); 128 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
121 129
122 // history is [blank, bot1, *bot3] 130 // history is [blank, bot1, *bot3]
123 131
124 ASSERT_FALSE(chrome::CanGoForward(browser())); 132 ASSERT_FALSE(CanGoForward());
125 EXPECT_EQ("bot3", GetTabTitle()); 133 EXPECT_EQ("bot3", GetTabTitle());
126 134
127 GoBack(); 135 GoBack();
128 EXPECT_EQ("bot1", GetTabTitle()); 136 EXPECT_EQ("bot1", GetTabTitle());
129 137
130 GoBack(); 138 GoBack();
131 EXPECT_EQ("about:blank", GetTabTitle()); 139 EXPECT_EQ("about:blank", GetTabTitle());
132 140
133 ASSERT_FALSE(chrome::CanGoBack(browser())); 141 ASSERT_FALSE(CanGoBack());
134 EXPECT_EQ("about:blank", GetTabTitle()); 142 EXPECT_EQ("about:blank", GetTabTitle());
135 143
136 GoForward(); 144 GoForward();
137 EXPECT_EQ("bot1", GetTabTitle()); 145 EXPECT_EQ("bot1", GetTabTitle());
138 146
139 GoForward(); 147 GoForward();
140 EXPECT_EQ("bot3", GetTabTitle()); 148 EXPECT_EQ("bot3", GetTabTitle());
141 } 149 }
142 150
143 // Test that back/forward works when navigating in subframes. 151 // Test that back/forward works when navigating in subframes.
144 // If this flakes, use http://crbug.com/48833 152 // If this flakes, use http://crbug.com/48833
145 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) { 153 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) {
146 // about:blank should be loaded first. 154 ASSERT_FALSE(CanGoBack());
147 GURL home(chrome::kAboutBlankURL);
148 ASSERT_FALSE(chrome::CanGoBack(browser()));
149 EXPECT_EQ("about:blank", GetTabTitle());
150 EXPECT_EQ(GURL(chrome::kAboutBlankURL), GetTabURL());
151 155
152 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); 156 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1"));
153 157
154 ClickLink("abot2"); 158 ClickLink("abot2");
155 EXPECT_EQ("bot2", GetTabTitle()); 159 EXPECT_EQ("bot2", GetTabTitle());
156 GURL frames(GetURL("frames.html")); 160 GURL frames(GetURL("frames.html"));
157 EXPECT_EQ(frames, GetTabURL()); 161 EXPECT_EQ(frames, GetTabURL());
158 162
159 ClickLink("abot3"); 163 ClickLink("abot3");
160 EXPECT_EQ("bot3", GetTabTitle()); 164 EXPECT_EQ("bot3", GetTabTitle());
161 EXPECT_EQ(frames, GetTabURL()); 165 EXPECT_EQ(frames, GetTabURL());
162 166
163 // history is [blank, bot1, bot2, *bot3] 167 // history is [blank, bot1, bot2, *bot3]
164 168
165 GoBack(); 169 GoBack();
166 EXPECT_EQ("bot2", GetTabTitle()); 170 EXPECT_EQ("bot2", GetTabTitle());
167 EXPECT_EQ(frames, GetTabURL()); 171 EXPECT_EQ(frames, GetTabURL());
168 172
169 GoBack(); 173 GoBack();
170 EXPECT_EQ("bot1", GetTabTitle()); 174 EXPECT_EQ("bot1", GetTabTitle());
171 EXPECT_EQ(frames, GetTabURL()); 175 EXPECT_EQ(frames, GetTabURL());
172 176
173 GoBack(); 177 GoBack();
174 EXPECT_EQ("about:blank", GetTabTitle()); 178 EXPECT_EQ("about:blank", GetTabTitle());
175 EXPECT_EQ(home, GetTabURL()); 179 EXPECT_EQ(GURL(chrome::kAboutBlankURL), GetTabURL());
176 180
177 GoForward(); 181 GoForward();
178 EXPECT_EQ("bot1", GetTabTitle()); 182 EXPECT_EQ("bot1", GetTabTitle());
179 EXPECT_EQ(frames, GetTabURL()); 183 EXPECT_EQ(frames, GetTabURL());
180 184
181 GoForward(); 185 GoForward();
182 EXPECT_EQ("bot2", GetTabTitle()); 186 EXPECT_EQ("bot2", GetTabTitle());
183 EXPECT_EQ(frames, GetTabURL()); 187 EXPECT_EQ(frames, GetTabURL());
184 188
185 ClickLink("abot1"); 189 ClickLink("abot1");
186 EXPECT_EQ("bot1", GetTabTitle()); 190 EXPECT_EQ("bot1", GetTabTitle());
187 EXPECT_EQ(frames, GetTabURL()); 191 EXPECT_EQ(frames, GetTabURL());
188 192
189 // history is [blank, bot1, bot2, *bot1] 193 // history is [blank, bot1, bot2, *bot1]
190 194
191 ASSERT_FALSE(chrome::CanGoForward(browser())); 195 ASSERT_FALSE(CanGoForward());
192 EXPECT_EQ("bot1", GetTabTitle()); 196 EXPECT_EQ("bot1", GetTabTitle());
193 EXPECT_EQ(frames, GetTabURL()); 197 EXPECT_EQ(frames, GetTabURL());
194 198
195 GoBack(); 199 GoBack();
196 EXPECT_EQ("bot2", GetTabTitle()); 200 EXPECT_EQ("bot2", GetTabTitle());
197 EXPECT_EQ(frames, GetTabURL()); 201 EXPECT_EQ(frames, GetTabURL());
198 202
199 GoBack(); 203 GoBack();
200 EXPECT_EQ("bot1", GetTabTitle()); 204 EXPECT_EQ("bot1", GetTabTitle());
201 EXPECT_EQ(frames, GetTabURL()); 205 EXPECT_EQ(frames, GetTabURL());
202 } 206 }
203 207
204 // Test that back/forward preserves POST data and document state in subframes. 208 // Test that back/forward preserves POST data and document state in subframes.
205 // If this flakes use http://crbug.com/61619 209 // If this flakes use http://crbug.com/61619
206 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameFormBackForward) { 210 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameFormBackForward) {
207 // about:blank should be loaded first. 211 ASSERT_FALSE(CanGoBack());
208 ASSERT_FALSE(chrome::CanGoBack(browser()));
209 EXPECT_EQ("about:blank", GetTabTitle());
210 212
211 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); 213 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1"));
212 214
213 ClickLink("aform"); 215 ClickLink("aform");
214 EXPECT_EQ("form", GetTabTitle()); 216 EXPECT_EQ("form", GetTabTitle());
215 GURL frames(GetURL("frames.html")); 217 GURL frames(GetURL("frames.html"));
216 EXPECT_EQ(frames, GetTabURL()); 218 EXPECT_EQ(frames, GetTabURL());
217 219
218 SubmitForm("isubmit"); 220 SubmitForm("isubmit");
219 EXPECT_EQ("text=&select=a", GetTabTitle()); 221 EXPECT_EQ("text=&select=a", GetTabTitle());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 EXPECT_EQ(frames, GetTabURL()); 254 EXPECT_EQ(frames, GetTabURL());
253 } 255 }
254 256
255 // TODO(mpcomplete): enable this when Bug 734372 is fixed: 257 // TODO(mpcomplete): enable this when Bug 734372 is fixed:
256 // "Doing a session history navigation does not restore newly-created subframe 258 // "Doing a session history navigation does not restore newly-created subframe
257 // document state" 259 // document state"
258 // Test that back/forward preserves POST data and document state when navigating 260 // Test that back/forward preserves POST data and document state when navigating
259 // across frames (ie, from frame -> nonframe). 261 // across frames (ie, from frame -> nonframe).
260 // Hangs, see http://crbug.com/45058. 262 // Hangs, see http://crbug.com/45058.
261 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, CrossFrameFormBackForward) { 263 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, CrossFrameFormBackForward) {
262 // about:blank should be loaded first. 264 ASSERT_FALSE(CanGoBack());
263 ASSERT_FALSE(chrome::CanGoBack(browser()));
264 EXPECT_EQ("about:blank", GetTabTitle());
265 265
266 GURL frames(GetURL("frames.html")); 266 GURL frames(GetURL("frames.html"));
267 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1")); 267 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1"));
268 268
269 ClickLink("aform"); 269 ClickLink("aform");
270 EXPECT_EQ("form", GetTabTitle()); 270 EXPECT_EQ("form", GetTabTitle());
271 EXPECT_EQ(frames, GetTabURL()); 271 EXPECT_EQ(frames, GetTabURL());
272 272
273 SubmitForm("isubmit"); 273 SubmitForm("isubmit");
274 EXPECT_EQ("text=&select=a", GetTabTitle()); 274 EXPECT_EQ("text=&select=a", GetTabTitle());
(...skipping 15 matching lines...) Expand all
290 290
291 SubmitForm("isubmit"); 291 SubmitForm("isubmit");
292 EXPECT_EQ("text=&select=a", GetTabTitle()); 292 EXPECT_EQ("text=&select=a", GetTabTitle());
293 EXPECT_EQ(frames, GetTabURL()); 293 EXPECT_EQ(frames, GetTabURL());
294 } 294 }
295 295
296 // Test that back/forward entries are created for reference fragment 296 // Test that back/forward entries are created for reference fragment
297 // navigations. Bug 730379. 297 // navigations. Bug 730379.
298 // If this flakes use http://crbug.com/61619. 298 // If this flakes use http://crbug.com/61619.
299 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) { 299 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) {
300 // about:blank should be loaded first. 300 ASSERT_FALSE(CanGoBack());
301 ASSERT_FALSE(chrome::CanGoBack(browser()));
302 EXPECT_EQ("about:blank", GetTabTitle());
303 301
304 GURL fragment(GetURL("fragment.html")); 302 GURL fragment(GetURL("fragment.html"));
305 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment")); 303 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment"));
306 304
307 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#a", "fragment")); 305 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#a", "fragment"));
308 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#b", "fragment")); 306 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#b", "fragment"));
309 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#c", "fragment")); 307 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#c", "fragment"));
310 308
311 // history is [blank, fragment, fragment#a, fragment#b, *fragment#c] 309 // history is [blank, fragment, fragment#a, fragment#b, *fragment#c]
312 310
313 GoBack(); 311 GoBack();
314 EXPECT_EQ(GetURL("fragment.html#b"), GetTabURL()); 312 EXPECT_EQ(GetURL("fragment.html#b"), GetTabURL());
315 313
316 GoBack(); 314 GoBack();
317 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL()); 315 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL());
318 316
319 GoBack(); 317 GoBack();
320 EXPECT_EQ(GetURL("fragment.html"), GetTabURL()); 318 EXPECT_EQ(GetURL("fragment.html"), GetTabURL());
321 319
322 GoForward(); 320 GoForward();
323 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL()); 321 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL());
324 322
325 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); 323 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
326 324
327 // history is [blank, fragment, fragment#a, bot3] 325 // history is [blank, fragment, fragment#a, bot3]
328 326
329 ASSERT_FALSE(chrome::CanGoForward(browser())); 327 ASSERT_FALSE(CanGoForward());
330 EXPECT_EQ(GetURL("bot3.html"), GetTabURL()); 328 EXPECT_EQ(GetURL("bot3.html"), GetTabURL());
331 329
332 GoBack(); 330 GoBack();
333 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL()); 331 EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL());
334 332
335 GoBack(); 333 GoBack();
336 EXPECT_EQ(GetURL("fragment.html"), GetTabURL()); 334 EXPECT_EQ(GetURL("fragment.html"), GetTabURL());
337 } 335 }
338 336
339 // Test that the javascript window.history object works. 337 // Test that the javascript window.history object works.
340 // NOTE: history.go(N) does not do anything if N is outside the bounds of the 338 // NOTE: history.go(N) does not do anything if N is outside the bounds of the
341 // back/forward list (such as trigger our start/stop loading events). This 339 // back/forward list (such as trigger our start/stop loading events). This
342 // means the test will hang if it attempts to navigate too far forward or back, 340 // means the test will hang if it attempts to navigate too far forward or back,
343 // since we'll be waiting forever for a load stop event. 341 // since we'll be waiting forever for a load stop event.
344 // 342 //
345 // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing 343 // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing
346 // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). 344 // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug).
347 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) { 345 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) {
348 // about:blank should be loaded first. 346 ASSERT_FALSE(CanGoBack());
349 ASSERT_FALSE(chrome::CanGoBack(browser()));
350 EXPECT_EQ("about:blank", GetTabTitle());
351 347
352 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1")); 348 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1"));
353 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2")); 349 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2"));
354 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); 350 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
355 351
356 // history is [blank, bot1, bot2, *bot3] 352 // history is [blank, bot1, bot2, *bot3]
357 353
358 JavascriptGo("-1"); 354 JavascriptGo("-1");
359 EXPECT_EQ("bot2", GetTabTitle()); 355 EXPECT_EQ("bot2", GetTabTitle());
360 356
361 JavascriptGo("-1"); 357 JavascriptGo("-1");
362 EXPECT_EQ("bot1", GetTabTitle()); 358 EXPECT_EQ("bot1", GetTabTitle());
363 359
364 JavascriptGo("1"); 360 JavascriptGo("1");
365 EXPECT_EQ("bot2", GetTabTitle()); 361 EXPECT_EQ("bot2", GetTabTitle());
366 362
367 JavascriptGo("-1"); 363 JavascriptGo("-1");
368 EXPECT_EQ("bot1", GetTabTitle()); 364 EXPECT_EQ("bot1", GetTabTitle());
369 365
370 JavascriptGo("2"); 366 JavascriptGo("2");
371 EXPECT_EQ("bot3", GetTabTitle()); 367 EXPECT_EQ("bot3", GetTabTitle());
372 368
373 // history is [blank, bot1, bot2, *bot3] 369 // history is [blank, bot1, bot2, *bot3]
374 370
375 JavascriptGo("-3"); 371 JavascriptGo("-3");
376 EXPECT_EQ("about:blank", GetTabTitle()); 372 EXPECT_EQ("about:blank", GetTabTitle());
377 373
378 ASSERT_FALSE(chrome::CanGoBack(browser())); 374 ASSERT_FALSE(CanGoBack());
379 EXPECT_EQ("about:blank", GetTabTitle()); 375 EXPECT_EQ("about:blank", GetTabTitle());
380 376
381 JavascriptGo("1"); 377 JavascriptGo("1");
382 EXPECT_EQ("bot1", GetTabTitle()); 378 EXPECT_EQ("bot1", GetTabTitle());
383 379
384 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3")); 380 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
385 381
386 // history is [blank, bot1, *bot3] 382 // history is [blank, bot1, *bot3]
387 383
388 ASSERT_FALSE(chrome::CanGoForward(browser())); 384 ASSERT_FALSE(CanGoForward());
389 EXPECT_EQ("bot3", GetTabTitle()); 385 EXPECT_EQ("bot3", GetTabTitle());
390 386
391 JavascriptGo("-1"); 387 JavascriptGo("-1");
392 EXPECT_EQ("bot1", GetTabTitle()); 388 EXPECT_EQ("bot1", GetTabTitle());
393 389
394 JavascriptGo("-1"); 390 JavascriptGo("-1");
395 EXPECT_EQ("about:blank", GetTabTitle()); 391 EXPECT_EQ("about:blank", GetTabTitle());
396 392
397 ASSERT_FALSE(chrome::CanGoBack(browser())); 393 ASSERT_FALSE(CanGoBack());
398 EXPECT_EQ("about:blank", GetTabTitle()); 394 EXPECT_EQ("about:blank", GetTabTitle());
399 395
400 JavascriptGo("1"); 396 JavascriptGo("1");
401 EXPECT_EQ("bot1", GetTabTitle()); 397 EXPECT_EQ("bot1", GetTabTitle());
402 398
403 JavascriptGo("1"); 399 JavascriptGo("1");
404 EXPECT_EQ("bot3", GetTabTitle()); 400 EXPECT_EQ("bot3", GetTabTitle());
405 401
406 // TODO(creis): Test that JavaScript history navigations work across tab 402 // TODO(creis): Test that JavaScript history navigations work across tab
407 // types. For example, load about:network in a tab, then a real page, then 403 // types. For example, load about:network in a tab, then a real page, then
408 // try to go back and forward with JavaScript. Bug 1136715. 404 // try to go back and forward with JavaScript. Bug 1136715.
409 // (Hard to test right now, because pages like about:network cause the 405 // (Hard to test right now, because pages like about:network cause the
410 // TabProxy to hang. This is because they do not appear to use the 406 // TabProxy to hang. This is because they do not appear to use the
411 // NotificationService.) 407 // NotificationService.)
412 } 408 }
413 409
414 // This test is failing consistently. See http://crbug.com/22560 410 // This test is failing consistently. See http://crbug.com/22560
415 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationReplace) { 411 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationReplace) {
416 // Test that using location.replace doesn't leave the title of the old page 412 // Test that using location.replace doesn't leave the title of the old page
417 // visible. 413 // visible.
418 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle( 414 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle(
419 "replace.html?bot1.html", "bot1")); 415 "replace.html?bot1.html", "bot1"));
420 } 416 }
421 417
422 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationChangeInSubframe) { 418 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationChangeInSubframe) {
423 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle( 419 ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle(
424 "location_redirect.html", "Default Title")); 420 "location_redirect.html", "Default Title"));
425 421
426 ui_test_utils::NavigateToURL( 422 NavigateToURL(shell(), GURL("javascript:void(frames[0].navigate())"));
427 browser(), GURL("javascript:void(frames[0].navigate())"));
428 EXPECT_EQ("foo", GetTabTitle()); 423 EXPECT_EQ("foo", GetTabTitle());
429 424
430 GoBack(); 425 GoBack();
431 EXPECT_EQ("Default Title", GetTabTitle()); 426 EXPECT_EQ("Default Title", GetTabTitle());
432 } 427 }
433 428
434 // http://code.google.com/p/chromium/issues/detail?id=56267 429 // http://code.google.com/p/chromium/issues/detail?id=56267
435 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { 430 IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) {
436 int length; 431 int length;
437 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( 432 ASSERT_TRUE(ExecuteJavaScriptAndExtractInt(
438 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 433 shell()->web_contents()->GetRenderViewHost(),
439 L"", L"domAutomationController.send(history.length)", &length)); 434 L"", L"domAutomationController.send(history.length)", &length));
440 EXPECT_EQ(1, length); 435 EXPECT_EQ(1, length);
441 436
442 ui_test_utils::NavigateToURL(browser(), GetURL("title1.html")); 437 NavigateToURL(shell(), GetURL("title1.html"));
443 438
444 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( 439 ASSERT_TRUE(ExecuteJavaScriptAndExtractInt(
445 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 440 shell()->web_contents()->GetRenderViewHost(),
446 L"", L"domAutomationController.send(history.length)", &length)); 441 L"", L"domAutomationController.send(history.length)", &length));
447 EXPECT_EQ(2, length); 442 EXPECT_EQ(2, length);
448 443
449 // Now test that history.length is updated when the navigation is committed. 444 // Now test that history.length is updated when the navigation is committed.
450 ui_test_utils::NavigateToURL(browser(), GetURL("record_length.html")); 445 NavigateToURL(shell(), GetURL("record_length.html"));
451 446
452 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( 447 ASSERT_TRUE(ExecuteJavaScriptAndExtractInt(
453 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 448 shell()->web_contents()->GetRenderViewHost(),
454 L"", L"domAutomationController.send(history.length)", &length)); 449 L"", L"domAutomationController.send(history.length)", &length));
455 EXPECT_EQ(3, length); 450 EXPECT_EQ(3, length);
456 451
457 GoBack(); 452 GoBack();
458 GoBack(); 453 GoBack();
459 454
460 // Ensure history.length is properly truncated. 455 // Ensure history.length is properly truncated.
461 ui_test_utils::NavigateToURL(browser(), GetURL("title2.html")); 456 NavigateToURL(shell(), GetURL("title2.html"));
462 457
463 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractInt( 458 ASSERT_TRUE(ExecuteJavaScriptAndExtractInt(
464 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 459 shell()->web_contents()->GetRenderViewHost(),
465 L"", L"domAutomationController.send(history.length)", &length)); 460 L"", L"domAutomationController.send(history.length)", &length));
466 EXPECT_EQ(2, length); 461 EXPECT_EQ(2, length);
467 } 462 }
463
464 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/data/speech/grammar_attribute.html ('k') | content/browser/speech/speech_recognition_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698