15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string_util.h"
6868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/stringprintf.h"
7868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_controller.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_types.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/url_constants.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/browser_test_utils.h"
14effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/public/test/content_browser_test.h"
15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "content/public/test/content_browser_test_utils.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/test_utils.h"
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/shell/browser/shell.h"
1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/test/embedded_test_server/embedded_test_server.h"
1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "net/test/embedded_test_server/http_request.h"
20868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "net/test/embedded_test_server/http_response.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)namespace {
2690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Handles |request| by serving a response with title set to request contents.
2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)scoped_ptr<net::test_server::HttpResponse> HandleEchoTitleRequest(
2990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const std::string& echotitle_path,
3090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    const net::test_server::HttpRequest& request) {
3190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  if (!StartsWithASCII(request.relative_url, echotitle_path, true))
327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)    return scoped_ptr<net::test_server::HttpResponse>();
3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  scoped_ptr<net::test_server::BasicHttpResponse> http_response(
3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      new net::test_server::BasicHttpResponse);
36eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  http_response->set_code(net::HTTP_OK);
3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  http_response->set_content(
3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      base::StringPrintf(
3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          "<html><head><title>%s</title></head></html>",
4090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)          request.content.c_str()));
4190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  return http_response.PassAs<net::test_server::HttpResponse>();
4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}
4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)}  // namespace
4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SessionHistoryTest : public ContentBrowserTest {
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SessionHistoryTest() {}
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUpOnMainThread() OVERRIDE {
5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    embedded_test_server()->RegisterRequestHandler(
5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        base::Bind(&HandleEchoTitleRequest, "/echotitle"));
5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
55f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)    NavigateToURL(shell(), GURL(url::kAboutBlankURL));
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Simulate clicking a link.  Only works on the frames.html testserver page.
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ClickLink(std::string node_id) {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("javascript:clickLink('" + node_id + "')");
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NavigateToURL(shell(), url);
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Simulate filling in form data.  Only works on the frames.html page with
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // subframe = form.html, and on form.html itself.
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void FillForm(std::string node_id, std::string value) {
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("javascript:fillForm('" + node_id + "', '" + value + "')");
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // This will return immediately, but since the JS executes synchronously
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // on the renderer, it will complete before the next navigate message is
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // processed.
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NavigateToURL(shell(), url);
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Simulate submitting a form.  Only works on the frames.html page with
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // subframe = form.html, and on form.html itself.
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SubmitForm(std::string node_id) {
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("javascript:submitForm('" + node_id + "')");
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NavigateToURL(shell(), url);
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Navigate session history using history.go(distance).
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void JavascriptGo(std::string distance) {
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url("javascript:history.go('" + distance + "')");
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NavigateToURL(shell(), url);
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string GetTabTitle() {
88a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return base::UTF16ToASCII(shell()->web_contents()->GetTitle());
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL GetTabURL() {
923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    return shell()->web_contents()->GetLastCommittedURL();
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL GetURL(const std::string file) {
9690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)    return embedded_test_server()->GetURL(
9790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)        std::string("/session_history/") + file);
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NavigateAndCheckTitle(const char* filename,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const std::string& expected_title) {
1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 expected_title16(base::ASCIIToUTF16(expected_title));
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TitleWatcher title_watcher(shell()->web_contents(), expected_title16);
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NavigateToURL(shell(), GetURL(filename));
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_EQ(expected_title16, title_watcher.WaitAndGetTitle());
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanGoBack() {
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return shell()->web_contents()->GetController().CanGoBack();
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanGoForward() {
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return shell()->web_contents()->GetController().CanGoForward();
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GoBack() {
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WindowedNotificationObserver load_stop_observer(
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        NOTIFICATION_LOAD_STOP,
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        NotificationService::AllSources());
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    shell()->web_contents()->GetController().GoBack();
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    load_stop_observer.Wait();
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void GoForward() {
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    WindowedNotificationObserver load_stop_observer(
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        NOTIFICATION_LOAD_STOP,
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)        NotificationService::AllSources());
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    shell()->web_contents()->GetController().GoForward();
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    load_stop_observer.Wait();
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If this flakes, use http://crbug.com/61619 on windows and
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://crbug.com/102094 on mac.
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, BasicBackForward) {
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1"));
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2"));
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, bot2, *bot3]
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoForward();
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, *bot3]
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoForward());
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot3", GetTabTitle());
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
167f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoForward();
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoForward();
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot3", GetTabTitle());
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that back/forward works when navigating in subframes.
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If this flakes, use http://crbug.com/48833
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameBackForward) {
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1"));
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("abot2");
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL frames(GetURL("frames.html"));
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("abot3");
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot3", GetTabTitle());
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, bot2, *bot3]
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
206f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
207f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(GURL(url::kAboutBlankURL), GetTabURL());
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoForward();
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoForward();
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("abot1");
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, bot2, *bot1]
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoForward());
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that back/forward preserves POST data and document state in subframes.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If this flakes use http://crbug.com/61619
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FrameFormBackForward) {
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1"));
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("aform");
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("form", GetTabTitle());
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL frames(GetURL("frames.html"));
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SubmitForm("isubmit");
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("text=&select=a", GetTabTitle());
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("form", GetTabTitle());
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, *form, post]
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("abot2");
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, form, *bot2]
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("form", GetTabTitle());
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SubmitForm("isubmit");
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("text=&select=a", GetTabTitle());
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, form, *post]
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(mpcomplete): reenable this when WebKit bug 10199 is fixed:
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // "returning to a POST result within a frame does a GET instead of a POST"
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("abot2");
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("text=&select=a", GetTabTitle());
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(mpcomplete): enable this when Bug 734372 is fixed:
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "Doing a session history navigation does not restore newly-created subframe
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// document state"
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that back/forward preserves POST data and document state when navigating
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// across frames (ie, from frame -> nonframe).
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Hangs, see http://crbug.com/45058.
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, CrossFrameFormBackForward) {
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL frames(GetURL("frames.html"));
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("frames.html", "bot1"));
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ClickLink("aform");
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("form", GetTabTitle());
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SubmitForm("isubmit");
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("text=&select=a", GetTabTitle());
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("form", GetTabTitle());
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, *form, post]
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2"));
3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, form, *bot2]
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SubmitForm("isubmit");
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("text=&select=a", GetTabTitle());
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(frames, GetTabURL());
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that back/forward entries are created for reference fragment
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// navigations. Bug 730379.
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// If this flakes use http://crbug.com/61619.
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, FragmentBackForward) {
32890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  embedded_test_server()->RegisterRequestHandler(
32990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      base::Bind(&HandleEchoTitleRequest, "/echotitle"));
33090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GURL fragment(GetURL("fragment.html"));
3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html", "fragment"));
3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#a", "fragment"));
3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#b", "fragment"));
3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("fragment.html#c", "fragment"));
3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, fragment, fragment#a, fragment#b, *fragment#c]
3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("fragment.html#b"), GetTabURL());
3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL());
3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("fragment.html"), GetTabURL());
3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoForward();
3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL());
3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, fragment, fragment#a, bot3]
3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoForward());
3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("bot3.html"), GetTabURL());
3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("fragment.html#a"), GetTabURL());
3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GetURL("fragment.html"), GetTabURL());
3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Test that the javascript window.history object works.
3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: history.go(N) does not do anything if N is outside the bounds of the
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// back/forward list (such as trigger our start/stop loading events).  This
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// means the test will hang if it attempts to navigate too far forward or back,
3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// since we'll be waiting forever for a load stop event.
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(brettw) bug 50648: fix flakyness. This test seems like it was failing
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// about 1/4 of the time on Vista by failing to execute JavascriptGo (see bug).
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, JavascriptHistory) {
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot1.html", "bot1"));
3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot2.html", "bot2"));
3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, bot2, *bot3]
3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("-1");
3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("-1");
3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("1");
3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot2", GetTabTitle());
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("-1");
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("2");
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot3", GetTabTitle());
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, bot2, *bot3]
4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("-3");
403f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
406f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("1");
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle("bot3.html", "bot3"));
4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // history is [blank, bot1, *bot3]
4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoForward());
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot3", GetTabTitle());
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("-1");
4195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("-1");
422f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
4235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_FALSE(CanGoBack());
425f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  EXPECT_EQ(std::string(url::kAboutBlankURL), GetTabTitle());
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("1");
4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot1", GetTabTitle());
4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  JavascriptGo("1");
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("bot3", GetTabTitle());
4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(creis): Test that JavaScript history navigations work across tab
4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // types.  For example, load about:network in a tab, then a real page, then
4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // try to go back and forward with JavaScript.  Bug 1136715.
4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (Hard to test right now, because pages like about:network cause the
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TabProxy to hang.  This is because they do not appear to use the
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // NotificationService.)
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This test is failing consistently. See http://crbug.com/22560
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationReplace) {
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Test that using location.replace doesn't leave the title of the old page
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // visible.
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle(
4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      "replace.html?bot1.html", "bot1"));
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, LocationChangeInSubframe) {
4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ASSERT_NO_FATAL_FAILURE(NavigateAndCheckTitle(
4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      "location_redirect.html", "Default Title"));
4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigateToURL(shell(), GURL("javascript:void(frames[0].navigate())"));
4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("foo", GetTabTitle());
4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ("Default Title", GetTabTitle());
4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// http://code.google.com/p/chromium/issues/detail?id=56267
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) {
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int length;
4632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(ExecuteScriptAndExtractInt(
4642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      shell()->web_contents(),
4652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      "domAutomationController.send(history.length)",
4662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      &length));
4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(1, length);
4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigateToURL(shell(), GetURL("title1.html"));
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(ExecuteScriptAndExtractInt(
4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      shell()->web_contents(),
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      "domAutomationController.send(history.length)",
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      &length));
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(2, length);
4765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Now test that history.length is updated when the navigation is committed.
4785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigateToURL(shell(), GetURL("record_length.html"));
4795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(ExecuteScriptAndExtractInt(
4812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      shell()->web_contents(),
4822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      "domAutomationController.send(history.length)",
4832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      &length));
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(3, length);
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
4875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GoBack();
4885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Ensure history.length is properly truncated.
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NavigateToURL(shell(), GetURL("title2.html"));
4915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ASSERT_TRUE(ExecuteScriptAndExtractInt(
4932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      shell()->web_contents(),
4942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      "domAutomationController.send(history.length)",
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      &length));
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(2, length);
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
500