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

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

Issue 1814002: Remove deprecated things from net test suite: (Closed)
Patch Set: Created 10 years, 7 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
OLDNEW
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
11 namespace { 11 namespace {
12 12
13 const wchar_t kDocRoot[] = L"chrome/test/data"; 13 const wchar_t kDocRoot[] = L"chrome/test/data";
14 14
15 class ViewSourceTest : public UITest { 15 class ViewSourceTest : public UITest {
16 protected: 16 protected:
17 ViewSourceTest() : UITest() { 17 ViewSourceTest() : test_html_("files/viewsource/test.html") {
18 test_html_ = L"files/viewsource/test.html";
19 } 18 }
20 19
21 bool IsPageMenuCommandEnabled(int command) { 20 bool IsPageMenuCommandEnabled(int command) {
22 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); 21 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
23 EXPECT_TRUE(window_proxy.get()); 22 EXPECT_TRUE(window_proxy.get());
24 if (!window_proxy.get()) 23 if (!window_proxy.get())
25 return false; 24 return false;
26 25
27 bool enabled; 26 bool enabled;
28 EXPECT_TRUE(window_proxy->IsPageMenuCommandEnabled(command, &enabled)); 27 EXPECT_TRUE(window_proxy->IsPageMenuCommandEnabled(command, &enabled));
29 return enabled; 28 return enabled;
30 } 29 }
31 30
32 protected: 31 protected:
33 std::wstring test_html_; 32 std::string test_html_;
34 }; 33 };
35 34
36 // This test renders a page in view-source and then checks to see if a cookie 35 // 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 36 // set in the html was set successfully (it shouldn't because we rendered the
38 // page in view source) 37 // page in view source)
39 TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { 38 TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) {
40 scoped_refptr<HTTPTestServer> server = 39 scoped_refptr<HTTPTestServer> server =
41 HTTPTestServer::CreateServer(kDocRoot, NULL); 40 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 = server->TestServerPageW(test_html_); 46 GURL url = server->TestServerPage(test_html_);
48 url = GURL("view-source:" + url.spec()); 47 url = GURL("view-source:" + url.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 52 // Try to retrieve the cookie that the page sets
54 // It should not be there (because we are in view-source mode 53 // It should not be there (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 =
66 HTTPTestServer::CreateServer(kDocRoot, NULL); 65 HTTPTestServer::CreateServer(kDocRoot, NULL);
67 ASSERT_TRUE(NULL != server.get()); 66 ASSERT_TRUE(NULL != server.get());
68 67
69 // First we navigate to google.html 68 // First we navigate to google.html
70 GURL url = server->TestServerPageW(test_html_); 69 GURL url = server->TestServerPage(test_html_);
71 NavigateToURL(url); 70 NavigateToURL(url);
72 71
73 // Then we navigate to the SAME url but with the view-source: prefix 72 // Then we navigate to the SAME url but with the view-source: prefix
74 GURL url_viewsource = GURL("view-source:" + url.spec()); 73 GURL url_viewsource = GURL("view-source:" + url.spec());
75 NavigateToURL(url_viewsource); 74 NavigateToURL(url_viewsource);
76 75
77 // The URL should still be prefixed with view-source: 76 // The URL should still be prefixed with view-source:
78 EXPECT_EQ(url_viewsource.spec(), GetActiveTabURL().spec()); 77 EXPECT_EQ(url_viewsource.spec(), GetActiveTabURL().spec());
79 } 78 }
80 79
81 // Make sure that when looking at the actual page, we can select 80 // Make sure that when looking at the actual page, we can select
82 // "View Source" from the Page menu. 81 // "View Source" from the Page menu.
83 TEST_F(ViewSourceTest, ViewSourceInPageMenuEnabledOnANormalPage) { 82 TEST_F(ViewSourceTest, ViewSourceInPageMenuEnabledOnANormalPage) {
84 scoped_refptr<HTTPTestServer> server = 83 scoped_refptr<HTTPTestServer> server =
85 HTTPTestServer::CreateServer(kDocRoot, NULL); 84 HTTPTestServer::CreateServer(kDocRoot, NULL);
86 ASSERT_TRUE(NULL != server.get()); 85 ASSERT_TRUE(NULL != server.get());
87 86
88 // First we navigate to google.html 87 // First we navigate to google.html
89 GURL url = server->TestServerPageW(test_html_); 88 GURL url = server->TestServerPage(test_html_);
90 NavigateToURL(url); 89 NavigateToURL(url);
91 90
92 EXPECT_TRUE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); 91 EXPECT_TRUE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE));
93 } 92 }
94 93
95 // Make sure that when looking at the page source, we can't select 94 // Make sure that when looking at the page source, we can't select
96 // "View Source" from the Page menu. 95 // "View Source" from the Page menu.
97 TEST_F(ViewSourceTest, ViewSourceInPageMenuDisabledWhileViewingSource) { 96 TEST_F(ViewSourceTest, ViewSourceInPageMenuDisabledWhileViewingSource) {
98 scoped_refptr<HTTPTestServer> server = 97 scoped_refptr<HTTPTestServer> server =
99 HTTPTestServer::CreateServer(kDocRoot, NULL); 98 HTTPTestServer::CreateServer(kDocRoot, NULL);
100 ASSERT_TRUE(NULL != server.get()); 99 ASSERT_TRUE(NULL != server.get());
101 100
102 // First we navigate to google.html 101 // First we navigate to google.html
103 GURL url = server->TestServerPageW(test_html_); 102 GURL url = server->TestServerPage(test_html_);
104 GURL url_viewsource = GURL("view-source:" + url.spec()); 103 GURL url_viewsource = GURL("view-source:" + url.spec());
105 NavigateToURL(url_viewsource); 104 NavigateToURL(url_viewsource);
106 105
107 EXPECT_FALSE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE)); 106 EXPECT_FALSE(IsPageMenuCommandEnabled(IDC_VIEW_SOURCE));
108 } 107 }
109 108
110 } // namespace 109 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698