| 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 "chrome/app/chrome_dll_resource.h" | 5 #include "chrome/app/chrome_dll_resource.h" |
| 6 #include "chrome/test/automation/browser_proxy.h" | 6 #include "chrome/test/automation/browser_proxy.h" |
| 7 #include "chrome/test/automation/tab_proxy.h" | 7 #include "chrome/test/automation/tab_proxy.h" |
| 8 #include "chrome/test/ui/ui_test.h" | 8 #include "chrome/test/ui/ui_test.h" |
| 9 #include "net/url_request/url_request_unittest.h" | 9 #include "net/url_request/url_request_unittest.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 protected: | 31 protected: |
| 32 std::wstring test_html_; | 32 std::wstring test_html_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 // This test renders a page in view-source and then checks to see if a cookie | 37 // This test renders a page in view-source and then checks to see if a cookie |
| 38 // set in the html was set successfully (it shouldn't because we rendered the | 38 // set in the html was set successfully (it shouldn't because we rendered the |
| 39 // page in view source) | 39 // page in view source) |
| 40 TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { | 40 TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { |
| 41 TestServer server(kDocRoot); | 41 scoped_refptr<HTTPTestServer> server = |
| 42 HTTPTestServer::CreateServer(kDocRoot); |
| 43 ASSERT_TRUE(NULL != server.get()); |
| 42 std::string cookie = "viewsource_cookie"; | 44 std::string cookie = "viewsource_cookie"; |
| 43 std::string cookie_data = "foo"; | 45 std::string cookie_data = "foo"; |
| 44 | 46 |
| 45 // First we navigate to our view-source test page | 47 // First we navigate to our view-source test page |
| 46 GURL url = server.TestServerPageW(test_html_); | 48 GURL url = server->TestServerPageW(test_html_); |
| 47 url = GURL("view-source:" + url.spec()); | 49 url = GURL("view-source:" + url.spec()); |
| 48 scoped_ptr<TabProxy> tab(GetActiveTab()); | 50 scoped_ptr<TabProxy> tab(GetActiveTab()); |
| 49 tab->NavigateToURL(url); | 51 tab->NavigateToURL(url); |
| 50 Sleep(kWaitForActionMsec); | 52 Sleep(kWaitForActionMsec); |
| 51 | 53 |
| 52 // Try to retrieve the cookie that the page sets | 54 // Try to retrieve the cookie that the page sets |
| 53 // It should not be there (because we are in view-source mode | 55 // It should not be there (because we are in view-source mode |
| 54 std::string cookie_found; | 56 std::string cookie_found; |
| 55 tab->GetCookieByName(url, cookie, &cookie_found); | 57 tab->GetCookieByName(url, cookie, &cookie_found); |
| 56 EXPECT_NE(cookie_data, cookie_found); | 58 EXPECT_NE(cookie_data, cookie_found); |
| 57 } | 59 } |
| 58 | 60 |
| 59 // This test renders a page normally and then renders the same page in | 61 // This test renders a page normally and then renders the same page in |
| 60 // view-source mode. This is done since we had a problem at one point during | 62 // view-source mode. This is done since we had a problem at one point during |
| 61 // implementation of the view-source: prefix being consumed (removed from the | 63 // implementation of the view-source: prefix being consumed (removed from the |
| 62 // URL) if the URL was not changed (apart from adding the view-source prefix) | 64 // URL) if the URL was not changed (apart from adding the view-source prefix) |
| 63 TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { | 65 TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { |
| 64 TestServer server(kDocRoot); | 66 scoped_refptr<HTTPTestServer> server = |
| 67 HTTPTestServer::CreateServer(kDocRoot); |
| 68 ASSERT_TRUE(NULL != server.get()); |
| 65 | 69 |
| 66 // First we navigate to google.html | 70 // First we navigate to google.html |
| 67 GURL url = server.TestServerPageW(test_html_); | 71 GURL url = server->TestServerPageW(test_html_); |
| 68 NavigateToURL(url); | 72 NavigateToURL(url); |
| 69 | 73 |
| 70 // Then we navigate to the SAME url but with the view-source: prefix | 74 // Then we navigate to the SAME url but with the view-source: prefix |
| 71 GURL url_viewsource = GURL("view-source:" + url.spec()); | 75 GURL url_viewsource = GURL("view-source:" + url.spec()); |
| 72 NavigateToURL(url_viewsource); | 76 NavigateToURL(url_viewsource); |
| 73 | 77 |
| 74 // The URL should still be prefixed with view-source: | 78 // The URL should still be prefixed with view-source: |
| 75 EXPECT_EQ(url_viewsource.spec(), GetActiveTabURL().spec()); | 79 EXPECT_EQ(url_viewsource.spec(), GetActiveTabURL().spec()); |
| 76 } | 80 } |
| 77 | 81 |
| 78 // Make sure that when looking at the actual page, we can select | 82 // Make sure that when looking at the actual page, we can select |
| 79 // "View Source" from the Page menu. | 83 // "View Source" from the Page menu. |
| 80 TEST_F(ViewSourceTest, ViewSourceInPageMenuEnabledOnANormalPage) { | 84 TEST_F(ViewSourceTest, ViewSourceInPageMenuEnabledOnANormalPage) { |
| 81 TestServer server(kDocRoot); | 85 scoped_refptr<HTTPTestServer> server = |
| 86 HTTPTestServer::CreateServer(kDocRoot); |
| 87 ASSERT_TRUE(NULL != server.get()); |
| 82 | 88 |
| 83 // First we navigate to google.html | 89 // First we navigate to google.html |
| 84 GURL url = server.TestServerPageW(test_html_); | 90 GURL url = server->TestServerPageW(test_html_); |
| 85 NavigateToURL(url); | 91 NavigateToURL(url); |
| 86 | 92 |
| 87 EXPECT_TRUE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); | 93 EXPECT_TRUE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); |
| 88 } | 94 } |
| 89 | 95 |
| 90 // Make sure that when looking at the page source, we can't select | 96 // Make sure that when looking at the page source, we can't select |
| 91 // "View Source" from the Page menu. | 97 // "View Source" from the Page menu. |
| 92 TEST_F(ViewSourceTest, ViewSourceInPageMenuDisabledWhileViewingSource) { | 98 TEST_F(ViewSourceTest, ViewSourceInPageMenuDisabledWhileViewingSource) { |
| 93 TestServer server(kDocRoot); | 99 scoped_refptr<HTTPTestServer> server = |
| 100 HTTPTestServer::CreateServer(kDocRoot); |
| 101 ASSERT_TRUE(NULL != server.get()); |
| 94 | 102 |
| 95 // First we navigate to google.html | 103 // First we navigate to google.html |
| 96 GURL url = server.TestServerPageW(test_html_); | 104 GURL url = server->TestServerPageW(test_html_); |
| 97 GURL url_viewsource = GURL("view-source:" + url.spec()); | 105 GURL url_viewsource = GURL("view-source:" + url.spec()); |
| 98 NavigateToURL(url_viewsource); | 106 NavigateToURL(url_viewsource); |
| 99 | 107 |
| 100 EXPECT_FALSE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); | 108 EXPECT_FALSE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); |
| 101 } | 109 } |
| 102 | 110 |
| OLD | NEW |