Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/tab_contents/view_source_uitest.cc

Issue 3034038: GTTF: Move more test server code from net/url_request/url_request_unittest.h (Closed)
Patch Set: hopefully final Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/sync/glue/http_bridge_unittest.cc ('k') | chrome/browser/tab_restore_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/test_server.h"
11 11
12 namespace { 12 namespace {
13 13
14 const wchar_t kDocRoot[] = L"chrome/test/data"; 14 const wchar_t kDocRoot[] = L"chrome/test/data";
15 15
16 class ViewSourceTest : public UITest { 16 class ViewSourceTest : public UITest {
17 protected: 17 protected:
18 ViewSourceTest() : test_html_("files/viewsource/test.html") { 18 ViewSourceTest() : test_html_("files/viewsource/test.html") {
19 } 19 }
20 20
21 bool IsMenuCommandEnabled(int command) { 21 bool IsMenuCommandEnabled(int command) {
22 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); 22 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
23 EXPECT_TRUE(window_proxy.get()); 23 EXPECT_TRUE(window_proxy.get());
24 if (!window_proxy.get()) 24 if (!window_proxy.get())
25 return false; 25 return false;
26 26
27 bool enabled; 27 bool enabled;
28 EXPECT_TRUE(window_proxy->IsMenuCommandEnabled(command, &enabled)); 28 EXPECT_TRUE(window_proxy->IsMenuCommandEnabled(command, &enabled));
29 return enabled; 29 return enabled;
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(HTTPTestServer::CreateServer(kDocRoot)); 40 scoped_refptr<net::HTTPTestServer> server(
41 net::HTTPTestServer::CreateServer(kDocRoot));
41 ASSERT_TRUE(NULL != server.get()); 42 ASSERT_TRUE(NULL != server.get());
42 std::string cookie = "viewsource_cookie"; 43 std::string cookie = "viewsource_cookie";
43 std::string cookie_data = "foo"; 44 std::string cookie_data = "foo";
44 45
45 // First we navigate to our view-source test page. 46 // First we navigate to our view-source test page.
46 GURL url(chrome::kViewSourceScheme + std::string(":") + 47 GURL url(chrome::kViewSourceScheme + std::string(":") +
47 server->TestServerPage(test_html_).spec()); 48 server->TestServerPage(test_html_).spec());
48 scoped_refptr<TabProxy> tab(GetActiveTab()); 49 scoped_refptr<TabProxy> tab(GetActiveTab());
49 ASSERT_TRUE(tab.get()); 50 ASSERT_TRUE(tab.get());
50 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url)); 51 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(url));
51 52
52 // Try to retrieve the cookie that the page sets. It should not be there 53 // Try to retrieve the cookie that the page sets. It should not be there
53 // (because we are in view-source mode). 54 // (because we are in view-source mode).
54 std::string cookie_found; 55 std::string cookie_found;
55 ASSERT_TRUE(tab->GetCookieByName(url, cookie, &cookie_found)); 56 ASSERT_TRUE(tab->GetCookieByName(url, cookie, &cookie_found));
56 EXPECT_NE(cookie_data, cookie_found); 57 EXPECT_NE(cookie_data, cookie_found);
57 } 58 }
58 59
59 // This test renders a page normally and then renders the same page in 60 // 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 61 // 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 62 // 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) 63 // URL) if the URL was not changed (apart from adding the view-source prefix)
63 TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { 64 TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) {
64 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 65 scoped_refptr<net::HTTPTestServer> server(
66 net::HTTPTestServer::CreateServer(kDocRoot));
65 ASSERT_TRUE(NULL != server.get()); 67 ASSERT_TRUE(NULL != server.get());
66 68
67 // First we navigate to google.html. 69 // First we navigate to google.html.
68 GURL url(server->TestServerPage(test_html_)); 70 GURL url(server->TestServerPage(test_html_));
69 NavigateToURL(url); 71 NavigateToURL(url);
70 72
71 // Then we navigate to the same url but with the "view-source:" prefix. 73 // Then we navigate to the same url but with the "view-source:" prefix.
72 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + 74 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") +
73 url.spec()); 75 url.spec());
74 NavigateToURL(url_viewsource); 76 NavigateToURL(url_viewsource);
75 77
76 // The URL should still be prefixed with "view-source:". 78 // The URL should still be prefixed with "view-source:".
77 EXPECT_EQ(url_viewsource.spec(), GetActiveTabURL().spec()); 79 EXPECT_EQ(url_viewsource.spec(), GetActiveTabURL().spec());
78 } 80 }
79 81
80 // Make sure that when looking at the actual page, we can select "View Source" 82 // Make sure that when looking at the actual page, we can select "View Source"
81 // from the menu. 83 // from the menu.
82 TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) { 84 TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) {
83 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 85 scoped_refptr<net::HTTPTestServer> server(
86 net::HTTPTestServer::CreateServer(kDocRoot));
84 ASSERT_TRUE(NULL != server.get()); 87 ASSERT_TRUE(NULL != server.get());
85 88
86 GURL url(server->TestServerPage(test_html_)); 89 GURL url(server->TestServerPage(test_html_));
87 NavigateToURL(url); 90 NavigateToURL(url);
88 91
89 EXPECT_TRUE(IsMenuCommandEnabled(IDC_VIEW_SOURCE)); 92 EXPECT_TRUE(IsMenuCommandEnabled(IDC_VIEW_SOURCE));
90 } 93 }
91 94
92 // Make sure that when looking at the page source, we can't select "View Source" 95 // Make sure that when looking at the page source, we can't select "View Source"
93 // from the menu. 96 // from the menu.
94 TEST_F(ViewSourceTest, ViewSourceInMenuDisabledWhileViewingSource) { 97 TEST_F(ViewSourceTest, ViewSourceInMenuDisabledWhileViewingSource) {
95 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 98 scoped_refptr<net::HTTPTestServer> server(
99 net::HTTPTestServer::CreateServer(kDocRoot));
96 ASSERT_TRUE(NULL != server.get()); 100 ASSERT_TRUE(NULL != server.get());
97 101
98 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") + 102 GURL url_viewsource(chrome::kViewSourceScheme + std::string(":") +
99 server->TestServerPage(test_html_).spec()); 103 server->TestServerPage(test_html_).spec());
100 NavigateToURL(url_viewsource); 104 NavigateToURL(url_viewsource);
101 105
102 EXPECT_FALSE(IsMenuCommandEnabled(IDC_VIEW_SOURCE)); 106 EXPECT_FALSE(IsMenuCommandEnabled(IDC_VIEW_SOURCE));
103 } 107 }
104 108
105 } // namespace 109 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/http_bridge_unittest.cc ('k') | chrome/browser/tab_restore_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698