| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_path.h" | 5 #include "base/file_path.h" |
| 6 #include "base/platform_thread.h" | 6 #include "base/platform_thread.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "chrome/common/url_constants.h" | 8 #include "chrome/common/url_constants.h" |
| 9 #include "chrome/test/automation/tab_proxy.h" | 9 #include "chrome/test/automation/tab_proxy.h" |
| 10 #include "chrome/test/automation/browser_proxy.h" | 10 #include "chrome/test/automation/browser_proxy.h" |
| 11 #include "chrome/test/ui/ui_test.h" | 11 #include "chrome/test/ui/ui_test.h" |
| 12 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 #include "net/url_request/url_request_unittest.h" | 14 #include "net/test/test_server.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const wchar_t kDocRoot[] = L"chrome/test/data"; | 18 const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 19 | 19 |
| 20 class SessionHistoryTest : public UITest { | 20 class SessionHistoryTest : public UITest { |
| 21 protected: | 21 protected: |
| 22 SessionHistoryTest() : UITest() { | 22 SessionHistoryTest() : UITest() { |
| 23 dom_automation_enabled_ = true; | 23 dom_automation_enabled_ = true; |
| 24 } | 24 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 EXPECT_TRUE(tab_->GetCurrentURL(&url)); | 73 EXPECT_TRUE(tab_->GetCurrentURL(&url)); |
| 74 return url; | 74 return url; |
| 75 } | 75 } |
| 76 | 76 |
| 77 protected: | 77 protected: |
| 78 scoped_refptr<BrowserProxy> window_; | 78 scoped_refptr<BrowserProxy> window_; |
| 79 scoped_refptr<TabProxy> tab_; | 79 scoped_refptr<TabProxy> tab_; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 TEST_F(SessionHistoryTest, BasicBackForward) { | 82 TEST_F(SessionHistoryTest, BasicBackForward) { |
| 83 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 83 scoped_refptr<net::HTTPTestServer> server( |
| 84 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 84 ASSERT_TRUE(NULL != server.get()); | 85 ASSERT_TRUE(NULL != server.get()); |
| 85 | 86 |
| 86 // about:blank should be loaded first. | 87 // about:blank should be loaded first. |
| 87 ASSERT_FALSE(tab_->GoBack()); | 88 ASSERT_FALSE(tab_->GoBack()); |
| 88 EXPECT_EQ(L"", GetTabTitle()); | 89 EXPECT_EQ(L"", GetTabTitle()); |
| 89 | 90 |
| 90 ASSERT_TRUE(tab_->NavigateToURL( | 91 ASSERT_TRUE(tab_->NavigateToURL( |
| 91 server->TestServerPage("files/session_history/bot1.html"))); | 92 server->TestServerPage("files/session_history/bot1.html"))); |
| 92 EXPECT_EQ(L"bot1", GetTabTitle()); | 93 EXPECT_EQ(L"bot1", GetTabTitle()); |
| 93 | 94 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 140 } |
| 140 | 141 |
| 141 // Test that back/forward works when navigating in subframes. | 142 // Test that back/forward works when navigating in subframes. |
| 142 // Fails on Windows. See crbug.com/TODO | 143 // Fails on Windows. See crbug.com/TODO |
| 143 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
| 144 #define MAYBE_FrameBackForward FLAKY_FrameBackForward | 145 #define MAYBE_FrameBackForward FLAKY_FrameBackForward |
| 145 #else | 146 #else |
| 146 #define MAYBE_FrameBackForward FrameBackForward | 147 #define MAYBE_FrameBackForward FrameBackForward |
| 147 #endif | 148 #endif |
| 148 TEST_F(SessionHistoryTest, MAYBE_FrameBackForward) { | 149 TEST_F(SessionHistoryTest, MAYBE_FrameBackForward) { |
| 149 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 150 scoped_refptr<net::HTTPTestServer> server( |
| 151 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 150 ASSERT_TRUE(NULL != server.get()); | 152 ASSERT_TRUE(NULL != server.get()); |
| 151 | 153 |
| 152 // about:blank should be loaded first. | 154 // about:blank should be loaded first. |
| 153 GURL home(WideToUTF8(homepage_)); | 155 GURL home(WideToUTF8(homepage_)); |
| 154 ASSERT_FALSE(tab_->GoBack()); | 156 ASSERT_FALSE(tab_->GoBack()); |
| 155 EXPECT_EQ(L"", GetTabTitle()); | 157 EXPECT_EQ(L"", GetTabTitle()); |
| 156 EXPECT_EQ(home, GetTabURL()); | 158 EXPECT_EQ(home, GetTabURL()); |
| 157 | 159 |
| 158 GURL frames(server->TestServerPage("files/session_history/frames.html")); | 160 GURL frames(server->TestServerPage("files/session_history/frames.html")); |
| 159 ASSERT_TRUE(tab_->NavigateToURL(frames)); | 161 ASSERT_TRUE(tab_->NavigateToURL(frames)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 EXPECT_EQ(L"bot2", GetTabTitle()); | 206 EXPECT_EQ(L"bot2", GetTabTitle()); |
| 205 EXPECT_EQ(frames, GetTabURL()); | 207 EXPECT_EQ(frames, GetTabURL()); |
| 206 | 208 |
| 207 ASSERT_TRUE(tab_->GoBack()); | 209 ASSERT_TRUE(tab_->GoBack()); |
| 208 EXPECT_EQ(L"bot1", GetTabTitle()); | 210 EXPECT_EQ(L"bot1", GetTabTitle()); |
| 209 EXPECT_EQ(frames, GetTabURL()); | 211 EXPECT_EQ(frames, GetTabURL()); |
| 210 } | 212 } |
| 211 | 213 |
| 212 // Test that back/forward preserves POST data and document state in subframes. | 214 // Test that back/forward preserves POST data and document state in subframes. |
| 213 TEST_F(SessionHistoryTest, FrameFormBackForward) { | 215 TEST_F(SessionHistoryTest, FrameFormBackForward) { |
| 214 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 216 scoped_refptr<net::HTTPTestServer> server( |
| 217 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 215 ASSERT_TRUE(NULL != server.get()); | 218 ASSERT_TRUE(NULL != server.get()); |
| 216 | 219 |
| 217 // about:blank should be loaded first. | 220 // about:blank should be loaded first. |
| 218 ASSERT_FALSE(tab_->GoBack()); | 221 ASSERT_FALSE(tab_->GoBack()); |
| 219 EXPECT_EQ(L"", GetTabTitle()); | 222 EXPECT_EQ(L"", GetTabTitle()); |
| 220 | 223 |
| 221 GURL frames(server->TestServerPage("files/session_history/frames.html")); | 224 GURL frames(server->TestServerPage("files/session_history/frames.html")); |
| 222 ASSERT_TRUE(tab_->NavigateToURL(frames)); | 225 ASSERT_TRUE(tab_->NavigateToURL(frames)); |
| 223 EXPECT_EQ(L"bot1", GetTabTitle()); | 226 EXPECT_EQ(L"bot1", GetTabTitle()); |
| 224 | 227 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 } | 268 } |
| 266 } | 269 } |
| 267 | 270 |
| 268 // TODO(mpcomplete): enable this when Bug 734372 is fixed: | 271 // TODO(mpcomplete): enable this when Bug 734372 is fixed: |
| 269 // "Doing a session history navigation does not restore newly-created subframe | 272 // "Doing a session history navigation does not restore newly-created subframe |
| 270 // document state" | 273 // document state" |
| 271 // Test that back/forward preserves POST data and document state when navigating | 274 // Test that back/forward preserves POST data and document state when navigating |
| 272 // across frames (ie, from frame -> nonframe). | 275 // across frames (ie, from frame -> nonframe). |
| 273 // Hangs, see http://crbug.com/45058. | 276 // Hangs, see http://crbug.com/45058. |
| 274 TEST_F(SessionHistoryTest, DISABLED_CrossFrameFormBackForward) { | 277 TEST_F(SessionHistoryTest, DISABLED_CrossFrameFormBackForward) { |
| 275 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 278 scoped_refptr<net::HTTPTestServer> server( |
| 279 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 276 ASSERT_TRUE(NULL != server.get()); | 280 ASSERT_TRUE(NULL != server.get()); |
| 277 | 281 |
| 278 // about:blank should be loaded first. | 282 // about:blank should be loaded first. |
| 279 ASSERT_FALSE(tab_->GoBack()); | 283 ASSERT_FALSE(tab_->GoBack()); |
| 280 EXPECT_EQ(L"", GetTabTitle()); | 284 EXPECT_EQ(L"", GetTabTitle()); |
| 281 | 285 |
| 282 GURL frames(server->TestServerPage("files/session_history/frames.html")); | 286 GURL frames(server->TestServerPage("files/session_history/frames.html")); |
| 283 ASSERT_TRUE(tab_->NavigateToURL(frames)); | 287 ASSERT_TRUE(tab_->NavigateToURL(frames)); |
| 284 EXPECT_EQ(L"bot1", GetTabTitle()); | 288 EXPECT_EQ(L"bot1", GetTabTitle()); |
| 285 | 289 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 310 EXPECT_EQ(frames, GetTabURL()); | 314 EXPECT_EQ(frames, GetTabURL()); |
| 311 | 315 |
| 312 SubmitForm("isubmit"); | 316 SubmitForm("isubmit"); |
| 313 EXPECT_EQ(L"text=&select=a", GetTabTitle()); | 317 EXPECT_EQ(L"text=&select=a", GetTabTitle()); |
| 314 EXPECT_EQ(frames, GetTabURL()); | 318 EXPECT_EQ(frames, GetTabURL()); |
| 315 } | 319 } |
| 316 | 320 |
| 317 // Test that back/forward entries are created for reference fragment | 321 // Test that back/forward entries are created for reference fragment |
| 318 // navigations. Bug 730379. | 322 // navigations. Bug 730379. |
| 319 TEST_F(SessionHistoryTest, FragmentBackForward) { | 323 TEST_F(SessionHistoryTest, FragmentBackForward) { |
| 320 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 324 scoped_refptr<net::HTTPTestServer> server( |
| 325 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 321 ASSERT_TRUE(NULL != server.get()); | 326 ASSERT_TRUE(NULL != server.get()); |
| 322 | 327 |
| 323 // about:blank should be loaded first. | 328 // about:blank should be loaded first. |
| 324 ASSERT_FALSE(tab_->GoBack()); | 329 ASSERT_FALSE(tab_->GoBack()); |
| 325 EXPECT_EQ(L"", GetTabTitle()); | 330 EXPECT_EQ(L"", GetTabTitle()); |
| 326 | 331 |
| 327 GURL fragment(server->TestServerPage("files/session_history/fragment.html")); | 332 GURL fragment(server->TestServerPage("files/session_history/fragment.html")); |
| 328 ASSERT_TRUE(tab_->NavigateToURL(fragment)); | 333 ASSERT_TRUE(tab_->NavigateToURL(fragment)); |
| 329 EXPECT_EQ(L"fragment", GetTabTitle()); | 334 EXPECT_EQ(L"fragment", GetTabTitle()); |
| 330 EXPECT_EQ(fragment, GetTabURL()); | 335 EXPECT_EQ(fragment, GetTabURL()); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 | 387 |
| 383 // Test that the javascript window.history object works. | 388 // Test that the javascript window.history object works. |
| 384 // NOTE: history.go(N) does not do anything if N is outside the bounds of the | 389 // NOTE: history.go(N) does not do anything if N is outside the bounds of the |
| 385 // back/forward list (such as trigger our start/stop loading events). This | 390 // back/forward list (such as trigger our start/stop loading events). This |
| 386 // means the test will hang if it attempts to navigate too far forward or back, | 391 // means the test will hang if it attempts to navigate too far forward or back, |
| 387 // since we'll be waiting forever for a load stop event. | 392 // since we'll be waiting forever for a load stop event. |
| 388 // | 393 // |
| 389 // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing | 394 // TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing |
| 390 // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). | 395 // about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug). |
| 391 TEST_F(SessionHistoryTest, FLAKY_JavascriptHistory) { | 396 TEST_F(SessionHistoryTest, FLAKY_JavascriptHistory) { |
| 392 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 397 scoped_refptr<net::HTTPTestServer> server( |
| 398 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 393 ASSERT_TRUE(NULL != server.get()); | 399 ASSERT_TRUE(NULL != server.get()); |
| 394 | 400 |
| 395 // about:blank should be loaded first. | 401 // about:blank should be loaded first. |
| 396 ASSERT_FALSE(tab_->GoBack()); | 402 ASSERT_FALSE(tab_->GoBack()); |
| 397 EXPECT_EQ(L"", GetTabTitle()); | 403 EXPECT_EQ(L"", GetTabTitle()); |
| 398 | 404 |
| 399 ASSERT_TRUE(tab_->NavigateToURL( | 405 ASSERT_TRUE(tab_->NavigateToURL( |
| 400 server->TestServerPage("files/session_history/bot1.html"))); | 406 server->TestServerPage("files/session_history/bot1.html"))); |
| 401 EXPECT_EQ(L"bot1", GetTabTitle()); | 407 EXPECT_EQ(L"bot1", GetTabTitle()); |
| 402 | 408 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 // try to go back and forward with JavaScript. Bug 1136715. | 471 // try to go back and forward with JavaScript. Bug 1136715. |
| 466 // (Hard to test right now, because pages like about:network cause the | 472 // (Hard to test right now, because pages like about:network cause the |
| 467 // TabProxy to hang. This is because they do not appear to use the | 473 // TabProxy to hang. This is because they do not appear to use the |
| 468 // NotificationService.) | 474 // NotificationService.) |
| 469 } | 475 } |
| 470 | 476 |
| 471 // This test is failing consistently. See http://crbug.com/22560 | 477 // This test is failing consistently. See http://crbug.com/22560 |
| 472 TEST_F(SessionHistoryTest, FAILS_LocationReplace) { | 478 TEST_F(SessionHistoryTest, FAILS_LocationReplace) { |
| 473 // Test that using location.replace doesn't leave the title of the old page | 479 // Test that using location.replace doesn't leave the title of the old page |
| 474 // visible. | 480 // visible. |
| 475 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 481 scoped_refptr<net::HTTPTestServer> server( |
| 482 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 476 ASSERT_TRUE(NULL != server.get()); | 483 ASSERT_TRUE(NULL != server.get()); |
| 477 | 484 |
| 478 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( | 485 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( |
| 479 "files/session_history/replace.html?no-title.html"))); | 486 "files/session_history/replace.html?no-title.html"))); |
| 480 EXPECT_EQ(L"", GetTabTitle()); | 487 EXPECT_EQ(L"", GetTabTitle()); |
| 481 } | 488 } |
| 482 | 489 |
| 483 // This test is flaky. See bug 22111. | 490 // This test is flaky. See bug 22111. |
| 484 TEST_F(SessionHistoryTest, FLAKY_HistorySearchXSS) { | 491 TEST_F(SessionHistoryTest, FLAKY_HistorySearchXSS) { |
| 485 // about:blank should be loaded first. | 492 // about:blank should be loaded first. |
| 486 ASSERT_FALSE(tab_->GoBack()); | 493 ASSERT_FALSE(tab_->GoBack()); |
| 487 EXPECT_EQ(L"", GetTabTitle()); | 494 EXPECT_EQ(L"", GetTabTitle()); |
| 488 | 495 |
| 489 GURL url(std::string(chrome::kChromeUIHistoryURL) + | 496 GURL url(std::string(chrome::kChromeUIHistoryURL) + |
| 490 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E"); | 497 "#q=%3Cimg%20src%3Dx%3Ax%20onerror%3D%22document.title%3D'XSS'%22%3E"); |
| 491 ASSERT_TRUE(tab_->NavigateToURL(url)); | 498 ASSERT_TRUE(tab_->NavigateToURL(url)); |
| 492 // Mainly, this is to ensure we send a synchronous message to the renderer | 499 // Mainly, this is to ensure we send a synchronous message to the renderer |
| 493 // so that we're not susceptible (less susceptible?) to a race condition. | 500 // so that we're not susceptible (less susceptible?) to a race condition. |
| 494 // Should a race condition ever trigger, it won't result in flakiness. | 501 // Should a race condition ever trigger, it won't result in flakiness. |
| 495 int num = tab_->FindInPage(L"<img", FWD, CASE_SENSITIVE, false, NULL); | 502 int num = tab_->FindInPage(L"<img", FWD, CASE_SENSITIVE, false, NULL); |
| 496 EXPECT_GT(num, 0); | 503 EXPECT_GT(num, 0); |
| 497 EXPECT_EQ(L"History", GetTabTitle()); | 504 EXPECT_EQ(L"History", GetTabTitle()); |
| 498 } | 505 } |
| 499 | 506 |
| 500 TEST_F(SessionHistoryTest, LocationChangeInSubframe) { | 507 TEST_F(SessionHistoryTest, LocationChangeInSubframe) { |
| 501 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 508 scoped_refptr<net::HTTPTestServer> server( |
| 509 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 502 ASSERT_TRUE(server.get()); | 510 ASSERT_TRUE(server.get()); |
| 503 | 511 |
| 504 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( | 512 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage( |
| 505 "files/session_history/location_redirect.html"))); | 513 "files/session_history/location_redirect.html"))); |
| 506 EXPECT_EQ(L"Default Title", GetTabTitle()); | 514 EXPECT_EQ(L"Default Title", GetTabTitle()); |
| 507 | 515 |
| 508 ASSERT_TRUE(tab_->NavigateToURL(GURL( | 516 ASSERT_TRUE(tab_->NavigateToURL(GURL( |
| 509 "javascript:void(frames[0].navigate())"))); | 517 "javascript:void(frames[0].navigate())"))); |
| 510 EXPECT_EQ(L"foo", GetTabTitle()); | 518 EXPECT_EQ(L"foo", GetTabTitle()); |
| 511 | 519 |
| 512 ASSERT_TRUE(tab_->GoBack()); | 520 ASSERT_TRUE(tab_->GoBack()); |
| 513 EXPECT_EQ(L"Default Title", GetTabTitle()); | 521 EXPECT_EQ(L"Default Title", GetTabTitle()); |
| 514 } | 522 } |
| 515 | 523 |
| 516 // Hangs, see http://crbug.com/38583. | 524 // Hangs, see http://crbug.com/38583. |
| 517 #if defined(OS_WIN) | 525 #if defined(OS_WIN) |
| 518 #define HistoryLength DISABLED_HistoryLength | 526 #define HistoryLength DISABLED_HistoryLength |
| 519 #endif // defined(OS_WIN) | 527 #endif // defined(OS_WIN) |
| 520 TEST_F(SessionHistoryTest, HistoryLength) { | 528 TEST_F(SessionHistoryTest, HistoryLength) { |
| 521 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); | 529 scoped_refptr<net::HTTPTestServer> server( |
| 530 net::HTTPTestServer::CreateServer(kDocRoot)); |
| 522 ASSERT_TRUE(server.get()); | 531 ASSERT_TRUE(server.get()); |
| 523 | 532 |
| 524 int length; | 533 int length; |
| 525 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 534 ASSERT_TRUE(tab_->ExecuteAndExtractInt( |
| 526 L"", L"domAutomationController.send(history.length)", &length)); | 535 L"", L"domAutomationController.send(history.length)", &length)); |
| 527 EXPECT_EQ(1, length); | 536 EXPECT_EQ(1, length); |
| 528 | 537 |
| 529 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage("files/title1.html"))); | 538 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage("files/title1.html"))); |
| 530 | 539 |
| 531 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 540 ASSERT_TRUE(tab_->ExecuteAndExtractInt( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 546 ASSERT_TRUE(tab_->GoBack()); | 555 ASSERT_TRUE(tab_->GoBack()); |
| 547 | 556 |
| 548 // Ensure history.length is properly truncated. | 557 // Ensure history.length is properly truncated. |
| 549 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage("files/title2.html"))); | 558 ASSERT_TRUE(tab_->NavigateToURL(server->TestServerPage("files/title2.html"))); |
| 550 ASSERT_TRUE(tab_->ExecuteAndExtractInt( | 559 ASSERT_TRUE(tab_->ExecuteAndExtractInt( |
| 551 L"", L"domAutomationController.send(history.length)", &length)); | 560 L"", L"domAutomationController.send(history.length)", &length)); |
| 552 EXPECT_EQ(2, length); | 561 EXPECT_EQ(2, length); |
| 553 } | 562 } |
| 554 | 563 |
| 555 } // namespace | 564 } // namespace |
| OLD | NEW |