license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 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 | |
| 12 | namespace { |
| 13 | |
| 14 | const wchar_t kDocRoot[] = L"chrome/test/data"; |
| 15 | |
| 16 | const std::string kInterstitialPageHTMLText = |
| 17 | "<html><head><title>Interstitial page</title></head><body><h1>This is an" |
| 18 | "interstitial page</h1></body></html>"; |
| 19 | |
| 20 | |
| 21 | class 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] | db300c9 | 2009-01-21 22:12:32 | [diff] [blame] | 54 | // This test is disabled as it occasionally makes the ui tests stop running. |
| 55 | // See bug 6729. |
| 56 | TEST_F(InterstitialPageTest, DISABLED_TestShowHideInterstitial) { |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 57 | scoped_refptr<HTTPTestServer> server = |
[email protected] | cad01431 | 2009-01-29 21:59:55 | [diff] [blame] | 58 | HTTPTestServer::CreateServer(kDocRoot, NULL); |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 59 | ASSERT_TRUE(NULL != server.get()); |
| 60 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); |
| 62 | NavigateTab(tab.get(), |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 63 | server->TestServerPageW(L"files/interstitial_page/google.html")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | NavigationEntry::PageType page_type; |
| 65 | EXPECT_TRUE(tab->GetPageType(&page_type)); |
| 66 | EXPECT_EQ(NavigationEntry::NORMAL_PAGE, page_type); |
| 67 | |
[email protected] | b6e5839 | 2008-12-18 18:21:53 | [diff] [blame] | 68 | tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | 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. |
| 85 | TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenBack) { |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 86 | scoped_refptr<HTTPTestServer> server = |
[email protected] | cad01431 | 2009-01-29 21:59:55 | [diff] [blame] | 87 | HTTPTestServer::CreateServer(kDocRoot, NULL); |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 88 | ASSERT_TRUE(NULL != server.get()); |
| 89 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 90 | ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); |
| 91 | NavigateTab(tab.get(), |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 92 | server->TestServerPageW(L"files/interstitial_page/google.html")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 93 | EXPECT_EQ(L"Google", GetActiveTabTitle()); |
| 94 | |
[email protected] | b6e5839 | 2008-12-18 18:21:53 | [diff] [blame] | 95 | tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 96 | 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. |
| 104 | TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenNavigate) { |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 105 | scoped_refptr<HTTPTestServer> server = |
[email protected] | cad01431 | 2009-01-29 21:59:55 | [diff] [blame] | 106 | HTTPTestServer::CreateServer(kDocRoot, NULL); |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 107 | ASSERT_TRUE(NULL != server.get()); |
| 108 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 109 | ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); |
| 110 | NavigateTab(tab.get(), |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 111 | server->TestServerPageW(L"files/interstitial_page/google.html")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | EXPECT_EQ(L"Google", GetActiveTabTitle()); |
| 113 | |
[email protected] | b6e5839 | 2008-12-18 18:21:53 | [diff] [blame] | 114 | tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | EXPECT_EQ(L"Interstitial page", GetActiveTabTitle()); |
| 116 | |
| 117 | tab->NavigateToURL( |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 118 | server->TestServerPageW(L"files/interstitial_page/shopping.html")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 119 | 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] | 848ecead | 2009-01-21 19:33:54 | [diff] [blame] | 123 | // This test is disabled as it occasionally makes the ui tests stop running. |
| 124 | // See bug 6729. |
| 125 | TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenCloseTab) { |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 126 | scoped_refptr<HTTPTestServer> server = |
[email protected] | cad01431 | 2009-01-29 21:59:55 | [diff] [blame] | 127 | HTTPTestServer::CreateServer(kDocRoot, NULL); |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 128 | ASSERT_TRUE(NULL != server.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | |
| 130 | // Create 2 tabs so closing one does not close the browser. |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 131 | AppendTab(server->TestServerPageW(L"files/interstitial_page/google.html")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 132 | ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); |
| 133 | EXPECT_EQ(L"Google", GetActiveTabTitle()); |
| 134 | |
[email protected] | b6e5839 | 2008-12-18 18:21:53 | [diff] [blame] | 135 | tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | 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. |
| 143 | TEST_F(InterstitialPageTest, DISABLED_TestShowInterstitialThenCloseBrowser) { |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 144 | scoped_refptr<HTTPTestServer> server = |
[email protected] | cad01431 | 2009-01-29 21:59:55 | [diff] [blame] | 145 | HTTPTestServer::CreateServer(kDocRoot, NULL); |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 146 | ASSERT_TRUE(NULL != server.get()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 147 | |
| 148 | ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); |
| 149 | tab->NavigateToURL( |
[email protected] | dd26501 | 2009-01-08 20:45:27 | [diff] [blame] | 150 | server->TestServerPageW(L"files/interstitial_page/google.html")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | EXPECT_EQ(L"Google", GetActiveTabTitle()); |
| 152 | |
[email protected] | b6e5839 | 2008-12-18 18:21:53 | [diff] [blame] | 153 | tab->ShowInterstitialPage(kInterstitialPageHTMLText, action_timeout_ms()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 154 | 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.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 164 | |