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

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

Issue 16268017: GTTF: convert some tests in chrome to use EmbeddedTestServer patch nr 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/app/chrome_command_ids.h" 6 #include "chrome/app/chrome_command_ids.h"
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/url_constants.h" 10 #include "chrome/common/url_constants.h"
11 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h" 12 #include "chrome/test/base/ui_test_utils.h"
13 #include "content/public/browser/navigation_entry.h" 13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/notification_types.h" 15 #include "content/public/browser/notification_types.h"
16 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "content/public/test/browser_test_utils.h" 18 #include "content/public/test/browser_test_utils.h"
19 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "net/test/spawned_test_server/spawned_test_server.h" 20 #include "net/test/embedded_test_server/embedded_test_server.h"
21 21
22 namespace { 22 namespace {
23 const char kTestHtml[] = "files/viewsource/test.html"; 23 const char kTestHtml[] = "/viewsource/test.html";
24 const char kTestMedia[] = "files/media/pink_noise_140ms.wav"; 24 const char kTestMedia[] = "files/media/pink_noise_140ms.wav";
25 } 25 }
26 26
27 typedef InProcessBrowserTest ViewSourceTest; 27 typedef InProcessBrowserTest ViewSourceTest;
28 28
29 // This test renders a page in view-source and then checks to see if the title 29 // This test renders a page in view-source and then checks to see if the title
30 // set in the html was set successfully (it shouldn't because we rendered the 30 // set in the html was set successfully (it shouldn't because we rendered the
31 // page in view source). 31 // page in view source).
32 // Flaky; see http://crbug.com/72201. 32 // Flaky; see http://crbug.com/72201.
33 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) { 33 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserRenderInViewSource) {
34 ASSERT_TRUE(test_server()->Start()); 34 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
35 35
36 // First we navigate to our view-source test page. 36 // First we navigate to our view-source test page.
37 GURL url(content::kViewSourceScheme + std::string(":") + 37 GURL url(content::kViewSourceScheme + std::string(":") +
38 test_server()->GetURL(kTestHtml).spec()); 38 embedded_test_server()->GetURL(kTestHtml).spec());
39 ui_test_utils::NavigateToURL(browser(), url); 39 ui_test_utils::NavigateToURL(browser(), url);
40 40
41 // Check that the title didn't get set. It should not be there (because we 41 // Check that the title didn't get set. It should not be there (because we
42 // are in view-source mode). 42 // are in view-source mode).
43 EXPECT_NE(ASCIIToUTF16("foo"), 43 EXPECT_NE(ASCIIToUTF16("foo"),
44 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 44 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
45 } 45 }
46 46
47 // This test renders a page normally and then renders the same page in 47 // This test renders a page normally and then renders the same page in
48 // view-source mode. This is done since we had a problem at one point during 48 // view-source mode. This is done since we had a problem at one point during
49 // implementation of the view-source: prefix being consumed (removed from the 49 // implementation of the view-source: prefix being consumed (removed from the
50 // URL) if the URL was not changed (apart from adding the view-source prefix) 50 // URL) if the URL was not changed (apart from adding the view-source prefix)
51 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) { 51 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DoesBrowserConsumeViewSourcePrefix) {
52 ASSERT_TRUE(test_server()->Start()); 52 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
53 53
54 // First we navigate to google.html. 54 // First we navigate to google.html.
55 GURL url(test_server()->GetURL(kTestHtml)); 55 GURL url(embedded_test_server()->GetURL(kTestHtml));
56 ui_test_utils::NavigateToURL(browser(), url); 56 ui_test_utils::NavigateToURL(browser(), url);
57 57
58 // Then we navigate to the same url but with the "view-source:" prefix. 58 // Then we navigate to the same url but with the "view-source:" prefix.
59 GURL url_viewsource(content::kViewSourceScheme + std::string(":") + 59 GURL url_viewsource(content::kViewSourceScheme + std::string(":") +
60 url.spec()); 60 url.spec());
61 ui_test_utils::NavigateToURL(browser(), url_viewsource); 61 ui_test_utils::NavigateToURL(browser(), url_viewsource);
62 62
63 // The URL should still be prefixed with "view-source:". 63 // The URL should still be prefixed with "view-source:".
64 EXPECT_EQ(url_viewsource.spec(), 64 EXPECT_EQ(url_viewsource.spec(),
65 browser()->tab_strip_model()->GetActiveWebContents()-> 65 browser()->tab_strip_model()->GetActiveWebContents()->
66 GetURL().spec()); 66 GetURL().spec());
67 } 67 }
68 68
69 // Make sure that when looking at the actual page, we can select "View Source" 69 // Make sure that when looking at the actual page, we can select "View Source"
70 // from the menu. 70 // from the menu.
71 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) { 71 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuEnabledOnANormalPage) {
72 ASSERT_TRUE(test_server()->Start()); 72 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
73 73
74 GURL url(test_server()->GetURL(kTestHtml)); 74 GURL url(embedded_test_server()->GetURL(kTestHtml));
75 ui_test_utils::NavigateToURL(browser(), url); 75 ui_test_utils::NavigateToURL(browser(), url);
76 76
77 EXPECT_TRUE(chrome::CanViewSource(browser())); 77 EXPECT_TRUE(chrome::CanViewSource(browser()));
78 } 78 }
79 79
80 // For page that is media content, make sure that we cannot select "View Source" 80 // For page that is media content, make sure that we cannot select "View Source"
81 // See http://crbug.com/83714 81 // See http://crbug.com/83714
82 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuDisabledOnAMediaPage) { 82 IN_PROC_BROWSER_TEST_F(ViewSourceTest, ViewSourceInMenuDisabledOnAMediaPage) {
83 ASSERT_TRUE(test_server()->Start()); 83 ASSERT_TRUE(test_server()->Start());
84 84
85 GURL url(test_server()->GetURL(kTestMedia)); 85 GURL url(test_server()->GetURL(kTestMedia));
86 ui_test_utils::NavigateToURL(browser(), url); 86 ui_test_utils::NavigateToURL(browser(), url);
87 87
88 const char* mime_type = browser()->tab_strip_model()->GetActiveWebContents()-> 88 const char* mime_type = browser()->tab_strip_model()->GetActiveWebContents()->
89 GetContentsMimeType().c_str(); 89 GetContentsMimeType().c_str();
90 90
91 EXPECT_STREQ("audio/wav", mime_type); 91 EXPECT_STREQ("audio/wav", mime_type);
92 EXPECT_FALSE(chrome::CanViewSource(browser())); 92 EXPECT_FALSE(chrome::CanViewSource(browser()));
93 } 93 }
94 94
95 // 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"
96 // from the menu. 96 // from the menu.
97 IN_PROC_BROWSER_TEST_F(ViewSourceTest, 97 IN_PROC_BROWSER_TEST_F(ViewSourceTest,
98 ViewSourceInMenuDisabledWhileViewingSource) { 98 ViewSourceInMenuDisabledWhileViewingSource) {
99 ASSERT_TRUE(test_server()->Start()); 99 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
100 100
101 GURL url_viewsource(content::kViewSourceScheme + std::string(":") + 101 GURL url_viewsource(content::kViewSourceScheme + std::string(":") +
102 test_server()->GetURL(kTestHtml).spec()); 102 embedded_test_server()->GetURL(kTestHtml).spec());
103 ui_test_utils::NavigateToURL(browser(), url_viewsource); 103 ui_test_utils::NavigateToURL(browser(), url_viewsource);
104 104
105 EXPECT_FALSE(chrome::CanViewSource(browser())); 105 EXPECT_FALSE(chrome::CanViewSource(browser()));
106 } 106 }
107 107
108 // Tests that reload initiated by the script on the view-source page leaves 108 // Tests that reload initiated by the script on the view-source page leaves
109 // the page in view-source mode. 109 // the page in view-source mode.
110 // Times out on Mac, Windows, ChromeOS Linux: crbug.com/162080 110 // Times out on Mac, Windows, ChromeOS Linux: crbug.com/162080
111 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DISABLED_TestViewSourceReload) { 111 IN_PROC_BROWSER_TEST_F(ViewSourceTest, DISABLED_TestViewSourceReload) {
112 ASSERT_TRUE(test_server()->Start()); 112 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
113 113
114 GURL url_viewsource(content::kViewSourceScheme + std::string(":") + 114 GURL url_viewsource(content::kViewSourceScheme + std::string(":") +
115 test_server()->GetURL(kTestHtml).spec()); 115 embedded_test_server()->GetURL(kTestHtml).spec());
116 116
117 content::WindowedNotificationObserver observer( 117 content::WindowedNotificationObserver observer(
118 content::NOTIFICATION_LOAD_STOP, 118 content::NOTIFICATION_LOAD_STOP,
119 content::NotificationService::AllSources()); 119 content::NotificationService::AllSources());
120 ui_test_utils::NavigateToURL(browser(), url_viewsource); 120 ui_test_utils::NavigateToURL(browser(), url_viewsource);
121 observer.Wait(); 121 observer.Wait();
122 122
123 ASSERT_TRUE( 123 ASSERT_TRUE(
124 content::ExecuteScript(browser()->tab_strip_model()->GetWebContentsAt(0), 124 content::ExecuteScript(browser()->tab_strip_model()->GetWebContentsAt(0),
125 "window.location.reload();")); 125 "window.location.reload();"));
126 126
127 content::WindowedNotificationObserver observer2( 127 content::WindowedNotificationObserver observer2(
128 content::NOTIFICATION_LOAD_STOP, 128 content::NOTIFICATION_LOAD_STOP,
129 content::NotificationService::AllSources()); 129 content::NotificationService::AllSources());
130 observer2.Wait(); 130 observer2.Wait();
131 ASSERT_TRUE(browser()->tab_strip_model()->GetWebContentsAt(0)-> 131 ASSERT_TRUE(browser()->tab_strip_model()->GetWebContentsAt(0)->
132 GetController().GetActiveEntry()->IsViewSourceMode()); 132 GetController().GetActiveEntry()->IsViewSourceMode());
133 } 133 }
OLDNEW
« no previous file with comments | « chrome/browser/sessions/tab_restore_browsertest.cc ('k') | chrome/browser/task_manager/task_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698