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