blob: 67b243547d607077991df731dd0f3d4a19411d84 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
5#include <string>
6
7#include "chrome/test/automation/tab_proxy.h"
8#include "chrome/test/automation/browser_proxy.h"
9#include "chrome/test/ui/ui_test.h"
10#include "net/url_request/url_request_unittest.h"
11
12namespace {
13
14const wchar_t kDocRoot[] = L"chrome/test/data";
15
16const std::string kInterstitialPageHTMLText =
17 "<html><head><title>Interstitial page</title></head><body><h1>This is an"
18 "interstitial page</h1></body></html>";
19
20
21class InterstitialPageTest : public UITest {
22 protected:
23 InterstitialPageTest() {
24 show_window_ = true;
25 }
26
27 TabProxy* GetActiveTabProxy() {
28 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
29 EXPECT_TRUE(browser_proxy.get());
30
31 int active_tab_index = 0;
32 EXPECT_TRUE(browser_proxy->GetActiveTabIndex(&active_tab_index));
33 return browser_proxy->GetTab(active_tab_index);
34 }
35
36 void NavigateTab(TabProxy* tab_proxy, const GURL& url) {
37 ASSERT_TRUE(tab_proxy->NavigateToURL(url));
38 }
39
40 void AppendTab(const GURL& url) {
41 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
42 EXPECT_TRUE(browser_proxy.get());
43 EXPECT_TRUE(browser_proxy->AppendTab(url));
44 }
45};
46
47} // namespace
48
49// Shows and hides an interstitial page.
50// Note that we cannot rely on the page title in this case (and we use the page
51// type instead) as showing an interstitial without creating a navigation entry
52// causes the actual navigation entry (title) to be modified by the content of
53// the interstitial.
[email protected]db300c92009-01-21 22:12:3254// This test is disabled as it occasionally makes the ui tests stop running.
55// See bug 6729.
56TEST_F(InterstitialPageTest, DISABLED_TestShowHideInterstitial) {
[email protected]dd265012009-01-08 20:45:2757 scoped_refptr<HTTPTestServer> server =
[email protected]cad014312009-01-29 21:59:5558 HTTPTestServer::CreateServer(kDocRoot, NULL);
[email protected]dd265012009-01-08 20:45:2759 ASSERT_TRUE(NULL != server.get());
60
initial.commit09911bf2008-07-26 23:55:2961 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy());
62 NavigateTab(tab.get(),
[email protected]dd265012009-01-08 20:45:2763 server->TestServerPageW(L"files/interstitial_page/google.html"));
initial.commit09911bf2008-07-26 23:55:2964 NavigationEntry::PageType page_type;
65 EXPECT_TRUE(tab->GetPageType(&page_type));
66 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
67
[email protected]b6e58392008-12-18 18:21:5368 tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms());
initial.commit09911bf2008-07-26 23:55:2969 EXPECT_TRUE(tab->GetPageType(&page_type));
70 EXPECT_EQ(NavigationEntry::INTERSTITIAL_PAGE, page_type);
71
72 tab->HideInterstitialPage();
73 EXPECT_TRUE(tab->GetPageType(&page_type));
74 EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type);
75}
76
77// Shows an interstitial page then goes back.
78// TODO(creis): We are disabling this test for now. We need to revisit
79// whether the interstitial page should actually commit a NavigationEntry,
80// because this clears the forward list and changes the meaning of back. It
81// seems like the interstitial should not affect the NavigationController,
82// who will remain in a pending state until the user either proceeds or cancels
83// the interstitial. In the mean time, we are treating Back like cancelling
84// the interstitial, which breaks this test because no notification occurs.
85TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenBack) {
[email protected]dd265012009-01-08 20:45:2786 scoped_refptr<HTTPTestServer> server =
[email protected]cad014312009-01-29 21:59:5587 HTTPTestServer::CreateServer(kDocRoot, NULL);
[email protected]dd265012009-01-08 20:45:2788 ASSERT_TRUE(NULL != server.get());
89
initial.commit09911bf2008-07-26 23:55:2990 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy());
91 NavigateTab(tab.get(),
[email protected]dd265012009-01-08 20:45:2792 server->TestServerPageW(L"files/interstitial_page/google.html"));
initial.commit09911bf2008-07-26 23:55:2993 EXPECT_EQ(L"Google", GetActiveTabTitle());
94
[email protected]b6e58392008-12-18 18:21:5395 tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms());
initial.commit09911bf2008-07-26 23:55:2996 EXPECT_EQ(L"Interstitial page", GetActiveTabTitle());
97
98 tab->GoBack();
99 EXPECT_EQ(L"Google", GetActiveTabTitle());
100}
101
102// Shows an interstitial page then navigates to a new URL.
103// Flacky on Windows 2000 bot. Disabled for now bug #1173138.
104TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenNavigate) {
[email protected]dd265012009-01-08 20:45:27105 scoped_refptr<HTTPTestServer> server =
[email protected]cad014312009-01-29 21:59:55106 HTTPTestServer::CreateServer(kDocRoot, NULL);
[email protected]dd265012009-01-08 20:45:27107 ASSERT_TRUE(NULL != server.get());
108
initial.commit09911bf2008-07-26 23:55:29109 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy());
110 NavigateTab(tab.get(),
[email protected]dd265012009-01-08 20:45:27111 server->TestServerPageW(L"files/interstitial_page/google.html"));
initial.commit09911bf2008-07-26 23:55:29112 EXPECT_EQ(L"Google", GetActiveTabTitle());
113
[email protected]b6e58392008-12-18 18:21:53114 tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms());
initial.commit09911bf2008-07-26 23:55:29115 EXPECT_EQ(L"Interstitial page", GetActiveTabTitle());
116
117 tab->NavigateToURL(
[email protected]dd265012009-01-08 20:45:27118 server->TestServerPageW(L"files/interstitial_page/shopping.html"));
initial.commit09911bf2008-07-26 23:55:29119 EXPECT_EQ(L"Google Product Search", GetActiveTabTitle());
120}
121
122// Shows an interstitial page then closes the tab (to make sure we don't crash).
[email protected]848ecead2009-01-21 19:33:54123// This test is disabled as it occasionally makes the ui tests stop running.
124// See bug 6729.
125TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenCloseTab) {
[email protected]dd265012009-01-08 20:45:27126 scoped_refptr<HTTPTestServer> server =
[email protected]cad014312009-01-29 21:59:55127 HTTPTestServer::CreateServer(kDocRoot, NULL);
[email protected]dd265012009-01-08 20:45:27128 ASSERT_TRUE(NULL != server.get());
initial.commit09911bf2008-07-26 23:55:29129
130 // Create 2 tabs so closing one does not close the browser.
[email protected]dd265012009-01-08 20:45:27131 AppendTab(server->TestServerPageW(L"files/interstitial_page/google.html"));
initial.commit09911bf2008-07-26 23:55:29132 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy());
133 EXPECT_EQ(L"Google", GetActiveTabTitle());
134
[email protected]b6e58392008-12-18 18:21:53135 tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms());
initial.commit09911bf2008-07-26 23:55:29136 EXPECT_EQ(L"Interstitial page", GetActiveTabTitle());
137 tab->Close();
138}
139
140// Shows an interstitial page then closes the browser (to make sure we don't
141// crash).
142// This test is disabled. See bug #1119448.
143TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenCloseBrowser) {
[email protected]dd265012009-01-08 20:45:27144 scoped_refptr<HTTPTestServer> server =
[email protected]cad014312009-01-29 21:59:55145 HTTPTestServer::CreateServer(kDocRoot, NULL);
[email protected]dd265012009-01-08 20:45:27146 ASSERT_TRUE(NULL != server.get());
initial.commit09911bf2008-07-26 23:55:29147
148 ::scoped_ptr<TabProxy> tab(GetActiveTabProxy());
149 tab->NavigateToURL(
[email protected]dd265012009-01-08 20:45:27150 server->TestServerPageW(L"files/interstitial_page/google.html"));
initial.commit09911bf2008-07-26 23:55:29151 EXPECT_EQ(L"Google", GetActiveTabTitle());
152
[email protected]b6e58392008-12-18 18:21:53153 tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms());
initial.commit09911bf2008-07-26 23:55:29154 EXPECT_EQ(L"Interstitial page", GetActiveTabTitle());
155
156 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
157 EXPECT_TRUE(browser_proxy.get());
158 bool application_closed;
159 EXPECT_TRUE(CloseBrowser(browser_proxy.get(), &application_closed));
160 EXPECT_TRUE(application_closed);
161}
162
163
license.botbf09a502008-08-24 00:55:55164